/[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 167 Revision 168
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; 40psiconv_error_handler_t psiconv_error_handler = psiconv_default_error_handler;
41 41
42 42
43#define MAX_MESSAGE 160 43#define MAX_MESSAGE 160
44 44
45void 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,...)
46{ 47{
47 char buffer[MAX_MESSAGE]; 48 char buffer[MAX_MESSAGE];
48 va_list ap; 49 va_list ap;
49 size_t curlen; 50 size_t curlen;
50 51
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_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);
75 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer); 77 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer);
76 } 78 }
77 va_end(ap); 79 va_end(ap);
78} 80}
79 81
80void 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,...)
81{ 84{
82 char buffer[MAX_MESSAGE]; 85 char buffer[MAX_MESSAGE];
83 va_list ap; 86 va_list ap;
84 size_t curlen; 87 size_t curlen;
85 int i; 88 int i;
86 89
87 va_start(ap,format); 90 va_start(ap,format);
88 if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) { 91 if (config->verbosity >= PSICONV_VERB_PROGRESS) {
89 snprintf(buffer,MAX_MESSAGE,"%08x ",off); 92 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
90 curlen = strlen(buffer); 93 curlen = strlen(buffer);
91 94
92 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) 95 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
93 buffer[i+curlen] = '='; 96 buffer[i+curlen] = '=';
105 108
106 va_end(ap); 109 va_end(ap);
107} 110}
108 111
109 112
110void 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,...)
111{ 115{
112 char buffer[MAX_MESSAGE]; 116 char buffer[MAX_MESSAGE];
113 va_list ap; 117 va_list ap;
114 size_t curlen; 118 size_t curlen;
115 int i; 119 int i;
116 120
117 va_start(ap,format); 121 va_start(ap,format);
118 if (psiconv_verbosity >= PSICONV_VERB_DEBUG) { 122 if (config->verbosity >= PSICONV_VERB_DEBUG) {
119 snprintf(buffer,MAX_MESSAGE,"%08x ",off); 123 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
120 curlen = strlen(buffer); 124 curlen = strlen(buffer);
121 125
122 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) 126 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
123 buffer[i+curlen] = '-'; 127 buffer[i+curlen] = '-';

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

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