]> git.saurik.com Git - bison.git/blob - src/complain.c
Avoid gcc -Wundef warnings reported by Gerald Pfeifer in
[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 #include "complain.h"
30 #include "files.h"
31
32 #ifndef _
33 # define _(String) String
34 #endif
35
36 /* The calling program should define program_name and set it to the
37 name of the executing program. */
38 extern char *program_name;
39
40 #if HAVE_STRERROR
41 # ifndef HAVE_DECL_STRERROR
42 "this configure-time declaration test was not run"
43 # endif
44 # if !HAVE_DECL_STRERROR && !defined strerror
45 char *strerror (int);
46 # endif
47 #else
48 static char *
49 private_strerror (int errnum)
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 }
58 # define strerror private_strerror
59 #endif /* HAVE_STRERROR */
60
61 /* This variable is set each time `warn' is called. */
62 bool warning_issued;
63
64 /* This variable is set each time `complain' is called. */
65 bool complaint_issued;
66
67 \f
68 /*--------------------------------.
69 | Report a warning, and proceed. |
70 `--------------------------------*/
71
72 void
73 warn_at (location loc, const char *message, ...)
74 {
75 va_list args;
76
77 location_print (stderr, loc);
78 fputs (": ", stderr);
79 fputs (_("warning: "), stderr);
80
81 va_start (args, message);
82 vfprintf (stderr, message, args);
83 va_end (args);
84
85 warning_issued = true;
86 putc ('\n', stderr);
87 }
88
89 void
90 warn (const char *message, ...)
91 {
92 va_list args;
93
94 fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: "));
95
96 va_start (args, message);
97 vfprintf (stderr, message, args);
98 va_end (args);
99
100 warning_issued = true;
101 putc ('\n', stderr);
102 }
103 \f
104 /*-----------------------------------------------------------.
105 | An error has occurred, but we can proceed, and die later. |
106 `-----------------------------------------------------------*/
107
108 void
109 complain_at (location loc, const char *message, ...)
110 {
111 va_list args;
112
113 location_print (stderr, loc);
114 fputs (": ", stderr);
115
116 va_start (args, message);
117 vfprintf (stderr, message, args);
118 va_end (args);
119
120 complaint_issued = true;
121 putc ('\n', stderr);
122 }
123
124 void
125 complain (const char *message, ...)
126 {
127 va_list args;
128
129 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
130
131 va_start (args, message);
132 vfprintf (stderr, message, args);
133 va_end (args);
134
135 complaint_issued = true;
136 putc ('\n', stderr);
137 }
138 \f
139 /*-------------------------------------------------.
140 | A severe error has occurred, we cannot proceed. |
141 `-------------------------------------------------*/
142
143 void
144 fatal_at (location loc, const char *message, ...)
145 {
146 va_list args;
147
148 location_print (stderr, loc);
149 fputs (": ", stderr);
150 fputs (_("fatal error: "), stderr);
151
152 va_start (args, message);
153 vfprintf (stderr, message, args);
154 va_end (args);
155 putc ('\n', stderr);
156 exit (EXIT_FAILURE);
157 }
158
159 void
160 fatal (const char *message, ...)
161 {
162 va_list args;
163
164 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
165
166 fputs (_("fatal error: "), stderr);
167
168 va_start (args, message);
169 vfprintf (stderr, message, args);
170 va_end (args);
171 putc ('\n', stderr);
172 exit (EXIT_FAILURE);
173 }