1 /* Default error handlers for CPP Library.
2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, 1999, 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 void print_containing_files PARAMS ((cpp_reader *, cpp_buffer *));
32 static void print_file_and_line PARAMS ((const char *, long, long));
33 static void v_message PARAMS ((cpp_reader *, int,
34 const char *, long, long,
35 const char *, va_list));
37 /* Print the file names and line numbers of the #include
38 commands which led to the current file. */
41 print_containing_files (pfile, ip)
47 /* If stack of files hasn't changed since we last printed
48 this info, don't repeat it. */
49 if (pfile->input_stack_listing_current)
52 /* Find the other, outer source files. */
53 for (ip = CPP_PREV_BUFFER (ip); ip != NULL; ip = CPP_PREV_BUFFER (ip))
56 cpp_buf_line_and_col (ip, &line, NULL);
60 fprintf (stderr, _("In file included from %s:%ld"),
61 ip->nominal_fname, line);
64 /* Translators note: this message is used in conjunction
65 with "In file included from %s:%ld" and some other
66 tricks. We want something like this:
68 In file included from sys/select.h:123,
71 bits/select.h:45: <error message here>
73 The trailing comma is at the beginning of this message,
74 and the trailing colon is not translated. */
75 fprintf (stderr, _(",\n from %s:%ld"),
76 ip->nominal_fname, line);
79 fputs (":\n", stderr);
81 /* Record we have printed the status as of this time. */
82 pfile->input_stack_listing_current = 1;
86 print_file_and_line (filename, line, column)
90 if (filename == 0 || *filename == '\0')
93 fputs (_("<command line>: "), stderr);
95 fprintf (stderr, "%s:%ld:%ld: ", filename, line, column);
97 fprintf (stderr, "%s:%ld: ", filename, line);
100 /* IS_ERROR is 3 for ICE, 2 for merely "fatal" error,
101 1 for error, 0 for warning. */
104 v_message (pfile, is_error, file, line, col, msg, ap)
113 cpp_buffer *ip = cpp_file_buffer (pfile);
118 file = ip->nominal_fname;
120 cpp_buf_line_and_col (ip, &line, &col);
122 print_containing_files (pfile, ip);
123 print_file_and_line (file, line, col);
126 fprintf (stderr, "%s: ", progname);
131 fprintf (stderr, _("warning: "));
134 if (pfile->errors < CPP_FATAL_LIMIT)
138 pfile->errors = CPP_FATAL_LIMIT;
141 fprintf (stderr, _("internal error: "));
142 pfile->errors = CPP_FATAL_LIMIT;
145 cpp_ice (pfile, "bad is_error(%d) in v_message", is_error);
148 vfprintf (stderr, _(msg), ap);
152 /* Exported interface. */
154 /* For reporting internal errors. Prints "internal error: " for you,
155 otherwise identical to cpp_fatal. */
158 cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
160 #ifndef ANSI_PROTOTYPES
166 VA_START (ap, msgid);
168 #ifndef ANSI_PROTOTYPES
169 pfile = va_arg (ap, cpp_reader *);
170 msgid = va_arg (ap, const char *);
173 v_message (pfile, 3, NULL, -1, -1, msgid, ap);
177 /* Same as cpp_error, except we consider the error to be "fatal",
178 such as inconsistent options. I.e. there is little point in continuing.
179 (We do not exit, to support use of cpplib as a library.
180 Instead, it is the caller's responsibility to check
184 cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
186 #ifndef ANSI_PROTOTYPES
192 VA_START (ap, msgid);
194 #ifndef ANSI_PROTOTYPES
195 pfile = va_arg (ap, cpp_reader *);
196 msgid = va_arg (ap, const char *);
199 v_message (pfile, 2, NULL, -1, -1, msgid, ap);
204 cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
206 #ifndef ANSI_PROTOTYPES
214 #ifndef ANSI_PROTOTYPES
215 pfile = va_arg (ap, cpp_reader *);
216 msgid = va_arg (ap, const char *);
219 if (CPP_OPTIONS (pfile)->inhibit_errors)
222 v_message (pfile, 1, NULL, -1, -1, msgid, ap);
227 cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
228 const char *msgid, ...))
230 #ifndef ANSI_PROTOTYPES
238 VA_START (ap, msgid);
240 #ifndef ANSI_PROTOTYPES
241 pfile = va_arg (ap, cpp_reader *);
242 line = va_arg (ap, int);
243 column = va_arg (ap, int);
244 msgid = va_arg (ap, const char *);
247 if (CPP_OPTIONS (pfile)->inhibit_errors)
250 v_message (pfile, 1, NULL, line, column, msgid, ap);
254 /* Error including a message from `errno'. */
256 cpp_error_from_errno (pfile, name)
260 cpp_error (pfile, "%s: %s", name, xstrerror (errno));
264 cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
266 #ifndef ANSI_PROTOTYPES
272 VA_START (ap, msgid);
274 #ifndef ANSI_PROTOTYPES
275 pfile = va_arg (ap, cpp_reader *);
276 msgid = va_arg (ap, const char *);
279 if (CPP_OPTIONS (pfile)->inhibit_warnings)
282 v_message (pfile, 0, NULL, -1, -1, msgid, ap);
287 cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
288 const char *msgid, ...))
290 #ifndef ANSI_PROTOTYPES
298 VA_START (ap, msgid);
300 #ifndef ANSI_PROTOTYPES
301 pfile = va_arg (ap, cpp_reader *);
302 line = va_arg (ap, int);
303 column = va_arg (ap, int);
304 msgid = va_arg (ap, const char *);
307 if (CPP_OPTIONS (pfile)->inhibit_warnings)
310 v_message (pfile, 0, NULL, line, column, msgid, ap);
315 cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
317 #ifndef ANSI_PROTOTYPES
323 VA_START (ap, msgid);
325 #ifndef ANSI_PROTOTYPES
326 pfile = va_arg (ap, cpp_reader *);
327 msgid = va_arg (ap, const char *);
330 if (CPP_OPTIONS (pfile)->pedantic_errors
331 ? CPP_OPTIONS (pfile)->inhibit_errors
332 : CPP_OPTIONS (pfile)->inhibit_warnings)
335 v_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
336 NULL, -1, -1, msgid, ap);
341 cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
342 const char *msgid, ...))
344 #ifndef ANSI_PROTOTYPES
352 VA_START (ap, msgid);
354 #ifndef ANSI_PROTOTYPES
355 pfile = va_arg (ap, cpp_reader *);
356 line = va_arg (ap, int);
357 column = va_arg (ap, int);
358 msgid = va_arg (ap, const char *);
361 if (CPP_OPTIONS (pfile)->pedantic_errors
362 ? CPP_OPTIONS (pfile)->inhibit_errors
363 : CPP_OPTIONS (pfile)->inhibit_warnings)
366 v_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
367 NULL, line, column, msgid, ap);
371 /* Report a warning (or an error if pedantic_errors)
372 giving specified file name and line number, not current. */
375 cpp_pedwarn_with_file_and_line VPARAMS ((cpp_reader *pfile,
376 const char *file, int line, int col,
377 const char *msgid, ...))
379 #ifndef ANSI_PROTOTYPES
388 VA_START (ap, msgid);
390 #ifndef ANSI_PROTOTYPES
391 pfile = va_arg (ap, cpp_reader *);
392 file = va_arg (ap, const char *);
393 line = va_arg (ap, int);
394 col = 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_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
404 file, line, col, msgid, ap);
408 /* Print an error message not associated with a file. */
410 cpp_notice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
412 #ifndef ANSI_PROTOTYPES
418 VA_START (ap, msgid);
420 #ifndef ANSI_PROTOTYPES
421 pfile = va_arg (ap, cpp_reader *);
422 msgid = va_arg (ap, const char *);
425 if (pfile->errors < CPP_FATAL_LIMIT)
428 vfprintf (stderr, _(msgid), ap);
435 cpp_notice_from_errno (pfile, name)
439 cpp_notice (pfile, "%s: %s", name, xstrerror (errno));