]> git.saurik.com Git - bison.git/blob - src/complain.c
Report rules which are never reduced by the parser: those hidden
[bison.git] / src / complain.c
1 /* Declaration for error-reporting function for Bison.
2 Copyright 2000, 2001 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
41 void exit ();
42 #endif
43
44 #include "complain.h"
45
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
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. */
59
60 # define program_name program_invocation_name
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
73 #else /* not _LIBC */
74
75 /* The calling program should define program_name and set it to the
76 name of the executing program. */
77 extern char *program_name;
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 */
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
109 \f
110 /*--------------------------------.
111 | Report a warning, and proceed. |
112 `--------------------------------*/
113
114 void
115 #if defined VA_START && defined __STDC__
116 warn_at (location_t location, const char *message, ...)
117 #else
118 warn_at (location, message, va_alist)
119 location_t location
120 char *message;
121 va_dcl
122 #endif
123 {
124 #ifdef VA_START
125 va_list args;
126 #endif
127
128 fflush (stdout);
129 LOCATION_PRINT (stderr, location);
130 fputs (": ", stderr);
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 }
145 \f
146 /*-----------------------------------------------------------.
147 | An error has occurred, but we can proceed, and die later. |
148 `-----------------------------------------------------------*/
149
150 void
151 #if defined VA_START && defined __STDC__
152 complain_at (location_t location, const char *message, ...)
153 #else
154 complain_at (location, message, va_alist)
155 location_t location;
156 char *message;
157 va_dcl
158 #endif
159 {
160 #ifdef VA_START
161 va_list args;
162 #endif
163
164 fflush (stdout);
165 LOCATION_PRINT (stderr, location);
166 fputs (": ", stderr);
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 }
180 \f
181 /*-------------------------------------------------.
182 | A severe error has occurred, we cannot proceed. |
183 `-------------------------------------------------*/
184
185 void
186 #if defined VA_START && defined __STDC__
187 fatal_at (location_t location, const char *message, ...)
188 #else
189 fatal (location, message, va_alist)
190 location_t location;
191 char *message;
192 va_dcl
193 #endif
194 {
195 #ifdef VA_START
196 va_list args;
197 #endif
198
199 fflush (stdout);
200 LOCATION_PRINT (stderr, location);
201 fputs (": ", stderr);
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
216 void
217 #if defined VA_START && defined __STDC__
218 fatal (const char *message, ...)
219 #else
220 fatal (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);
230 fprintf (stderr, "%s: ", infile ? infile : program_name);
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 }