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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 142 - (hide annotations)
Tue Jan 29 18:38:38 2002 UTC (22 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 3449 byte(s)
(Frodo) DMALLOC support

1 frodo 62 /*
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 frodo 71 #include "compat.h"
22 frodo 62 #include <stdarg.h>
23     #include <stdio.h>
24     #include <stdlib.h>
25    
26     #include "error.h"
27    
28 frodo 142 #ifdef DMALLOC
29     #include <dmalloc.h>
30     #endif
31    
32 frodo 62 static void psiconv_default_error_handler(int kind, psiconv_u32 off,
33     const char *message)
34     {
35     fprintf(stderr,"%s\n",message);
36     }
37    
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
44    
45     void psiconv_fatal(int level, psiconv_u32 off, const char *format,...)
46     {
47     char buffer[MAX_MESSAGE];
48     va_list ap;
49     size_t curlen;
50    
51     va_start(ap,format);
52     snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off);
53     curlen = strlen(buffer);
54    
55     vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
56     psiconv_error_handler(PSICONV_VERB_FATAL,off,buffer);
57     va_end(ap);
58    
59     exit(1);
60     }
61    
62     void psiconv_warn(int level, psiconv_u32 off, const char *format,...)
63     {
64     char buffer[MAX_MESSAGE];
65     va_list ap;
66     size_t curlen;
67    
68     va_start(ap,format);
69    
70     if (psiconv_verbosity >= PSICONV_VERB_WARN) {
71     snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off);
72     curlen = strlen(buffer);
73    
74     vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
75     psiconv_error_handler(PSICONV_VERB_WARN,off,buffer);
76     }
77     va_end(ap);
78     }
79    
80     void psiconv_progress(int level, psiconv_u32 off, const char *format,...)
81     {
82     char buffer[MAX_MESSAGE];
83     va_list ap;
84     size_t curlen;
85     int i;
86    
87     va_start(ap,format);
88     if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) {
89     snprintf(buffer,MAX_MESSAGE,"%08x ",off);
90     curlen = strlen(buffer);
91    
92     for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
93     buffer[i+curlen] = '=';
94     curlen += i;
95    
96     buffer[curlen] = '>';
97     buffer[curlen+1] = ' ';
98     buffer[curlen+2] = '\0';
99     curlen += 2;
100    
101     vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
102    
103     psiconv_error_handler(PSICONV_VERB_PROGRESS,off,buffer);
104     }
105 frodo 65
106 frodo 62 va_end(ap);
107     }
108    
109    
110     void psiconv_debug(int level, psiconv_u32 off, const char *format,...)
111     {
112     char buffer[MAX_MESSAGE];
113     va_list ap;
114     size_t curlen;
115     int i;
116    
117     va_start(ap,format);
118     if (psiconv_verbosity >= PSICONV_VERB_DEBUG) {
119     snprintf(buffer,MAX_MESSAGE,"%08x ",off);
120     curlen = strlen(buffer);
121    
122     for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
123     buffer[i+curlen] = '-';
124     curlen += i;
125    
126     buffer[curlen] = '>';
127     buffer[curlen+1] = ' ';
128     buffer[curlen+2] = '\0';
129     curlen += 2;
130    
131     vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
132    
133     psiconv_error_handler(PSICONV_VERB_DEBUG,off,buffer);
134     }
135     va_end(ap);
136     }

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