]> git.saurik.com Git - bison.git/blame - src/complain.c
* src/LR0.c (state_list_t, state_list_append): New.
[bison.git] / src / complain.c
CommitLineData
a0f6b076 1/* Declaration for error-reporting function for Bison.
0e41b407 2 Copyright 2000, 2001 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
41void exit ();
42#endif
43
9b53a24f
AD
44/* To get error_one_per_line. */
45#include "error.h"
46
a0f6b076
AD
47#include "complain.h"
48
8f13fe33
AD
49#ifndef HAVE_DECL_STRERROR_R
50"this configure-time declaration test was not run"
51#endif
52#if !HAVE_DECL_STRERROR_R
53char *strerror_r ();
54#endif
55
a0f6b076
AD
56#ifndef _
57# define _(String) String
58#endif
59
60#ifdef _LIBC
61/* In the GNU C library, there is a predefined variable for this. */
8f13fe33 62
a0f6b076 63# define program_name program_invocation_name
8f13fe33
AD
64# include <errno.h>
65
66/* In GNU libc we want do not want to use the common name `error' directly.
67 Instead make it a weak alias. */
68# define error __error
69# define error_at_line __error_at_line
70
71# ifdef USE_IN_LIBIO
72# include <libio/iolibio.h>
73# define fflush(s) _IO_fflush (s)
74# endif
75
a0f6b076 76#else /* not _LIBC */
8f13fe33 77
a0f6b076
AD
78/* The calling program should define program_name and set it to the
79 name of the executing program. */
80extern char *program_name;
8f13fe33
AD
81
82# ifdef HAVE_STRERROR_R
83# define __strerror_r strerror_r
84# else
85# if HAVE_STRERROR
86# ifndef strerror /* On some systems, strerror is a macro */
87char *strerror ();
88# endif
89# else
90static char *
91private_strerror (errnum)
92 int errnum;
93{
94 extern char *sys_errlist[];
95 extern int sys_nerr;
96
97 if (errnum > 0 && errnum <= sys_nerr)
98 return _(sys_errlist[errnum]);
99 return _("Unknown system error");
100}
101# define strerror private_strerror
102# endif /* HAVE_STRERROR */
103# endif /* HAVE_STRERROR_R */
104#endif /* not _LIBC */
a0f6b076
AD
105
106/* This variable is incremented each time `warn' is called. */
107unsigned int warn_message_count;
108
109/* This variable is incremented each time `complain' is called. */
110unsigned int complain_message_count;
111
a0f6b076
AD
112\f
113/*--------------------------------.
114| Report a warning, and proceed. |
115`--------------------------------*/
116
e9955c83
AD
117void
118#if defined VA_START && defined __STDC__
ee000ba4 119warn_at (location_t location, const char *message, ...)
e9955c83
AD
120#else
121warn_at (location, message, va_alist)
ee000ba4 122 location_t location
e9955c83
AD
123 char *message;
124 va_dcl
125#endif
126{
127#ifdef VA_START
128 va_list args;
129#endif
130
131 if (error_one_per_line)
132 {
133 static const char *old_infile;
134 static int old_lineno;
135
ee000ba4 136 if (old_lineno == location.first_line &&
e9955c83
AD
137 (infile == old_infile || !strcmp (old_infile, infile)))
138 /* Simply return and print nothing. */
139 return;
140
141 old_infile = infile;
ee000ba4 142 old_lineno = location.first_line;
e9955c83
AD
143 }
144
145 fflush (stdout);
ee000ba4
AD
146 LOCATION_PRINT (stderr, location);
147 fputs (": ", stderr);
e9955c83
AD
148 fputs (_("warning: "), stderr);
149
150#ifdef VA_START
151 VA_START (args, message);
152 vfprintf (stderr, message, args);
153 va_end (args);
154#else
155 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
156#endif
157
158 ++warn_message_count;
159 putc ('\n', stderr);
160 fflush (stderr);
161}
162
163
a0f6b076 164void
342b8b6e 165#if defined VA_START && defined __STDC__
a0f6b076
AD
166warn (const char *message, ...)
167#else
168warn (message, va_alist)
169 char *message;
170 va_dcl
171#endif
172{
173#ifdef VA_START
174 va_list args;
175#endif
176
177 if (error_one_per_line)
178 {
179 static const char *old_infile;
4a120d45 180 static int old_lineno;
a0f6b076
AD
181
182 if (old_lineno == lineno &&
183 (infile == old_infile || !strcmp (old_infile, infile)))
184 /* Simply return and print nothing. */
185 return;
186
187 old_infile = infile;
188 old_lineno = lineno;
189 }
190
191 fflush (stdout);
192 if (infile != NULL)
193 fprintf (stderr, "%s:%d: ", infile, lineno);
194 else
195 fprintf (stderr, "%s:", program_name);
196
197 fputs (_("warning: "), stderr);
198
199#ifdef VA_START
200 VA_START (args, message);
201 vfprintf (stderr, message, args);
202 va_end (args);
203#else
204 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
205#endif
206
207 ++warn_message_count;
208 putc ('\n', stderr);
209 fflush (stderr);
210}
211\f
212/*-----------------------------------------------------------.
213| An error has occurred, but we can proceed, and die later. |
214`-----------------------------------------------------------*/
215
e9955c83
AD
216void
217#if defined VA_START && defined __STDC__
ee000ba4 218complain_at (location_t location, const char *message, ...)
e9955c83
AD
219#else
220complain_at (location, message, va_alist)
ee000ba4 221 location_t location;
e9955c83
AD
222 char *message;
223 va_dcl
224#endif
225{
226#ifdef VA_START
227 va_list args;
228#endif
229
230 if (error_one_per_line)
231 {
232 static const char *old_infile;
233 static int old_lineno;
234
ee000ba4 235 if (old_lineno == location.first_line &&
e9955c83
AD
236 (infile == old_infile || !strcmp (old_infile, infile)))
237 /* Simply return and print nothing. */
238 return;
239
240 old_infile = infile;
ee000ba4 241 old_lineno = location.first_line;
e9955c83
AD
242 }
243
244 fflush (stdout);
ee000ba4
AD
245 LOCATION_PRINT (stderr, location);
246 fputs (": ", stderr);
e9955c83
AD
247
248#ifdef VA_START
249 VA_START (args, message);
250 vfprintf (stderr, message, args);
251 va_end (args);
252#else
253 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
254#endif
255
256 ++complain_message_count;
257 putc ('\n', stderr);
258 fflush (stderr);
259}
260
261
a0f6b076 262void
342b8b6e 263#if defined VA_START && defined __STDC__
a0f6b076
AD
264complain (const char *message, ...)
265#else
266complain (message, va_alist)
267 char *message;
268 va_dcl
269#endif
270{
271#ifdef VA_START
272 va_list args;
273#endif
274
275 if (error_one_per_line)
276 {
277 static const char *old_infile;
4a120d45 278 static int old_lineno;
a0f6b076
AD
279
280 if (old_lineno == lineno &&
281 (infile == old_infile || !strcmp (old_infile, infile)))
282 /* Simply return and print nothing. */
283 return;
284
285 old_infile = infile;
286 old_lineno = lineno;
287 }
288
289 fflush (stdout);
290 if (infile != NULL)
291 fprintf (stderr, "%s:%d: ", infile, lineno);
292 else
293 fprintf (stderr, "%s:", program_name);
294
295#ifdef VA_START
296 VA_START (args, message);
297 vfprintf (stderr, message, args);
298 va_end (args);
299#else
300 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
301#endif
302
303 ++complain_message_count;
304 putc ('\n', stderr);
305 fflush (stderr);
306}
307\f
308/*-------------------------------------------------.
309| A severe error has occurred, we cannot proceed. |
310`-------------------------------------------------*/
311
e9955c83
AD
312void
313#if defined VA_START && defined __STDC__
ee000ba4 314fatal_at (location_t location, const char *message, ...)
e9955c83
AD
315#else
316fatal (location, message, va_alist)
ee000ba4 317 location_t location;
e9955c83
AD
318 char *message;
319 va_dcl
320#endif
321{
322#ifdef VA_START
323 va_list args;
324#endif
325
326 fflush (stdout);
ee000ba4
AD
327 LOCATION_PRINT (stderr, location);
328 fputs (": ", stderr);
e9955c83
AD
329 fputs (_("fatal error: "), stderr);
330
331#ifdef VA_START
332 VA_START (args, message);
333 vfprintf (stderr, message, args);
334 va_end (args);
335#else
336 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
337#endif
338 putc ('\n', stderr);
339 fflush (stderr);
340 exit (1);
341}
342
a0f6b076 343void
342b8b6e 344#if defined VA_START && defined __STDC__
a0f6b076
AD
345fatal (const char *message, ...)
346#else
347fatal (message, va_alist)
348 char *message;
349 va_dcl
350#endif
351{
352#ifdef VA_START
353 va_list args;
354#endif
355
356 fflush (stdout);
357 if (infile != NULL)
358 fprintf (stderr, "%s:%d: ", infile, lineno);
359 else
360 fprintf (stderr, "%s:", program_name);
361
362 fputs (_("fatal error: "), stderr);
363
364#ifdef VA_START
365 VA_START (args, message);
366 vfprintf (stderr, message, args);
367 va_end (args);
368#else
369 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
370#endif
371 putc ('\n', stderr);
372 fflush (stderr);
373 exit (1);
374}