]>
Commit | Line | Data |
---|---|---|
a0f6b076 | 1 | /* Declaration for error-reporting function for Bison. |
6e26ca8c | 2 | Copyright (C) 2000, 2001, 2002, 2004 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 | 24 | #include <stdarg.h> |
a0f6b076 | 25 | |
a0f6b076 | 26 | #include "complain.h" |
4b68955b | 27 | #include "files.h" |
a0f6b076 | 28 | |
a0f6b076 AD |
29 | /* The calling program should define program_name and set it to the |
30 | name of the executing program. */ | |
31 | extern char *program_name; | |
8f13fe33 | 32 | |
0ae6073a PE |
33 | /* This variable is set each time `warn' is called. */ |
34 | bool warning_issued; | |
a0f6b076 | 35 | |
0ae6073a PE |
36 | /* This variable is set each time `complain' is called. */ |
37 | bool complaint_issued; | |
a0f6b076 | 38 | |
a0f6b076 AD |
39 | \f |
40 | /*--------------------------------. | |
41 | | Report a warning, and proceed. | | |
42 | `--------------------------------*/ | |
43 | ||
e9955c83 | 44 | void |
41f83caf | 45 | warn_at (location loc, const char *message, ...) |
e9955c83 | 46 | { |
e9955c83 | 47 | va_list args; |
e9955c83 | 48 | |
41f83caf | 49 | location_print (stderr, loc); |
ee000ba4 | 50 | fputs (": ", stderr); |
e9955c83 AD |
51 | fputs (_("warning: "), stderr); |
52 | ||
21184140 | 53 | va_start (args, message); |
52489d44 AD |
54 | vfprintf (stderr, message, args); |
55 | va_end (args); | |
52489d44 | 56 | |
0ae6073a | 57 | warning_issued = true; |
52489d44 | 58 | putc ('\n', stderr); |
52489d44 AD |
59 | } |
60 | ||
61 | void | |
52489d44 | 62 | warn (const char *message, ...) |
52489d44 | 63 | { |
52489d44 | 64 | va_list args; |
52489d44 | 65 | |
95612cfa | 66 | fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: ")); |
52489d44 | 67 | |
21184140 | 68 | va_start (args, message); |
e9955c83 AD |
69 | vfprintf (stderr, message, args); |
70 | va_end (args); | |
e9955c83 | 71 | |
0ae6073a | 72 | warning_issued = true; |
e9955c83 | 73 | putc ('\n', stderr); |
e9955c83 | 74 | } |
a0f6b076 AD |
75 | \f |
76 | /*-----------------------------------------------------------. | |
77 | | An error has occurred, but we can proceed, and die later. | | |
78 | `-----------------------------------------------------------*/ | |
79 | ||
e9955c83 | 80 | void |
41f83caf | 81 | complain_at (location loc, const char *message, ...) |
e9955c83 | 82 | { |
e9955c83 | 83 | va_list args; |
e9955c83 | 84 | |
41f83caf | 85 | location_print (stderr, loc); |
ee000ba4 | 86 | fputs (": ", stderr); |
e9955c83 | 87 | |
21184140 | 88 | va_start (args, message); |
52489d44 AD |
89 | vfprintf (stderr, message, args); |
90 | va_end (args); | |
52489d44 | 91 | |
0ae6073a | 92 | complaint_issued = true; |
52489d44 | 93 | putc ('\n', stderr); |
52489d44 AD |
94 | } |
95 | ||
96 | void | |
52489d44 | 97 | complain (const char *message, ...) |
52489d44 | 98 | { |
52489d44 | 99 | va_list args; |
52489d44 | 100 | |
95612cfa | 101 | fprintf (stderr, "%s: ", current_file ? current_file : program_name); |
52489d44 | 102 | |
21184140 | 103 | va_start (args, message); |
e9955c83 AD |
104 | vfprintf (stderr, message, args); |
105 | va_end (args); | |
e9955c83 | 106 | |
0ae6073a | 107 | complaint_issued = true; |
e9955c83 | 108 | putc ('\n', stderr); |
e9955c83 | 109 | } |
a0f6b076 AD |
110 | \f |
111 | /*-------------------------------------------------. | |
112 | | A severe error has occurred, we cannot proceed. | | |
113 | `-------------------------------------------------*/ | |
114 | ||
e9955c83 | 115 | void |
41f83caf | 116 | fatal_at (location loc, const char *message, ...) |
e9955c83 | 117 | { |
e9955c83 | 118 | va_list args; |
e9955c83 | 119 | |
41f83caf | 120 | location_print (stderr, loc); |
ee000ba4 | 121 | fputs (": ", stderr); |
e9955c83 AD |
122 | fputs (_("fatal error: "), stderr); |
123 | ||
21184140 | 124 | va_start (args, message); |
e9955c83 AD |
125 | vfprintf (stderr, message, args); |
126 | va_end (args); | |
e9955c83 | 127 | putc ('\n', stderr); |
0ae6073a | 128 | exit (EXIT_FAILURE); |
e9955c83 AD |
129 | } |
130 | ||
a0f6b076 | 131 | void |
a0f6b076 | 132 | fatal (const char *message, ...) |
a0f6b076 | 133 | { |
a0f6b076 | 134 | va_list args; |
a0f6b076 | 135 | |
95612cfa | 136 | fprintf (stderr, "%s: ", current_file ? current_file : program_name); |
a0f6b076 AD |
137 | |
138 | fputs (_("fatal error: "), stderr); | |
139 | ||
21184140 | 140 | va_start (args, message); |
a0f6b076 AD |
141 | vfprintf (stderr, message, args); |
142 | va_end (args); | |
a0f6b076 | 143 | putc ('\n', stderr); |
0ae6073a | 144 | exit (EXIT_FAILURE); |
a0f6b076 | 145 | } |