]>
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 (int 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
&&
137 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
138 /* Simply return and print nothing. */
142 old_lineno
= location
;
147 fprintf (stderr
, "%s:%d: ", infile
, location
);
149 fprintf (stderr
, "%s:", program_name
);
151 fputs (_("warning: "), stderr
);
154 VA_START (args
, message
);
155 vfprintf (stderr
, message
, args
);
158 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
161 ++warn_message_count
;
168 #if defined VA_START && defined __STDC__
169 warn (const char *message
, ...)
171 warn (message
, va_alist
)
180 if (error_one_per_line
)
182 static const char *old_infile
;
183 static int old_lineno
;
185 if (old_lineno
== lineno
&&
186 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
187 /* Simply return and print nothing. */
196 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
198 fprintf (stderr
, "%s:", program_name
);
200 fputs (_("warning: "), stderr
);
203 VA_START (args
, message
);
204 vfprintf (stderr
, message
, args
);
207 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
210 ++warn_message_count
;
215 /*-----------------------------------------------------------.
216 | An error has occurred, but we can proceed, and die later. |
217 `-----------------------------------------------------------*/
220 #if defined VA_START && defined __STDC__
221 complain_at (int location
, const char *message
, ...)
223 complain_at (location
, message
, va_alist
)
233 if (error_one_per_line
)
235 static const char *old_infile
;
236 static int old_lineno
;
238 if (old_lineno
== location
&&
239 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
240 /* Simply return and print nothing. */
244 old_lineno
= location
;
249 fprintf (stderr
, "%s:%d: ", infile
, location
);
251 fprintf (stderr
, "%s:", program_name
);
254 VA_START (args
, message
);
255 vfprintf (stderr
, message
, args
);
258 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
261 ++complain_message_count
;
268 #if defined VA_START && defined __STDC__
269 complain (const char *message
, ...)
271 complain (message
, va_alist
)
280 if (error_one_per_line
)
282 static const char *old_infile
;
283 static int old_lineno
;
285 if (old_lineno
== lineno
&&
286 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
287 /* Simply return and print nothing. */
296 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
298 fprintf (stderr
, "%s:", program_name
);
301 VA_START (args
, message
);
302 vfprintf (stderr
, message
, args
);
305 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
308 ++complain_message_count
;
313 /*-------------------------------------------------.
314 | A severe error has occurred, we cannot proceed. |
315 `-------------------------------------------------*/
318 #if defined VA_START && defined __STDC__
319 fatal_at (int location
, const char *message
, ...)
321 fatal (location
, message
, va_alist
)
333 fprintf (stderr
, "%s:%d: ", infile
, location
);
335 fprintf (stderr
, "%s:", program_name
);
337 fputs (_("fatal error: "), stderr
);
340 VA_START (args
, message
);
341 vfprintf (stderr
, message
, args
);
344 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
352 #if defined VA_START && defined __STDC__
353 fatal (const char *message
, ...)
355 fatal (message
, va_alist
)
366 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
368 fprintf (stderr
, "%s:", program_name
);
370 fputs (_("fatal error: "), stderr
);
373 VA_START (args
, message
);
374 vfprintf (stderr
, message
, args
);
377 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);