oops - omitted from previous delta fixing UNIQUE_SECTION
[official-gcc.git] / gcc / cpperror.c
blobd0900e84373ddca1c53e36b906b342a3c42b5566
1 /* Default error handlers for CPP Library.
2 Copyright (C) 1986, 87, 89, 92-95, 98, 99, 2000 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
10 later version.
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! */
25 #ifndef EMACS
26 #include "config.h"
27 #include "system.h"
28 #else
29 #include <stdio.h>
30 #endif /* not EMACS */
32 #include "cpplib.h"
33 #include "intl.h"
35 /* Print the file names and line numbers of the #include
36 commands which led to the current file. */
38 void
39 cpp_print_containing_files (pfile)
40 cpp_reader *pfile;
42 cpp_buffer *ip;
43 int first = 1;
45 /* If stack of files hasn't changed since we last printed
46 this info, don't repeat it. */
47 if (pfile->input_stack_listing_current)
48 return;
50 ip = cpp_file_buffer (pfile);
52 /* Give up if we don't find a source file. */
53 if (ip == NULL)
54 return;
56 /* Find the other, outer source files. */
57 while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
59 long line, col;
60 cpp_buf_line_and_col (ip, &line, &col);
61 if (ip->fname != NULL)
63 if (first)
65 first = 0;
66 cpp_message (pfile, -1, "In file included from %s:%ld",
67 ip->nominal_fname, line);
69 else
70 cpp_message (pfile, -1, ",\n from %s:%ld",
71 ip->nominal_fname, line);
74 if (! first)
75 fputs (":\n", stderr);
77 /* Record we have printed the status as of this time. */
78 pfile->input_stack_listing_current = 1;
81 void
82 cpp_file_line_for_message (pfile, filename, line, column)
83 cpp_reader *pfile ATTRIBUTE_UNUSED;
84 const char *filename;
85 int line, column;
87 if (filename == 0 || *filename == '\0')
88 filename = "<stdin>";
89 if (line == 0)
90 fputs (_("<command line>: "), stderr);
91 else if (column > 0)
92 fprintf (stderr, "%s:%d:%d: ", filename, line, column);
93 else
94 fprintf (stderr, "%s:%d: ", filename, line);
97 /* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning, -1 for notice */
99 void
100 v_cpp_message (pfile, is_error, msgid, ap)
101 cpp_reader * pfile;
102 int is_error;
103 const char *msgid;
104 va_list ap;
106 switch (is_error)
108 case -1:
109 break;
110 case 0:
111 fprintf (stderr, _("warning: "));
112 break;
113 case 1:
114 if (pfile->errors < CPP_FATAL_LIMIT)
115 pfile->errors++;
116 break;
117 case 2:
118 pfile->errors = CPP_FATAL_LIMIT;
119 break;
120 default:
121 cpp_fatal (pfile, "internal error: bad is_error(%d) in v_cpp_message", is_error);
124 vfprintf (stderr, _(msgid), ap);
126 if (0 <= is_error)
127 fprintf (stderr, "\n");
130 void
131 cpp_message VPARAMS ((cpp_reader *pfile, int is_error, const char *msgid, ...))
133 #ifndef ANSI_PROTOTYPES
134 cpp_reader *pfile;
135 int is_error;
136 const char *msgid;
137 #endif
138 va_list ap;
140 VA_START (ap, msgid);
142 #ifndef ANSI_PROTOTYPES
143 pfile = va_arg (ap, cpp_reader *);
144 is_error = va_arg (ap, int);
145 msgid = va_arg (ap, const char *);
146 #endif
148 v_cpp_message(pfile, is_error, msgid, ap);
149 va_end(ap);
152 /* Same as cpp_error, except we consider the error to be "fatal",
153 such as inconsistent options. I.e. there is little point in continuing.
154 (We do not exit, to support use of cpplib as a library.
155 Instead, it is the caller's responsibility to check
156 CPP_FATAL_ERRORS. */
158 void
159 cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
161 #ifndef ANSI_PROTOTYPES
162 cpp_reader *pfile;
163 const char *msgid;
164 #endif
165 va_list ap;
167 VA_START (ap, msgid);
169 #ifndef ANSI_PROTOTYPES
170 pfile = va_arg (ap, cpp_reader *);
171 msgid = va_arg (ap, const char *);
172 #endif
174 fprintf (stderr, "%s: ", progname);
175 v_cpp_message (pfile, 2, msgid, ap);
176 va_end(ap);
179 void
180 cpp_pfatal_with_name (pfile, name)
181 cpp_reader *pfile;
182 const char *name;
184 cpp_perror_with_name (pfile, name);
185 #ifdef VMS
186 exit (vaxc$errno);
187 #else
188 exit (FATAL_EXIT_CODE);
189 #endif
192 /* Print an error message. */
194 void
195 cpp_notice VPARAMS ((const char *msgid, ...))
197 #ifndef ANSI_PROTOTYPES
198 const char *msgid;
199 #endif
200 va_list ap;
202 VA_START (ap, msgid);
204 #ifndef ANSI_PROTOTYPES
205 msgid = va_arg (ap, const char *);
206 #endif
208 fprintf (stderr, "%s: ", progname);
209 v_cpp_message ((cpp_reader *) 0, -1, msgid, ap);
210 va_end(ap);