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