--- psiconv/trunk/lib/psiconv/error.c 2000/12/13 16:17:54 62 +++ psiconv/trunk/lib/psiconv/error.c 2003/11/27 11:43:51 173 @@ -18,12 +18,18 @@ */ #include "config.h" +#include "compat.h" #include #include #include +#include -#include "data.h" #include "error.h" +#include "config.h" + +#ifdef DMALLOC +#include +#endif static void psiconv_default_error_handler(int kind, psiconv_u32 off, const char *message) @@ -31,14 +37,10 @@ fprintf(stderr,"%s\n",message); } -int psiconv_verbosity = PSICONV_VERB_WARN; - -psiconv_error_handler_t psiconv_error_handler = psiconv_default_error_handler; - - #define MAX_MESSAGE 160 -void psiconv_fatal(int level, psiconv_u32 off, const char *format,...) +void psiconv_fatal(psiconv_config config, int level, psiconv_u32 off, + const char *format,...) { char buffer[MAX_MESSAGE]; va_list ap; @@ -49,13 +51,17 @@ curlen = strlen(buffer); vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); - psiconv_error_handler(PSICONV_VERB_FATAL,off,buffer); + if (config->error_handler) + config->error_handler(PSICONV_VERB_FATAL,off,buffer); + else + psiconv_default_error_handler(PSICONV_VERB_FATAL,off,buffer); va_end(ap); exit(1); } -void psiconv_warn(int level, psiconv_u32 off, const char *format,...) +void psiconv_warn(psiconv_config config, int level, psiconv_u32 off, + const char *format,...) { char buffer[MAX_MESSAGE]; va_list ap; @@ -63,17 +69,21 @@ va_start(ap,format); - if (psiconv_verbosity >= PSICONV_VERB_WARN) { + if (config->verbosity >= PSICONV_VERB_WARN) { snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off); curlen = strlen(buffer); vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); - psiconv_error_handler(PSICONV_VERB_WARN,off,buffer); + if (config->error_handler) + config->error_handler(PSICONV_VERB_WARN,off,buffer); + else + psiconv_default_error_handler(PSICONV_VERB_WARN,off,buffer); } va_end(ap); } -void psiconv_progress(int level, psiconv_u32 off, const char *format,...) +void psiconv_progress(psiconv_config config,int level, psiconv_u32 off, + const char *format,...) { char buffer[MAX_MESSAGE]; va_list ap; @@ -81,7 +91,7 @@ int i; va_start(ap,format); - if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) { + if (config->verbosity >= PSICONV_VERB_PROGRESS) { snprintf(buffer,MAX_MESSAGE,"%08x ",off); curlen = strlen(buffer); @@ -96,13 +106,18 @@ vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); - psiconv_error_handler(PSICONV_VERB_PROGRESS,off,buffer); + if (config->error_handler) + config->error_handler(PSICONV_VERB_PROGRESS,off,buffer); + else + psiconv_default_error_handler(PSICONV_VERB_PROGRESS,off,buffer); } + va_end(ap); } -void psiconv_debug(int level, psiconv_u32 off, const char *format,...) +void psiconv_debug(psiconv_config config, int level, psiconv_u32 off, + const char *format,...) { char buffer[MAX_MESSAGE]; va_list ap; @@ -110,7 +125,7 @@ int i; va_start(ap,format); - if (psiconv_verbosity >= PSICONV_VERB_DEBUG) { + if (config->verbosity >= PSICONV_VERB_DEBUG) { snprintf(buffer,MAX_MESSAGE,"%08x ",off); curlen = strlen(buffer); @@ -125,7 +140,10 @@ vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); - psiconv_error_handler(PSICONV_VERB_DEBUG,off,buffer); + if (config->error_handler) + config->error_handler(PSICONV_VERB_DEBUG,off,buffer); + else + psiconv_default_error_handler(PSICONV_VERB_DEBUG,off,buffer); } va_end(ap); }