]>
Commit | Line | Data |
---|---|---|
a0f6b076 | 1 | /* Declaration for error-reporting function for Bison. |
52489d44 | 2 | Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. |
a0f6b076 AD |
3 | |
4 | This program is free software; you can redistribute it and/or modify it | |
5 | under the terms of the GNU General Public License as published by the | |
6 | Free Software Foundation; either version 2, or (at your option) any | |
7 | later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program; if not, write to the Free Software | |
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
17 | USA. */ | |
18 | ||
19 | /* Based on error.c and error.h, | |
20 | written by David MacKenzie <djm@gnu.ai.mit.edu>. */ | |
21 | ||
342b8b6e | 22 | #include "system.h" |
a0f6b076 AD |
23 | |
24 | #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC | |
342b8b6e | 25 | # ifdef __STDC__ |
a0f6b076 AD |
26 | # include <stdarg.h> |
27 | # define VA_START(args, lastarg) va_start(args, lastarg) | |
28 | # else | |
29 | # include <varargs.h> | |
30 | # define VA_START(args, lastarg) va_start(args) | |
31 | # endif | |
32 | #else | |
33 | # define va_alist a1, a2, a3, a4, a5, a6, a7, a8 | |
34 | # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; | |
35 | #endif | |
36 | ||
37 | #if STDC_HEADERS || _LIBC | |
38 | # include <stdlib.h> | |
39 | # include <string.h> | |
40 | #else | |
41 | void exit (); | |
42 | #endif | |
43 | ||
44 | #include "complain.h" | |
45 | ||
8f13fe33 AD |
46 | #ifndef HAVE_DECL_STRERROR_R |
47 | "this configure-time declaration test was not run" | |
48 | #endif | |
49 | #if !HAVE_DECL_STRERROR_R | |
50 | char *strerror_r (); | |
51 | #endif | |
52 | ||
a0f6b076 AD |
53 | #ifndef _ |
54 | # define _(String) String | |
55 | #endif | |
56 | ||
57 | #ifdef _LIBC | |
58 | /* In the GNU C library, there is a predefined variable for this. */ | |
8f13fe33 | 59 | |
a0f6b076 | 60 | # define program_name program_invocation_name |
8f13fe33 AD |
61 | # include <errno.h> |
62 | ||
63 | /* In GNU libc we want do not want to use the common name `error' directly. | |
64 | Instead make it a weak alias. */ | |
65 | # define error __error | |
66 | # define error_at_line __error_at_line | |
67 | ||
68 | # ifdef USE_IN_LIBIO | |
69 | # include <libio/iolibio.h> | |
70 | # define fflush(s) _IO_fflush (s) | |
71 | # endif | |
72 | ||
a0f6b076 | 73 | #else /* not _LIBC */ |
8f13fe33 | 74 | |
a0f6b076 AD |
75 | /* The calling program should define program_name and set it to the |
76 | name of the executing program. */ | |
77 | extern char *program_name; | |
8f13fe33 AD |
78 | |
79 | # ifdef HAVE_STRERROR_R | |
80 | # define __strerror_r strerror_r | |
81 | # else | |
82 | # if HAVE_STRERROR | |
83 | # ifndef strerror /* On some systems, strerror is a macro */ | |
84 | char *strerror (); | |
85 | # endif | |
86 | # else | |
87 | static char * | |
88 | private_strerror (errnum) | |
89 | int errnum; | |
90 | { | |
91 | extern char *sys_errlist[]; | |
92 | extern int sys_nerr; | |
93 | ||
94 | if (errnum > 0 && errnum <= sys_nerr) | |
95 | return _(sys_errlist[errnum]); | |
96 | return _("Unknown system error"); | |
97 | } | |
98 | # define strerror private_strerror | |
99 | # endif /* HAVE_STRERROR */ | |
100 | # endif /* HAVE_STRERROR_R */ | |
101 | #endif /* not _LIBC */ | |
a0f6b076 AD |
102 | |
103 | /* This variable is incremented each time `warn' is called. */ | |
104 | unsigned int warn_message_count; | |
105 | ||
106 | /* This variable is incremented each time `complain' is called. */ | |
107 | unsigned int complain_message_count; | |
108 | ||
a0f6b076 AD |
109 | \f |
110 | /*--------------------------------. | |
111 | | Report a warning, and proceed. | | |
112 | `--------------------------------*/ | |
113 | ||
e9955c83 AD |
114 | void |
115 | #if defined VA_START && defined __STDC__ | |
ee000ba4 | 116 | warn_at (location_t location, const char *message, ...) |
e9955c83 AD |
117 | #else |
118 | warn_at (location, message, va_alist) | |
ee000ba4 | 119 | location_t location |
e9955c83 AD |
120 | char *message; |
121 | va_dcl | |
122 | #endif | |
123 | { | |
124 | #ifdef VA_START | |
125 | va_list args; | |
126 | #endif | |
127 | ||
e9955c83 | 128 | fflush (stdout); |
ee000ba4 AD |
129 | LOCATION_PRINT (stderr, location); |
130 | fputs (": ", stderr); | |
e9955c83 AD |
131 | fputs (_("warning: "), stderr); |
132 | ||
52489d44 AD |
133 | #ifdef VA_START |
134 | VA_START (args, message); | |
135 | vfprintf (stderr, message, args); | |
136 | va_end (args); | |
137 | #else | |
138 | fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); | |
139 | #endif | |
140 | ||
141 | ++warn_message_count; | |
142 | putc ('\n', stderr); | |
143 | fflush (stderr); | |
144 | } | |
145 | ||
146 | void | |
147 | #if defined VA_START && defined __STDC__ | |
148 | warn (const char *message, ...) | |
149 | #else | |
150 | warn (message, va_alist) | |
151 | char *message; | |
152 | va_dcl | |
153 | #endif | |
154 | { | |
155 | #ifdef VA_START | |
156 | va_list args; | |
157 | #endif | |
158 | ||
159 | fflush (stdout); | |
160 | fprintf (stderr, "%s: %s", infile ? infile : program_name, _("warning: ")); | |
161 | ||
e9955c83 AD |
162 | #ifdef VA_START |
163 | VA_START (args, message); | |
164 | vfprintf (stderr, message, args); | |
165 | va_end (args); | |
166 | #else | |
167 | fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); | |
168 | #endif | |
169 | ||
170 | ++warn_message_count; | |
171 | putc ('\n', stderr); | |
172 | fflush (stderr); | |
173 | } | |
a0f6b076 AD |
174 | \f |
175 | /*-----------------------------------------------------------. | |
176 | | An error has occurred, but we can proceed, and die later. | | |
177 | `-----------------------------------------------------------*/ | |
178 | ||
e9955c83 AD |
179 | void |
180 | #if defined VA_START && defined __STDC__ | |
ee000ba4 | 181 | complain_at (location_t location, const char *message, ...) |
e9955c83 AD |
182 | #else |
183 | complain_at (location, message, va_alist) | |
ee000ba4 | 184 | location_t location; |
e9955c83 AD |
185 | char *message; |
186 | va_dcl | |
187 | #endif | |
188 | { | |
189 | #ifdef VA_START | |
190 | va_list args; | |
191 | #endif | |
192 | ||
e9955c83 | 193 | fflush (stdout); |
ee000ba4 AD |
194 | LOCATION_PRINT (stderr, location); |
195 | fputs (": ", stderr); | |
e9955c83 | 196 | |
52489d44 AD |
197 | #ifdef VA_START |
198 | VA_START (args, message); | |
199 | vfprintf (stderr, message, args); | |
200 | va_end (args); | |
201 | #else | |
202 | fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); | |
203 | #endif | |
204 | ||
205 | ++complain_message_count; | |
206 | putc ('\n', stderr); | |
207 | fflush (stderr); | |
208 | } | |
209 | ||
210 | void | |
211 | #if defined VA_START && defined __STDC__ | |
212 | complain (const char *message, ...) | |
213 | #else | |
214 | complain (message, va_alist) | |
215 | char *message; | |
216 | va_dcl | |
217 | #endif | |
218 | { | |
219 | #ifdef VA_START | |
220 | va_list args; | |
221 | #endif | |
222 | ||
223 | fflush (stdout); | |
224 | fprintf (stderr, "%s: ", infile ? infile : program_name); | |
225 | ||
e9955c83 AD |
226 | #ifdef VA_START |
227 | VA_START (args, message); | |
228 | vfprintf (stderr, message, args); | |
229 | va_end (args); | |
230 | #else | |
231 | fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); | |
232 | #endif | |
233 | ||
234 | ++complain_message_count; | |
235 | putc ('\n', stderr); | |
236 | fflush (stderr); | |
237 | } | |
a0f6b076 AD |
238 | \f |
239 | /*-------------------------------------------------. | |
240 | | A severe error has occurred, we cannot proceed. | | |
241 | `-------------------------------------------------*/ | |
242 | ||
e9955c83 AD |
243 | void |
244 | #if defined VA_START && defined __STDC__ | |
ee000ba4 | 245 | fatal_at (location_t location, const char *message, ...) |
e9955c83 | 246 | #else |
52489d44 | 247 | fatal_at (location, message, va_alist) |
ee000ba4 | 248 | location_t location; |
e9955c83 AD |
249 | char *message; |
250 | va_dcl | |
251 | #endif | |
252 | { | |
253 | #ifdef VA_START | |
254 | va_list args; | |
255 | #endif | |
256 | ||
257 | fflush (stdout); | |
ee000ba4 AD |
258 | LOCATION_PRINT (stderr, location); |
259 | fputs (": ", stderr); | |
e9955c83 AD |
260 | fputs (_("fatal error: "), stderr); |
261 | ||
262 | #ifdef VA_START | |
263 | VA_START (args, message); | |
264 | vfprintf (stderr, message, args); | |
265 | va_end (args); | |
266 | #else | |
267 | fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); | |
268 | #endif | |
269 | putc ('\n', stderr); | |
270 | fflush (stderr); | |
271 | exit (1); | |
272 | } | |
273 | ||
a0f6b076 | 274 | void |
342b8b6e | 275 | #if defined VA_START && defined __STDC__ |
a0f6b076 AD |
276 | fatal (const char *message, ...) |
277 | #else | |
278 | fatal (message, va_alist) | |
279 | char *message; | |
280 | va_dcl | |
281 | #endif | |
282 | { | |
283 | #ifdef VA_START | |
284 | va_list args; | |
285 | #endif | |
286 | ||
287 | fflush (stdout); | |
a5d50994 | 288 | fprintf (stderr, "%s: ", infile ? infile : program_name); |
a0f6b076 AD |
289 | |
290 | fputs (_("fatal error: "), stderr); | |
291 | ||
292 | #ifdef VA_START | |
293 | VA_START (args, message); | |
294 | vfprintf (stderr, message, args); | |
295 | va_end (args); | |
296 | #else | |
297 | fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); | |
298 | #endif | |
299 | putc ('\n', stderr); | |
300 | fflush (stderr); | |
301 | exit (1); | |
302 | } |