]> git.saurik.com Git - bison.git/blame_incremental - src/complain.c
Omit mentions of %lex-param and %parse-param from the documentation
[bison.git] / src / complain.c
... / ...
CommitLineData
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. */
38extern 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
45char *strerror (int);
46# endif
47#else
48static char *
49private_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. */
62bool warning_issued;
63
64/* This variable is set each time `complain' is called. */
65bool complaint_issued;
66
67\f
68/*--------------------------------.
69| Report a warning, and proceed. |
70`--------------------------------*/
71
72void
73warn_at (location loc, const char *message, ...)
74{
75 va_list args;
76
77 fflush (stdout);
78 location_print (stderr, loc);
79 fputs (": ", stderr);
80 fputs (_("warning: "), stderr);
81
82 va_start (args, message);
83 vfprintf (stderr, message, args);
84 va_end (args);
85
86 warning_issued = true;
87 putc ('\n', stderr);
88 fflush (stderr);
89}
90
91void
92warn (const char *message, ...)
93{
94 va_list args;
95
96 fflush (stdout);
97 fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: "));
98
99 va_start (args, message);
100 vfprintf (stderr, message, args);
101 va_end (args);
102
103 warning_issued = true;
104 putc ('\n', stderr);
105 fflush (stderr);
106}
107\f
108/*-----------------------------------------------------------.
109| An error has occurred, but we can proceed, and die later. |
110`-----------------------------------------------------------*/
111
112void
113complain_at (location loc, const char *message, ...)
114{
115 va_list args;
116
117 fflush (stdout);
118 location_print (stderr, loc);
119 fputs (": ", stderr);
120
121 va_start (args, message);
122 vfprintf (stderr, message, args);
123 va_end (args);
124
125 complaint_issued = true;
126 putc ('\n', stderr);
127 fflush (stderr);
128}
129
130void
131complain (const char *message, ...)
132{
133 va_list args;
134
135 fflush (stdout);
136 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
137
138 va_start (args, message);
139 vfprintf (stderr, message, args);
140 va_end (args);
141
142 complaint_issued = true;
143 putc ('\n', stderr);
144 fflush (stderr);
145}
146\f
147/*-------------------------------------------------.
148| A severe error has occurred, we cannot proceed. |
149`-------------------------------------------------*/
150
151void
152fatal_at (location loc, const char *message, ...)
153{
154 va_list args;
155
156 fflush (stdout);
157 location_print (stderr, loc);
158 fputs (": ", stderr);
159 fputs (_("fatal error: "), stderr);
160
161 va_start (args, message);
162 vfprintf (stderr, message, args);
163 va_end (args);
164 putc ('\n', stderr);
165 fflush (stderr);
166 exit (EXIT_FAILURE);
167}
168
169void
170fatal (const char *message, ...)
171{
172 va_list args;
173
174 fflush (stdout);
175 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
176
177 fputs (_("fatal error: "), stderr);
178
179 va_start (args, message);
180 vfprintf (stderr, message, args);
181 va_end (args);
182 putc ('\n', stderr);
183 fflush (stderr);
184 exit (EXIT_FAILURE);
185}