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! */
32 static void print_containing_files
PARAMS ((cpp_buffer
*));
33 static void print_location
PARAMS ((cpp_reader
*,
35 const cpp_lexer_pos
*));
37 /* Don't remove the blank before do, as otherwise the exgettext
38 script will mistake this as a function definition */
39 #define v_message(msgid, ap) \
40 do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
42 /* Print the file names and line numbers of the #include
43 commands which led to the current file. */
45 print_containing_files (ip
)
50 /* Find the other, outer source files. */
51 for (ip
= ip
->prev
; ip
; ip
= ip
->prev
)
56 /* The current line in each outer source file is now the
57 same as the line of the #include. */
58 fprintf (stderr
, _("In file included from %s:%u"),
59 ip
->nominal_fname
, CPP_BUF_LINE (ip
));
62 /* Translators note: this message is used in conjunction
63 with "In file included from %s:%ld" and some other
64 tricks. We want something like this:
66 | In file included from sys/select.h:123,
67 | from sys/types.h:234,
69 | bits/select.h:45: <error message here>
71 with all the "from"s lined up.
72 The trailing comma is at the beginning of this message,
73 and the trailing colon is not translated. */
74 fprintf (stderr
, _(",\n from %s:%u"),
75 ip
->nominal_fname
, CPP_BUF_LINE (ip
));
77 fputs (":\n", stderr
);
81 print_location (pfile
, filename
, pos
)
84 const cpp_lexer_pos
*pos
;
86 cpp_buffer
*buffer
= pfile
->buffer
;
89 fprintf (stderr
, "%s: ", progname
);
92 unsigned int line
, col
= 0;
93 enum cpp_buffer_type type
= buffer
->type
;
95 /* For _Pragma buffers, we want to print the location as
96 "foo.c:5:8: _Pragma:", where foo.c is the containing buffer.
97 For diagnostics relating to command line options, we want to
98 print "<command line>:" with no line number. */
99 if (type
== BUF_CL_OPTION
|| type
== BUF_BUILTIN
)
103 if (type
== BUF_PRAGMA
)
105 buffer
= buffer
->prev
;
106 line
= CPP_BUF_LINE (buffer
);
107 col
= CPP_BUF_COL (buffer
);
112 pos
= cpp_get_line (pfile
);
120 /* Don't repeat the include stack unnecessarily. */
121 if (buffer
->prev
&& ! buffer
->include_stack_listed
)
123 buffer
->include_stack_listed
= 1;
124 print_containing_files (buffer
);
129 filename
= buffer
->nominal_fname
;
132 fprintf (stderr
, "%s: ", filename
);
133 else if (CPP_OPTION (pfile
, show_column
) == 0)
134 fprintf (stderr
, "%s:%u: ", filename
, line
);
136 fprintf (stderr
, "%s:%u:%u: ", filename
, line
, col
);
138 if (type
== BUF_PRAGMA
)
139 fprintf (stderr
, "_Pragma: ");
143 /* Set up for an error message: print the file and line, bump the error
145 If it returns 0, this error has been suppressed. */
148 _cpp_begin_message (pfile
, code
, file
, pos
)
150 enum error_type code
;
152 const cpp_lexer_pos
*pos
;
160 if (CPP_IN_SYSTEM_HEADER (pfile
)
161 && ! CPP_OPTION (pfile
, warn_system_headers
))
164 if (CPP_OPTION (pfile
, warnings_are_errors
)
165 || (code
== PEDWARN
&& CPP_OPTION (pfile
, pedantic_errors
)))
167 if (CPP_OPTION (pfile
, inhibit_errors
))
169 if (pfile
->errors
< CPP_FATAL_LIMIT
)
174 if (CPP_OPTION (pfile
, inhibit_warnings
))
181 if (CPP_OPTION (pfile
, inhibit_errors
))
183 if (pfile
->errors
< CPP_FATAL_LIMIT
)
186 /* Fatal errors cannot be inhibited. */
188 pfile
->errors
= CPP_FATAL_LIMIT
;
191 fprintf (stderr
, _("internal error: "));
192 pfile
->errors
= CPP_FATAL_LIMIT
;
196 print_location (pfile
, file
, pos
);
198 fputs (_("warning: "), stderr
);
203 /* Exported interface. */
205 /* For reporting internal errors. Prints "internal error: " for you,
206 otherwise identical to cpp_fatal. */
209 cpp_ice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
211 #ifndef ANSI_PROTOTYPES
217 VA_START (ap
, msgid
);
219 #ifndef ANSI_PROTOTYPES
220 pfile
= va_arg (ap
, cpp_reader
*);
221 msgid
= va_arg (ap
, const char *);
224 if (_cpp_begin_message (pfile
, ICE
, NULL
, 0))
225 v_message (msgid
, ap
);
229 /* Same as cpp_error, except we consider the error to be "fatal",
230 such as inconsistent options. I.e. there is little point in continuing.
231 (We do not exit, to support use of cpplib as a library.
232 Instead, it is the caller's responsibility to check
236 cpp_fatal
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
238 #ifndef ANSI_PROTOTYPES
244 VA_START (ap
, msgid
);
246 #ifndef ANSI_PROTOTYPES
247 pfile
= va_arg (ap
, cpp_reader
*);
248 msgid
= va_arg (ap
, const char *);
251 if (_cpp_begin_message (pfile
, FATAL
, NULL
, 0))
252 v_message (msgid
, ap
);
257 cpp_error
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
259 #ifndef ANSI_PROTOTYPES
267 #ifndef ANSI_PROTOTYPES
268 pfile
= va_arg (ap
, cpp_reader
*);
269 msgid
= va_arg (ap
, const char *);
272 if (_cpp_begin_message (pfile
, ERROR
, NULL
, 0))
273 v_message (msgid
, ap
);
278 cpp_error_with_line
VPARAMS ((cpp_reader
*pfile
, int line
, int column
,
279 const char *msgid
, ...))
281 #ifndef ANSI_PROTOTYPES
290 VA_START (ap
, msgid
);
292 #ifndef ANSI_PROTOTYPES
293 pfile
= va_arg (ap
, cpp_reader
*);
294 line
= va_arg (ap
, int);
295 column
= va_arg (ap
, int);
296 msgid
= va_arg (ap
, const char *);
301 if (_cpp_begin_message (pfile
, ERROR
, NULL
, &pos
))
302 v_message (msgid
, ap
);
306 /* Error including a message from `errno'. */
308 cpp_error_from_errno (pfile
, name
)
312 cpp_error (pfile
, "%s: %s", name
, xstrerror (errno
));
316 cpp_warning
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
318 #ifndef ANSI_PROTOTYPES
324 VA_START (ap
, msgid
);
326 #ifndef ANSI_PROTOTYPES
327 pfile
= va_arg (ap
, cpp_reader
*);
328 msgid
= va_arg (ap
, const char *);
331 if (_cpp_begin_message (pfile
, WARNING
, NULL
, 0))
332 v_message (msgid
, ap
);
337 cpp_warning_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
338 const char *msgid
, ...))
340 #ifndef ANSI_PROTOTYPES
349 VA_START (ap
, msgid
);
351 #ifndef ANSI_PROTOTYPES
352 pfile
= va_arg (ap
, cpp_reader
*);
353 line
= va_arg (ap
, int);
354 column
= va_arg (ap
, int);
355 msgid
= va_arg (ap
, const char *);
360 if (_cpp_begin_message (pfile
, WARNING
, NULL
, &pos
))
361 v_message (msgid
, ap
);
366 cpp_pedwarn
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
368 #ifndef ANSI_PROTOTYPES
374 VA_START (ap
, msgid
);
376 #ifndef ANSI_PROTOTYPES
377 pfile
= va_arg (ap
, cpp_reader
*);
378 msgid
= va_arg (ap
, const char *);
381 if (_cpp_begin_message (pfile
, PEDWARN
, NULL
, 0))
382 v_message (msgid
, ap
);
387 cpp_pedwarn_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
388 const char *msgid
, ...))
390 #ifndef ANSI_PROTOTYPES
399 VA_START (ap
, msgid
);
401 #ifndef ANSI_PROTOTYPES
402 pfile
= va_arg (ap
, cpp_reader
*);
403 line
= va_arg (ap
, int);
404 column
= va_arg (ap
, int);
405 msgid
= va_arg (ap
, const char *);
410 if (_cpp_begin_message (pfile
, PEDWARN
, NULL
, &pos
))
411 v_message (msgid
, ap
);
415 /* Report a warning (or an error if pedantic_errors)
416 giving specified file name and line number, not current. */
419 cpp_pedwarn_with_file_and_line
VPARAMS ((cpp_reader
*pfile
,
420 const char *file
, int line
, int col
,
421 const char *msgid
, ...))
423 #ifndef ANSI_PROTOTYPES
433 VA_START (ap
, msgid
);
435 #ifndef ANSI_PROTOTYPES
436 pfile
= va_arg (ap
, cpp_reader
*);
437 file
= va_arg (ap
, const char *);
438 line
= va_arg (ap
, int);
439 col
= va_arg (ap
, int);
440 msgid
= va_arg (ap
, const char *);
445 if (_cpp_begin_message (pfile
, PEDWARN
, file
, &pos
))
446 v_message (msgid
, ap
);
450 /* Print an error message not associated with a file. */
452 cpp_notice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
454 #ifndef ANSI_PROTOTYPES
460 VA_START (ap
, msgid
);
462 #ifndef ANSI_PROTOTYPES
463 pfile
= va_arg (ap
, cpp_reader
*);
464 msgid
= va_arg (ap
, const char *);
467 if (pfile
->errors
< CPP_FATAL_LIMIT
)
470 vfprintf (stderr
, _(msgid
), ap
);
477 cpp_notice_from_errno (pfile
, name
)
483 cpp_notice (pfile
, "%s: %s", name
, xstrerror (errno
));