amd64 - add kvtop and add back ed(4) to AMD64_GENERIC
[dragonfly.git] / usr.bin / yacc / error.c
blobbc61a3bf1facaedfd94aaa853e235433951db2ab
1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Robert Paul Corbett.
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.
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.
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.5 2005/01/05 15:26:05 joerg Exp $
41 /* routines for printing error messages */
43 #include <stdlib.h>
44 #include "defs.h"
46 static void print_pos(const char *, const char *);
48 void
49 fatal(const char *msg)
51 errx(2, "f - %s", msg);
55 void
56 no_space(void)
58 errx(2, "f - out of space");
62 void
63 open_error(const char *filename)
65 errx(2, "f - cannot open \"%s\"", filename);
69 void
70 unexpected_EOF(void)
72 errx(1, "e - line %d of \"%s\", unexpected end-of-file",
73 lineno, input_file_name);
77 static void
78 print_pos(const char *st_line, const char *st_cptr)
80 const char *s;
82 if (st_line == 0) return;
83 for (s = st_line; *s != '\n'; ++s)
85 if (isprint(*s) || *s == '\t')
86 putc(*s, stderr);
87 else
88 putc('?', stderr);
90 putc('\n', stderr);
91 for (s = st_line; s < st_cptr; ++s)
93 if (*s == '\t')
94 putc('\t', stderr);
95 else
96 putc(' ', stderr);
98 putc('^', stderr);
99 putc('\n', stderr);
103 void
104 syntax_error(int st_lineno, const char *st_line, const char *st_cptr)
106 warnx("e - line %d of \"%s\", syntax error",
107 st_lineno, input_file_name);
108 print_pos(st_line, st_cptr);
109 exit(1);
113 void
114 unterminated_comment(int c_lineno, const char *c_line, const char *c_cptr)
116 warnx("e - line %d of \"%s\", unmatched /*",
117 c_lineno, input_file_name);
118 print_pos(c_line, c_cptr);
119 exit(1);
123 void
124 unterminated_string(int s_lineno, const char *s_line, const char *s_cptr)
126 warnx("e - line %d of \"%s\", unterminated string",
127 s_lineno, input_file_name);
128 print_pos(s_line, s_cptr);
129 exit(1);
133 void
134 unterminated_text(int t_lineno, const char *t_line, const char *t_cptr)
136 warnx("e - line %d of \"%s\", unmatched %%{",
137 t_lineno, input_file_name);
138 print_pos(t_line, t_cptr);
139 exit(1);
143 void
144 unterminated_union(int u_lineno, const char *u_line, const char *u_cptr)
146 warnx("e - line %d of \"%s\", unterminated %%union declaration",
147 u_lineno, input_file_name);
148 print_pos(u_line, u_cptr);
149 exit(1);
153 void
154 over_unionized(const char *u_cptr)
156 warnx("e - line %d of \"%s\", too many %%union declarations",
157 lineno, input_file_name);
158 print_pos(line, u_cptr);
159 exit(1);
163 void
164 illegal_tag(int t_lineno, const char *t_line, const char *t_cptr)
166 warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
167 print_pos(t_line, t_cptr);
168 exit(1);
172 void
173 illegal_character(const char *c_cptr)
175 warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
176 print_pos(line, c_cptr);
177 exit(1);
181 void
182 used_reserved(const char *s)
184 errx(1, "e - line %d of \"%s\", illegal use of reserved symbol %s",
185 lineno, input_file_name, s);
189 void
190 tokenized_start(const char *s)
192 errx(1, "e - line %d of \"%s\", the start symbol %s cannot be \
193 declared to be a token", lineno, input_file_name, s);
197 void
198 retyped_warning(const char *s)
200 warnx("w - line %d of \"%s\", the type of %s has been redeclared",
201 lineno, input_file_name, s);
205 void
206 reprec_warning(const char *s)
208 warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
209 lineno, input_file_name, s);
213 void
214 revalued_warning(const char *s)
216 warnx("w - line %d of \"%s\", the value of %s has been redeclared",
217 lineno, input_file_name, s);
221 void
222 terminal_start(const char *s)
224 errx(1, "e - line %d of \"%s\", the start symbol %s is a token",
225 lineno, input_file_name, s);
229 void
230 restarted_warning(void)
232 warnx("w - line %d of \"%s\", the start symbol has been redeclared",
233 lineno, input_file_name);
237 void
238 no_grammar(void)
240 errx(1, "e - line %d of \"%s\", no grammar has been specified",
241 lineno, input_file_name);
245 void
246 terminal_lhs(int s_lineno)
248 errx(1, "e - line %d of \"%s\", a token appears on the lhs of a production",
249 s_lineno, input_file_name);
253 void
254 prec_redeclared(void)
256 warnx("w - line %d of \"%s\", conflicting %%prec specifiers",
257 lineno, input_file_name);
261 void
262 unterminated_action(int a_lineno, const char *a_line, const char *a_cptr)
264 warnx("e - line %d of \"%s\", unterminated action",
265 a_lineno, input_file_name);
266 print_pos(a_line, a_cptr);
270 void
271 dollar_warning(int a_lineno, int i)
273 warnx("w - line %d of \"%s\", $%d references beyond the \
274 end of the current rule", a_lineno, input_file_name, i);
278 void
279 dollar_error(int a_lineno, const char *a_line, const char *a_cptr)
281 warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
282 print_pos(a_line, a_cptr);
283 exit(1);
287 void
288 untyped_lhs(void)
290 errx(1, "e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
294 void
295 untyped_rhs(int i, const char *s)
297 errx(1, "e - line %d of \"%s\", $%d (%s) is untyped",
298 lineno, input_file_name, i, s);
302 void
303 unknown_rhs(int i)
305 errx(1, "e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
309 void
310 default_action_warning(void)
312 warnx("w - line %d of \"%s\", the default action assigns an \
313 undefined value to $$", lineno, input_file_name);
317 void
318 undefined_goal(const char *s)
320 errx(1, "e - the start symbol %s is undefined", s);
324 void
325 undefined_symbol_warning(const char *s)
327 warnx("w - the symbol %s is undefined", s);