00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
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
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