]> git.saurik.com Git - bison.git/blame - src/complain.c
* src/reduce.c (reduce_grammar): When the language is empty,
[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
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
50char *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. */
77extern 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 */
84char *strerror ();
85# endif
86# else
87static char *
88private_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. */
104unsigned int warn_message_count;
105
106/* This variable is incremented each time `complain' is called. */
107unsigned int complain_message_count;
108
a0f6b076
AD
109\f
110/*--------------------------------.
111| Report a warning, and proceed. |
112`--------------------------------*/
113
e9955c83
AD
114void
115#if defined VA_START && defined __STDC__
ee000ba4 116warn_at (location_t location, const char *message, ...)
e9955c83
AD
117#else
118warn_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
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}
a0f6b076
AD
145\f
146/*-----------------------------------------------------------.
147| An error has occurred, but we can proceed, and die later. |
148`-----------------------------------------------------------*/
149
e9955c83
AD
150void
151#if defined VA_START && defined __STDC__
ee000ba4 152complain_at (location_t location, const char *message, ...)
e9955c83
AD
153#else
154complain_at (location, message, va_alist)
ee000ba4 155 location_t location;
e9955c83
AD
156 char *message;
157 va_dcl
158#endif
159{
160#ifdef VA_START
161 va_list args;
162#endif
163
e9955c83 164 fflush (stdout);
ee000ba4
AD
165 LOCATION_PRINT (stderr, location);
166 fputs (": ", stderr);
e9955c83
AD
167
168#ifdef VA_START
169 VA_START (args, message);
170 vfprintf (stderr, message, args);
171 va_end (args);
172#else
173 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
174#endif
175
176 ++complain_message_count;
177 putc ('\n', stderr);
178 fflush (stderr);
179}
a0f6b076
AD
180\f
181/*-------------------------------------------------.
182| A severe error has occurred, we cannot proceed. |
183`-------------------------------------------------*/
184
e9955c83
AD
185void
186#if defined VA_START && defined __STDC__
ee000ba4 187fatal_at (location_t location, const char *message, ...)
e9955c83
AD
188#else
189fatal (location, message, va_alist)
ee000ba4 190 location_t location;
e9955c83
AD
191 char *message;
192 va_dcl
193#endif
194{
195#ifdef VA_START
196 va_list args;
197#endif
198
199 fflush (stdout);
ee000ba4
AD
200 LOCATION_PRINT (stderr, location);
201 fputs (": ", stderr);
e9955c83
AD
202 fputs (_("fatal error: "), stderr);
203
204#ifdef VA_START
205 VA_START (args, message);
206 vfprintf (stderr, message, args);
207 va_end (args);
208#else
209 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
210#endif
211 putc ('\n', stderr);
212 fflush (stderr);
213 exit (1);
214}
215
a0f6b076 216void
342b8b6e 217#if defined VA_START && defined __STDC__
a0f6b076
AD
218fatal (const char *message, ...)
219#else
220fatal (message, va_alist)
221 char *message;
222 va_dcl
223#endif
224{
225#ifdef VA_START
226 va_list args;
227#endif
228
229 fflush (stdout);
a5d50994 230 fprintf (stderr, "%s: ", infile ? infile : program_name);
a0f6b076
AD
231
232 fputs (_("fatal error: "), stderr);
233
234#ifdef VA_START
235 VA_START (args, message);
236 vfprintf (stderr, message, args);
237 va_end (args);
238#else
239 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
240#endif
241 putc ('\n', stderr);
242 fflush (stderr);
243 exit (1);
244}