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! */
33 static void print_containing_files
PARAMS ((cpp_reader
*, cpp_buffer
*));
34 static void print_file_and_line
PARAMS ((const char *, unsigned int,
36 static void v_message
PARAMS ((cpp_reader
*, int,
38 unsigned int, unsigned int,
39 const char *, va_list));
41 /* Print the file names and line numbers of the #include
42 commands which led to the current file. */
45 print_containing_files (pfile
, ip
)
51 /* If stack of files hasn't changed since we last printed
52 this info, don't repeat it. */
53 if (pfile
->input_stack_listing_current
)
56 /* Find the other, outer source files. */
57 for (ip
= CPP_PREV_BUFFER (ip
); ip
!= NULL
; ip
= CPP_PREV_BUFFER (ip
))
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,
73 bits/select.h:45: <error message here>
75 The trailing comma is at the beginning of this message,
76 and the trailing colon is not translated. */
77 fprintf (stderr
, _(",\n from %s:%u"),
78 ip
->nominal_fname
, CPP_BUF_LINE (ip
));
81 fputs (":\n", stderr
);
83 /* Record we have printed the status as of this time. */
84 pfile
->input_stack_listing_current
= 1;
88 print_file_and_line (filename
, line
, column
)
90 unsigned int line
, column
;
92 if (filename
== 0 || *filename
== '\0')
95 fputs (_("<command line>: "), stderr
);
97 fprintf (stderr
, "%s:%u:%u: ", filename
, line
, column
);
99 fprintf (stderr
, "%s:%u: ", filename
, line
);
102 /* IS_ERROR is 3 for ICE, 2 for merely "fatal" error,
103 1 for error, 0 for warning. */
106 v_message (pfile
, is_error
, file
, line
, col
, msg
, ap
)
115 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
120 file
= ip
->nominal_fname
;
123 line
= CPP_BUF_LINE (ip
);
124 col
= CPP_BUF_COL (ip
);
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 fprintf (stderr
, _("warning: "));
139 if (pfile
->errors
< CPP_FATAL_LIMIT
)
143 pfile
->errors
= CPP_FATAL_LIMIT
;
146 fprintf (stderr
, _("internal error: "));
147 pfile
->errors
= CPP_FATAL_LIMIT
;
150 cpp_ice (pfile
, "bad is_error(%d) in v_message", is_error
);
153 vfprintf (stderr
, _(msg
), ap
);
157 /* Exported interface. */
159 /* For reporting internal errors. Prints "internal error: " for you,
160 otherwise identical to cpp_fatal. */
163 cpp_ice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
165 #ifndef ANSI_PROTOTYPES
171 VA_START (ap
, msgid
);
173 #ifndef ANSI_PROTOTYPES
174 pfile
= va_arg (ap
, cpp_reader
*);
175 msgid
= va_arg (ap
, const char *);
178 v_message (pfile
, 3, NULL
, 0, 0, msgid
, ap
);
182 /* Same as cpp_error, except we consider the error to be "fatal",
183 such as inconsistent options. I.e. there is little point in continuing.
184 (We do not exit, to support use of cpplib as a library.
185 Instead, it is the caller's responsibility to check
189 cpp_fatal
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
191 #ifndef ANSI_PROTOTYPES
197 VA_START (ap
, msgid
);
199 #ifndef ANSI_PROTOTYPES
200 pfile
= va_arg (ap
, cpp_reader
*);
201 msgid
= va_arg (ap
, const char *);
204 v_message (pfile
, 2, NULL
, 0, 0, msgid
, ap
);
209 cpp_error
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
211 #ifndef ANSI_PROTOTYPES
219 #ifndef ANSI_PROTOTYPES
220 pfile
= va_arg (ap
, cpp_reader
*);
221 msgid
= va_arg (ap
, const char *);
224 if (CPP_OPTION (pfile
, inhibit_errors
))
227 v_message (pfile
, 1, NULL
, 0, 0, msgid
, ap
);
232 cpp_error_with_line
VPARAMS ((cpp_reader
*pfile
, int line
, int column
,
233 const char *msgid
, ...))
235 #ifndef ANSI_PROTOTYPES
243 VA_START (ap
, msgid
);
245 #ifndef ANSI_PROTOTYPES
246 pfile
= va_arg (ap
, cpp_reader
*);
247 line
= va_arg (ap
, int);
248 column
= va_arg (ap
, int);
249 msgid
= va_arg (ap
, const char *);
252 if (CPP_OPTION (pfile
, inhibit_errors
))
255 v_message (pfile
, 1, NULL
, line
, column
, msgid
, ap
);
259 /* Error including a message from `errno'. */
261 cpp_error_from_errno (pfile
, name
)
265 cpp_error (pfile
, "%s: %s", name
, xstrerror (errno
));
269 cpp_warning
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
271 #ifndef ANSI_PROTOTYPES
277 VA_START (ap
, msgid
);
279 #ifndef ANSI_PROTOTYPES
280 pfile
= va_arg (ap
, cpp_reader
*);
281 msgid
= va_arg (ap
, const char *);
284 if (CPP_OPTION (pfile
, inhibit_warnings
))
287 v_message (pfile
, 0, NULL
, 0, 0, msgid
, ap
);
292 cpp_warning_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
293 const char *msgid
, ...))
295 #ifndef ANSI_PROTOTYPES
303 VA_START (ap
, msgid
);
305 #ifndef ANSI_PROTOTYPES
306 pfile
= va_arg (ap
, cpp_reader
*);
307 line
= va_arg (ap
, int);
308 column
= va_arg (ap
, int);
309 msgid
= va_arg (ap
, const char *);
312 if (CPP_OPTION (pfile
, inhibit_warnings
))
315 v_message (pfile
, 0, NULL
, line
, column
, msgid
, ap
);
320 cpp_pedwarn
VPARAMS ((cpp_reader
* pfile
, const char *msgid
, ...))
322 #ifndef ANSI_PROTOTYPES
328 VA_START (ap
, msgid
);
330 #ifndef ANSI_PROTOTYPES
331 pfile
= va_arg (ap
, cpp_reader
*);
332 msgid
= va_arg (ap
, const char *);
335 if (CPP_OPTION (pfile
, pedantic_errors
)
336 ? CPP_OPTION (pfile
, inhibit_errors
)
337 : CPP_OPTION (pfile
, inhibit_warnings
))
340 v_message (pfile
, CPP_OPTION (pfile
, pedantic_errors
),
341 NULL
, 0, 0, msgid
, ap
);
346 cpp_pedwarn_with_line
VPARAMS ((cpp_reader
* pfile
, int line
, int column
,
347 const char *msgid
, ...))
349 #ifndef ANSI_PROTOTYPES
357 VA_START (ap
, msgid
);
359 #ifndef ANSI_PROTOTYPES
360 pfile
= va_arg (ap
, cpp_reader
*);
361 line
= va_arg (ap
, int);
362 column
= va_arg (ap
, int);
363 msgid
= va_arg (ap
, const char *);
366 if (CPP_OPTION (pfile
, pedantic_errors
)
367 ? CPP_OPTION (pfile
, inhibit_errors
)
368 : CPP_OPTION (pfile
, inhibit_warnings
))
371 v_message (pfile
, CPP_OPTION (pfile
, pedantic_errors
),
372 NULL
, line
, column
, msgid
, ap
);
376 /* Report a warning (or an error if pedantic_errors)
377 giving specified file name and line number, not current. */
380 cpp_pedwarn_with_file_and_line
VPARAMS ((cpp_reader
*pfile
,
381 const char *file
, int line
, int col
,
382 const char *msgid
, ...))
384 #ifndef ANSI_PROTOTYPES
393 VA_START (ap
, msgid
);
395 #ifndef ANSI_PROTOTYPES
396 pfile
= va_arg (ap
, cpp_reader
*);
397 file
= va_arg (ap
, const char *);
398 line
= va_arg (ap
, int);
399 col
= va_arg (ap
, int);
400 msgid
= va_arg (ap
, const char *);
403 if (CPP_OPTION (pfile
, pedantic_errors
)
404 ? CPP_OPTION (pfile
, inhibit_errors
)
405 : CPP_OPTION (pfile
, inhibit_warnings
))
408 v_message (pfile
, CPP_OPTION (pfile
, pedantic_errors
),
409 file
, line
, col
, msgid
, ap
);
413 /* Print an error message not associated with a file. */
415 cpp_notice
VPARAMS ((cpp_reader
*pfile
, const char *msgid
, ...))
417 #ifndef ANSI_PROTOTYPES
423 VA_START (ap
, msgid
);
425 #ifndef ANSI_PROTOTYPES
426 pfile
= va_arg (ap
, cpp_reader
*);
427 msgid
= va_arg (ap
, const char *);
430 if (pfile
->errors
< CPP_FATAL_LIMIT
)
433 vfprintf (stderr
, _(msgid
), ap
);
440 cpp_notice_from_errno (pfile
, name
)
446 cpp_notice (pfile
, "%s: %s", name
, xstrerror (errno
));