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