/[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 168
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; 40psiconv_error_handler_t psiconv_error_handler = psiconv_default_error_handler;
37 41
38 42
39#define MAX_MESSAGE 160 43#define MAX_MESSAGE 160
40 44
41void psiconv_fatal(int level, psiconv_u32 off, const char *format,...) 45void psiconv_fatal(psiconv_config config, int level, psiconv_u32 off,
46 const char *format,...)
42{ 47{
43 char buffer[MAX_MESSAGE]; 48 char buffer[MAX_MESSAGE];
44 va_list ap; 49 va_list ap;
45 size_t curlen; 50 size_t curlen;
46 51
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_warn(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
66 if (psiconv_verbosity >= PSICONV_VERB_WARN) { 72 if (config->verbosity >= PSICONV_VERB_WARN) {
67 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off); 73 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off);
68 curlen = strlen(buffer); 74 curlen = strlen(buffer);
69 75
70 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 76 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
71 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer); 77 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer);
72 } 78 }
73 va_end(ap); 79 va_end(ap);
74} 80}
75 81
76void psiconv_progress(int level, psiconv_u32 off, const char *format,...) 82void psiconv_progress(psiconv_config config,int level, psiconv_u32 off,
83 const char *format,...)
77{ 84{
78 char buffer[MAX_MESSAGE]; 85 char buffer[MAX_MESSAGE];
79 va_list ap; 86 va_list ap;
80 size_t curlen; 87 size_t curlen;
81 int i; 88 int i;
82 89
83 va_start(ap,format); 90 va_start(ap,format);
84 if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) { 91 if (config->verbosity >= PSICONV_VERB_PROGRESS) {
85 snprintf(buffer,MAX_MESSAGE,"%08x ",off); 92 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
86 curlen = strlen(buffer); 93 curlen = strlen(buffer);
87 94
88 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) 95 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
89 buffer[i+curlen] = '='; 96 buffer[i+curlen] = '=';
101 108
102 va_end(ap); 109 va_end(ap);
103} 110}
104 111
105 112
106void psiconv_debug(int level, psiconv_u32 off, const char *format,...) 113void psiconv_debug(psiconv_config config, int level, psiconv_u32 off,
114 const char *format,...)
107{ 115{
108 char buffer[MAX_MESSAGE]; 116 char buffer[MAX_MESSAGE];
109 va_list ap; 117 va_list ap;
110 size_t curlen; 118 size_t curlen;
111 int i; 119 int i;
112 120
113 va_start(ap,format); 121 va_start(ap,format);
114 if (psiconv_verbosity >= PSICONV_VERB_DEBUG) { 122 if (config->verbosity >= PSICONV_VERB_DEBUG) {
115 snprintf(buffer,MAX_MESSAGE,"%08x ",off); 123 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
116 curlen = strlen(buffer); 124 curlen = strlen(buffer);
117 125
118 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) 126 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
119 buffer[i+curlen] = '-'; 127 buffer[i+curlen] = '-';

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

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