Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[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  * $DragonFly: src/usr.bin/yacc/error.c,v 1.2 2003/06/17 04:29:34 dillon Exp $
39  */
40
41 /* routines for printing error messages  */
42
43 #include "defs.h"
44
45 static void print_pos __P((char *, char *));
46
47 void
48 fatal(msg)
49 char *msg;
50 {
51     warnx("f - %s", msg);
52     done(2);
53 }
54
55
56 void
57 no_space()
58 {
59     warnx("f - out of space");
60     done(2);
61 }
62
63
64 void
65 open_error(filename)
66 char *filename;
67 {
68     warnx("f - cannot open \"%s\"", filename);
69     done(2);
70 }
71
72
73 void
74 unexpected_EOF()
75 {
76     warnx("e - line %d of \"%s\", unexpected end-of-file",
77             lineno, input_file_name);
78     done(1);
79 }
80
81
82 static void
83 print_pos(st_line, st_cptr)
84 char *st_line;
85 char *st_cptr;
86 {
87     register char *s;
88
89     if (st_line == 0) return;
90     for (s = st_line; *s != '\n'; ++s)
91     {
92         if (isprint(*s) || *s == '\t')
93             putc(*s, stderr);
94         else
95             putc('?', stderr);
96     }
97     putc('\n', stderr);
98     for (s = st_line; s < st_cptr; ++s)
99     {
100         if (*s == '\t')
101             putc('\t', stderr);
102         else
103             putc(' ', stderr);
104     }
105     putc('^', stderr);
106     putc('\n', stderr);
107 }
108
109
110 void
111 syntax_error(st_lineno, st_line, st_cptr)
112 int st_lineno;
113 char *st_line;
114 char *st_cptr;
115 {
116     warnx("e - line %d of \"%s\", syntax error",
117             st_lineno, input_file_name);
118     print_pos(st_line, st_cptr);
119     done(1);
120 }
121
122
123 void
124 unterminated_comment(c_lineno, c_line, c_cptr)
125 int c_lineno;
126 char *c_line;
127 char *c_cptr;
128 {
129     warnx("e - line %d of \"%s\", unmatched /*",
130             c_lineno, input_file_name);
131     print_pos(c_line, c_cptr);
132     done(1);
133 }
134
135
136 void
137 unterminated_string(s_lineno, s_line, s_cptr)
138 int s_lineno;
139 char *s_line;
140 char *s_cptr;
141 {
142     warnx("e - line %d of \"%s\", unterminated string",
143             s_lineno, input_file_name);
144     print_pos(s_line, s_cptr);
145     done(1);
146 }
147
148
149 void
150 unterminated_text(t_lineno, t_line, t_cptr)
151 int t_lineno;
152 char *t_line;
153 char *t_cptr;
154 {
155     warnx("e - line %d of \"%s\", unmatched %%{",
156             t_lineno, input_file_name);
157     print_pos(t_line, t_cptr);
158     done(1);
159 }
160
161
162 void
163 unterminated_union(u_lineno, u_line, u_cptr)
164 int u_lineno;
165 char *u_line;
166 char *u_cptr;
167 {
168     warnx("e - line %d of \"%s\", unterminated %%union declaration",
169                 u_lineno, input_file_name);
170     print_pos(u_line, u_cptr);
171     done(1);
172 }
173
174
175 void
176 over_unionized(u_cptr)
177 char *u_cptr;
178 {
179     warnx("e - line %d of \"%s\", too many %%union declarations",
180                 lineno, input_file_name);
181     print_pos(line, u_cptr);
182     done(1);
183 }
184
185
186 void
187 illegal_tag(t_lineno, t_line, t_cptr)
188 int t_lineno;
189 char *t_line;
190 char *t_cptr;
191 {
192     warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
193     print_pos(t_line, t_cptr);
194     done(1);
195 }
196
197
198 void
199 illegal_character(c_cptr)
200 char *c_cptr;
201 {
202     warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
203     print_pos(line, c_cptr);
204     done(1);
205 }
206
207
208 void
209 used_reserved(s)
210 char *s;
211 {
212     warnx("e - line %d of \"%s\", illegal use of reserved symbol %s",
213                 lineno, input_file_name, s);
214     done(1);
215 }
216
217
218 void
219 tokenized_start(s)
220 char *s;
221 {
222      warnx("e - line %d of \"%s\", the start symbol %s cannot be \
223 declared to be a token", lineno, input_file_name, s);
224      done(1);
225 }
226
227
228 void
229 retyped_warning(s)
230 char *s;
231 {
232     warnx("w - line %d of \"%s\", the type of %s has been redeclared",
233                 lineno, input_file_name, s);
234 }
235
236
237 void
238 reprec_warning(s)
239 char *s;
240 {
241     warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
242                 lineno, input_file_name, s);
243 }
244
245
246 void
247 revalued_warning(s)
248 char *s;
249 {
250     warnx("w - line %d of \"%s\", the value of %s has been redeclared",
251                 lineno, input_file_name, s);
252 }
253
254
255 void
256 terminal_start(s)
257 char *s;
258 {
259     warnx("e - line %d of \"%s\", the start symbol %s is a token",
260                 lineno, input_file_name, s);
261     done(1);
262 }
263
264
265 void
266 restarted_warning()
267 {
268     warnx("w - line %d of \"%s\", the start symbol has been redeclared",
269                 lineno, input_file_name);
270 }
271
272
273 void
274 no_grammar()
275 {
276     warnx("e - line %d of \"%s\", no grammar has been specified",
277                 lineno, input_file_name);
278     done(1);
279 }
280
281
282 void
283 terminal_lhs(s_lineno)
284 int s_lineno;
285 {
286     warnx("e - line %d of \"%s\", a token appears on the lhs of a production",
287                 s_lineno, input_file_name);
288     done(1);
289 }
290
291
292 void
293 prec_redeclared()
294 {
295     warnx("w - line %d of  \"%s\", conflicting %%prec specifiers",
296                 lineno, input_file_name);
297 }
298
299
300 void
301 unterminated_action(a_lineno, a_line, a_cptr)
302 int a_lineno;
303 char *a_line;
304 char *a_cptr;
305 {
306     warnx("e - line %d of \"%s\", unterminated action",
307             a_lineno, input_file_name);
308     print_pos(a_line, a_cptr);
309     done(1);
310 }
311
312
313 void
314 dollar_warning(a_lineno, i)
315 int a_lineno;
316 int i;
317 {
318     warnx("w - line %d of \"%s\", $%d references beyond the \
319 end of the current rule", a_lineno, input_file_name, i);
320 }
321
322
323 void
324 dollar_error(a_lineno, a_line, a_cptr)
325 int a_lineno;
326 char *a_line;
327 char *a_cptr;
328 {
329     warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
330     print_pos(a_line, a_cptr);
331     done(1);
332 }
333
334
335 void
336 untyped_lhs()
337 {
338     warnx("e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
339     done(1);
340 }
341
342
343 void
344 untyped_rhs(i, s)
345 int i;
346 char *s;
347 {
348     warnx("e - line %d of \"%s\", $%d (%s) is untyped",
349             lineno, input_file_name, i, s);
350     done(1);
351 }
352
353
354 void
355 unknown_rhs(i)
356 int i;
357 {
358     warnx("e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
359     done(1);
360 }
361
362
363 void
364 default_action_warning()
365 {
366     warnx("w - line %d of \"%s\", the default action assigns an \
367 undefined value to $$", lineno, input_file_name);
368 }
369
370
371 void
372 undefined_goal(s)
373 char *s;
374 {
375     warnx("e - the start symbol %s is undefined", s);
376     done(1);
377 }
378
379
380 void
381 undefined_symbol_warning(s)
382 char *s;
383 {
384     warnx("w - the symbol %s is undefined", s);
385 }