--- psiconv/trunk/lib/psiconv/error.c 2003/11/25 17:57:05 168 +++ psiconv/trunk/lib/psiconv/error.c 2004/02/22 22:24:39 217 @@ -1,6 +1,6 @@ /* error.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 1999, 2000 Frodo Looijaard + Copyright (c) 1999-2004 Frodo Looijaard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include #include "error.h" -#include "config.h" #ifdef DMALLOC #include @@ -37,10 +36,7 @@ fprintf(stderr,"%s\n",message); } -psiconv_error_handler_t psiconv_error_handler = psiconv_default_error_handler; - - -#define MAX_MESSAGE 160 +#define MAX_MESSAGE 1024 void psiconv_fatal(psiconv_config config, int level, psiconv_u32 off, const char *format,...) @@ -54,12 +50,37 @@ 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_error(psiconv_config config, int level, psiconv_u32 off, + const char *format,...) +{ + char buffer[MAX_MESSAGE]; + va_list ap; + size_t curlen; + + va_start(ap,format); + + if (config->verbosity >= PSICONV_VERB_ERROR) { + snprintf(buffer,MAX_MESSAGE,"ERROR (offset %08x): ",off); + curlen = strlen(buffer); + + vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); + if (config->error_handler) + config->error_handler(PSICONV_VERB_ERROR,off,buffer); + else + psiconv_default_error_handler(PSICONV_VERB_ERROR,off,buffer); + } + va_end(ap); +} + void psiconv_warn(psiconv_config config, int level, psiconv_u32 off, const char *format,...) { @@ -74,7 +95,10 @@ 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); } @@ -103,7 +127,10 @@ 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); @@ -134,7 +161,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); }