/[public]/psiconv/trunk/lib/psiconv/error.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/error.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 168 Revision 184
35 const char *message) 35 const char *message)
36{ 36{
37 fprintf(stderr,"%s\n",message); 37 fprintf(stderr,"%s\n",message);
38} 38}
39 39
40psiconv_error_handler_t psiconv_error_handler = psiconv_default_error_handler;
41
42
43#define MAX_MESSAGE 160 40#define MAX_MESSAGE 160
44 41
45void psiconv_fatal(psiconv_config config, int level, psiconv_u32 off, 42void psiconv_fatal(psiconv_config config, int level, psiconv_u32 off,
46 const char *format,...) 43 const char *format,...)
47{ 44{
52 va_start(ap,format); 49 va_start(ap,format);
53 snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off); 50 snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off);
54 curlen = strlen(buffer); 51 curlen = strlen(buffer);
55 52
56 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 53 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
54 if (config->error_handler)
55 config->error_handler(PSICONV_VERB_FATAL,off,buffer);
56 else
57 psiconv_error_handler(PSICONV_VERB_FATAL,off,buffer); 57 psiconv_default_error_handler(PSICONV_VERB_FATAL,off,buffer);
58 va_end(ap); 58 va_end(ap);
59 59
60 exit(1); 60 exit(1);
61}
62
63void psiconv_error(psiconv_config config, int level, psiconv_u32 off,
64 const char *format,...)
65{
66 char buffer[MAX_MESSAGE];
67 va_list ap;
68 size_t curlen;
69
70 va_start(ap,format);
71
72 if (config->verbosity >= PSICONV_VERB_ERROR) {
73 snprintf(buffer,MAX_MESSAGE,"ERROR (offset %08x): ",off);
74 curlen = strlen(buffer);
75
76 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
77 if (config->error_handler)
78 config->error_handler(PSICONV_VERB_ERROR,off,buffer);
79 else
80 psiconv_default_error_handler(PSICONV_VERB_ERROR,off,buffer);
81 }
82 va_end(ap);
61} 83}
62 84
63void psiconv_warn(psiconv_config config, int level, psiconv_u32 off, 85void psiconv_warn(psiconv_config config, int level, psiconv_u32 off,
64 const char *format,...) 86 const char *format,...)
65{ 87{
72 if (config->verbosity >= PSICONV_VERB_WARN) { 94 if (config->verbosity >= PSICONV_VERB_WARN) {
73 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off); 95 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off);
74 curlen = strlen(buffer); 96 curlen = strlen(buffer);
75 97
76 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 98 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
99 if (config->error_handler)
100 config->error_handler(PSICONV_VERB_WARN,off,buffer);
101 else
77 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer); 102 psiconv_default_error_handler(PSICONV_VERB_WARN,off,buffer);
78 } 103 }
79 va_end(ap); 104 va_end(ap);
80} 105}
81 106
82void psiconv_progress(psiconv_config config,int level, psiconv_u32 off, 107void psiconv_progress(psiconv_config config,int level, psiconv_u32 off,
101 buffer[curlen+2] = '\0'; 126 buffer[curlen+2] = '\0';
102 curlen += 2; 127 curlen += 2;
103 128
104 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 129 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
105 130
131 if (config->error_handler)
132 config->error_handler(PSICONV_VERB_PROGRESS,off,buffer);
133 else
106 psiconv_error_handler(PSICONV_VERB_PROGRESS,off,buffer); 134 psiconv_default_error_handler(PSICONV_VERB_PROGRESS,off,buffer);
107 } 135 }
108 136
109 va_end(ap); 137 va_end(ap);
110} 138}
111 139
132 buffer[curlen+2] = '\0'; 160 buffer[curlen+2] = '\0';
133 curlen += 2; 161 curlen += 2;
134 162
135 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 163 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
136 164
165 if (config->error_handler)
166 config->error_handler(PSICONV_VERB_DEBUG,off,buffer);
167 else
137 psiconv_error_handler(PSICONV_VERB_DEBUG,off,buffer); 168 psiconv_default_error_handler(PSICONV_VERB_DEBUG,off,buffer);
138 } 169 }
139 va_end(ap); 170 va_end(ap);
140} 171}

Legend:
Removed from v.168  
changed lines
  Added in v.184

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26