]> git.saurik.com Git - bison.git/blame_incremental - src/complain.c
* doc/bison.texinfo (Stack Overflow): xref to Recursion.
[bison.git] / src / complain.c
... / ...
CommitLineData
1/* Declaration for error-reporting function for Bison.
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
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
22#include "system.h"
23
24#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
25# ifdef __STDC__
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
44#include "complain.h"
45
46#ifndef _
47# define _(String) String
48#endif
49
50#ifdef _LIBC
51/* In the GNU C library, there is a predefined variable for this. */
52
53# define program_name program_invocation_name
54# include <errno.h>
55
56/* In GNU libc we want do not want to use the common name `error' directly.
57 Instead make it a weak alias. */
58# define error __error
59# define error_at_line __error_at_line
60
61# ifdef USE_IN_LIBIO
62# include <libio/iolibio.h>
63# define fflush(s) _IO_fflush (s)
64# endif
65
66#else /* not _LIBC */
67
68/* The calling program should define program_name and set it to the
69 name of the executing program. */
70extern char *program_name;
71
72# if HAVE_STRERROR
73# ifndef HAVE_DECL_STRERROR
74"this configure-time declaration test was not run"
75# endif
76# if !HAVE_DECL_STRERROR && !defined strerror
77char *strerror PARAMS ((int));
78# endif
79# else
80static char *
81private_strerror (errnum)
82 int errnum;
83{
84 extern char *sys_errlist[];
85 extern int sys_nerr;
86
87 if (errnum > 0 && errnum <= sys_nerr)
88 return _(sys_errlist[errnum]);
89 return _("Unknown system error");
90}
91# define strerror private_strerror
92# endif /* HAVE_STRERROR */
93#endif /* not _LIBC */
94
95/* This variable is incremented each time `warn' is called. */
96unsigned int warn_message_count;
97
98/* This variable is incremented each time `complain' is called. */
99unsigned int complain_message_count;
100
101\f
102/*--------------------------------.
103| Report a warning, and proceed. |
104`--------------------------------*/
105
106void
107#if defined VA_START && defined __STDC__
108warn_at (location_t location, const char *message, ...)
109#else
110warn_at (location, message, va_alist)
111 location_t location
112 char *message;
113 va_dcl
114#endif
115{
116#ifdef VA_START
117 va_list args;
118#endif
119
120 fflush (stdout);
121 LOCATION_PRINT (stderr, location);
122 fputs (": ", stderr);
123 fputs (_("warning: "), stderr);
124
125#ifdef VA_START
126 VA_START (args, message);
127 vfprintf (stderr, message, args);
128 va_end (args);
129#else
130 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
131#endif
132
133 ++warn_message_count;
134 putc ('\n', stderr);
135 fflush (stderr);
136}
137
138void
139#if defined VA_START && defined __STDC__
140warn (const char *message, ...)
141#else
142warn (message, va_alist)
143 char *message;
144 va_dcl
145#endif
146{
147#ifdef VA_START
148 va_list args;
149#endif
150
151 fflush (stdout);
152 fprintf (stderr, "%s: %s", infile ? infile : program_name, _("warning: "));
153
154#ifdef VA_START
155 VA_START (args, message);
156 vfprintf (stderr, message, args);
157 va_end (args);
158#else
159 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
160#endif
161
162 ++warn_message_count;
163 putc ('\n', stderr);
164 fflush (stderr);
165}
166\f
167/*-----------------------------------------------------------.
168| An error has occurred, but we can proceed, and die later. |
169`-----------------------------------------------------------*/
170
171void
172#if defined VA_START && defined __STDC__
173complain_at (location_t location, const char *message, ...)
174#else
175complain_at (location, message, va_alist)
176 location_t location;
177 char *message;
178 va_dcl
179#endif
180{
181#ifdef VA_START
182 va_list args;
183#endif
184
185 fflush (stdout);
186 LOCATION_PRINT (stderr, location);
187 fputs (": ", stderr);
188
189#ifdef VA_START
190 VA_START (args, message);
191 vfprintf (stderr, message, args);
192 va_end (args);
193#else
194 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
195#endif
196
197 ++complain_message_count;
198 putc ('\n', stderr);
199 fflush (stderr);
200}
201
202void
203#if defined VA_START && defined __STDC__
204complain (const char *message, ...)
205#else
206complain (message, va_alist)
207 char *message;
208 va_dcl
209#endif
210{
211#ifdef VA_START
212 va_list args;
213#endif
214
215 fflush (stdout);
216 fprintf (stderr, "%s: ", infile ? infile : program_name);
217
218#ifdef VA_START
219 VA_START (args, message);
220 vfprintf (stderr, message, args);
221 va_end (args);
222#else
223 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
224#endif
225
226 ++complain_message_count;
227 putc ('\n', stderr);
228 fflush (stderr);
229}
230\f
231/*-------------------------------------------------.
232| A severe error has occurred, we cannot proceed. |
233`-------------------------------------------------*/
234
235void
236#if defined VA_START && defined __STDC__
237fatal_at (location_t location, const char *message, ...)
238#else
239fatal_at (location, message, va_alist)
240 location_t location;
241 char *message;
242 va_dcl
243#endif
244{
245#ifdef VA_START
246 va_list args;
247#endif
248
249 fflush (stdout);
250 LOCATION_PRINT (stderr, location);
251 fputs (": ", stderr);
252 fputs (_("fatal error: "), stderr);
253
254#ifdef VA_START
255 VA_START (args, message);
256 vfprintf (stderr, message, args);
257 va_end (args);
258#else
259 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
260#endif
261 putc ('\n', stderr);
262 fflush (stderr);
263 exit (1);
264}
265
266void
267#if defined VA_START && defined __STDC__
268fatal (const char *message, ...)
269#else
270fatal (message, va_alist)
271 char *message;
272 va_dcl
273#endif
274{
275#ifdef VA_START
276 va_list args;
277#endif
278
279 fflush (stdout);
280 fprintf (stderr, "%s: ", infile ? infile : program_name);
281
282 fputs (_("fatal error: "), stderr);
283
284#ifdef VA_START
285 VA_START (args, message);
286 vfprintf (stderr, message, args);
287 va_end (args);
288#else
289 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
290#endif
291 putc ('\n', stderr);
292 fflush (stderr);
293 exit (1);
294}