force all files to end in "/* end of filename"
[deliverable/binutils-gdb.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 #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 = 0; /* 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 = 0;
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 extern int sys_nerr;
121 extern char *sys_errlist[];
122
123 as_where();
124 fprintf(stderr,gripe,filename);
125
126 if (errno > sys_nerr)
127 fprintf(stderr, "Unknown error #%d.\n", errno);
128 else
129 fprintf(stderr, "%s.\n", sys_errlist[errno]);
130 errno = 0; /* After reporting, clear it. */
131 } /* as_perror() */
132
133 /*
134 * a s _ t s k t s k ()
135 *
136 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning, and locate warning
137 * in input file(s).
138 * Please only use this for when we have some recovery action.
139 * Please explain in string (which may have '\n's) what recovery was done.
140 */
141
142 #ifndef NO_STDARG
143 void as_tsktsk(Format)
144 const char *Format;
145 {
146 va_list args;
147
148 as_where();
149 va_start(args, Format);
150 vfprintf(stderr, Format, args);
151 va_end(args);
152 (void) putc('\n', stderr);
153 } /* as_tsktsk() */
154 #else
155 #ifndef NO_VARARGS
156 void as_tsktsk(Format,va_alist)
157 char *Format;
158 va_dcl
159 {
160 va_list args;
161
162 as_where();
163 va_start(args);
164 vfprintf(stderr, Format, args);
165 va_end(args);
166 (void) putc('\n', stderr);
167 } /* as_tsktsk() */
168 #else
169 /*VARARGS1 */
170 as_tsktsk(Format,args)
171 char *Format;
172 {
173 as_where();
174 _doprnt (Format, &args, stderr);
175 (void)putc ('\n', stderr);
176 /* as_where(); */
177 } /* as_tsktsk */
178 #endif /* not NO_VARARGS */
179 #endif /* not NO_STDARG */
180
181 #ifdef DONTDEF
182 void as_tsktsk(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an)
183 char *format;
184 {
185 as_where();
186 fprintf(stderr,Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an);
187 (void)putc('\n',stderr);
188 } /* as_tsktsk() */
189 #endif
190 /*
191 * a s _ w a r n ()
192 *
193 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning, and locate warning
194 * in input file(s).
195 * Please only use this for when we have some recovery action.
196 * Please explain in string (which may have '\n's) what recovery was done.
197 */
198
199 #ifndef NO_STDARG
200 void as_warn(Format)
201 const char *Format;
202 {
203 va_list args;
204 char buffer[200];
205
206 if(!flagseen['W']) {
207 ++warning_count;
208 as_where();
209 va_start(args, Format);
210 fprintf(stderr,"Warning: ");
211 vsprintf(buffer, Format, args);
212 fprintf(stderr, buffer);
213 #ifndef NO_LISTING
214 listing_warning(buffer);
215 #endif
216 va_end(args);
217 (void) putc('\n', stderr);
218 }
219 } /* as_warn() */
220 #else
221 #ifndef NO_VARARGS
222 void as_warn(Format,va_alist)
223 char *Format;
224 va_dcl
225 {
226 va_list args;
227 char buffer[200];
228
229 if(!flagseen['W']) {
230 ++warning_count;
231 as_where();
232 va_start(args);
233 fprintf(stderr,"Warning: ");
234 vsprintf(buffer, Format, args);
235 fprintf(stderr,buffer);
236 #ifndef NO_LISTING
237 listing_warning(buffer);
238 #endif
239 va_end(args);
240 (void) putc('\n', stderr);
241 }
242 } /* as_warn() */
243 #else
244 /*VARARGS1 */
245 as_warn(Format,args)
246 char *Format;
247 {
248 /* -W supresses warning messages. */
249 if (! flagseen ['W']) {
250 ++warning_count;
251 as_where();
252 _doprnt (Format, &args, stderr);
253 (void)putc ('\n', stderr);
254 /* as_where(); */
255 }
256 } /* as_warn() */
257 #endif /* not NO_VARARGS */
258 #endif /* not NO_STDARG */
259
260 #ifdef DONTDEF
261 void as_warn(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an)
262 char *format;
263 {
264 if(!flagseen['W']) {
265 ++warning_count;
266 as_where();
267 fprintf(stderr,Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an);
268 (void)putc('\n',stderr);
269 }
270 } /* as_warn() */
271 #endif
272 /*
273 * a s _ b a d ()
274 *
275 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning,
276 * and locate warning in input file(s).
277 * Please us when there is no recovery, but we want to continue processing
278 * but not produce an object file.
279 * Please explain in string (which may have '\n's) what recovery was done.
280 */
281
282 #ifndef NO_STDARG
283 void as_bad(Format)
284 const char *Format;
285 {
286 va_list args;
287 char buffer[200];
288
289 ++error_count;
290 as_where();
291 va_start(args, Format);
292 fprintf(stderr,"Error: ");
293
294 vsprintf(buffer, Format, args);
295 fprintf(stderr,buffer);
296 #ifndef NO_LISTING
297 listing_error(buffer);
298 #endif
299 va_end(args);
300 (void) putc('\n', stderr);
301 } /* as_bad() */
302 #else
303 #ifndef NO_VARARGS
304 void as_bad(Format,va_alist)
305 char *Format;
306 va_dcl
307 {
308 va_list args;
309 char buffer[200];
310
311 ++error_count;
312 as_where();
313 va_start(args);
314 vsprintf(buffer, Format, args);
315 fprintf(stderr,buffer);
316 #ifndef NO_LISTING
317 listing_error(buffer);
318 #endif
319
320 va_end(args);
321 (void) putc('\n', stderr);
322 } /* as_bad() */
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 #endif /* not NO_VARARGS */
337 #endif /* not NO_STDARG */
338
339 #ifdef DONTDEF
340 void as_bad(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an)
341 char *format;
342 {
343 ++error_count;
344 as_where();
345 fprintf(stderr,Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an);
346 (void)putc('\n',stderr);
347 } /* as_bad() */
348 #endif
349
350 /*
351 * a s _ f a t a l ()
352 *
353 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a fatal
354 * message, and locate stdsource in input file(s).
355 * Please only use this for when we DON'T have some recovery action.
356 * It exit()s with a warning status.
357 */
358
359 #ifndef NO_STDARG
360 void as_fatal(Format)
361 const char *Format;
362 {
363 va_list args;
364
365 as_where();
366 va_start(args, Format);
367 fprintf (stderr, "FATAL:");
368 vfprintf(stderr, Format, args);
369 (void) putc('\n', stderr);
370 va_end(args);
371 exit(33);
372 } /* as_fatal() */
373 #else
374 #ifndef NO_VARARGS
375 void as_fatal(Format,va_alist)
376 char *Format;
377 va_dcl
378 {
379 va_list args;
380
381 as_where();
382 va_start(args);
383 fprintf (stderr, "FATAL:");
384 vfprintf(stderr, Format, args);
385 (void) putc('\n', stderr);
386 va_end(args);
387 exit(33);
388 } /* as_fatal() */
389 #else
390 /*VARARGS1 */
391 as_fatal(Format, args)
392 char *Format;
393 {
394 as_where();
395 fprintf(stderr,"FATAL:");
396 _doprnt (Format, &args, stderr);
397 (void)putc ('\n', stderr);
398 /* as_where(); */
399 exit(33); /* What is a good exit status? */
400 } /* as_fatal() */
401 #endif /* not NO_VARARGS */
402 #endif /* not NO_STDARG */
403
404 #ifdef DONTDEF
405 void as_fatal(Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an)
406 char *Format;
407 {
408 as_where();
409 fprintf (stderr, "FATAL:");
410 fprintf(stderr, Format,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an);
411 (void) putc('\n', stderr);
412 exit(33);
413 } /* as_fatal() */
414 #endif
415
416 /* end of messages.c */
This page took 0.0393019999999999 seconds and 5 git commands to generate.