]>
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
46 #ifndef HAVE_DECL_STRERROR_R
47 "this configure-time declaration test was not run"
49 #if !HAVE_DECL_STRERROR_R
54 # define _(String) String
58 /* In the GNU C library, there is a predefined variable for this. */
60 # define program_name program_invocation_name
63 /* In GNU libc we want do not want to use the common name `error' directly.
64 Instead make it a weak alias. */
65 # define error __error
66 # define error_at_line __error_at_line
69 # include <libio/iolibio.h>
70 # define fflush(s) _IO_fflush (s)
75 /* The calling program should define program_name and set it to the
76 name of the executing program. */
77 extern char *program_name
;
79 # ifdef HAVE_STRERROR_R
80 # define __strerror_r strerror_r
83 # ifndef strerror /* On some systems, strerror is a macro */
88 private_strerror (errnum
)
91 extern char *sys_errlist
[];
94 if (errnum
> 0 && errnum
<= sys_nerr
)
95 return _(sys_errlist
[errnum
]);
96 return _("Unknown system error");
98 # define strerror private_strerror
99 # endif /* HAVE_STRERROR */
100 # endif /* HAVE_STRERROR_R */
101 #endif /* not _LIBC */
103 /* This variable is incremented each time `warn' is called. */
104 unsigned int warn_message_count
;
106 /* This variable is incremented each time `complain' is called. */
107 unsigned int complain_message_count
;
109 /* Sometimes we want to have at most one error per line. This
110 variable controls whether this mode is selected or not. */
111 int error_one_per_line
;
113 /*--------------------------------.
114 | Report a warning, and proceed. |
115 `--------------------------------*/
118 #if defined VA_START && defined __STDC__
119 warn (const char *message
, ...)
121 warn (message
, va_alist
)
130 if (error_one_per_line
)
132 static const char *old_infile
;
133 static int old_lineno
;
135 if (old_lineno
== lineno
&&
136 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
137 /* Simply return and print nothing. */
146 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
148 fprintf (stderr
, "%s:", program_name
);
150 fputs (_("warning: "), stderr
);
153 VA_START (args
, message
);
154 vfprintf (stderr
, message
, args
);
157 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
160 ++warn_message_count
;
165 /*-----------------------------------------------------------.
166 | An error has occurred, but we can proceed, and die later. |
167 `-----------------------------------------------------------*/
170 #if defined VA_START && defined __STDC__
171 complain (const char *message
, ...)
173 complain (message
, va_alist
)
182 if (error_one_per_line
)
184 static const char *old_infile
;
185 static int old_lineno
;
187 if (old_lineno
== lineno
&&
188 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
189 /* Simply return and print nothing. */
198 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
200 fprintf (stderr
, "%s:", program_name
);
203 VA_START (args
, message
);
204 vfprintf (stderr
, message
, args
);
207 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
210 ++complain_message_count
;
215 /*-------------------------------------------------.
216 | A severe error has occurred, we cannot proceed. |
217 `-------------------------------------------------*/
220 #if defined VA_START && defined __STDC__
221 fatal (const char *message
, ...)
223 fatal (message
, va_alist
)
234 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
236 fprintf (stderr
, "%s:", program_name
);
238 fputs (_("fatal error: "), stderr
);
241 VA_START (args
, message
);
242 vfprintf (stderr
, message
, args
);
245 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);