/[public]/psiconv/trunk/lib/psiconv/error.c
ViewVC logotype

Contents of /psiconv/trunk/lib/psiconv/error.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations)
Wed Dec 13 16:17:54 2000 UTC (19 years, 7 months ago) by frodo
File MIME type: text/plain
File size: 3402 byte(s)
(Frodo) Several important changes:
  * Created new misc.c, error.c and error.h files
  * Split parse_aux.c among them
  * Made list.c, data.c, error.c, checkuid.c and misc.c failsafe.

1 /*
2 error.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
4
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
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "data.h"
26 #include "error.h"
27
28 static void psiconv_default_error_handler(int kind, psiconv_u32 off,
29 const char *message)
30 {
31 fprintf(stderr,"%s\n",message);
32 }
33
34 int psiconv_verbosity = PSICONV_VERB_WARN;
35
36 psiconv_error_handler_t psiconv_error_handler = psiconv_default_error_handler;
37
38
39 #define MAX_MESSAGE 160
40
41 void psiconv_fatal(int level, psiconv_u32 off, const char *format,...)
42 {
43 char buffer[MAX_MESSAGE];
44 va_list ap;
45 size_t curlen;
46
47 va_start(ap,format);
48 snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off);
49 curlen = strlen(buffer);
50
51 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
52 psiconv_error_handler(PSICONV_VERB_FATAL,off,buffer);
53 va_end(ap);
54
55 exit(1);
56 }
57
58 void psiconv_warn(int level, psiconv_u32 off, const char *format,...)
59 {
60 char buffer[MAX_MESSAGE];
61 va_list ap;
62 size_t curlen;
63
64 va_start(ap,format);
65
66 if (psiconv_verbosity >= PSICONV_VERB_WARN) {
67 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off);
68 curlen = strlen(buffer);
69
70 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
71 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer);
72 }
73 va_end(ap);
74 }
75
76 void psiconv_progress(int level, psiconv_u32 off, const char *format,...)
77 {
78 char buffer[MAX_MESSAGE];
79 va_list ap;
80 size_t curlen;
81 int i;
82
83 va_start(ap,format);
84 if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) {
85 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
86 curlen = strlen(buffer);
87
88 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
89 buffer[i+curlen] = '=';
90 curlen += i;
91
92 buffer[curlen] = '>';
93 buffer[curlen+1] = ' ';
94 buffer[curlen+2] = '\0';
95 curlen += 2;
96
97 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
98
99 psiconv_error_handler(PSICONV_VERB_PROGRESS,off,buffer);
100 }
101 va_end(ap);
102 }
103
104
105 void psiconv_debug(int level, psiconv_u32 off, const char *format,...)
106 {
107 char buffer[MAX_MESSAGE];
108 va_list ap;
109 size_t curlen;
110 int i;
111
112 va_start(ap,format);
113 if (psiconv_verbosity >= PSICONV_VERB_DEBUG) {
114 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
115 curlen = strlen(buffer);
116
117 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
118 buffer[i+curlen] = '-';
119 curlen += i;
120
121 buffer[curlen] = '>';
122 buffer[curlen+1] = ' ';
123 buffer[curlen+2] = '\0';
124 curlen += 2;
125
126 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
127
128 psiconv_error_handler(PSICONV_VERB_DEBUG,off,buffer);
129 }
130 va_end(ap);
131 }

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