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

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

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