--- psiconv/trunk/lib/psiconv/error.c 2002/01/29 18:38:38 142 +++ psiconv/trunk/lib/psiconv/error.c 2003/11/27 11:43:51 173 @@ -22,8 +22,10 @@ #include #include #include +#include #include "error.h" +#include "config.h" #ifdef DMALLOC #include @@ -35,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; @@ -53,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; @@ -67,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; @@ -85,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); @@ -100,14 +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; @@ -115,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); @@ -130,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); }