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_reader
*, cpp_buffer
*));
33 static void print_file_and_line
PARAMS ((const char *, unsigned int,
36 #define v_message(msgid, ap) \
37 do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
39 /* Print the file names and line numbers of the #include
40 commands which led to the current file. */
43 print_containing_files (pfile
, ip
)
49 /* If stack of files hasn't changed since we last printed
50 this info, don't repeat it. */
51 if (pfile
->input_stack_listing_current
)
54 /* Find the other, outer source files. */
55 for (ip
= CPP_PREV_BUFFER (ip
); ip
!= NULL
; ip
= CPP_PREV_BUFFER (ip
))
60 /* The current line in each outer source file is now the
61 same as the line of the #include. */
62 fprintf (stderr
, _("In file included from %s:%u"),
63 ip
->nominal_fname
, CPP_BUF_LINE (ip
));
66 /* Translators note: this message is used in conjunction
67 with "In file included from %s:%ld" and some other
68 tricks. We want something like this:
70 | In file included from sys/select.h:123,
71 | from sys/types.h:234,
73 | bits/select.h:45: <error message here>
75 with all the "from"s lined up.
76 The trailing comma is at the beginning of this message,
77 and the trailing colon is not translated. */
78 fprintf (stderr
, _(",\n from %s:%u"),
79 ip
->nominal_fname
, CPP_BUF_LINE (ip
) - 1);
82 fputs (":\n", stderr
);
84 /* Record we have printed the status as of this time. */
85 pfile
->input_stack_listing_current
= 1;
89 print_file_and_line (filename
, line
, col
)
91 unsigned int line
, col
;
93 if (filename
== 0 || *filename
== '\0')
97 fprintf (stderr
, "%s: ", filename
);
99 fprintf (stderr
, "%s:%u: ", filename
, line
);
101 fprintf (stderr
, "%s:%u:%u: ", filename
, line
, col
);
104 /* Set up for an error message: print the file and line, bump the error
106 If it returns 0, this error has been suppressed. */
109 _cpp_begin_message (pfile
, code
, file
, pos
)
111 enum error_type code
;
113 const cpp_lexer_pos
*pos
;
115 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
121 if (CPP_IN_SYSTEM_HEADER (pfile
)
122 && ! CPP_OPTION (pfile
, warn_system_headers
))
124 if (! CPP_OPTION (pfile
, warnings_are_errors
))
126 if (CPP_OPTION (pfile
, inhibit_warnings
))
132 if (CPP_OPTION (pfile
, inhibit_errors
))
134 if (pfile
->errors
< CPP_FATAL_LIMIT
)
140 if (CPP_IN_SYSTEM_HEADER (pfile
)
141 && ! CPP_OPTION (pfile
, warn_system_headers
))
143 if (! CPP_OPTION (pfile
, pedantic_errors
))
145 if (CPP_OPTION (pfile
, inhibit_warnings
))
151 if (CPP_OPTION (pfile
, inhibit_errors
))
153 if (pfile
->errors
< CPP_FATAL_LIMIT
)
159 if (CPP_OPTION (pfile
, inhibit_errors
))
161 if (pfile
->errors
< CPP_FATAL_LIMIT
)
164 /* Fatal errors cannot be inhibited. */
166 pfile
->errors
= CPP_FATAL_LIMIT
;
169 fprintf (stderr
, _("internal error: "));
170 pfile
->errors
= CPP_FATAL_LIMIT
;
177 file
= ip
->nominal_fname
;
179 pos
= cpp_get_line (pfile
);
180 print_containing_files (pfile
, ip
);
181 print_file_and_line (file
, pos
->line
,
182 CPP_OPTION (pfile
, show_column
) ? pos
->col
: 0);
185 fprintf (stderr
, "%s: ", progname
);
188 fputs (_("warning: "), stderr
);
193 /* Exported interface. */
195 /* For reporting internal errors. Prints "internal error: " for you,
196 otherwise identical to cpp_fatal. */
199 cpp_ice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
201 #ifndef ANSI_PROTOTYPES
207 VA_START (ap
, msgid
);
209 #ifndef ANSI_PROTOTYPES
210 pfile
= va_arg (ap
, cpp_reader
*);
211 msgid
= va_arg (ap
, const char *);
214 if (_cpp_begin_message (pfile
, ICE
, NULL
, 0))
215 v_message (msgid
, ap
);
219 /* Same as cpp_error, except we consider the error to be "fatal",
220 such as inconsistent options. I.e. there is little point in continuing.
221 (We do not exit, to support use of cpplib as a library.
222 Instead, it is the caller's responsibility to check
226 cpp_fatal
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
228 #ifndef ANSI_PROTOTYPES
234 VA_START (ap
, msgid
);
236 #ifndef ANSI_PROTOTYPES
237 pfile
= va_arg (ap
, cpp_reader
*);
238 msgid
= va_arg (ap
, const char *);
241 if (_cpp_begin_message (pfile
, FATAL
, NULL
, 0))
242 v_message (msgid
, ap
);
247 cpp_error
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
249 #ifndef ANSI_PROTOTYPES
257 #ifndef ANSI_PROTOTYPES
258 pfile
= va_arg (ap
, cpp_reader
*);
259 msgid
= va_arg (ap
, const char *);
262 if (_cpp_begin_message (pfile
, ERROR
, NULL
, 0))
263 v_message (msgid
, ap
);
268 cpp_error_with_line
VPARAMS ((cpp_reader
*pfile
, int line
, int column
,
269 const char *msgid
, ...))
271 #ifndef ANSI_PROTOTYPES
280 VA_START (ap
, msgid
);
282 #ifndef ANSI_PROTOTYPES
283 pfile
= va_arg (ap
, cpp_reader
*);
284 line
= va_arg (ap
, int);
285 column
= va_arg (ap
, int);
286 msgid
= va_arg (ap
, const char *);
291 if (_cpp_begin_message (pfile
, ERROR
, NULL
, &pos
))
292 v_message (msgid
, ap
);
296 /* Error including a message from `errno'. */
298 cpp_error_from_errno (pfile
, name
)
302 cpp_error (pfile
, "%s: %s", name
, xstrerror (errno
));
306 cpp_warning
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
308 #ifndef ANSI_PROTOTYPES
314 VA_START (ap
, msgid
);
316 #ifndef ANSI_PROTOTYPES
317 pfile
= va_arg (ap
, cpp_reader
*);
318 msgid
= va_arg (ap
, const char *);
321 if (_cpp_begin_message (pfile
, WARNING
, NULL
, 0))
322 v_message (msgid
, ap
);
327 cpp_warning_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
328 const char *msgid
, ...))
330 #ifndef ANSI_PROTOTYPES
339 VA_START (ap
, msgid
);
341 #ifndef ANSI_PROTOTYPES
342 pfile
= va_arg (ap
, cpp_reader
*);
343 line
= va_arg (ap
, int);
344 column
= va_arg (ap
, int);
345 msgid
= va_arg (ap
, const char *);
350 if (_cpp_begin_message (pfile
, WARNING
, NULL
, &pos
))
351 v_message (msgid
, ap
);
356 cpp_pedwarn
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
358 #ifndef ANSI_PROTOTYPES
364 VA_START (ap
, msgid
);
366 #ifndef ANSI_PROTOTYPES
367 pfile
= va_arg (ap
, cpp_reader
*);
368 msgid
= va_arg (ap
, const char *);
371 if (_cpp_begin_message (pfile
, PEDWARN
, NULL
, 0))
372 v_message (msgid
, ap
);
377 cpp_pedwarn_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
378 const char *msgid
, ...))
380 #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 *);
400 if (_cpp_begin_message (pfile
, PEDWARN
, NULL
, &pos
))
401 v_message (msgid
, ap
);
405 /* Report a warning (or an error if pedantic_errors)
406 giving specified file name and line number, not current. */
409 cpp_pedwarn_with_file_and_line
VPARAMS ((cpp_reader
*pfile
,
410 const char *file
, int line
, int col
,
411 const char *msgid
, ...))
413 #ifndef ANSI_PROTOTYPES
423 VA_START (ap
, msgid
);
425 #ifndef ANSI_PROTOTYPES
426 pfile
= va_arg (ap
, cpp_reader
*);
427 file
= va_arg (ap
, const char *);
428 line
= va_arg (ap
, int);
429 col
= va_arg (ap
, int);
430 msgid
= va_arg (ap
, const char *);
435 if (_cpp_begin_message (pfile
, PEDWARN
, file
, &pos
))
436 v_message (msgid
, ap
);
440 /* Print an error message not associated with a file. */
442 cpp_notice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
444 #ifndef ANSI_PROTOTYPES
450 VA_START (ap
, msgid
);
452 #ifndef ANSI_PROTOTYPES
453 pfile
= va_arg (ap
, cpp_reader
*);
454 msgid
= va_arg (ap
, const char *);
457 if (pfile
->errors
< CPP_FATAL_LIMIT
)
460 vfprintf (stderr
, _(msgid
), ap
);
467 cpp_notice_from_errno (pfile
, name
)
473 cpp_notice (pfile
, "%s: %s", name
, xstrerror (errno
));