]>
Commit | Line | Data |
---|---|---|
fecd2382 RP |
1 | /* messages.c - error reporter - |
2 | Copyright (C) 1987, 1991 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
6 | GAS is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 1, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GAS is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GAS; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | /* $Id$ */ | |
21 | ||
22 | #include <stdio.h> /* define stderr */ | |
23 | #include <errno.h> | |
24 | ||
25 | #include "as.h" | |
26 | ||
27 | #ifndef NO_STDARG | |
28 | #include <stdarg.h> | |
29 | #else | |
30 | #ifndef NO_VARARGS | |
31 | #include <varargs.h> | |
32 | #endif /* NO_VARARGS */ | |
33 | #endif /* NO_STDARG */ | |
34 | ||
35 | /* | |
36 | * Despite the rest of the comments in this file, (FIXME-SOON), | |
37 | * here is the current scheme for error messages etc: | |
38 | * | |
39 | * as_fatal() is used when gas is quite confused and | |
40 | * continuing the assembly is pointless. In this case we | |
41 | * exit immediately with error status. | |
42 | * | |
43 | * as_bad() is used to mark errors that result in what we | |
44 | * presume to be a useless object file. Say, we ignored | |
45 | * something that might have been vital. If we see any of | |
46 | * these, assembly will continue to the end of the source, | |
47 | * no object file will be produced, and we will terminate | |
48 | * with error status. The new option, -Z, tells us to | |
49 | * produce an object file anyway but we still exit with | |
50 | * error status. The assumption here is that you don't want | |
51 | * this object file but we could be wrong. | |
52 | * | |
53 | * as_warn() is used when we have an error from which we | |
54 | * have a plausible error recovery. eg, masking the top | |
55 | * bits of a constant that is longer than will fit in the | |
56 | * destination. In this case we will continue to assemble | |
57 | * the source, although we may have made a bad assumption, | |
58 | * and we will produce an object file and return normal exit | |
59 | * status (ie, no error). The new option -X tells us to | |
60 | * treat all as_warn() errors as as_bad() errors. That is, | |
61 | * no object file will be produced and we will exit with | |
62 | * error status. The idea here is that we don't kill an | |
63 | * entire make because of an error that we knew how to | |
64 | * correct. On the other hand, sometimes you might want to | |
65 | * stop the make at these points. | |
66 | * | |
67 | * as_tsktsk() is used when we see a minor error for which | |
68 | * our error recovery action is almost certainly correct. | |
69 | * In this case, we print a message and then assembly | |
70 | * continues as though no error occurred. | |
71 | */ | |
72 | ||
73 | /* | |
74 | ERRORS | |
75 | ||
76 | JF: this is now bogus. We now print more standard error messages | |
77 | that try to look like everyone else's. | |
78 | ||
79 | We print the error message 1st, beginning in column 1. | |
80 | All ancillary info starts in column 2 on lines after the | |
81 | key error text. | |
82 | We try to print a location in logical and physical file | |
83 | just after the main error text. | |
84 | Caller then prints any appendices after that, begining all | |
85 | lines with at least 1 space. | |
86 | ||
87 | Optionally, we may die. | |
88 | There is no need for a trailing '\n' in your error text format | |
89 | because we supply one. | |
90 | ||
91 | as_warn(fmt,args) Like fprintf(stderr,fmt,args) but also call errwhere(). | |
92 | ||
93 | as_fatal(fmt,args) Like as_warn() but exit with a fatal status. | |
94 | ||
95 | */ | |
96 | ||
97 | static int warning_count = 0; /* Count of number of warnings issued */ | |
98 | ||
99 | int had_warnings() { | |
100 | return(warning_count); | |
101 | } /* had_err() */ | |
102 | ||
103 | /* Nonzero if we've hit a 'bad error', and should not write an obj file, | |
104 | and exit with a nonzero error code */ | |
105 | ||
106 | static int error_count = 0; | |
107 | ||
108 | int had_errors() { | |
109 | return(error_count); | |
110 | } /* had_errors() */ | |
111 | ||
112 | ||
113 | /* | |
114 | * a s _ p e r r o r | |
115 | * | |
116 | * Like perror(3), but with more info. | |
117 | */ | |
118 | void as_perror(gripe, filename) | |
119 | char *gripe; /* Unpunctuated error theme. */ | |
120 | char *filename; | |
121 | { | |
122 | extern int sys_nerr; | |
123 | extern char *sys_errlist[]; | |
124 | ||
125 | as_where(); | |
126 | fprintf(stderr,gripe,filename); | |
127 | ||
128 | if (errno > sys_nerr) | |
129 | fprintf(stderr, "Unknown error #%d.\n", errno); | |
130 | else | |
131 | fprintf(stderr, "%s.\n", sys_errlist[errno]); | |
132 | errno = 0; /* After reporting, clear it. */ | |
133 | } /* as_perror() */ | |
134 | ||
135 | /* | |
136 | * a s _ t s k t s k () | |
137 | * | |
138 | * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning, and locate warning | |
139 | * in input file(s). | |
140 | * Please only use this for when we have some recovery action. | |
141 | * Please explain in string (which may have '\n's) what recovery was done. | |
142 | */ | |
143 | ||
144 | #ifndef NO_STDARG | |
145 | void as_tsktsk(Format) | |
146 | const char *Format; | |
147 | { | |
148 | va_list args; | |
149 | ||
150 | as_where(); | |
151 | va_start(args, Format); | |
152 | vfprintf(stderr, Format, args); | |
153 | va_end(args); | |
154 | (void) putc('\n', stderr); | |
155 | } /* as_tsktsk() */ | |
156 | #else | |
157 | #ifndef NO_VARARGS | |
158 | void as_tsktsk(Format,va_alist) | |
159 | char *Format; | |
160 | va_dcl | |
161 | { | |
162 | va_list args; | |
163 | ||
164 | as_where(); | |
165 | va_start(args); | |
166 | vfprintf(stderr, Format, args); | |
167 | va_end(args); | |
168 | (void) putc('\n', stderr); | |
169 | } /* as_tsktsk() */ | |
170 | #else | |
171 | /*VARARGS1 */ | |
172 | as_tsktsk(Format,args) | |
173 | char *Format; | |
174 | { | |
175 | as_where(); | |
176 | _doprnt (Format, &args, stderr); | |
177 | (void)putc ('\n', stderr); | |
178 | /* as_where(); */ | |
179 | } /* as_tsktsk */ | |
180 | #endif /* not NO_VARARGS */ | |
181 | #endif /* not NO_STDARG */ | |
182 | ||
183 | #ifdef DONTDEF | |
184 | void as_tsktsk(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an) | |
185 | char *format; | |
186 | { | |
187 | as_where(); | |
188 | fprintf(stderr,Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an); | |
189 | (void)putc('\n',stderr); | |
190 | } /* as_tsktsk() */ | |
191 | #endif | |
192 | /* | |
193 | * a s _ w a r n () | |
194 | * | |
195 | * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning, and locate warning | |
196 | * in input file(s). | |
197 | * Please only use this for when we have some recovery action. | |
198 | * Please explain in string (which may have '\n's) what recovery was done. | |
199 | */ | |
200 | ||
201 | #ifndef NO_STDARG | |
202 | void as_warn(Format) | |
203 | const char *Format; | |
204 | { | |
205 | va_list args; | |
206 | ||
207 | if(!flagseen['W']) { | |
208 | ++warning_count; | |
209 | as_where(); | |
210 | va_start(args, Format); | |
211 | vfprintf(stderr, Format, args); | |
212 | va_end(args); | |
213 | (void) putc('\n', stderr); | |
214 | } | |
215 | } /* as_warn() */ | |
216 | #else | |
217 | #ifndef NO_VARARGS | |
218 | void as_warn(Format,va_alist) | |
219 | char *Format; | |
220 | va_dcl | |
221 | { | |
222 | va_list args; | |
223 | ||
224 | if(!flagseen['W']) { | |
225 | ++warning_count; | |
226 | as_where(); | |
227 | va_start(args); | |
228 | vfprintf(stderr, Format, args); | |
229 | va_end(args); | |
230 | (void) putc('\n', stderr); | |
231 | } | |
232 | } /* as_warn() */ | |
233 | #else | |
234 | /*VARARGS1 */ | |
235 | as_warn(Format,args) | |
236 | char *Format; | |
237 | { | |
238 | /* -W supresses warning messages. */ | |
239 | if (! flagseen ['W']) { | |
240 | ++warning_count; | |
241 | as_where(); | |
242 | _doprnt (Format, &args, stderr); | |
243 | (void)putc ('\n', stderr); | |
244 | /* as_where(); */ | |
245 | } | |
246 | } /* as_warn() */ | |
247 | #endif /* not NO_VARARGS */ | |
248 | #endif /* not NO_STDARG */ | |
249 | ||
250 | #ifdef DONTDEF | |
251 | void as_warn(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an) | |
252 | char *format; | |
253 | { | |
254 | if(!flagseen['W']) { | |
255 | ++warning_count; | |
256 | as_where(); | |
257 | fprintf(stderr,Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an); | |
258 | (void)putc('\n',stderr); | |
259 | } | |
260 | } /* as_warn() */ | |
261 | #endif | |
262 | /* | |
263 | * a s _ b a d () | |
264 | * | |
265 | * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning, | |
266 | * and locate warning in input file(s). | |
267 | * Please us when there is no recovery, but we want to continue processing | |
268 | * but not produce an object file. | |
269 | * Please explain in string (which may have '\n's) what recovery was done. | |
270 | */ | |
271 | ||
272 | #ifndef NO_STDARG | |
273 | void as_bad(Format) | |
274 | const char *Format; | |
275 | { | |
276 | va_list args; | |
277 | ||
278 | ++error_count; | |
279 | as_where(); | |
280 | va_start(args, Format); | |
281 | vfprintf(stderr, Format, args); | |
282 | va_end(args); | |
283 | (void) putc('\n', stderr); | |
284 | } /* as_bad() */ | |
285 | #else | |
286 | #ifndef NO_VARARGS | |
287 | void as_bad(Format,va_alist) | |
288 | char *Format; | |
289 | va_dcl | |
290 | { | |
291 | va_list args; | |
292 | ||
293 | ++error_count; | |
294 | as_where(); | |
295 | va_start(args); | |
296 | vfprintf(stderr, Format, args); | |
297 | va_end(args); | |
298 | (void) putc('\n', stderr); | |
299 | } /* as_bad() */ | |
300 | #else | |
301 | /*VARARGS1 */ | |
302 | as_bad(Format,args) | |
303 | char *Format; | |
304 | { | |
305 | ++error_count; | |
306 | as_where(); | |
307 | _doprnt (Format, &args, stderr); | |
308 | (void)putc ('\n', stderr); | |
309 | /* as_where(); */ | |
310 | } /* as_bad() */ | |
311 | #endif /* not NO_VARARGS */ | |
312 | #endif /* not NO_STDARG */ | |
313 | ||
314 | #ifdef DONTDEF | |
315 | void as_bad(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an) | |
316 | char *format; | |
317 | { | |
318 | ++error_count; | |
319 | as_where(); | |
320 | fprintf(stderr,Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an); | |
321 | (void)putc('\n',stderr); | |
322 | } /* as_bad() */ | |
323 | #endif | |
324 | ||
325 | /* | |
326 | * a s _ f a t a l () | |
327 | * | |
328 | * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a fatal | |
329 | * message, and locate stdsource in input file(s). | |
330 | * Please only use this for when we DON'T have some recovery action. | |
331 | * It exit()s with a warning status. | |
332 | */ | |
333 | ||
334 | #ifndef NO_STDARG | |
335 | void as_fatal(Format) | |
336 | const char *Format; | |
337 | { | |
338 | va_list args; | |
339 | ||
340 | as_where(); | |
341 | va_start(args, Format); | |
342 | fprintf (stderr, "FATAL:"); | |
343 | vfprintf(stderr, Format, args); | |
344 | (void) putc('\n', stderr); | |
345 | va_end(args); | |
346 | exit(42); | |
347 | } /* as_fatal() */ | |
348 | #else | |
349 | #ifndef NO_VARARGS | |
350 | void as_fatal(Format,va_alist) | |
351 | char *Format; | |
352 | va_dcl | |
353 | { | |
354 | va_list args; | |
355 | ||
356 | as_where(); | |
357 | va_start(args); | |
358 | fprintf (stderr, "FATAL:"); | |
359 | vfprintf(stderr, Format, args); | |
360 | (void) putc('\n', stderr); | |
361 | va_end(args); | |
362 | exit(42); | |
363 | } /* as_fatal() */ | |
364 | #else | |
365 | /*VARARGS1 */ | |
366 | as_fatal(Format, args) | |
367 | char *Format; | |
368 | { | |
369 | as_where(); | |
370 | fprintf(stderr,"FATAL:"); | |
371 | _doprnt (Format, &args, stderr); | |
372 | (void)putc ('\n', stderr); | |
373 | /* as_where(); */ | |
374 | exit(42); /* What is a good exit status? */ | |
375 | } /* as_fatal() */ | |
376 | #endif /* not NO_VARARGS */ | |
377 | #endif /* not NO_STDARG */ | |
378 | ||
379 | #ifdef DONTDEF | |
380 | void as_fatal(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an) | |
381 | char *Format; | |
382 | { | |
383 | as_where(); | |
384 | fprintf (stderr, "FATAL:"); | |
385 | fprintf(stderr, Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an); | |
386 | (void) putc('\n', stderr); | |
387 | exit(42); | |
388 | } /* as_fatal() */ | |
389 | #endif | |
390 | ||
391 | /* end: messages.c */ |