]>
git.saurik.com Git - bison.git/blob - src/complain.c
1 /* Declaration for error-reporting function for Bison.
2 Copyright 2000, 2001 Free Software Foundation, Inc.
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
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.
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,
19 /* Based on error.c and error.h,
20 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
24 #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
27 # define VA_START(args, lastarg) va_start(args, lastarg)
30 # define VA_START(args, lastarg) va_start(args)
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;
37 #if STDC_HEADERS || _LIBC
44 /* To get error_one_per_line. */
49 #ifndef HAVE_DECL_STRERROR_R
50 "this configure-time declaration test was not run"
52 #if !HAVE_DECL_STRERROR_R
57 # define _(String) String
61 /* In the GNU C library, there is a predefined variable for this. */
63 # define program_name program_invocation_name
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
72 # include <libio/iolibio.h>
73 # define fflush(s) _IO_fflush (s)
78 /* The calling program should define program_name and set it to the
79 name of the executing program. */
80 extern char *program_name
;
82 # ifdef HAVE_STRERROR_R
83 # define __strerror_r strerror_r
86 # ifndef strerror /* On some systems, strerror is a macro */
91 private_strerror (errnum
)
94 extern char *sys_errlist
[];
97 if (errnum
> 0 && errnum
<= sys_nerr
)
98 return _(sys_errlist
[errnum
]);
99 return _("Unknown system error");
101 # define strerror private_strerror
102 # endif /* HAVE_STRERROR */
103 # endif /* HAVE_STRERROR_R */
104 #endif /* not _LIBC */
106 /* This variable is incremented each time `warn' is called. */
107 unsigned int warn_message_count
;
109 /* This variable is incremented each time `complain' is called. */
110 unsigned int complain_message_count
;
113 /*--------------------------------.
114 | Report a warning, and proceed. |
115 `--------------------------------*/
118 #if defined VA_START && defined __STDC__
119 warn_at (location_t location
, const char *message
, ...)
121 warn_at (location
, message
, va_alist
)
131 if (error_one_per_line
)
133 static const char *old_infile
;
134 static int old_lineno
;
136 if (old_lineno
== location
.first_line
&&
137 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
138 /* Simply return and print nothing. */
142 old_lineno
= location
.first_line
;
146 LOCATION_PRINT (stderr
, location
);
147 fputs (": ", stderr
);
148 fputs (_("warning: "), stderr
);
151 VA_START (args
, message
);
152 vfprintf (stderr
, message
, args
);
155 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
158 ++warn_message_count
;
165 #if defined VA_START && defined __STDC__
166 warn (const char *message
, ...)
168 warn (message
, va_alist
)
177 if (error_one_per_line
)
179 static const char *old_infile
;
180 static int old_lineno
;
182 if (old_lineno
== lineno
&&
183 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
184 /* Simply return and print nothing. */
193 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
195 fprintf (stderr
, "%s:", program_name
);
197 fputs (_("warning: "), stderr
);
200 VA_START (args
, message
);
201 vfprintf (stderr
, message
, args
);
204 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
207 ++warn_message_count
;
212 /*-----------------------------------------------------------.
213 | An error has occurred, but we can proceed, and die later. |
214 `-----------------------------------------------------------*/
217 #if defined VA_START && defined __STDC__
218 complain_at (location_t location
, const char *message
, ...)
220 complain_at (location
, message
, va_alist
)
230 if (error_one_per_line
)
232 static const char *old_infile
;
233 static int old_lineno
;
235 if (old_lineno
== location
.first_line
&&
236 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
237 /* Simply return and print nothing. */
241 old_lineno
= location
.first_line
;
245 LOCATION_PRINT (stderr
, location
);
246 fputs (": ", stderr
);
249 VA_START (args
, message
);
250 vfprintf (stderr
, message
, args
);
253 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
256 ++complain_message_count
;
263 #if defined VA_START && defined __STDC__
264 complain (const char *message
, ...)
266 complain (message
, va_alist
)
275 if (error_one_per_line
)
277 static const char *old_infile
;
278 static int old_lineno
;
280 if (old_lineno
== lineno
&&
281 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
282 /* Simply return and print nothing. */
291 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
293 fprintf (stderr
, "%s:", program_name
);
296 VA_START (args
, message
);
297 vfprintf (stderr
, message
, args
);
300 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
303 ++complain_message_count
;
308 /*-------------------------------------------------.
309 | A severe error has occurred, we cannot proceed. |
310 `-------------------------------------------------*/
313 #if defined VA_START && defined __STDC__
314 fatal_at (location_t location
, const char *message
, ...)
316 fatal (location
, message
, va_alist
)
327 LOCATION_PRINT (stderr
, location
);
328 fputs (": ", stderr
);
329 fputs (_("fatal error: "), stderr
);
332 VA_START (args
, message
);
333 vfprintf (stderr
, message
, args
);
336 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
344 #if defined VA_START && defined __STDC__
345 fatal (const char *message
, ...)
347 fatal (message
, va_alist
)
358 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
360 fprintf (stderr
, "%s:", program_name
);
362 fputs (_("fatal error: "), stderr
);
365 VA_START (args
, message
);
366 vfprintf (stderr
, message
, args
);
369 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);