i386v host/target/native separation
[deliverable/binutils-gdb.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 had_warnings() {
104 return(warning_count);
105 } /* had_err() */
106
107 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
108 and exit with a nonzero error code */
109
110 static int error_count;
111
112 int had_errors() {
113 return(error_count);
114 } /* had_errors() */
115
116
117 /*
118 * a s _ p e r r o r
119 *
120 * Like perror(3), but with more info.
121 */
122 void as_perror(gripe, filename)
123 char *gripe; /* Unpunctuated error theme. */
124 char *filename;
125 {
126 #ifndef HAVE_STRERROR
127 extern char *strerror();
128 #endif /* HAVE_STRERROR */
129
130 as_where();
131 fprintf(stderr, gripe, filename);
132 fprintf(stderr, ": %s\n", strerror(errno));
133 errno = 0; /* After reporting, clear it. */
134 } /* as_perror() */
135
136 /*
137 * a s _ t s k t s k ()
138 *
139 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning, and locate warning
140 * in input file(s).
141 * Please only use this for when we have some recovery action.
142 * Please explain in string (which may have '\n's) what recovery was done.
143 */
144
145 #ifndef NO_STDARG
146 void as_tsktsk(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 /*
184 * a s _ w a r n ()
185 *
186 * Send to stderr a string as a warning, and locate warning
187 * in input file(s).
188 * Please only use this for when we have some recovery action.
189 * Please explain in string (which may have '\n's) what recovery was done.
190 */
191
192 #ifndef NO_STDARG
193 void as_warn(const char *Format, ...)
194 {
195 va_list args;
196 char buffer[200];
197
198 if(!flagseen['W']) {
199 ++warning_count;
200 as_where();
201 va_start(args, Format);
202 fprintf(stderr,"Warning: ");
203 vsprintf(buffer, Format, args);
204 fputs (buffer, stderr);
205 #ifndef NO_LISTING
206 listing_warning(buffer);
207 #endif
208 va_end(args);
209 (void) putc('\n', stderr);
210 }
211 } /* as_warn() */
212 #else
213 #ifndef NO_VARARGS
214 void as_warn(Format,va_alist)
215 char *Format;
216 va_dcl
217 {
218 va_list args;
219 char buffer[200];
220
221 if(!flagseen['W']) {
222 ++warning_count;
223 as_where();
224 va_start(args);
225 fprintf(stderr,"Warning: ");
226 vsprintf(buffer, Format, args);
227 fputs (buffer, stderr);
228 #ifndef NO_LISTING
229 listing_warning(buffer);
230 #endif
231 va_end(args);
232 (void) putc('\n', stderr);
233 }
234 } /* as_warn() */
235 #else
236 /*VARARGS1 */
237 as_warn(Format,args)
238 char *Format;
239 {
240 /* -W supresses warning messages. */
241 if (! flagseen ['W']) {
242 ++warning_count;
243 as_where();
244 _doprnt (Format, &args, stderr);
245 (void)putc ('\n', stderr);
246 /* as_where(); */
247 }
248 } /* as_warn() */
249 #endif /* not NO_VARARGS */
250 #endif /* not NO_STDARG */
251
252 /*
253 * a s _ b a d ()
254 *
255 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a warning,
256 * and locate warning in input file(s).
257 * Please us when there is no recovery, but we want to continue processing
258 * but not produce an object file.
259 * Please explain in string (which may have '\n's) what recovery was done.
260 */
261
262 #ifndef NO_STDARG
263 void as_bad(const char *Format, ...)
264 {
265 va_list args;
266 char buffer[200];
267
268 ++error_count;
269 as_where();
270 va_start(args, Format);
271 fprintf(stderr,"Error: ");
272
273 vsprintf(buffer, Format, args);
274 fputs (buffer,stderr);
275 #ifndef NO_LISTING
276 listing_error(buffer);
277 #endif
278 va_end(args);
279 (void) putc('\n', stderr);
280 } /* as_bad() */
281 #else
282 #ifndef NO_VARARGS
283 void as_bad(Format,va_alist)
284 char *Format;
285 va_dcl
286 {
287 va_list args;
288 char buffer[200];
289
290 ++error_count;
291 as_where();
292 va_start(args);
293 vsprintf(buffer, Format, args);
294 fputs (buffer, stderr);
295 #ifndef NO_LISTING
296 listing_error(buffer);
297 #endif
298
299 va_end(args);
300 (void) putc('\n', stderr);
301 } /* as_bad() */
302 #else
303 /*VARARGS1 */
304 as_bad(Format,args)
305 char *Format;
306 {
307 ++error_count;
308
309 as_where();
310 fprintf(stderr,"Error: ");
311 _doprnt (Format, &args, stderr);
312 (void)putc ('\n', stderr);
313 /* as_where(); */
314 } /* as_bad() */
315 #endif /* not NO_VARARGS */
316 #endif /* not NO_STDARG */
317
318 /*
319 * a s _ f a t a l ()
320 *
321 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a fatal
322 * message, and locate stdsource in input file(s).
323 * Please only use this for when we DON'T have some recovery action.
324 * It exit()s with a warning status.
325 */
326
327 #ifndef NO_STDARG
328 void as_fatal(const char *Format, ...)
329 {
330 va_list args;
331
332 as_where();
333 va_start(args, Format);
334 fprintf (stderr, "FATAL:");
335 vfprintf(stderr, Format, args);
336 (void) putc('\n', stderr);
337 va_end(args);
338 exit(33);
339 } /* as_fatal() */
340 #else
341 #ifndef NO_VARARGS
342 void as_fatal(Format,va_alist)
343 char *Format;
344 va_dcl
345 {
346 va_list args;
347
348 as_where();
349 va_start(args);
350 fprintf (stderr, "FATAL:");
351 vfprintf(stderr, Format, args);
352 (void) putc('\n', stderr);
353 va_end(args);
354 exit(33);
355 } /* as_fatal() */
356 #else
357 /*VARARGS1 */
358 as_fatal(Format, args)
359 char *Format;
360 {
361 as_where();
362 fprintf(stderr,"FATAL:");
363 _doprnt (Format, &args, stderr);
364 (void)putc ('\n', stderr);
365 /* as_where(); */
366 exit(33); /* What is a good exit status? */
367 } /* as_fatal() */
368 #endif /* not NO_VARARGS */
369 #endif /* not NO_STDARG */
370
371 /* end of messages.c */
This page took 0.053478 seconds and 4 git commands to generate.