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