]> git.saurik.com Git - bison.git/blob - src/complain.c
* NEWS (2.3a+): Mention yesterday's state-removal change.
[bison.git] / src / complain.c
1 /* Declaration for error-reporting function for Bison.
2
3 Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006
4 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 USA. */
20
21 /* Based on error.c and error.h,
22 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
23
24 #include <config.h>
25 #include "system.h"
26
27 #include <stdarg.h>
28
29 #include "complain.h"
30 #include "files.h"
31 #include "getargs.h"
32
33 bool complaint_issued;
34
35 \f
36
37 /** Report an error message.
38 *
39 * \param loc the location, defaulting to the current file,
40 * or the program name.
41 * \param prefix put before the message (e.g., "warning").
42 * \param message the error message, a printf format string.
43 * \param args the arguments of the format string.
44 */
45 static
46 void
47 error_message (location *loc,
48 const char *prefix,
49 const char *message, va_list args)
50 {
51 if (loc)
52 location_print (stderr, *loc);
53 else
54 fputs (current_file ? current_file : program_name, stderr);
55 fputs (": ", stderr);
56
57 if (prefix)
58 fprintf (stderr, "%s: ", prefix);
59
60 vfprintf (stderr, message, args);
61 va_end (args);
62 putc ('\n', stderr);
63 fflush (stderr);
64 }
65
66 /** Wrap error_message() with varargs handling. */
67 #define ERROR_MESSAGE(Loc, Prefix, Message) \
68 { \
69 va_list args; \
70 va_start (args, Message); \
71 error_message (Loc, Prefix, Message, args); \
72 }
73
74
75 /*--------------------------------.
76 | Report a warning, and proceed. |
77 `--------------------------------*/
78
79 static void
80 set_warning_issued (void)
81 {
82 static bool warning_issued = false;
83 if (!warning_issued && (warnings_flag & warnings_error))
84 {
85 fprintf (stderr, "%s: warnings being treated as errors\n", program_name);
86 complaint_issued = true;
87 }
88 warning_issued = true;
89 }
90
91 void
92 warn_at (location loc, const char *message, ...)
93 {
94 set_warning_issued ();
95 ERROR_MESSAGE (&loc, _("warning"), message);
96 }
97
98 void
99 warn (const char *message, ...)
100 {
101 set_warning_issued ();
102 ERROR_MESSAGE (NULL, _("warning"), message);
103 }
104
105
106 /*-----------------------------------------------------------.
107 | An error has occurred, but we can proceed, and die later. |
108 `-----------------------------------------------------------*/
109
110 void
111 complain_at (location loc, const char *message, ...)
112 {
113 ERROR_MESSAGE (&loc, NULL, message);
114 complaint_issued = true;
115 }
116
117 void
118 complain (const char *message, ...)
119 {
120 ERROR_MESSAGE (NULL, NULL, message);
121 complaint_issued = true;
122 }
123
124
125 /*-------------------------------------------------.
126 | A severe error has occurred, we cannot proceed. |
127 `-------------------------------------------------*/
128
129 void
130 fatal_at (location loc, const char *message, ...)
131 {
132 ERROR_MESSAGE (&loc, _("fatal error"), message);
133 exit (EXIT_FAILURE);
134 }
135
136 void
137 fatal (const char *message, ...)
138 {
139 ERROR_MESSAGE (NULL, _("fatal error"), message);
140 exit (EXIT_FAILURE);
141 }