White space and comments only. The devo tree prior to this delta is
[external/binutils.git] / gas / messages.c
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 2, 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         char buffer[200];
207         
208         if(!flagseen['W']) {
209                 ++warning_count;
210                 as_where();
211                 va_start(args, Format);
212                 fprintf(stderr,"Warning: ");
213                 vsprintf(buffer, Format, args);
214                 fprintf(stderr, buffer);
215 #ifndef NO_LISTING
216                 listing_warning(buffer);
217 #endif
218                 va_end(args);
219                 (void) putc('\n', stderr);
220         }
221 } /* as_warn() */
222 #else
223 #ifndef NO_VARARGS
224 void as_warn(Format,va_alist)
225 char *Format;
226 va_dcl
227 {
228         va_list args;
229         char buffer[200];
230         
231         if(!flagseen['W']) {
232                 ++warning_count;
233                 as_where();
234                 va_start(args);
235                 fprintf(stderr,"Warning: ");
236                 vsprintf(buffer, Format, args);
237                 fprintf(stderr,buffer);
238 #ifndef NO_LISTING
239                 listing_warning(buffer);
240 #endif          
241                 va_end(args);
242                 (void) putc('\n', stderr);
243         }
244 } /* as_warn() */
245 #else
246 /*VARARGS1 */
247 as_warn(Format,args)
248 char *Format;
249 {
250         /* -W supresses warning messages. */
251         if (! flagseen ['W']) {
252                 ++warning_count;
253                 as_where();
254                 _doprnt (Format, &args, stderr);
255                 (void)putc ('\n', stderr);
256                 /* as_where(); */
257         }
258 } /* as_warn() */
259 #endif /* not NO_VARARGS */
260 #endif /* not NO_STDARG */
261
262 #ifdef DONTDEF
263 void as_warn(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an)
264 char *format;
265 {
266         if(!flagseen['W']) {
267                 ++warning_count;
268                 as_where();
269                 fprintf(stderr,Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an);
270                 (void)putc('\n',stderr);
271         }
272 } /* as_warn() */
273 #endif
274 /*
275  *                      a s _ b a d ()
276  *
277  * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning,
278  * and locate warning in input file(s).
279  * Please us when there is no recovery, but we want to continue processing
280  * but not produce an object file.
281  * Please explain in string (which may have '\n's) what recovery was done.
282  */
283
284 #ifndef NO_STDARG
285 void as_bad(Format)
286 const char *Format;
287 {
288         va_list args;
289         char buffer[200];
290         
291         ++error_count;
292         as_where();
293         va_start(args, Format);
294         fprintf(stderr,"Error: ");
295         
296         vsprintf(buffer, Format, args);
297         fprintf(stderr,buffer);
298 #ifndef NO_LISTING
299         listing_error(buffer);
300 #endif
301         va_end(args);
302         (void) putc('\n', stderr);
303 } /* as_bad() */
304 #else
305 #ifndef NO_VARARGS
306 void as_bad(Format,va_alist)
307 char *Format;
308 va_dcl
309 {
310         va_list args;
311         char buffer[200];
312         
313         ++error_count;
314         as_where();
315         va_start(args);
316         vsprintf(buffer, Format, args);
317         fprintf(stderr,buffer);
318 #ifndef NO_LISTING
319         listing_error(buffer);
320 #endif
321         
322         va_end(args);
323         (void) putc('\n', stderr);
324 }                               /* as_bad() */
325 #else
326 /*VARARGS1 */
327 as_bad(Format,args)
328 char *Format;
329 {
330         ++error_count;
331         
332         as_where();
333         fprintf(stderr,"Error: ");
334         _doprnt (Format, &args, stderr);
335         (void)putc ('\n', stderr);
336         /* as_where(); */
337 } /* as_bad() */
338 #endif /* not NO_VARARGS */
339 #endif /* not NO_STDARG */
340
341 #ifdef DONTDEF
342 void as_bad(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an)
343 char *format;
344 {
345         ++error_count;
346         as_where();
347         fprintf(stderr,Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an);
348         (void)putc('\n',stderr);
349 } /* as_bad() */
350 #endif
351
352 /*
353  *                      a s _ f a t a l ()
354  *
355  * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a fatal
356  * message, and locate stdsource in input file(s).
357  * Please only use this for when we DON'T have some recovery action.
358  * It exit()s with a warning status.
359  */
360
361 #ifndef NO_STDARG
362 void as_fatal(Format)
363 const char *Format;
364 {
365         va_list args;
366         
367         as_where();
368         va_start(args, Format);
369         fprintf (stderr, "FATAL:");
370         vfprintf(stderr, Format, args);
371         (void) putc('\n', stderr);
372         va_end(args);
373         exit(33);
374 } /* as_fatal() */
375 #else
376 #ifndef NO_VARARGS
377 void as_fatal(Format,va_alist)
378 char *Format;
379 va_dcl
380 {
381         va_list args;
382         
383         as_where();
384         va_start(args);
385         fprintf (stderr, "FATAL:");
386         vfprintf(stderr, Format, args);
387         (void) putc('\n', stderr);
388         va_end(args);
389         exit(33);
390 } /* as_fatal() */
391 #else
392 /*VARARGS1 */
393 as_fatal(Format, args)
394 char *Format;
395 {
396         as_where();
397         fprintf(stderr,"FATAL:");
398         _doprnt (Format, &args, stderr);
399         (void)putc ('\n', stderr);
400         /* as_where(); */
401         exit(33);               /* What is a good exit status? */
402 } /* as_fatal() */
403 #endif /* not NO_VARARGS */
404 #endif /* not NO_STDARG */
405
406 #ifdef DONTDEF
407 void as_fatal(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an)
408 char *Format;
409 {
410         as_where();
411         fprintf (stderr, "FATAL:");
412         fprintf(stderr, Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an);
413         (void) putc('\n', stderr);
414         exit(33);
415 } /* as_fatal() */
416 #endif
417
418 /* end: messages.c */