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 cpp_print_containing_files
PARAMS ((cpp_reader
*, cpp_buffer
*));
32 static void cpp_print_file_and_line
PARAMS ((const char *, long, long));
33 static void v_cpp_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 cpp_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
);
54 ip
!= CPP_NULL_BUFFER (pfile
);
55 ip
= CPP_PREV_BUFFER (ip
))
56 if (ip
->fname
!= NULL
)
59 cpp_buf_line_and_col (ip
, &line
, NULL
);
63 fprintf (stderr
, _("In file included from %s:%ld"),
64 ip
->nominal_fname
, line
);
67 /* Translators note: this message is used in conjunction
68 with "In file included from %s:%ld" and some other
69 tricks. We want something like this:
71 In file included from sys/select.h:123,
74 bits/select.h:45: <error message here>
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:%ld"),
79 ip
->nominal_fname
, line
);
82 fputs (":\n", stderr
);
84 /* Record we have printed the status as of this time. */
85 pfile
->input_stack_listing_current
= 1;
89 cpp_print_file_and_line (filename
, line
, column
)
93 if (filename
== 0 || *filename
== '\0')
96 fputs (_("<command line>: "), stderr
);
98 fprintf (stderr
, "%s:%ld:%ld: ", filename
, line
, column
);
100 fprintf (stderr
, "%s:%ld: ", filename
, line
);
103 /* IS_ERROR is 3 for ICE, 2 for merely "fatal" error,
104 1 for error, 0 for warning. */
107 v_cpp_message (pfile
, is_error
, file
, line
, col
, msg
, ap
)
116 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
121 file
= ip
->nominal_fname
;
123 cpp_buf_line_and_col (ip
, &line
, &col
);
125 cpp_print_containing_files (pfile
, ip
);
126 cpp_print_file_and_line (file
, line
, col
);
129 fprintf (stderr
, "%s: ", progname
);
134 fprintf (stderr
, _("warning: "));
137 if (pfile
->errors
< CPP_FATAL_LIMIT
)
141 pfile
->errors
= CPP_FATAL_LIMIT
;
144 fprintf (stderr
, _("internal error: "));
145 pfile
->errors
= CPP_FATAL_LIMIT
;
148 cpp_ice (pfile
, "bad is_error(%d) in v_cpp_message", is_error
);
151 vfprintf (stderr
, _(msg
), ap
);
155 /* Exported interface. */
157 /* For reporting internal errors. Prints "internal error: " for you,
158 otherwise identical to cpp_fatal. */
161 cpp_ice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
163 #ifndef ANSI_PROTOTYPES
169 VA_START (ap
, msgid
);
171 #ifndef ANSI_PROTOTYPES
172 pfile
= va_arg (ap
, cpp_reader
*);
173 msgid
= va_arg (ap
, const char *);
176 v_cpp_message (pfile
, 3, NULL
, -1, -1, msgid
, ap
);
180 /* Same as cpp_error, except we consider the error to be "fatal",
181 such as inconsistent options. I.e. there is little point in continuing.
182 (We do not exit, to support use of cpplib as a library.
183 Instead, it is the caller's responsibility to check
187 cpp_fatal
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
189 #ifndef ANSI_PROTOTYPES
195 VA_START (ap
, msgid
);
197 #ifndef ANSI_PROTOTYPES
198 pfile
= va_arg (ap
, cpp_reader
*);
199 msgid
= va_arg (ap
, const char *);
202 v_cpp_message (pfile
, 2, NULL
, -1, -1, msgid
, ap
);
207 cpp_error
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
209 #ifndef ANSI_PROTOTYPES
217 #ifndef ANSI_PROTOTYPES
218 pfile
= va_arg (ap
, cpp_reader
*);
219 msgid
= va_arg (ap
, const char *);
222 if (CPP_OPTIONS (pfile
)->inhibit_errors
)
225 v_cpp_message (pfile
, 1, NULL
, -1, -1, msgid
, ap
);
230 cpp_error_with_line
VPARAMS ((cpp_reader
*pfile
, int line
, int column
,
231 const char *msgid
, ...))
233 #ifndef ANSI_PROTOTYPES
241 VA_START (ap
, msgid
);
243 #ifndef ANSI_PROTOTYPES
244 pfile
= va_arg (ap
, cpp_reader
*);
245 line
= va_arg (ap
, int);
246 column
= va_arg (ap
, int);
247 msgid
= va_arg (ap
, const char *);
250 if (CPP_OPTIONS (pfile
)->inhibit_errors
)
253 v_cpp_message (pfile
, 1, NULL
, line
, column
, msgid
, ap
);
257 /* Error including a message from `errno'. */
259 cpp_error_from_errno (pfile
, name
)
263 cpp_error (pfile
, "%s: %s", name
, xstrerror (errno
));
267 cpp_warning
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
269 #ifndef ANSI_PROTOTYPES
275 VA_START (ap
, msgid
);
277 #ifndef ANSI_PROTOTYPES
278 pfile
= va_arg (ap
, cpp_reader
*);
279 msgid
= va_arg (ap
, const char *);
282 if (CPP_OPTIONS (pfile
)->inhibit_warnings
)
285 v_cpp_message (pfile
, 0, NULL
, -1, -1, msgid
, ap
);
290 cpp_warning_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
291 const char *msgid
, ...))
293 #ifndef ANSI_PROTOTYPES
301 VA_START (ap
, msgid
);
303 #ifndef ANSI_PROTOTYPES
304 pfile
= va_arg (ap
, cpp_reader
*);
305 line
= va_arg (ap
, int);
306 column
= va_arg (ap
, int);
307 msgid
= va_arg (ap
, const char *);
310 if (CPP_OPTIONS (pfile
)->inhibit_warnings
)
313 v_cpp_message (pfile
, 0, NULL
, line
, column
, msgid
, ap
);
318 cpp_pedwarn
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
320 #ifndef ANSI_PROTOTYPES
326 VA_START (ap
, msgid
);
328 #ifndef ANSI_PROTOTYPES
329 pfile
= va_arg (ap
, cpp_reader
*);
330 msgid
= va_arg (ap
, const char *);
333 if (CPP_OPTIONS (pfile
)->pedantic_errors
334 ? CPP_OPTIONS (pfile
)->inhibit_errors
335 : CPP_OPTIONS (pfile
)->inhibit_warnings
)
338 v_cpp_message (pfile
, CPP_OPTIONS (pfile
)->pedantic_errors
,
339 NULL
, -1, -1, msgid
, ap
);
344 cpp_pedwarn_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
345 const char *msgid
, ...))
347 #ifndef ANSI_PROTOTYPES
355 VA_START (ap
, msgid
);
357 #ifndef ANSI_PROTOTYPES
358 pfile
= va_arg (ap
, cpp_reader
*);
359 line
= va_arg (ap
, int);
360 column
= va_arg (ap
, int);
361 msgid
= va_arg (ap
, const char *);
364 if (CPP_OPTIONS (pfile
)->pedantic_errors
365 ? CPP_OPTIONS (pfile
)->inhibit_errors
366 : CPP_OPTIONS (pfile
)->inhibit_warnings
)
369 v_cpp_message (pfile
, CPP_OPTIONS (pfile
)->pedantic_errors
,
370 NULL
, line
, column
, msgid
, ap
);
374 /* Report a warning (or an error if pedantic_errors)
375 giving specified file name and line number, not current. */
378 cpp_pedwarn_with_file_and_line
VPARAMS ((cpp_reader
*pfile
,
379 const char *file
, int line
, int col
,
380 const char *msgid
, ...))
382 #ifndef ANSI_PROTOTYPES
391 VA_START (ap
, msgid
);
393 #ifndef ANSI_PROTOTYPES
394 pfile
= va_arg (ap
, cpp_reader
*);
395 file
= va_arg (ap
, const char *);
396 line
= va_arg (ap
, int);
397 col
= va_arg (ap
, int);
398 msgid
= va_arg (ap
, const char *);
401 if (CPP_OPTIONS (pfile
)->pedantic_errors
402 ? CPP_OPTIONS (pfile
)->inhibit_errors
403 : CPP_OPTIONS (pfile
)->inhibit_warnings
)
406 v_cpp_message (pfile
, CPP_OPTIONS (pfile
)->pedantic_errors
,
407 file
, line
, col
, msgid
, ap
);
411 /* Print an error message not associated with a file. */
413 cpp_notice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
415 #ifndef ANSI_PROTOTYPES
421 VA_START (ap
, msgid
);
423 #ifndef ANSI_PROTOTYPES
424 pfile
= va_arg (ap
, cpp_reader
*);
425 msgid
= va_arg (ap
, const char *);
428 if (pfile
->errors
< CPP_FATAL_LIMIT
)
431 vfprintf (stderr
, _(msgid
), ap
);
438 cpp_notice_from_errno (pfile
, name
)
442 cpp_notice (pfile
, "%s: %s", name
, xstrerror (errno
));