Sweep-fix comparing pointers with 0 (and assigning 0 to pointers).
[dragonfly.git] / usr.bin / yacc / error.c
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Robert Paul Corbett.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the University of
19  *      California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * @(#)error.c  5.3 (Berkeley) 6/1/90
37  * $FreeBSD: src/usr.bin/yacc/error.c,v 1.7 1999/08/28 01:07:59 peter Exp $
38  */
39
40 /* routines for printing error messages  */
41
42 #include <stdlib.h>
43 #include "defs.h"
44
45 static void print_pos(const char *, const char *);
46
47 void
48 fatal(const char *msg)
49 {
50     errx(2, "f - %s", msg);
51 }
52
53
54 void
55 no_space(void)
56 {
57     errx(2, "f - out of space");
58 }
59
60
61 void
62 open_error(const char *filename)
63 {
64     errx(2, "f - cannot open \"%s\"", filename);
65 }
66
67
68 void
69 unexpected_EOF(void)
70 {
71     errx(1, "e - line %d of \"%s\", unexpected end-of-file",
72             lineno, input_file_name);
73 }
74
75
76 static void
77 print_pos(const char *st_line, const char *st_cptr)
78 {
79     const char *s;
80
81     if (st_line == NULL) return;
82     for (s = st_line; *s != '\n'; ++s)
83     {
84         if (isprint(*s) || *s == '\t')
85             putc(*s, stderr);
86         else
87             putc('?', stderr);
88     }
89     putc('\n', stderr);
90     for (s = st_line; s < st_cptr; ++s)
91     {
92         if (*s == '\t')
93             putc('\t', stderr);
94         else
95             putc(' ', stderr);
96     }
97     putc('^', stderr);
98     putc('\n', stderr);
99 }
100
101
102 void
103 syntax_error(int st_lineno, const char *st_line, const char *st_cptr)
104 {
105     warnx("e - line %d of \"%s\", syntax error",
106             st_lineno, input_file_name);
107     print_pos(st_line, st_cptr);
108     exit(1);
109 }
110
111
112 void
113 unterminated_comment(int c_lineno, const char *c_line, const char *c_cptr)
114 {
115     warnx("e - line %d of \"%s\", unmatched /*",
116             c_lineno, input_file_name);
117     print_pos(c_line, c_cptr);
118     exit(1);
119 }
120
121
122 void
123 unterminated_string(int s_lineno, const char *s_line, const char *s_cptr)
124 {
125     warnx("e - line %d of \"%s\", unterminated string",
126             s_lineno, input_file_name);
127     print_pos(s_line, s_cptr);
128     exit(1);
129 }
130
131
132 void
133 unterminated_text(int t_lineno, const char *t_line, const char *t_cptr)
134 {
135     warnx("e - line %d of \"%s\", unmatched %%{",
136             t_lineno, input_file_name);
137     print_pos(t_line, t_cptr);
138     exit(1);
139 }
140
141
142 void
143 unterminated_union(int u_lineno, const char *u_line, const char *u_cptr)
144 {
145     warnx("e - line %d of \"%s\", unterminated %%union declaration",
146                 u_lineno, input_file_name);
147     print_pos(u_line, u_cptr);
148     exit(1);
149 }
150
151
152 void
153 over_unionized(const char *u_cptr)
154 {
155     warnx("e - line %d of \"%s\", too many %%union declarations",
156                 lineno, input_file_name);
157     print_pos(line, u_cptr);
158     exit(1);
159 }
160
161
162 void
163 illegal_tag(int t_lineno, const char *t_line, const char *t_cptr)
164 {
165     warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
166     print_pos(t_line, t_cptr);
167     exit(1);
168 }
169
170
171 void
172 illegal_character(const char *c_cptr)
173 {
174     warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
175     print_pos(line, c_cptr);
176     exit(1);
177 }
178
179
180 void
181 used_reserved(const char *s)
182 {
183     errx(1, "e - line %d of \"%s\", illegal use of reserved symbol %s",
184                 lineno, input_file_name, s);
185 }
186
187
188 void
189 tokenized_start(const char *s)
190 {
191      errx(1, "e - line %d of \"%s\", the start symbol %s cannot be \
192 declared to be a token", lineno, input_file_name, s);
193 }
194
195
196 void
197 retyped_warning(const char *s)
198 {
199     warnx("w - line %d of \"%s\", the type of %s has been redeclared",
200                 lineno, input_file_name, s);
201 }
202
203
204 void
205 reprec_warning(const char *s)
206 {
207     warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
208                 lineno, input_file_name, s);
209 }
210
211
212 void
213 revalued_warning(const char *s)
214 {
215     warnx("w - line %d of \"%s\", the value of %s has been redeclared",
216                 lineno, input_file_name, s);
217 }
218
219
220 void
221 terminal_start(const char *s)
222 {
223     errx(1, "e - line %d of \"%s\", the start symbol %s is a token",
224                 lineno, input_file_name, s);
225 }
226
227
228 void
229 restarted_warning(void)
230 {
231     warnx("w - line %d of \"%s\", the start symbol has been redeclared",
232                 lineno, input_file_name);
233 }
234
235
236 void
237 no_grammar(void)
238 {
239     errx(1, "e - line %d of \"%s\", no grammar has been specified",
240                 lineno, input_file_name);
241 }
242
243
244 void
245 terminal_lhs(int s_lineno)
246 {
247     errx(1, "e - line %d of \"%s\", a token appears on the lhs of a production",
248                 s_lineno, input_file_name);
249 }
250
251
252 void
253 prec_redeclared(void)
254 {
255     warnx("w - line %d of  \"%s\", conflicting %%prec specifiers",
256                 lineno, input_file_name);
257 }
258
259
260 void
261 unterminated_action(int a_lineno, const char *a_line, const char *a_cptr)
262 {
263     warnx("e - line %d of \"%s\", unterminated action",
264             a_lineno, input_file_name);
265     print_pos(a_line, a_cptr);
266 }
267
268
269 void
270 dollar_warning(int a_lineno, int i)
271 {
272     warnx("w - line %d of \"%s\", $%d references beyond the \
273 end of the current rule", a_lineno, input_file_name, i);
274 }
275
276
277 void
278 dollar_error(int a_lineno, const char *a_line, const char *a_cptr)
279 {
280     warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
281     print_pos(a_line, a_cptr);
282     exit(1);
283 }
284
285
286 void
287 untyped_lhs(void)
288 {
289     errx(1, "e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
290 }
291
292
293 void
294 untyped_rhs(int i, const char *s)
295 {
296     errx(1, "e - line %d of \"%s\", $%d (%s) is untyped",
297             lineno, input_file_name, i, s);
298 }
299
300
301 void
302 unknown_rhs(int i)
303 {
304     errx(1, "e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
305 }
306
307
308 void
309 default_action_warning(void)
310 {
311     warnx("w - line %d of \"%s\", the default action assigns an \
312 undefined value to $$", lineno, input_file_name);
313 }
314
315
316 void
317 undefined_goal(const char *s)
318 {
319     errx(1, "e - the start symbol %s is undefined", s);
320 }
321
322
323 void
324 undefined_symbol_warning(const char *s)
325 {
326     warnx("w - the symbol %s is undefined", s);
327 }