1 /* Default error handlers for CPP Library.
2 Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994.
4 Based on CCCP program by by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding! */
28 /* This defines "errno" properly for VMS, and gives us EACCES. */
38 extern const char *const sys_errlist[];
40 extern char *sys_errlist[];
42 #else /* HAVE_STERRROR */
46 char *strerror (int,...);
49 /* Print the file names and line numbers of the #include
50 commands which led to the current file. */
53 cpp_print_containing_files (pfile)
60 /* If stack of files hasn't changed since we last printed
61 this info, don't repeat it. */
62 if (pfile->input_stack_listing_current)
65 ip = cpp_file_buffer (pfile);
67 /* Give up if we don't find a source file. */
71 /* Find the other, outer source files. */
72 while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
75 cpp_buf_line_and_col (ip, &line, &col);
76 if (ip->fname != NULL)
81 fprintf (stderr, "In file included");
84 fprintf (stderr, ",\n ");
87 /* start-sanitize-mpw */
89 fprintf (stderr, " File \"%s\"; Line %d # ", ip->nominal_fname, line);
91 /* end-sanitize-mpw */
92 fprintf (stderr, " from %s:%d", ip->nominal_fname, line);
93 /* start-sanitize-mpw */
95 /* end-sanitize-mpw */
98 fprintf (stderr, ":\n");
100 /* Record we have printed the status as of this time. */
101 pfile->input_stack_listing_current = 1;
105 cpp_print_file_and_line (pfile)
108 cpp_buffer *ip = cpp_file_buffer (pfile);
113 cpp_buf_line_and_col (ip, &line, &col);
114 if (pfile->show_column)
115 fprintf (stderr, "%s:%d:%d: ", ip->nominal_fname, line, col);
117 fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
122 cpp_error (pfile, msg, arg1, arg2, arg3)
125 char *arg1, *arg2, *arg3;
127 cpp_print_containing_files (pfile);
128 cpp_print_file_and_line (pfile);
129 fprintf (stderr, msg, arg1, arg2, arg3);
130 fprintf (stderr, "\n");
134 /* Print error message but don't count it. */
137 cpp_warning (pfile, msg, arg1, arg2, arg3)
140 char *arg1, *arg2, *arg3;
142 if (CPP_OPTIONS (pfile)->inhibit_warnings)
145 if (CPP_OPTIONS (pfile)->warnings_are_errors)
148 cpp_print_containing_files (pfile);
149 cpp_print_file_and_line (pfile);
150 fprintf (stderr, "warning: ");
151 fprintf (stderr, msg, arg1, arg2, arg3);
152 fprintf (stderr, "\n");
156 cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3)
160 char *arg1, *arg2, *arg3;
163 cpp_buffer *ip = cpp_file_buffer (pfile);
165 cpp_print_containing_files (pfile);
168 fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
170 fprintf (stderr, msg, arg1, arg2, arg3);
171 fprintf (stderr, "\n");
176 cpp_warning_with_line (pfile, line, msg, arg1, arg2, arg3)
180 char *arg1, *arg2, *arg3;
185 if (CPP_OPTIONS (pfile)->inhibit_warnings)
188 if (CPP_OPTIONS (pfile)->warnings_are_errors)
191 cpp_print_containing_files (pfile);
193 ip = cpp_file_buffer (pfile);
196 fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
197 fprintf (stderr, "warning: ");
198 fprintf (stderr, msg, arg1, arg2, arg3);
199 fprintf (stderr, "\n");
202 /* Print an error message and maybe count it. */
205 cpp_pedwarn (pfile, msg, arg1, arg2, arg3)
208 char *arg1, *arg2, *arg3;
210 if (CPP_OPTIONS (pfile)->pedantic_errors)
211 cpp_error (pfile, msg, arg1, arg2, arg3);
213 cpp_warning (pfile, msg, arg1, arg2, arg3);
217 cpp_pedwarn_with_line (pfile, line, msg, arg1, arg2, arg3)
221 char *arg1, *arg2, *arg3;
223 if (CPP_OPTIONS (pfile)->pedantic_errors)
224 cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3);
226 cpp_warning_with_line (pfile, line, msg, arg1, arg2, arg3);
229 /* Report a warning (or an error if pedantic_errors)
230 giving specified file name and line number, not current. */
233 cpp_pedwarn_with_file_and_line (pfile, file, line, msg, arg1, arg2, arg3)
238 char *arg1, *arg2, *arg3;
240 if (!CPP_OPTIONS (pfile)->pedantic_errors
241 && CPP_OPTIONS (pfile)->inhibit_warnings)
244 fprintf (stderr, "%s:%d: ", file, line);
245 if (CPP_OPTIONS (pfile)->pedantic_errors)
248 fprintf (stderr, "warning: ");
249 fprintf (stderr, msg, arg1, arg2, arg3);
250 fprintf (stderr, "\n");
257 fprintf (stderr, "%s: ", progname);
258 fprintf (stderr, str, arg);
259 fprintf (stderr, "\n");
260 exit (FAILURE_EXIT_CODE);
265 * my_strerror - return the descriptive text associated with an `errno' code.
275 #ifndef HAVE_STRERROR
276 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
278 result = strerror (errnum);
281 /* VAXCRTL's strerror() takes an optional second argument, which only
282 matters when the first argument is EVMSERR. However, it's simplest
283 just to pass it unconditionally. `vaxc$errno' is declared in
284 <errno.h>, and maintained by the library in parallel with `errno'.
285 We assume that caller's `errnum' either matches the last setting of
286 `errno' by the library or else does not have the value `EVMSERR'. */
288 result = strerror (errnum, vaxc$errno);
292 result = "undocumented I/O error";
297 /* Error including a message from `errno'. */
300 cpp_error_from_errno (pfile, name)
305 cpp_buffer *ip = cpp_file_buffer (pfile);
307 cpp_print_containing_files (pfile);
310 fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
312 fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
318 cpp_perror_with_name (pfile, name)
322 fprintf (stderr, "%s: ", progname);
323 fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
328 cpp_pfatal_with_name (pfile, name)
332 cpp_perror_with_name (pfile, name);
336 exit (FAILURE_EXIT_CODE);