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,
35 static void v_message
PARAMS ((cpp_reader
*, int,
37 unsigned int, unsigned int,
38 const char *, va_list));
40 /* Print the file names and line numbers of the #include
41 commands which led to the current file. */
44 print_containing_files (pfile
, ip
)
50 /* If stack of files hasn't changed since we last printed
51 this info, don't repeat it. */
52 if (pfile
->input_stack_listing_current
)
55 /* Find the other, outer source files. */
56 for (ip
= CPP_PREV_BUFFER (ip
); ip
!= NULL
; ip
= CPP_PREV_BUFFER (ip
))
61 /* N.B. The current line in each outer source file is one
62 greater than the line of the #include, so we must
63 subtract one to correct for that. */
64 fprintf (stderr
, _("In file included from %s:%u"),
65 ip
->nominal_fname
, CPP_BUF_LINE (ip
) - 1);
68 /* Translators note: this message is used in conjunction
69 with "In file included from %s:%ld" and some other
70 tricks. We want something like this:
72 | In file included from sys/select.h:123,
73 | from sys/types.h:234,
75 | bits/select.h:45: <error message here>
77 with all the "from"s lined up.
78 The trailing comma is at the beginning of this message,
79 and the trailing colon is not translated. */
80 fprintf (stderr
, _(",\n from %s:%u"),
81 ip
->nominal_fname
, CPP_BUF_LINE (ip
) - 1);
84 fputs (":\n", stderr
);
86 /* Record we have printed the status as of this time. */
87 pfile
->input_stack_listing_current
= 1;
91 print_file_and_line (filename
, line
, column
)
93 unsigned int line
, column
;
95 if (filename
== 0 || *filename
== '\0')
98 fputs (_("<command line>: "), stderr
);
100 fprintf (stderr
, "%s:%u:%u: ", filename
, line
, column
);
102 fprintf (stderr
, "%s:%u: ", filename
, line
);
105 /* IS_ERROR is 3 for ICE, 2 for merely "fatal" error,
106 1 for error, 0 for warning. */
109 v_message (pfile
, is_error
, file
, line
, col
, msg
, ap
)
118 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
123 file
= ip
->nominal_fname
;
125 line
= _cpp_get_line (pfile
, &col
);
126 print_containing_files (pfile
, ip
);
127 print_file_and_line (file
, line
,
128 CPP_OPTION (pfile
, show_column
) ? col
: 0);
131 fprintf (stderr
, "%s: ", progname
);
136 if (! CPP_OPTION (pfile
, warnings_are_errors
))
138 fprintf (stderr
, _("warning: "));
141 /* else fall through */
143 if (pfile
->errors
< CPP_FATAL_LIMIT
)
147 pfile
->errors
= CPP_FATAL_LIMIT
;
150 fprintf (stderr
, _("internal error: "));
151 pfile
->errors
= CPP_FATAL_LIMIT
;
154 cpp_ice (pfile
, "bad is_error(%d) in v_message", is_error
);
157 vfprintf (stderr
, _(msg
), ap
);
161 /* Exported interface. */
163 /* For reporting internal errors. Prints "internal error: " for you,
164 otherwise identical to cpp_fatal. */
167 cpp_ice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
169 #ifndef ANSI_PROTOTYPES
175 VA_START (ap
, msgid
);
177 #ifndef ANSI_PROTOTYPES
178 pfile
= va_arg (ap
, cpp_reader
*);
179 msgid
= va_arg (ap
, const char *);
182 v_message (pfile
, 3, NULL
, 0, 0, msgid
, ap
);
186 /* Same as cpp_error, except we consider the error to be "fatal",
187 such as inconsistent options. I.e. there is little point in continuing.
188 (We do not exit, to support use of cpplib as a library.
189 Instead, it is the caller's responsibility to check
193 cpp_fatal
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
195 #ifndef ANSI_PROTOTYPES
201 VA_START (ap
, msgid
);
203 #ifndef ANSI_PROTOTYPES
204 pfile
= va_arg (ap
, cpp_reader
*);
205 msgid
= va_arg (ap
, const char *);
208 v_message (pfile
, 2, NULL
, 0, 0, msgid
, ap
);
213 cpp_error
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
215 #ifndef ANSI_PROTOTYPES
223 #ifndef ANSI_PROTOTYPES
224 pfile
= va_arg (ap
, cpp_reader
*);
225 msgid
= va_arg (ap
, const char *);
228 if (CPP_OPTION (pfile
, inhibit_errors
))
231 v_message (pfile
, 1, NULL
, 0, 0, msgid
, ap
);
236 cpp_error_with_line
VPARAMS ((cpp_reader
*pfile
, int line
, int column
,
237 const char *msgid
, ...))
239 #ifndef ANSI_PROTOTYPES
247 VA_START (ap
, msgid
);
249 #ifndef ANSI_PROTOTYPES
250 pfile
= va_arg (ap
, cpp_reader
*);
251 line
= va_arg (ap
, int);
252 column
= va_arg (ap
, int);
253 msgid
= va_arg (ap
, const char *);
256 if (CPP_OPTION (pfile
, inhibit_errors
))
259 v_message (pfile
, 1, NULL
, line
, column
, msgid
, ap
);
263 /* Error including a message from `errno'. */
265 cpp_error_from_errno (pfile
, name
)
269 cpp_error (pfile
, "%s: %s", name
, xstrerror (errno
));
273 cpp_warning
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
275 #ifndef ANSI_PROTOTYPES
281 VA_START (ap
, msgid
);
283 #ifndef ANSI_PROTOTYPES
284 pfile
= va_arg (ap
, cpp_reader
*);
285 msgid
= va_arg (ap
, const char *);
288 if (CPP_OPTION (pfile
, inhibit_warnings
))
291 v_message (pfile
, 0, NULL
, 0, 0, msgid
, ap
);
296 cpp_warning_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
297 const char *msgid
, ...))
299 #ifndef ANSI_PROTOTYPES
307 VA_START (ap
, msgid
);
309 #ifndef ANSI_PROTOTYPES
310 pfile
= va_arg (ap
, cpp_reader
*);
311 line
= va_arg (ap
, int);
312 column
= va_arg (ap
, int);
313 msgid
= va_arg (ap
, const char *);
316 if (CPP_OPTION (pfile
, inhibit_warnings
))
319 v_message (pfile
, 0, NULL
, line
, column
, msgid
, ap
);
324 cpp_pedwarn
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
326 #ifndef ANSI_PROTOTYPES
332 VA_START (ap
, msgid
);
334 #ifndef ANSI_PROTOTYPES
335 pfile
= va_arg (ap
, cpp_reader
*);
336 msgid
= va_arg (ap
, const char *);
339 if (CPP_OPTION (pfile
, pedantic_errors
)
340 ? CPP_OPTION (pfile
, inhibit_errors
)
341 : CPP_OPTION (pfile
, inhibit_warnings
))
344 v_message (pfile
, CPP_OPTION (pfile
, pedantic_errors
),
345 NULL
, 0, 0, msgid
, ap
);
350 cpp_pedwarn_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
351 const char *msgid
, ...))
353 #ifndef ANSI_PROTOTYPES
361 VA_START (ap
, msgid
);
363 #ifndef ANSI_PROTOTYPES
364 pfile
= va_arg (ap
, cpp_reader
*);
365 line
= va_arg (ap
, int);
366 column
= va_arg (ap
, int);
367 msgid
= va_arg (ap
, const char *);
370 if (CPP_OPTION (pfile
, pedantic_errors
)
371 ? CPP_OPTION (pfile
, inhibit_errors
)
372 : CPP_OPTION (pfile
, inhibit_warnings
))
375 v_message (pfile
, CPP_OPTION (pfile
, pedantic_errors
),
376 NULL
, line
, column
, msgid
, ap
);
380 /* Report a warning (or an error if pedantic_errors)
381 giving specified file name and line number, not current. */
384 cpp_pedwarn_with_file_and_line
VPARAMS ((cpp_reader
*pfile
,
385 const char *file
, int line
, int col
,
386 const char *msgid
, ...))
388 #ifndef ANSI_PROTOTYPES
397 VA_START (ap
, msgid
);
399 #ifndef ANSI_PROTOTYPES
400 pfile
= va_arg (ap
, cpp_reader
*);
401 file
= va_arg (ap
, const char *);
402 line
= va_arg (ap
, int);
403 col
= va_arg (ap
, int);
404 msgid
= va_arg (ap
, const char *);
407 if (CPP_OPTION (pfile
, pedantic_errors
)
408 ? CPP_OPTION (pfile
, inhibit_errors
)
409 : CPP_OPTION (pfile
, inhibit_warnings
))
412 v_message (pfile
, CPP_OPTION (pfile
, pedantic_errors
),
413 file
, line
, col
, msgid
, ap
);
417 /* Print an error message not associated with a file. */
419 cpp_notice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
421 #ifndef ANSI_PROTOTYPES
427 VA_START (ap
, msgid
);
429 #ifndef ANSI_PROTOTYPES
430 pfile
= va_arg (ap
, cpp_reader
*);
431 msgid
= va_arg (ap
, const char *);
434 if (pfile
->errors
< CPP_FATAL_LIMIT
)
437 vfprintf (stderr
, _(msgid
), ap
);
444 cpp_notice_from_errno (pfile
, name
)
450 cpp_notice (pfile
, "%s: %s", name
, xstrerror (errno
));