]>
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
;
163 /*-----------------------------------------------------------.
164 | An error has occurred, but we can proceed, and die later. |
165 `-----------------------------------------------------------*/
168 #if defined VA_START && defined __STDC__
169 complain_at (location_t location
, const char *message
, ...)
171 complain_at (location
, message
, va_alist
)
181 if (error_one_per_line
)
183 static const char *old_infile
;
184 static int old_lineno
;
186 if (old_lineno
== location
.first_line
&&
187 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
188 /* Simply return and print nothing. */
192 old_lineno
= location
.first_line
;
196 LOCATION_PRINT (stderr
, location
);
197 fputs (": ", stderr
);
200 VA_START (args
, message
);
201 vfprintf (stderr
, message
, args
);
204 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
207 ++complain_message_count
;
212 /*-------------------------------------------------.
213 | A severe error has occurred, we cannot proceed. |
214 `-------------------------------------------------*/
217 #if defined VA_START && defined __STDC__
218 fatal_at (location_t location
, const char *message
, ...)
220 fatal (location
, message
, va_alist
)
231 LOCATION_PRINT (stderr
, location
);
232 fputs (": ", stderr
);
233 fputs (_("fatal error: "), stderr
);
236 VA_START (args
, message
);
237 vfprintf (stderr
, message
, args
);
240 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
248 #if defined VA_START && defined __STDC__
249 fatal (const char *message
, ...)
251 fatal (message
, va_alist
)
261 fprintf (stderr
, "%s: ", infile
? infile
: program_name
);
263 fputs (_("fatal error: "), stderr
);
266 VA_START (args
, message
);
267 vfprintf (stderr
, message
, args
);
270 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);