]>
git.saurik.com Git - bison.git/blob - src/complain.c
1 /* Declaration for error-reporting function for Bison.
2 Copyright (C) 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
51 # define _(String) String
55 /* In the GNU C library, there is a predefined variable for this. */
56 # define program_name program_invocation_name
58 /* The calling program should define program_name and set it to the
59 name of the executing program. */
60 extern char *program_name
;
63 /* This variable is incremented each time `warn' is called. */
64 unsigned int warn_message_count
;
66 /* This variable is incremented each time `complain' is called. */
67 unsigned int complain_message_count
;
69 /* Sometimes we want to have at most one error per line. This
70 variable controls whether this mode is selected or not. */
71 int error_one_per_line
;
73 /*--------------------------------.
74 | Report a warning, and proceed. |
75 `--------------------------------*/
78 #if defined VA_START && __STDC__
79 warn (const char *message
, ...)
81 warn (message
, va_alist
)
90 if (error_one_per_line
)
92 static const char *old_infile
;
93 static unsigned int old_lineno
;
95 if (old_lineno
== lineno
&&
96 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
97 /* Simply return and print nothing. */
106 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
108 fprintf (stderr
, "%s:", program_name
);
110 fputs (_("warning: "), stderr
);
113 VA_START (args
, message
);
114 vfprintf (stderr
, message
, args
);
117 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
120 ++warn_message_count
;
125 /*-----------------------------------------------------------.
126 | An error has occurred, but we can proceed, and die later. |
127 `-----------------------------------------------------------*/
130 #if defined VA_START && __STDC__
131 complain (const char *message
, ...)
133 complain (message
, va_alist
)
142 if (error_one_per_line
)
144 static const char *old_infile
;
145 static unsigned int old_lineno
;
147 if (old_lineno
== lineno
&&
148 (infile
== old_infile
|| !strcmp (old_infile
, infile
)))
149 /* Simply return and print nothing. */
158 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
160 fprintf (stderr
, "%s:", program_name
);
163 VA_START (args
, message
);
164 vfprintf (stderr
, message
, args
);
167 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
170 ++complain_message_count
;
175 /*-------------------------------------------------.
176 | A severe error has occurred, we cannot proceed. |
177 `-------------------------------------------------*/
180 #if defined VA_START && __STDC__
181 fatal (const char *message
, ...)
183 fatal (message
, va_alist
)
194 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
196 fprintf (stderr
, "%s:", program_name
);
198 fputs (_("fatal error: "), stderr
);
201 VA_START (args
, message
);
202 vfprintf (stderr
, message
, args
);
205 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
212 /*------------------------------------------------------------------.
213 | A severe error has occurred, we cannot proceed. Exit with STATUS, |
214 | and report the error message of the errno ERRNUM. |
215 `------------------------------------------------------------------*/
218 #if defined VA_START && __STDC__
219 error (int status
, int errnum
,
220 const char *message
, ...)
222 error (status
, errnum
, message
, va_alist
)
235 fprintf (stderr
, "%s:%d: ", infile
, lineno
);
237 fprintf (stderr
, "%s:", program_name
);
239 fputs (_("fatal error: "), stderr
);
242 VA_START (args
, message
);
243 vfprintf (stderr
, message
, args
);
246 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
251 #if defined HAVE_STRERROR_R || _LIBC
253 # if HAVE_WORKING_STRERROR_R || _LIBC
254 fprintf (stderr
, ": %s", __strerror_r (errnum
, errbuf
, sizeof errbuf
));
256 /* Don't use __strerror_r's return value because on some systems
257 (at least DEC UNIX 4.0[A-D]) strerror_r returns `int'. */
258 __strerror_r (errnum
, errbuf
, sizeof errbuf
);
259 fprintf (stderr
, ": %s", errbuf
);
262 fprintf (stderr
, ": %s", strerror (errnum
));