Main Page   Modules   Compound List   File List   Compound Members   File Members   Related Pages  

wbxml_log.c

Go to the documentation of this file.
00001 /*
00002  * WBXML Lib, the WBXML Library.
00003  * Copyright (C) 2002-2003  Aymerick Jéhanne
00004  * 
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License (version 2.1) as published by the Free Software Foundation.
00008  * 
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  * LGPL v2.1: http://www.gnu.org/licenses/lgpl.txt
00019  *
00020  * Author Contact: libwbxml@jehanne.org
00021  * WBXML Lib home: http://libwbxml.jehanne.org
00022  */
00023  
00034 #include "wbxml.h"
00035 
00036 
00037 #if defined( WBXML_LIB_VERBOSE ) && !defined( WBXML_USE_LEAKTRACKER )
00038 
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 #include <string.h>
00042 #include <stdarg.h>
00043 
00044 
00046 #define WBXML_LOG_FORMAt_SIZE 1024
00047 
00048 
00049 /* Private Functions Prototypes */
00050 static void format_log_message(WB_TINY *buf, WB_UTINY type, const WB_TINY *fmt);
00051 static const WB_TINY *get_type(WB_UTINY type);
00052 
00053 
00054 /***************************************************
00055  *    Public Functions
00056  */
00057 
00058 WBXML_DECLARE(void) wbxml_log_debug(WB_UTINY type, const WB_TINY *fmt, ...)
00059 {
00060     char buf[WBXML_LOG_FORMAt_SIZE];
00061     va_list args;
00062     
00063     format_log_message(buf, type, fmt);
00064     
00065     va_start(args, fmt);
00066     vfprintf(stderr, buf, args);   
00067     va_end(args);
00068 }
00069 
00070 WBXML_DECLARE(void) wbxml_log_warning(WB_UTINY type, const WB_TINY *fmt, ...)
00071 {
00072     char buf[WBXML_LOG_FORMAt_SIZE];
00073     va_list args;
00074     
00075     format_log_message(buf, type, fmt);
00076     
00077     va_start(args, fmt);
00078     vfprintf(stderr, buf, args);   
00079     va_end(args);
00080 }
00081 
00082 WBXML_DECLARE(void) wbxml_log_error(WB_UTINY type, const WB_TINY *fmt, ...)
00083 {
00084     char buf[WBXML_LOG_FORMAt_SIZE];
00085     va_list args;
00086     
00087     format_log_message(buf, type, fmt);
00088     
00089     va_start(args, fmt);
00090     vfprintf(stderr, buf, args);   
00091     va_end(args);
00092 }
00093 
00094 
00095 /***************************************************
00096  *    Private Functions
00097  */
00098 
00105 static void format_log_message(WB_TINY *buf, WB_UTINY type, const WB_TINY *fmt)
00106 {
00107     WB_TINY *p, prefix[WBXML_LOG_FORMAt_SIZE];
00108     
00109     p = prefix;
00110     
00111     sprintf(p, "%s> ", get_type(type));
00112     
00113     if (WBXML_STRLEN(prefix) + WBXML_STRLEN(fmt) > WBXML_LOG_FORMAt_SIZE / 2) {
00114             sprintf(buf, "(LOG MESSAGE TOO LONG !)\n");
00115             return;
00116     }
00117     
00118         sprintf(buf, "%s%s\n", prefix, fmt);    
00119 }
00120 
00126 static const WB_TINY *get_type(WB_UTINY type) 
00127 {
00128     switch (type)
00129     {
00130         case WBXML_PARSER:
00131             return "WBXML Parser";
00132         
00133         case WBXML_ENCODER:
00134             return "WBXML Encoder";
00135 
00136         case WBXML_CONV:
00137             return "WBXML Converter";
00138         
00139         default:
00140             return "WBXML Unknown";
00141     }
00142 }
00143 
00144 #endif /* WBXML_LIB_VERBOSE */

Generated on Mon Nov 24 20:09:43 2003 for WBXML Library by doxygen1.3-rc1