… | |
… | |
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 | |
38 | int psiconv_verbosity = PSICONV_VERB_WARN; |
|
|
39 | |
|
|
40 | psiconv_error_handler_t psiconv_error_handler = psiconv_default_error_handler; |
|
|
41 | |
|
|
42 | |
|
|
43 | #define MAX_MESSAGE 160 |
40 | #define MAX_MESSAGE 160 |
44 | |
41 | |
45 | void psiconv_fatal(int level, psiconv_u32 off, const char *format,...) |
42 | void 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 | |
62 | void psiconv_warn(int level, psiconv_u32 off, const char *format,...) |
63 | void psiconv_warn(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 | |
70 | if (psiconv_verbosity >= PSICONV_VERB_WARN) { |
72 | if (config->verbosity >= PSICONV_VERB_WARN) { |
71 | snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off); |
73 | snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off); |
72 | curlen = strlen(buffer); |
74 | curlen = strlen(buffer); |
73 | |
75 | |
74 | vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); |
76 | vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); |
|
|
77 | if (config->error_handler) |
|
|
78 | config->error_handler(PSICONV_VERB_WARN,off,buffer); |
|
|
79 | else |
75 | psiconv_error_handler(PSICONV_VERB_WARN,off,buffer); |
80 | psiconv_default_error_handler(PSICONV_VERB_WARN,off,buffer); |
76 | } |
81 | } |
77 | va_end(ap); |
82 | va_end(ap); |
78 | } |
83 | } |
79 | |
84 | |
80 | void psiconv_progress(int level, psiconv_u32 off, const char *format,...) |
85 | void psiconv_progress(psiconv_config config,int level, psiconv_u32 off, |
|
|
86 | const char *format,...) |
81 | { |
87 | { |
82 | char buffer[MAX_MESSAGE]; |
88 | char buffer[MAX_MESSAGE]; |
83 | va_list ap; |
89 | va_list ap; |
84 | size_t curlen; |
90 | size_t curlen; |
85 | int i; |
91 | int i; |
86 | |
92 | |
87 | va_start(ap,format); |
93 | va_start(ap,format); |
88 | if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) { |
94 | if (config->verbosity >= PSICONV_VERB_PROGRESS) { |
89 | snprintf(buffer,MAX_MESSAGE,"%08x ",off); |
95 | snprintf(buffer,MAX_MESSAGE,"%08x ",off); |
90 | curlen = strlen(buffer); |
96 | curlen = strlen(buffer); |
91 | |
97 | |
92 | for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) |
98 | for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) |
93 | buffer[i+curlen] = '='; |
99 | buffer[i+curlen] = '='; |
… | |
… | |
98 | buffer[curlen+2] = '\0'; |
104 | buffer[curlen+2] = '\0'; |
99 | curlen += 2; |
105 | curlen += 2; |
100 | |
106 | |
101 | vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); |
107 | vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); |
102 | |
108 | |
|
|
109 | if (config->error_handler) |
|
|
110 | config->error_handler(PSICONV_VERB_PROGRESS,off,buffer); |
|
|
111 | else |
103 | psiconv_error_handler(PSICONV_VERB_PROGRESS,off,buffer); |
112 | psiconv_default_error_handler(PSICONV_VERB_PROGRESS,off,buffer); |
104 | } |
113 | } |
105 | |
114 | |
106 | va_end(ap); |
115 | va_end(ap); |
107 | } |
116 | } |
108 | |
117 | |
109 | |
118 | |
110 | void psiconv_debug(int level, psiconv_u32 off, const char *format,...) |
119 | void psiconv_debug(psiconv_config config, int level, psiconv_u32 off, |
|
|
120 | const char *format,...) |
111 | { |
121 | { |
112 | char buffer[MAX_MESSAGE]; |
122 | char buffer[MAX_MESSAGE]; |
113 | va_list ap; |
123 | va_list ap; |
114 | size_t curlen; |
124 | size_t curlen; |
115 | int i; |
125 | int i; |
116 | |
126 | |
117 | va_start(ap,format); |
127 | va_start(ap,format); |
118 | if (psiconv_verbosity >= PSICONV_VERB_DEBUG) { |
128 | if (config->verbosity >= PSICONV_VERB_DEBUG) { |
119 | snprintf(buffer,MAX_MESSAGE,"%08x ",off); |
129 | snprintf(buffer,MAX_MESSAGE,"%08x ",off); |
120 | curlen = strlen(buffer); |
130 | curlen = strlen(buffer); |
121 | |
131 | |
122 | for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) |
132 | for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) |
123 | buffer[i+curlen] = '-'; |
133 | buffer[i+curlen] = '-'; |
… | |
… | |
128 | buffer[curlen+2] = '\0'; |
138 | buffer[curlen+2] = '\0'; |
129 | curlen += 2; |
139 | curlen += 2; |
130 | |
140 | |
131 | vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); |
141 | vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); |
132 | |
142 | |
|
|
143 | if (config->error_handler) |
|
|
144 | config->error_handler(PSICONV_VERB_DEBUG,off,buffer); |
|
|
145 | else |
133 | psiconv_error_handler(PSICONV_VERB_DEBUG,off,buffer); |
146 | psiconv_default_error_handler(PSICONV_VERB_DEBUG,off,buffer); |
134 | } |
147 | } |
135 | va_end(ap); |
148 | va_end(ap); |
136 | } |
149 | } |