]> git.saurik.com Git - bison.git/blame - src/complain.c
* src/output.c (prepare): Use MUSCLE_INSERT_STRING.
[bison.git] / src / complain.c
CommitLineData
a0f6b076 1/* Declaration for error-reporting function for Bison.
52489d44 2 Copyright (C) 2000, 2001, 2002 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
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. */
8f13fe33 52
a0f6b076 53# define program_name program_invocation_name
8f13fe33
AD
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
a0f6b076 66#else /* not _LIBC */
8f13fe33 67
a0f6b076
AD
68/* The calling program should define program_name and set it to the
69 name of the executing program. */
70extern char *program_name;
8f13fe33 71
9ff012ca
PE
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
8f13fe33 79# else
8f13fe33
AD
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}
9ff012ca
PE
91# define strerror private_strerror
92# endif /* HAVE_STRERROR */
8f13fe33 93#endif /* not _LIBC */
a0f6b076
AD
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
a0f6b076
AD
101\f
102/*--------------------------------.
103| Report a warning, and proceed. |
104`--------------------------------*/
105
e9955c83
AD
106void
107#if defined VA_START && defined __STDC__
ee000ba4 108warn_at (location_t location, const char *message, ...)
e9955c83
AD
109#else
110warn_at (location, message, va_alist)
ee000ba4 111 location_t location
e9955c83
AD
112 char *message;
113 va_dcl
114#endif
115{
116#ifdef VA_START
117 va_list args;
118#endif
119
e9955c83 120 fflush (stdout);
ee000ba4
AD
121 LOCATION_PRINT (stderr, location);
122 fputs (": ", stderr);
e9955c83
AD
123 fputs (_("warning: "), stderr);
124
52489d44
AD
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
e9955c83
AD
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}
a0f6b076
AD
166\f
167/*-----------------------------------------------------------.
168| An error has occurred, but we can proceed, and die later. |
169`-----------------------------------------------------------*/
170
e9955c83
AD
171void
172#if defined VA_START && defined __STDC__
ee000ba4 173complain_at (location_t location, const char *message, ...)
e9955c83
AD
174#else
175complain_at (location, message, va_alist)
ee000ba4 176 location_t location;
e9955c83
AD
177 char *message;
178 va_dcl
179#endif
180{
181#ifdef VA_START
182 va_list args;
183#endif
184
e9955c83 185 fflush (stdout);
ee000ba4
AD
186 LOCATION_PRINT (stderr, location);
187 fputs (": ", stderr);
e9955c83 188
52489d44
AD
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
e9955c83
AD
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}
a0f6b076
AD
230\f
231/*-------------------------------------------------.
232| A severe error has occurred, we cannot proceed. |
233`-------------------------------------------------*/
234
e9955c83
AD
235void
236#if defined VA_START && defined __STDC__
ee000ba4 237fatal_at (location_t location, const char *message, ...)
e9955c83 238#else
52489d44 239fatal_at (location, message, va_alist)
ee000ba4 240 location_t location;
e9955c83
AD
241 char *message;
242 va_dcl
243#endif
244{
245#ifdef VA_START
246 va_list args;
247#endif
248
249 fflush (stdout);
ee000ba4
AD
250 LOCATION_PRINT (stderr, location);
251 fputs (": ", stderr);
e9955c83
AD
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
a0f6b076 266void
342b8b6e 267#if defined VA_START && defined __STDC__
a0f6b076
AD
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);
a5d50994 280 fprintf (stderr, "%s: ", infile ? infile : program_name);
a0f6b076
AD
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}