]>
Commit | Line | Data |
---|---|---|
a0f6b076 | 1 | /* Declaration for error-reporting function for Bison. |
4b68955b | 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 | ||
a0f6b076 | 29 | #include "complain.h" |
4b68955b | 30 | #include "files.h" |
a0f6b076 AD |
31 | |
32 | #ifndef _ | |
33 | # define _(String) String | |
34 | #endif | |
35 | ||
a0f6b076 AD |
36 | /* The calling program should define program_name and set it to the |
37 | name of the executing program. */ | |
38 | extern char *program_name; | |
8f13fe33 | 39 | |
41f83caf PE |
40 | #if HAVE_STRERROR |
41 | # ifndef HAVE_DECL_STRERROR | |
9ff012ca | 42 | "this configure-time declaration test was not run" |
41f83caf PE |
43 | # endif |
44 | # if !HAVE_DECL_STRERROR && !defined strerror | |
21184140 | 45 | char *strerror (int); |
41f83caf PE |
46 | # endif |
47 | #else | |
8f13fe33 | 48 | static char * |
21184140 | 49 | private_strerror (int errnum) |
8f13fe33 AD |
50 | { |
51 | extern char *sys_errlist[]; | |
52 | extern int sys_nerr; | |
53 | ||
54 | if (errnum > 0 && errnum <= sys_nerr) | |
55 | return _(sys_errlist[errnum]); | |
56 | return _("Unknown system error"); | |
57 | } | |
41f83caf PE |
58 | # define strerror private_strerror |
59 | #endif /* HAVE_STRERROR */ | |
a0f6b076 | 60 | |
0ae6073a PE |
61 | /* This variable is set each time `warn' is called. */ |
62 | bool warning_issued; | |
a0f6b076 | 63 | |
0ae6073a PE |
64 | /* This variable is set each time `complain' is called. */ |
65 | bool complaint_issued; | |
a0f6b076 | 66 | |
a0f6b076 AD |
67 | \f |
68 | /*--------------------------------. | |
69 | | Report a warning, and proceed. | | |
70 | `--------------------------------*/ | |
71 | ||
e9955c83 | 72 | void |
41f83caf | 73 | warn_at (location loc, const char *message, ...) |
e9955c83 | 74 | { |
e9955c83 | 75 | va_list args; |
e9955c83 | 76 | |
e9955c83 | 77 | fflush (stdout); |
41f83caf | 78 | location_print (stderr, loc); |
ee000ba4 | 79 | fputs (": ", stderr); |
e9955c83 AD |
80 | fputs (_("warning: "), stderr); |
81 | ||
21184140 | 82 | va_start (args, message); |
52489d44 AD |
83 | vfprintf (stderr, message, args); |
84 | va_end (args); | |
52489d44 | 85 | |
0ae6073a | 86 | warning_issued = true; |
52489d44 AD |
87 | putc ('\n', stderr); |
88 | fflush (stderr); | |
89 | } | |
90 | ||
91 | void | |
52489d44 | 92 | warn (const char *message, ...) |
52489d44 | 93 | { |
52489d44 | 94 | va_list args; |
52489d44 AD |
95 | |
96 | fflush (stdout); | |
95612cfa | 97 | fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: ")); |
52489d44 | 98 | |
21184140 | 99 | va_start (args, message); |
e9955c83 AD |
100 | vfprintf (stderr, message, args); |
101 | va_end (args); | |
e9955c83 | 102 | |
0ae6073a | 103 | warning_issued = true; |
e9955c83 AD |
104 | putc ('\n', stderr); |
105 | fflush (stderr); | |
106 | } | |
a0f6b076 AD |
107 | \f |
108 | /*-----------------------------------------------------------. | |
109 | | An error has occurred, but we can proceed, and die later. | | |
110 | `-----------------------------------------------------------*/ | |
111 | ||
e9955c83 | 112 | void |
41f83caf | 113 | complain_at (location loc, const char *message, ...) |
e9955c83 | 114 | { |
e9955c83 | 115 | va_list args; |
e9955c83 | 116 | |
e9955c83 | 117 | fflush (stdout); |
41f83caf | 118 | location_print (stderr, loc); |
ee000ba4 | 119 | fputs (": ", stderr); |
e9955c83 | 120 | |
21184140 | 121 | va_start (args, message); |
52489d44 AD |
122 | vfprintf (stderr, message, args); |
123 | va_end (args); | |
52489d44 | 124 | |
0ae6073a | 125 | complaint_issued = true; |
52489d44 AD |
126 | putc ('\n', stderr); |
127 | fflush (stderr); | |
128 | } | |
129 | ||
130 | void | |
52489d44 | 131 | complain (const char *message, ...) |
52489d44 | 132 | { |
52489d44 | 133 | va_list args; |
52489d44 AD |
134 | |
135 | fflush (stdout); | |
95612cfa | 136 | fprintf (stderr, "%s: ", current_file ? current_file : program_name); |
52489d44 | 137 | |
21184140 | 138 | va_start (args, message); |
e9955c83 AD |
139 | vfprintf (stderr, message, args); |
140 | va_end (args); | |
e9955c83 | 141 | |
0ae6073a | 142 | complaint_issued = true; |
e9955c83 AD |
143 | putc ('\n', stderr); |
144 | fflush (stderr); | |
145 | } | |
a0f6b076 AD |
146 | \f |
147 | /*-------------------------------------------------. | |
148 | | A severe error has occurred, we cannot proceed. | | |
149 | `-------------------------------------------------*/ | |
150 | ||
e9955c83 | 151 | void |
41f83caf | 152 | fatal_at (location loc, const char *message, ...) |
e9955c83 | 153 | { |
e9955c83 | 154 | va_list args; |
e9955c83 AD |
155 | |
156 | fflush (stdout); | |
41f83caf | 157 | location_print (stderr, loc); |
ee000ba4 | 158 | fputs (": ", stderr); |
e9955c83 AD |
159 | fputs (_("fatal error: "), stderr); |
160 | ||
21184140 | 161 | va_start (args, message); |
e9955c83 AD |
162 | vfprintf (stderr, message, args); |
163 | va_end (args); | |
e9955c83 AD |
164 | putc ('\n', stderr); |
165 | fflush (stderr); | |
0ae6073a | 166 | exit (EXIT_FAILURE); |
e9955c83 AD |
167 | } |
168 | ||
a0f6b076 | 169 | void |
a0f6b076 | 170 | fatal (const char *message, ...) |
a0f6b076 | 171 | { |
a0f6b076 | 172 | va_list args; |
a0f6b076 AD |
173 | |
174 | fflush (stdout); | |
95612cfa | 175 | fprintf (stderr, "%s: ", current_file ? current_file : program_name); |
a0f6b076 AD |
176 | |
177 | fputs (_("fatal error: "), stderr); | |
178 | ||
21184140 | 179 | va_start (args, message); |
a0f6b076 AD |
180 | vfprintf (stderr, message, args); |
181 | va_end (args); | |
a0f6b076 AD |
182 | putc ('\n', stderr); |
183 | fflush (stderr); | |
0ae6073a | 184 | exit (EXIT_FAILURE); |
a0f6b076 | 185 | } |