/[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 196
1/* 1/*
2 error.c - Part of psiconv, a PSION 5 file formats converter 2 error.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
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"
27 28
28#ifdef DMALLOC 29#ifdef DMALLOC
29#include <dmalloc.h> 30#include <dmalloc.h>
33 const char *message) 34 const char *message)
34{ 35{
35 fprintf(stderr,"%s\n",message); 36 fprintf(stderr,"%s\n",message);
36} 37}
37 38
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 39#define MAX_MESSAGE 160
44 40
45void psiconv_fatal(int level, psiconv_u32 off, const char *format,...) 41void psiconv_fatal(psiconv_config config, int level, psiconv_u32 off,
42 const char *format,...)
46{ 43{
47 char buffer[MAX_MESSAGE]; 44 char buffer[MAX_MESSAGE];
48 va_list ap; 45 va_list ap;
49 size_t curlen; 46 size_t curlen;
50 47
51 va_start(ap,format); 48 va_start(ap,format);
52 snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off); 49 snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off);
53 curlen = strlen(buffer); 50 curlen = strlen(buffer);
54 51
55 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 52 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
53 if (config->error_handler)
54 config->error_handler(PSICONV_VERB_FATAL,off,buffer);
55 else
56 psiconv_error_handler(PSICONV_VERB_FATAL,off,buffer); 56 psiconv_default_error_handler(PSICONV_VERB_FATAL,off,buffer);
57 va_end(ap); 57 va_end(ap);
58 58
59 exit(1); 59 exit(1);
60} 60}
61 61
62void psiconv_warn(int level, psiconv_u32 off, const char *format,...) 62void psiconv_error(psiconv_config config, int level, psiconv_u32 off,
63 const char *format,...)
63{ 64{
64 char buffer[MAX_MESSAGE]; 65 char buffer[MAX_MESSAGE];
65 va_list ap; 66 va_list ap;
66 size_t curlen; 67 size_t curlen;
67 68
68 va_start(ap,format); 69 va_start(ap,format);
69 70
71 if (config->verbosity >= PSICONV_VERB_ERROR) {
72 snprintf(buffer,MAX_MESSAGE,"ERROR (offset %08x): ",off);
73 curlen = strlen(buffer);
74
75 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
76 if (config->error_handler)
77 config->error_handler(PSICONV_VERB_ERROR,off,buffer);
78 else
79 psiconv_default_error_handler(PSICONV_VERB_ERROR,off,buffer);
80 }
81 va_end(ap);
82}
83
84void psiconv_warn(psiconv_config config, int level, psiconv_u32 off,
85 const char *format,...)
86{
87 char buffer[MAX_MESSAGE];
88 va_list ap;
89 size_t curlen;
90
91 va_start(ap,format);
92
70 if (psiconv_verbosity >= PSICONV_VERB_WARN) { 93 if (config->verbosity >= PSICONV_VERB_WARN) {
71 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off); 94 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off);
72 curlen = strlen(buffer); 95 curlen = strlen(buffer);
73 96
74 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 97 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
98 if (config->error_handler)
99 config->error_handler(PSICONV_VERB_WARN,off,buffer);
100 else
75 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer); 101 psiconv_default_error_handler(PSICONV_VERB_WARN,off,buffer);
76 } 102 }
77 va_end(ap); 103 va_end(ap);
78} 104}
79 105
80void psiconv_progress(int level, psiconv_u32 off, const char *format,...) 106void psiconv_progress(psiconv_config config,int level, psiconv_u32 off,
107 const char *format,...)
81{ 108{
82 char buffer[MAX_MESSAGE]; 109 char buffer[MAX_MESSAGE];
83 va_list ap; 110 va_list ap;
84 size_t curlen; 111 size_t curlen;
85 int i; 112 int i;
86 113
87 va_start(ap,format); 114 va_start(ap,format);
88 if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) { 115 if (config->verbosity >= PSICONV_VERB_PROGRESS) {
89 snprintf(buffer,MAX_MESSAGE,"%08x ",off); 116 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
90 curlen = strlen(buffer); 117 curlen = strlen(buffer);
91 118
92 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) 119 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
93 buffer[i+curlen] = '='; 120 buffer[i+curlen] = '=';
98 buffer[curlen+2] = '\0'; 125 buffer[curlen+2] = '\0';
99 curlen += 2; 126 curlen += 2;
100 127
101 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 128 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
102 129
130 if (config->error_handler)
131 config->error_handler(PSICONV_VERB_PROGRESS,off,buffer);
132 else
103 psiconv_error_handler(PSICONV_VERB_PROGRESS,off,buffer); 133 psiconv_default_error_handler(PSICONV_VERB_PROGRESS,off,buffer);
104 } 134 }
105 135
106 va_end(ap); 136 va_end(ap);
107} 137}
108 138
109 139
110void psiconv_debug(int level, psiconv_u32 off, const char *format,...) 140void psiconv_debug(psiconv_config config, int level, psiconv_u32 off,
141 const char *format,...)
111{ 142{
112 char buffer[MAX_MESSAGE]; 143 char buffer[MAX_MESSAGE];
113 va_list ap; 144 va_list ap;
114 size_t curlen; 145 size_t curlen;
115 int i; 146 int i;
116 147
117 va_start(ap,format); 148 va_start(ap,format);
118 if (psiconv_verbosity >= PSICONV_VERB_DEBUG) { 149 if (config->verbosity >= PSICONV_VERB_DEBUG) {
119 snprintf(buffer,MAX_MESSAGE,"%08x ",off); 150 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
120 curlen = strlen(buffer); 151 curlen = strlen(buffer);
121 152
122 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++) 153 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
123 buffer[i+curlen] = '-'; 154 buffer[i+curlen] = '-';
128 buffer[curlen+2] = '\0'; 159 buffer[curlen+2] = '\0';
129 curlen += 2; 160 curlen += 2;
130 161
131 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap); 162 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
132 163
164 if (config->error_handler)
165 config->error_handler(PSICONV_VERB_DEBUG,off,buffer);
166 else
133 psiconv_error_handler(PSICONV_VERB_DEBUG,off,buffer); 167 psiconv_default_error_handler(PSICONV_VERB_DEBUG,off,buffer);
134 } 168 }
135 va_end(ap); 169 va_end(ap);
136} 170}

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

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