1 /* Default error handlers for CPP Library.
2 Copyright (C) 1986, 87, 89, 92-95, 98, 99, 2000
3 Free Software Foundation, Inc.
4 Written by Per Bothner, 1994.
5 Based on CCCP program by Paul Rubin, June 1986
6 Adapted to ANSI C, Richard Stallman, Jan 1987
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 In other words, you are welcome to use, share and improve this program.
23 You are forbidden to forbid anyone else to use, share and improve
24 what you give them. Help stamp out software-hoarding! */
31 static const char *my_strerror PARAMS ((int));
32 static void cpp_print_containing_files PARAMS ((cpp_reader *, cpp_buffer *));
33 static void cpp_print_file_and_line PARAMS ((const char *, long, long));
34 static void v_cpp_message PARAMS ((cpp_reader *, int,
35 const char *, long, long,
36 const char *, va_list));
38 /* my_strerror - return the descriptive text associated with an
40 XXX - link with libiberty so we can use its strerror(). */
50 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
52 result = strerror (errnum);
55 /* VAXCRTL's strerror() takes an optional second argument, which only
56 matters when the first argument is EVMSERR. However, it's simplest
57 just to pass it unconditionally. `vaxc$errno' is declared in
58 <errno.h>, and maintained by the library in parallel with `errno'.
59 We assume that caller's `errnum' either matches the last setting of
60 `errno' by the library or else does not have the value `EVMSERR'. */
62 result = strerror (errnum, vaxc$errno);
71 /* Print the file names and line numbers of the #include
72 commands which led to the current file. */
75 cpp_print_containing_files (pfile, ip)
81 /* If stack of files hasn't changed since we last printed
82 this info, don't repeat it. */
83 if (pfile->input_stack_listing_current)
86 /* Find the other, outer source files. */
87 for (ip = CPP_PREV_BUFFER (ip);
88 ip != CPP_NULL_BUFFER (pfile);
89 ip = CPP_PREV_BUFFER (ip))
90 if (ip->fname != NULL)
93 cpp_buf_line_and_col (ip, &line, NULL);
97 fprintf (stderr, _("In file included from %s:%ld"),
98 ip->nominal_fname, line);
101 /* Translators note: this message is used in conjunction
102 with "In file included from %s:%ld" and some other
103 tricks. We want something like this:
105 In file included from sys/select.h:123,
106 from sys/types.h:234,
108 bits/select.h:45: <error message here>
110 The trailing comma is at the beginning of this message,
111 and the trailing colon is not translated. */
112 fprintf (stderr, _(",\n from %s:%ld"),
113 ip->nominal_fname, line);
116 fputs (":\n", stderr);
118 /* Record we have printed the status as of this time. */
119 pfile->input_stack_listing_current = 1;
123 cpp_print_file_and_line (filename, line, column)
124 const char *filename;
127 if (filename == 0 || *filename == '\0')
128 filename = "<stdin>";
130 fputs (_("<command line>: "), stderr);
132 fprintf (stderr, "%s:%ld:%ld: ", filename, line, column);
134 fprintf (stderr, "%s:%ld: ", filename, line);
137 /* IS_ERROR is 3 for ICE, 2 for merely "fatal" error,
138 1 for error, 0 for warning. */
141 v_cpp_message (pfile, is_error, file, line, col, msg, ap)
150 cpp_buffer *ip = cpp_file_buffer (pfile);
155 file = ip->nominal_fname;
157 cpp_buf_line_and_col (ip, &line, &col);
159 cpp_print_containing_files (pfile, ip);
160 cpp_print_file_and_line (file, line, col);
163 fprintf (stderr, "%s: ", progname);
168 fprintf (stderr, _("warning: "));
171 if (pfile->errors < CPP_FATAL_LIMIT)
175 pfile->errors = CPP_FATAL_LIMIT;
178 fprintf (stderr, _("internal error: "));
179 pfile->errors = CPP_FATAL_LIMIT;
182 cpp_ice (pfile, "bad is_error(%d) in v_cpp_message", is_error);
185 vfprintf (stderr, _(msg), ap);
189 /* Exported interface. */
191 /* For reporting internal errors. Prints "internal error: " for you,
192 otherwise identical to cpp_fatal. */
195 cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
197 #ifndef ANSI_PROTOTYPES
203 VA_START (ap, msgid);
205 #ifndef ANSI_PROTOTYPES
206 pfile = va_arg (ap, cpp_reader *);
207 msgid = va_arg (ap, const char *);
210 v_cpp_message (pfile, 3, NULL, -1, -1, msgid, ap);
214 /* Same as cpp_error, except we consider the error to be "fatal",
215 such as inconsistent options. I.e. there is little point in continuing.
216 (We do not exit, to support use of cpplib as a library.
217 Instead, it is the caller's responsibility to check
221 cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
223 #ifndef ANSI_PROTOTYPES
229 VA_START (ap, msgid);
231 #ifndef ANSI_PROTOTYPES
232 pfile = va_arg (ap, cpp_reader *);
233 msgid = va_arg (ap, const char *);
236 v_cpp_message (pfile, 2, NULL, -1, -1, msgid, ap);
241 cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
243 #ifndef ANSI_PROTOTYPES
251 #ifndef ANSI_PROTOTYPES
252 pfile = va_arg (ap, cpp_reader *);
253 msgid = va_arg (ap, const char *);
256 if (CPP_OPTIONS (pfile)->inhibit_errors)
259 v_cpp_message (pfile, 1, NULL, -1, -1, msgid, ap);
264 cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
265 const char *msgid, ...))
267 #ifndef ANSI_PROTOTYPES
275 VA_START (ap, msgid);
277 #ifndef ANSI_PROTOTYPES
278 pfile = va_arg (ap, cpp_reader *);
279 line = va_arg (ap, int);
280 column = va_arg (ap, int);
281 msgid = va_arg (ap, const char *);
284 if (CPP_OPTIONS (pfile)->inhibit_errors)
287 v_cpp_message (pfile, 1, NULL, line, column, msgid, ap);
291 /* Error including a message from `errno'. */
293 cpp_error_from_errno (pfile, name)
297 cpp_error (pfile, "%s: %s", name, my_strerror (errno));
301 cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
303 #ifndef ANSI_PROTOTYPES
309 VA_START (ap, msgid);
311 #ifndef ANSI_PROTOTYPES
312 pfile = va_arg (ap, cpp_reader *);
313 msgid = va_arg (ap, const char *);
316 if (CPP_OPTIONS (pfile)->inhibit_warnings)
319 v_cpp_message (pfile, 0, NULL, -1, -1, msgid, ap);
324 cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
325 const char *msgid, ...))
327 #ifndef ANSI_PROTOTYPES
335 VA_START (ap, msgid);
337 #ifndef ANSI_PROTOTYPES
338 pfile = va_arg (ap, cpp_reader *);
339 line = va_arg (ap, int);
340 column = va_arg (ap, int);
341 msgid = va_arg (ap, const char *);
344 if (CPP_OPTIONS (pfile)->inhibit_warnings)
347 v_cpp_message (pfile, 0, NULL, line, column, msgid, ap);
352 cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
354 #ifndef ANSI_PROTOTYPES
360 VA_START (ap, msgid);
362 #ifndef ANSI_PROTOTYPES
363 pfile = va_arg (ap, cpp_reader *);
364 msgid = va_arg (ap, const char *);
367 if (CPP_OPTIONS (pfile)->pedantic_errors
368 ? CPP_OPTIONS (pfile)->inhibit_errors
369 : CPP_OPTIONS (pfile)->inhibit_warnings)
372 v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
373 NULL, -1, -1, msgid, ap);
378 cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
379 const char *msgid, ...))
381 #ifndef ANSI_PROTOTYPES
389 VA_START (ap, msgid);
391 #ifndef ANSI_PROTOTYPES
392 pfile = va_arg (ap, cpp_reader *);
393 line = va_arg (ap, int);
394 column = va_arg (ap, int);
395 msgid = va_arg (ap, const char *);
398 if (CPP_OPTIONS (pfile)->pedantic_errors
399 ? CPP_OPTIONS (pfile)->inhibit_errors
400 : CPP_OPTIONS (pfile)->inhibit_warnings)
403 v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
404 NULL, line, column, msgid, ap);
408 /* Report a warning (or an error if pedantic_errors)
409 giving specified file name and line number, not current. */
412 cpp_pedwarn_with_file_and_line VPARAMS ((cpp_reader *pfile,
413 const char *file, int line, int col,
414 const char *msgid, ...))
416 #ifndef ANSI_PROTOTYPES
425 VA_START (ap, msgid);
427 #ifndef ANSI_PROTOTYPES
428 pfile = va_arg (ap, cpp_reader *);
429 file = va_arg (ap, const char *);
430 line = va_arg (ap, int);
431 col = va_arg (ap, int);
432 msgid = va_arg (ap, const char *);
435 if (CPP_OPTIONS (pfile)->pedantic_errors
436 ? CPP_OPTIONS (pfile)->inhibit_errors
437 : CPP_OPTIONS (pfile)->inhibit_warnings)
440 v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
441 file, line, col, msgid, ap);
445 /* Print an error message not associated with a file. */
447 cpp_notice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
449 #ifndef ANSI_PROTOTYPES
455 VA_START (ap, msgid);
457 #ifndef ANSI_PROTOTYPES
458 pfile = va_arg (ap, cpp_reader *);
459 msgid = va_arg (ap, const char *);
462 if (pfile->errors < CPP_FATAL_LIMIT)
465 vfprintf (stderr, _(msgid), ap);
472 cpp_notice_from_errno (pfile, name)
476 cpp_notice (pfile, "%s: %s", name, my_strerror (errno));