changes, what else?
[deliverable/binutils-gdb.git] / gas / messages.c
CommitLineData
fecd2382 1/* messages.c - error reporter -
c1c28543 2 Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc.
a39116f1 3
fecd2382 4 This file is part of GAS, the GNU Assembler.
a39116f1 5
fecd2382
RP
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
a39116f1 8 the Free Software Foundation; either version 2, or (at your option)
fecd2382 9 any later version.
a39116f1 10
fecd2382
RP
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.
a39116f1 15
fecd2382
RP
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
fecd2382
RP
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
a39116f1 73
fecd2382
RP
74 JF: this is now bogus. We now print more standard error messages
75 that try to look like everyone else's.
a39116f1 76
fecd2382
RP
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.
a39116f1 84
fecd2382
RP
85 Optionally, we may die.
86 There is no need for a trailing '\n' in your error text format
87 because we supply one.
a39116f1 88
fecd2382 89 as_warn(fmt,args) Like fprintf(stderr,fmt,args) but also call errwhere().
a39116f1 90
fecd2382 91 as_fatal(fmt,args) Like as_warn() but exit with a fatal status.
a39116f1
RP
92
93 */
fecd2382 94
09952cd9 95static int warning_count; /* Count of number of warnings issued */
fecd2382
RP
96
97int 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
09952cd9 104static int error_count;
fecd2382
RP
105
106int 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 */
116void as_perror(gripe, filename)
117char *gripe; /* Unpunctuated error theme. */
118char *filename;
119{
c1c28543
KR
120#ifndef HAVE_STRERROR
121 extern char *strerror();
122#endif /* HAVE_STRERROR */
123
fecd2382 124 as_where();
c1c28543
KR
125 fprintf(stderr, gripe, filename);
126 fprintf(stderr, "%s.\n", strerror(errno));
fecd2382
RP
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
c1c28543 140void as_tsktsk(const char *Format, ...)
fecd2382
RP
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
152void as_tsktsk(Format,va_alist)
153char *Format;
154va_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 */
166as_tsktsk(Format,args)
167char *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
fecd2382
RP
177/*
178 * a s _ w a r n ()
179 *
09952cd9 180 * Send to stderr a string as a warning, and locate warning
fecd2382
RP
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
c1c28543 187void as_warn(const char *Format, ...)
fecd2382
RP
188{
189 va_list args;
a39116f1 190 char buffer[200];
fecd2382
RP
191
192 if(!flagseen['W']) {
193 ++warning_count;
194 as_where();
195 va_start(args, Format);
a39116f1
RP
196 fprintf(stderr,"Warning: ");
197 vsprintf(buffer, Format, args);
4772861e 198 fputs (buffer, stderr);
a39116f1
RP
199#ifndef NO_LISTING
200 listing_warning(buffer);
201#endif
fecd2382
RP
202 va_end(args);
203 (void) putc('\n', stderr);
204 }
205} /* as_warn() */
206#else
207#ifndef NO_VARARGS
208void as_warn(Format,va_alist)
209char *Format;
210va_dcl
211{
212 va_list args;
a39116f1 213 char buffer[200];
fecd2382
RP
214
215 if(!flagseen['W']) {
216 ++warning_count;
217 as_where();
218 va_start(args);
a39116f1
RP
219 fprintf(stderr,"Warning: ");
220 vsprintf(buffer, Format, args);
4772861e 221 fputs (buffer, stderr);
a39116f1
RP
222#ifndef NO_LISTING
223 listing_warning(buffer);
224#endif
fecd2382
RP
225 va_end(args);
226 (void) putc('\n', stderr);
227 }
228} /* as_warn() */
229#else
230/*VARARGS1 */
231as_warn(Format,args)
232char *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
fecd2382
RP
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
c1c28543 257void as_bad(const char *Format, ...)
fecd2382
RP
258{
259 va_list args;
a39116f1
RP
260 char buffer[200];
261
fecd2382
RP
262 ++error_count;
263 as_where();
264 va_start(args, Format);
a39116f1
RP
265 fprintf(stderr,"Error: ");
266
267 vsprintf(buffer, Format, args);
4772861e 268 fputs (buffer,stderr);
a39116f1
RP
269#ifndef NO_LISTING
270 listing_error(buffer);
271#endif
fecd2382
RP
272 va_end(args);
273 (void) putc('\n', stderr);
274} /* as_bad() */
275#else
276#ifndef NO_VARARGS
277void as_bad(Format,va_alist)
278char *Format;
279va_dcl
280{
281 va_list args;
a39116f1
RP
282 char buffer[200];
283
fecd2382
RP
284 ++error_count;
285 as_where();
286 va_start(args);
a39116f1 287 vsprintf(buffer, Format, args);
4772861e 288 fputs (buffer, stderr);
a39116f1
RP
289#ifndef NO_LISTING
290 listing_error(buffer);
291#endif
292
fecd2382
RP
293 va_end(args);
294 (void) putc('\n', stderr);
a39116f1 295} /* as_bad() */
fecd2382
RP
296#else
297/*VARARGS1 */
298as_bad(Format,args)
299char *Format;
300{
301 ++error_count;
a39116f1 302
fecd2382 303 as_where();
a39116f1 304 fprintf(stderr,"Error: ");
fecd2382
RP
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
fecd2382
RP
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
c1c28543 322void as_fatal(const char *Format, ...)
fecd2382
RP
323{
324 va_list args;
a39116f1 325
fecd2382
RP
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);
a39116f1 332 exit(33);
fecd2382
RP
333} /* as_fatal() */
334#else
335#ifndef NO_VARARGS
336void as_fatal(Format,va_alist)
337char *Format;
338va_dcl
339{
340 va_list args;
a39116f1 341
fecd2382
RP
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);
a39116f1 348 exit(33);
fecd2382
RP
349} /* as_fatal() */
350#else
351/*VARARGS1 */
352as_fatal(Format, args)
353char *Format;
354{
355 as_where();
356 fprintf(stderr,"FATAL:");
357 _doprnt (Format, &args, stderr);
358 (void)putc ('\n', stderr);
359 /* as_where(); */
a39116f1 360 exit(33); /* What is a good exit status? */
fecd2382
RP
361} /* as_fatal() */
362#endif /* not NO_VARARGS */
363#endif /* not NO_STDARG */
364
8b228fe9 365/* end of messages.c */
This page took 0.066024 seconds and 4 git commands to generate.