]> git.saurik.com Git - bison.git/blob - src/complain.c
* src/complain.h, src/complain.c (warn, complain): Remove, unused.
[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 /* To get error_one_per_line. */
45 #include "error.h"
46
47 #include "complain.h"
48
49 #ifndef HAVE_DECL_STRERROR_R
50 "this configure-time declaration test was not run"
51 #endif
52 #if !HAVE_DECL_STRERROR_R
53 char *strerror_r ();
54 #endif
55
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. */
62
63 # define program_name program_invocation_name
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
76 #else /* not _LIBC */
77
78 /* The calling program should define program_name and set it to the
79 name of the executing program. */
80 extern char *program_name;
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 */
87 char *strerror ();
88 # endif
89 # else
90 static char *
91 private_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 */
105
106 /* This variable is incremented each time `warn' is called. */
107 unsigned int warn_message_count;
108
109 /* This variable is incremented each time `complain' is called. */
110 unsigned int complain_message_count;
111
112 \f
113 /*--------------------------------.
114 | Report a warning, and proceed. |
115 `--------------------------------*/
116
117 void
118 #if defined VA_START && defined __STDC__
119 warn_at (location_t location, const char *message, ...)
120 #else
121 warn_at (location, message, va_alist)
122 location_t location
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
136 if (old_lineno == location.first_line &&
137 (infile == old_infile || !strcmp (old_infile, infile)))
138 /* Simply return and print nothing. */
139 return;
140
141 old_infile = infile;
142 old_lineno = location.first_line;
143 }
144
145 fflush (stdout);
146 LOCATION_PRINT (stderr, location);
147 fputs (": ", stderr);
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 \f
163 /*-----------------------------------------------------------.
164 | An error has occurred, but we can proceed, and die later. |
165 `-----------------------------------------------------------*/
166
167 void
168 #if defined VA_START && defined __STDC__
169 complain_at (location_t location, const char *message, ...)
170 #else
171 complain_at (location, message, va_alist)
172 location_t location;
173 char *message;
174 va_dcl
175 #endif
176 {
177 #ifdef VA_START
178 va_list args;
179 #endif
180
181 if (error_one_per_line)
182 {
183 static const char *old_infile;
184 static int old_lineno;
185
186 if (old_lineno == location.first_line &&
187 (infile == old_infile || !strcmp (old_infile, infile)))
188 /* Simply return and print nothing. */
189 return;
190
191 old_infile = infile;
192 old_lineno = location.first_line;
193 }
194
195 fflush (stdout);
196 LOCATION_PRINT (stderr, location);
197 fputs (": ", 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 ++complain_message_count;
208 putc ('\n', stderr);
209 fflush (stderr);
210 }
211 \f
212 /*-------------------------------------------------.
213 | A severe error has occurred, we cannot proceed. |
214 `-------------------------------------------------*/
215
216 void
217 #if defined VA_START && defined __STDC__
218 fatal_at (location_t location, const char *message, ...)
219 #else
220 fatal (location, message, va_alist)
221 location_t location;
222 char *message;
223 va_dcl
224 #endif
225 {
226 #ifdef VA_START
227 va_list args;
228 #endif
229
230 fflush (stdout);
231 LOCATION_PRINT (stderr, location);
232 fputs (": ", stderr);
233 fputs (_("fatal error: "), stderr);
234
235 #ifdef VA_START
236 VA_START (args, message);
237 vfprintf (stderr, message, args);
238 va_end (args);
239 #else
240 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
241 #endif
242 putc ('\n', stderr);
243 fflush (stderr);
244 exit (1);
245 }
246
247 void
248 #if defined VA_START && defined __STDC__
249 fatal (const char *message, ...)
250 #else
251 fatal (message, va_alist)
252 char *message;
253 va_dcl
254 #endif
255 {
256 #ifdef VA_START
257 va_list args;
258 #endif
259
260 fflush (stdout);
261 fprintf (stderr, "%s: ", infile ? infile : program_name);
262
263 fputs (_("fatal error: "), stderr);
264
265 #ifdef VA_START
266 VA_START (args, message);
267 vfprintf (stderr, message, args);
268 va_end (args);
269 #else
270 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
271 #endif
272 putc ('\n', stderr);
273 fflush (stderr);
274 exit (1);
275 }