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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61 - (show annotations)
Wed Dec 13 00:42:04 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 3683 byte(s)
(Frodo) Error printing can now be captured by another program

1 /*
2 parse_aux.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 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 "parse.h"
26 #include "parse_routines.h"
27 #include "data.h"
28
29 static void psiconv_default_error_handler(int kind, psiconv_u32 off,
30 const char *message)
31 {
32 fprintf(stderr,"%s\n",message);
33 }
34
35 int psiconv_verbosity = PSICONV_VERB_WARN;
36
37 psiconv_error_handler_t psiconv_error_handler = psiconv_default_error_handler;
38
39
40 #define MAX_MESSAGE 160
41
42 void psiconv_fatal(int level, psiconv_u32 off, const char *format,...)
43 {
44 char buffer[MAX_MESSAGE];
45 va_list ap;
46 size_t curlen;
47
48 va_start(ap,format);
49 snprintf(buffer,MAX_MESSAGE,"Fatal error (offset %08x): ",off);
50 curlen = strlen(buffer);
51
52 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
53 psiconv_error_handler(PSICONV_VERB_FATAL,off,buffer);
54 va_end(ap);
55
56 exit(1);
57 }
58
59 void psiconv_warn(int level, psiconv_u32 off, const char *format,...)
60 {
61 char buffer[MAX_MESSAGE];
62 va_list ap;
63 size_t curlen;
64
65 va_start(ap,format);
66
67 if (psiconv_verbosity >= PSICONV_VERB_WARN) {
68 snprintf(buffer,MAX_MESSAGE,"WARNING (offset %08x): ",off);
69 curlen = strlen(buffer);
70
71 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
72 psiconv_error_handler(PSICONV_VERB_WARN,off,buffer);
73 }
74 va_end(ap);
75 }
76
77 void psiconv_progress(int level, psiconv_u32 off, const char *format,...)
78 {
79 char buffer[MAX_MESSAGE];
80 va_list ap;
81 size_t curlen;
82 int i;
83
84 va_start(ap,format);
85 if (psiconv_verbosity >= PSICONV_VERB_PROGRESS) {
86 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
87 curlen = strlen(buffer);
88
89 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
90 buffer[i+curlen] = '=';
91 curlen += i;
92
93 buffer[curlen] = '>';
94 buffer[curlen+1] = ' ';
95 buffer[curlen+2] = '\0';
96 curlen += 2;
97
98 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
99
100 psiconv_error_handler(PSICONV_VERB_PROGRESS,off,buffer);
101 }
102 va_end(ap);
103 }
104
105
106 void psiconv_debug(int level, psiconv_u32 off, const char *format,...)
107 {
108 char buffer[MAX_MESSAGE];
109 va_list ap;
110 size_t curlen;
111 int i;
112
113 va_start(ap,format);
114 if (psiconv_verbosity >= PSICONV_VERB_DEBUG) {
115 snprintf(buffer,MAX_MESSAGE,"%08x ",off);
116 curlen = strlen(buffer);
117
118 for (i = 0; (i < level) && (i+curlen+3 < MAX_MESSAGE); i++)
119 buffer[i+curlen] = '-';
120 curlen += i;
121
122 buffer[curlen] = '>';
123 buffer[curlen+1] = ' ';
124 buffer[curlen+2] = '\0';
125 curlen += 2;
126
127 vsnprintf(buffer+curlen,MAX_MESSAGE-curlen,format,ap);
128
129 psiconv_error_handler(PSICONV_VERB_DEBUG,off,buffer);
130 }
131 va_end(ap);
132 }
133
134 char *psiconv_make_printable(const char *s)
135 {
136 int i;
137 char *res = malloc(strlen(s) + 1);
138 for (i = 0; i < strlen(s); i ++)
139 if (s[i] < 0x20 || s[i] >= 0x7f)
140 res[i] = '.';
141 else
142 res[i] = s[i];
143 res[strlen(s)] = 0;
144 return res;
145 }
146
147

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