]>
git.saurik.com Git - bison.git/blob - src/complain.c
1 /* Declaration for error-reporting function for Bison.
2 Copyright 2000 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>. */
28 #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
31 # define VA_START(args, lastarg) va_start(args, lastarg)
34 # define VA_START(args, lastarg) va_start(args)
37 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
38 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
41 #if STDC_HEADERS || _LIBC
50 #ifndef HAVE_DECL_STRERROR_R
51 "this configure-time declaration test was not run"
53 #if !HAVE_DECL_STRERROR_R
58 # define _(String) String
62 /* In the GNU C library, there is a predefined variable for this. */
64 # define program_name program_invocation_name
67 /* In GNU libc we want do not want to use the common name `error' directly.
68 Instead make it a weak alias. */
69 # define error __error
70 # define error_at_line __error_at_line
73 # include <libio/iolibio.h>
74 # define fflush(s) _IO_fflush (s)
79 /* The calling program should define program_name and set it to the
80 name of the executing program. */
81 extern char *program_name
;
83 # ifdef HAVE_STRERROR_R
84 # define __strerror_r strerror_r
87 # ifndef strerror /* On some systems, strerror is a macro */
92 private_strerror (errnum
)
95 extern char *sys_errlist
[];
98 if (errnum
> 0 && errnum
<= sys_nerr
)
99 return _(sys_errlist
[errnum
]);
100 return _("Unknown system error");
102 # define strerror private_strerror
103 # endif /* HAVE_STRERROR */
104 # endif /* HAVE_STRERROR_R */
105 #endif /* not _LIBC */
107 /* This variable is incremented each time `warn' is called. */
108 unsigned int warn_message_count
;
110 /* This variable is incremented each time `complain' is called. */
111 unsigned int complain_message_count
;
113 /* Sometimes we want to have at most one error per line. This
114 variable controls whether this mode is selected or not. */
115 int error_one_per_line
;
117 /*--------------------------------.
118 | Report a warning, and proceed. |
119 `--------------------------------*/
122 #if defined VA_START && __STDC__
123 warn (const char *message
, ...)
125 warn (message
, va_alist
)
134 if (error_one_per_line
)
136 static const char *old_infile
;
137 static int old_lineno
;
139 if (old_lineno
== lineno
&&
140 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
141 /* Simply return and print nothing. */
150 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
152 fprintf (stderr
, "%s:", program_name
);
154 fputs (_("warning: "), stderr
);
157 VA_START (args
, message
);
158 vfprintf (stderr
, message
, args
);
161 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
164 ++warn_message_count
;
169 /*-----------------------------------------------------------.
170 | An error has occurred, but we can proceed, and die later. |
171 `-----------------------------------------------------------*/
174 #if defined VA_START && __STDC__
175 complain (const char *message
, ...)
177 complain (message
, va_alist
)
186 if (error_one_per_line
)
188 static const char *old_infile
;
189 static int old_lineno
;
191 if (old_lineno
== lineno
&&
192 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
193 /* Simply return and print nothing. */
202 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
204 fprintf (stderr
, "%s:", program_name
);
207 VA_START (args
, message
);
208 vfprintf (stderr
, message
, args
);
211 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
214 ++complain_message_count
;
219 /*-------------------------------------------------.
220 | A severe error has occurred, we cannot proceed. |
221 `-------------------------------------------------*/
224 #if defined VA_START && __STDC__
225 fatal (const char *message
, ...)
227 fatal (message
, va_alist
)
238 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
240 fprintf (stderr
, "%s:", program_name
);
242 fputs (_("fatal error: "), stderr
);
245 VA_START (args
, message
);
246 vfprintf (stderr
, message
, args
);
249 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
256 /*------------------------------------------------------------------.
257 | A severe error has occurred, we cannot proceed. Exit with STATUS, |
258 | and report the error message of the errno ERRNUM. |
259 `------------------------------------------------------------------*/
262 #if defined VA_START && __STDC__
263 error (int status
, int errnum
,
264 const char *message
, ...)
266 error (status
, errnum
, message
, va_alist
)
279 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
281 fprintf (stderr
, "%s:", program_name
);
283 fputs (_("fatal error: "), stderr
);
286 VA_START (args
, message
);
287 vfprintf (stderr
, message
, args
);
290 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
295 #if defined HAVE_STRERROR_R || _LIBC
297 # if HAVE_WORKING_STRERROR_R || _LIBC
298 fprintf (stderr
, ": %s", __strerror_r (errnum
, errbuf
, sizeof errbuf
));
300 /* Don't use __strerror_r's return value because on some systems
301 (at least DEC UNIX 4.0[A-D]) strerror_r returns `int'. */
302 __strerror_r (errnum
, errbuf
, sizeof errbuf
);
303 fprintf (stderr
, ": %s", errbuf
);
306 fprintf (stderr
, ": %s", strerror (errnum
));