]> git.saurik.com Git - bison.git/blame - src/complain.c
Do not include <assert.h>.
[bison.git] / src / complain.c
CommitLineData
a0f6b076 1/* Declaration for error-reporting function for Bison.
52489d44 2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
a0f6b076
AD
3
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
7 later version.
8
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.
13
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,
17 USA. */
18
19/* Based on error.c and error.h,
20 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
21
342b8b6e 22#include "system.h"
a0f6b076 23
21184140
PE
24#include <stdarg.h>
25#if ! (HAVE_VPRINTF || defined vfprintf)
26# define vfprintf(stream, message, args) _doprnt (message, args, stream)
a0f6b076
AD
27#endif
28
29#if STDC_HEADERS || _LIBC
30# include <stdlib.h>
31# include <string.h>
a0f6b076
AD
32#endif
33
34#include "complain.h"
35
36#ifndef _
37# define _(String) String
38#endif
39
40#ifdef _LIBC
41/* In the GNU C library, there is a predefined variable for this. */
8f13fe33 42
a0f6b076 43# define program_name program_invocation_name
8f13fe33
AD
44# include <errno.h>
45
46/* In GNU libc we want do not want to use the common name `error' directly.
47 Instead make it a weak alias. */
48# define error __error
49# define error_at_line __error_at_line
50
51# ifdef USE_IN_LIBIO
52# include <libio/iolibio.h>
53# define fflush(s) _IO_fflush (s)
54# endif
55
a0f6b076 56#else /* not _LIBC */
8f13fe33 57
a0f6b076
AD
58/* The calling program should define program_name and set it to the
59 name of the executing program. */
60extern char *program_name;
8f13fe33 61
9ff012ca
PE
62# if HAVE_STRERROR
63# ifndef HAVE_DECL_STRERROR
64"this configure-time declaration test was not run"
65# endif
66# if !HAVE_DECL_STRERROR && !defined strerror
21184140 67char *strerror (int);
9ff012ca 68# endif
8f13fe33 69# else
8f13fe33 70static char *
21184140 71private_strerror (int errnum)
8f13fe33
AD
72{
73 extern char *sys_errlist[];
74 extern int sys_nerr;
75
76 if (errnum > 0 && errnum <= sys_nerr)
77 return _(sys_errlist[errnum]);
78 return _("Unknown system error");
79}
9ff012ca
PE
80# define strerror private_strerror
81# endif /* HAVE_STRERROR */
8f13fe33 82#endif /* not _LIBC */
a0f6b076 83
0ae6073a
PE
84/* This variable is set each time `warn' is called. */
85bool warning_issued;
a0f6b076 86
0ae6073a
PE
87/* This variable is set each time `complain' is called. */
88bool complaint_issued;
a0f6b076 89
a0f6b076
AD
90\f
91/*--------------------------------.
92| Report a warning, and proceed. |
93`--------------------------------*/
94
e9955c83 95void
ee000ba4 96warn_at (location_t location, const char *message, ...)
e9955c83 97{
e9955c83 98 va_list args;
e9955c83 99
e9955c83 100 fflush (stdout);
ee000ba4
AD
101 LOCATION_PRINT (stderr, location);
102 fputs (": ", stderr);
e9955c83
AD
103 fputs (_("warning: "), stderr);
104
21184140 105 va_start (args, message);
52489d44
AD
106 vfprintf (stderr, message, args);
107 va_end (args);
52489d44 108
0ae6073a 109 warning_issued = true;
52489d44
AD
110 putc ('\n', stderr);
111 fflush (stderr);
112}
113
114void
52489d44 115warn (const char *message, ...)
52489d44 116{
52489d44 117 va_list args;
52489d44
AD
118
119 fflush (stdout);
95612cfa 120 fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: "));
52489d44 121
21184140 122 va_start (args, message);
e9955c83
AD
123 vfprintf (stderr, message, args);
124 va_end (args);
e9955c83 125
0ae6073a 126 warning_issued = true;
e9955c83
AD
127 putc ('\n', stderr);
128 fflush (stderr);
129}
a0f6b076
AD
130\f
131/*-----------------------------------------------------------.
132| An error has occurred, but we can proceed, and die later. |
133`-----------------------------------------------------------*/
134
e9955c83 135void
ee000ba4 136complain_at (location_t location, const char *message, ...)
e9955c83 137{
e9955c83 138 va_list args;
e9955c83 139
e9955c83 140 fflush (stdout);
ee000ba4
AD
141 LOCATION_PRINT (stderr, location);
142 fputs (": ", stderr);
e9955c83 143
21184140 144 va_start (args, message);
52489d44
AD
145 vfprintf (stderr, message, args);
146 va_end (args);
52489d44 147
0ae6073a 148 complaint_issued = true;
52489d44
AD
149 putc ('\n', stderr);
150 fflush (stderr);
151}
152
153void
52489d44 154complain (const char *message, ...)
52489d44 155{
52489d44 156 va_list args;
52489d44
AD
157
158 fflush (stdout);
95612cfa 159 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
52489d44 160
21184140 161 va_start (args, message);
e9955c83
AD
162 vfprintf (stderr, message, args);
163 va_end (args);
e9955c83 164
0ae6073a 165 complaint_issued = true;
e9955c83
AD
166 putc ('\n', stderr);
167 fflush (stderr);
168}
a0f6b076
AD
169\f
170/*-------------------------------------------------.
171| A severe error has occurred, we cannot proceed. |
172`-------------------------------------------------*/
173
e9955c83 174void
ee000ba4 175fatal_at (location_t location, const char *message, ...)
e9955c83 176{
e9955c83 177 va_list args;
e9955c83
AD
178
179 fflush (stdout);
ee000ba4
AD
180 LOCATION_PRINT (stderr, location);
181 fputs (": ", stderr);
e9955c83
AD
182 fputs (_("fatal error: "), stderr);
183
21184140 184 va_start (args, message);
e9955c83
AD
185 vfprintf (stderr, message, args);
186 va_end (args);
e9955c83
AD
187 putc ('\n', stderr);
188 fflush (stderr);
0ae6073a 189 exit (EXIT_FAILURE);
e9955c83
AD
190}
191
a0f6b076 192void
a0f6b076 193fatal (const char *message, ...)
a0f6b076 194{
a0f6b076 195 va_list args;
a0f6b076
AD
196
197 fflush (stdout);
95612cfa 198 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
a0f6b076
AD
199
200 fputs (_("fatal error: "), stderr);
201
21184140 202 va_start (args, message);
a0f6b076
AD
203 vfprintf (stderr, message, args);
204 va_end (args);
a0f6b076
AD
205 putc ('\n', stderr);
206 fflush (stderr);
0ae6073a 207 exit (EXIT_FAILURE);
a0f6b076 208}