1 /* Default error handlers for CPP Library.
2 Copyright (C) 1986, 87, 89, 92 - 95, 1998 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994.
4 Based on CCCP program 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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! */
30 #endif /* not EMACS */
34 /* Print the file names and line numbers of the #include
35 commands which led to the current file. */
38 cpp_print_containing_files (pfile)
44 /* If stack of files hasn't changed since we last printed
45 this info, don't repeat it. */
46 if (pfile->input_stack_listing_current)
49 ip = cpp_file_buffer (pfile);
51 /* Give up if we don't find a source file. */
55 /* Find the other, outer source files. */
56 while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
59 cpp_buf_line_and_col (ip, &line, &col);
60 if (ip->fname != NULL)
65 fprintf (stderr, "In file included");
68 fprintf (stderr, ",\n ");
71 fprintf (stderr, " from %s:%ld", ip->nominal_fname, line);
74 fprintf (stderr, ":\n");
76 /* Record we have printed the status as of this time. */
77 pfile->input_stack_listing_current = 1;
81 cpp_file_line_for_message (pfile, filename, line, column)
82 cpp_reader *pfile ATTRIBUTE_UNUSED;
87 fprintf (stderr, "%s:%d:%d: ", filename, line, column);
89 fprintf (stderr, "%s:%d: ", filename, line);
92 /* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning */
95 v_cpp_message (pfile, is_error, msg, ap)
102 fprintf (stderr, "warning: ");
103 else if (is_error == 2)
104 pfile->errors = CPP_FATAL_LIMIT;
105 else if (pfile->errors < CPP_FATAL_LIMIT)
107 vfprintf (stderr, msg, ap);
108 fprintf (stderr, "\n");
112 cpp_message VPROTO ((cpp_reader *pfile, int is_error, const char *msg, ...))
124 pfile = va_arg (ap, cpp_reader *);
125 is_error = va_arg (ap, int);
126 msg = va_arg (ap, const char *);
129 v_cpp_message(pfile, is_error, msg, ap);
133 /* Same as cpp_error, except we consider the error to be "fatal",
134 such as inconsistent options. I.e. there is little point in continuing.
135 (We do not exit, to support use of cpplib as a library.
136 Instead, it is the caller's responsibility to check
140 cpp_fatal VPROTO ((cpp_reader *pfile, const char *str, ...))
151 pfile = va_arg (ap, cpp_reader *);
152 str = va_arg (ap, const char *);
155 fprintf (stderr, "%s: ", progname);
156 v_cpp_message (pfile, 2, str, ap);
161 cpp_pfatal_with_name (pfile, name)
165 cpp_perror_with_name (pfile, name);
169 exit (FATAL_EXIT_CODE);