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