/[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 142 Revision 184
20#include "config.h" 20#include "config.h"
21#include "compat.h" 21#include "compat.h"
22#include <stdarg.h> 22#include <stdarg.h>
23#include <stdio.h> 23#include <stdio.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <string.h>
25 26
26#include "error.h" 27#include "error.h"
28#include "config.h"
27 29
28#ifdef DMALLOC 30#ifdef DMALLOC
29#include <dmalloc.h> 31#include <dmalloc.h>
30#endif 32#endif
31 33
33 const char *message) 35 const char *message)
34{ 36{
35 fprintf(stderr,"%s\n",message); 37 fprintf(stderr,"%s\n",message);
36} 38}
37 39
38int psiconv_verbosity = PSICONV_VERB_WARN;
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(int level, psiconv_u32 off, const char *format,...) 42void psiconv_fatal(psiconv_config config, int level, psiconv_u32 off,
43 const char *format,...)
46{ 44{
47 char buffer[MAX_MESSAGE]; 45 char buffer[MAX_MESSAGE];
48 va_list ap; 46 va_list ap;
49 size_t curlen; 47 size_t curlen;
50 48
51 va_start(ap,format); 49 va_start(ap,format);
52 snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off); 50 snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off);
53 curlen = strlen(buffer); 51 curlen = strlen(buffer);
54 52
55 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
56 psiconv_error_handler(PSICONV_VERB_FATAL,off,buffer); 57 psiconv_default_error_handler(PSICONV_VERB_FATAL,off,buffer);
57 va_end(ap); 58 va_end(ap);
58 59
59 exit(1); 60 exit(1);
60} 61}
61 62
62void psiconv_warn(int level, psiconv_u32 off, const char *format,...) 63void psiconv_error(psiconv_config config, int level, psiconv_u32 off,
64 const char *format,...)
63{ 65{
64 char buffer[MAX_MESSAGE]; 66 char buffer[MAX_MESSAGE];
65 va_list ap; 67 va_list ap;
66 size_t curlen; 68 size_t curlen;
67 69
68 va_start(ap,format); 70 va_start(ap,format);
69 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);
83}
84
85void psiconv_warn(psiconv_config config, int level, psiconv_u32 off,
86 const char *format,...)
87{
88 char buffer[MAX_MESSAGE];
89 va_list ap;
90 size_t curlen;
91
92 va_start(ap,format);
93
70 if (psiconv_verbosity >= PSICONV_VERB_WARN) { 94 if (config->verbosity >= PSICONV_VERB_WARN) {
71 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off); 95 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off);
72 curlen = strlen(buffer); 96 curlen = strlen(buffer);
73 97
74 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
75 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer); 102 psiconv_default_error_handler(PSICONV_VERB_WARN,off,buffer);
76 } 103 }
77 va_end(ap); 104 va_end(ap);
78} 105}
79 106
80void psiconv_progress(int level, psiconv_u32 off, const char *format,...) 107void psiconv_progress(psiconv_config config,int level, psiconv_u32 off,
108 const char *format,...)
81{ 109{
82 char buffer[MAX_MESSAGE]; 110 char buffer[MAX_MESSAGE];
83 va_list ap; 111 va_list ap;
84 size_t curlen; 112 size_t curlen;
85 int i; 113 int i;
86 114
87 va_start(ap,format); 115 va_start(ap,format);
88 if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) { 116 if (config->verbosity >= PSICONV_VERB_PROGRESS) {
89 snprintf(buffer,MAX_MESSAGE,"%08x ",off); 117 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
90 curlen = strlen(buffer); 118 curlen = strlen(buffer);
91 119
92 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) 120 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
93 buffer[i+curlen] = '='; 121 buffer[i+curlen] = '=';
98 buffer[curlen+2] = '\0'; 126 buffer[curlen+2] = '\0';
99 curlen += 2; 127 curlen += 2;
100 128
101 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 129 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
102 130
131 if (config->error_handler)
132 config->error_handler(PSICONV_VERB_PROGRESS,off,buffer);
133 else
103 psiconv_error_handler(PSICONV_VERB_PROGRESS,off,buffer); 134 psiconv_default_error_handler(PSICONV_VERB_PROGRESS,off,buffer);
104 } 135 }
105 136
106 va_end(ap); 137 va_end(ap);
107} 138}
108 139
109 140
110void psiconv_debug(int level, psiconv_u32 off, const char *format,...) 141void psiconv_debug(psiconv_config config, int level, psiconv_u32 off,
142 const char *format,...)
111{ 143{
112 char buffer[MAX_MESSAGE]; 144 char buffer[MAX_MESSAGE];
113 va_list ap; 145 va_list ap;
114 size_t curlen; 146 size_t curlen;
115 int i; 147 int i;
116 148
117 va_start(ap,format); 149 va_start(ap,format);
118 if (psiconv_verbosity >= PSICONV_VERB_DEBUG) { 150 if (config->verbosity >= PSICONV_VERB_DEBUG) {
119 snprintf(buffer,MAX_MESSAGE,"%08x ",off); 151 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
120 curlen = strlen(buffer); 152 curlen = strlen(buffer);
121 153
122 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) 154 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
123 buffer[i+curlen] = '-'; 155 buffer[i+curlen] = '-';
128 buffer[curlen+2] = '\0'; 160 buffer[curlen+2] = '\0';
129 curlen += 2; 161 curlen += 2;
130 162
131 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 163 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
132 164
165 if (config->error_handler)
166 config->error_handler(PSICONV_VERB_DEBUG,off,buffer);
167 else
133 psiconv_error_handler(PSICONV_VERB_DEBUG,off,buffer); 168 psiconv_default_error_handler(PSICONV_VERB_DEBUG,off,buffer);
134 } 169 }
135 va_end(ap); 170 va_end(ap);
136} 171}

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

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