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