]>
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 | #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. */ | |
42 | ||
43 | # define program_name program_invocation_name | |
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 | ||
56 | #else /* not _LIBC */ | |
57 | ||
58 | /* The calling program should define program_name and set it to the | |
59 | name of the executing program. */ | |
60 | extern char *program_name; | |
61 | ||
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 | |
67 | char *strerror (int); | |
68 | # endif | |
69 | # else | |
70 | static char * | |
71 | private_strerror (int errnum) | |
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 | } | |
80 | # define strerror private_strerror | |
81 | # endif /* HAVE_STRERROR */ | |
82 | #endif /* not _LIBC */ | |
83 | ||
84 | /* This variable is set each time `warn' is called. */ | |
85 | bool warning_issued; | |
86 | ||
87 | /* This variable is set each time `complain' is called. */ | |
88 | bool complaint_issued; | |
89 | ||
90 | \f | |
91 | /*--------------------------------. | |
92 | | Report a warning, and proceed. | | |
93 | `--------------------------------*/ | |
94 | ||
95 | void | |
96 | warn_at (location_t location, const char *message, ...) | |
97 | { | |
98 | va_list args; | |
99 | ||
100 | fflush (stdout); | |
101 | LOCATION_PRINT (stderr, location); | |
102 | fputs (": ", stderr); | |
103 | fputs (_("warning: "), stderr); | |
104 | ||
105 | va_start (args, message); | |
106 | vfprintf (stderr, message, args); | |
107 | va_end (args); | |
108 | ||
109 | warning_issued = true; | |
110 | putc ('\n', stderr); | |
111 | fflush (stderr); | |
112 | } | |
113 | ||
114 | void | |
115 | warn (const char *message, ...) | |
116 | { | |
117 | va_list args; | |
118 | ||
119 | fflush (stdout); | |
120 | fprintf (stderr, "%s: %s", infile ? infile : program_name, _("warning: ")); | |
121 | ||
122 | va_start (args, message); | |
123 | vfprintf (stderr, message, args); | |
124 | va_end (args); | |
125 | ||
126 | warning_issued = true; | |
127 | putc ('\n', stderr); | |
128 | fflush (stderr); | |
129 | } | |
130 | \f | |
131 | /*-----------------------------------------------------------. | |
132 | | An error has occurred, but we can proceed, and die later. | | |
133 | `-----------------------------------------------------------*/ | |
134 | ||
135 | void | |
136 | complain_at (location_t location, const char *message, ...) | |
137 | { | |
138 | va_list args; | |
139 | ||
140 | fflush (stdout); | |
141 | LOCATION_PRINT (stderr, location); | |
142 | fputs (": ", stderr); | |
143 | ||
144 | va_start (args, message); | |
145 | vfprintf (stderr, message, args); | |
146 | va_end (args); | |
147 | ||
148 | complaint_issued = true; | |
149 | putc ('\n', stderr); | |
150 | fflush (stderr); | |
151 | } | |
152 | ||
153 | void | |
154 | complain (const char *message, ...) | |
155 | { | |
156 | va_list args; | |
157 | ||
158 | fflush (stdout); | |
159 | fprintf (stderr, "%s: ", infile ? infile : program_name); | |
160 | ||
161 | va_start (args, message); | |
162 | vfprintf (stderr, message, args); | |
163 | va_end (args); | |
164 | ||
165 | complaint_issued = true; | |
166 | putc ('\n', stderr); | |
167 | fflush (stderr); | |
168 | } | |
169 | \f | |
170 | /*-------------------------------------------------. | |
171 | | A severe error has occurred, we cannot proceed. | | |
172 | `-------------------------------------------------*/ | |
173 | ||
174 | void | |
175 | fatal_at (location_t location, const char *message, ...) | |
176 | { | |
177 | va_list args; | |
178 | ||
179 | fflush (stdout); | |
180 | LOCATION_PRINT (stderr, location); | |
181 | fputs (": ", stderr); | |
182 | fputs (_("fatal error: "), stderr); | |
183 | ||
184 | va_start (args, message); | |
185 | vfprintf (stderr, message, args); | |
186 | va_end (args); | |
187 | putc ('\n', stderr); | |
188 | fflush (stderr); | |
189 | exit (EXIT_FAILURE); | |
190 | } | |
191 | ||
192 | void | |
193 | fatal (const char *message, ...) | |
194 | { | |
195 | va_list args; | |
196 | ||
197 | fflush (stdout); | |
198 | fprintf (stderr, "%s: ", infile ? infile : program_name); | |
199 | ||
200 | fputs (_("fatal error: "), stderr); | |
201 | ||
202 | va_start (args, message); | |
203 | vfprintf (stderr, message, args); | |
204 | va_end (args); | |
205 | putc ('\n', stderr); | |
206 | fflush (stderr); | |
207 | exit (EXIT_FAILURE); | |
208 | } |