]> git.saurik.com Git - bison.git/blob - src/complain.c
Display the changes in cross-options.texi.
[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
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any 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, see <http://www.gnu.org/licenses/>. */
18
19 /* Based on error.c and error.h,
20 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
21
22 #include <config.h>
23 #include "system.h"
24
25 #include <stdarg.h>
26
27 #include "complain.h"
28 #include "files.h"
29 #include "getargs.h"
30
31 bool complaint_issued;
32
33 \f
34
35 /** Report an error message.
36 *
37 * \param loc the location, defaulting to the current file,
38 * or the program name.
39 * \param prefix put before the message (e.g., "warning").
40 * \param message the error message, a printf format string.
41 * \param args the arguments of the format string.
42 */
43 static
44 void
45 error_message (location *loc,
46 const char *prefix,
47 const char *message, va_list args)
48 {
49 if (loc)
50 location_print (stderr, *loc);
51 else
52 fputs (current_file ? current_file : program_name, stderr);
53 fputs (": ", stderr);
54
55 if (prefix)
56 fprintf (stderr, "%s: ", prefix);
57
58 vfprintf (stderr, message, args);
59 va_end (args);
60 putc ('\n', stderr);
61 fflush (stderr);
62 }
63
64 /** Wrap error_message() with varargs handling. */
65 #define ERROR_MESSAGE(Loc, Prefix, Message) \
66 { \
67 va_list args; \
68 va_start (args, Message); \
69 error_message (Loc, Prefix, Message, args); \
70 }
71
72
73 /*--------------------------------.
74 | Report a warning, and proceed. |
75 `--------------------------------*/
76
77 static void
78 set_warning_issued (void)
79 {
80 static bool warning_issued = false;
81 if (!warning_issued && (warnings_flag & warnings_error))
82 {
83 fprintf (stderr, "%s: warnings being treated as errors\n", program_name);
84 complaint_issued = true;
85 }
86 warning_issued = true;
87 }
88
89 void
90 warn_at (location loc, const char *message, ...)
91 {
92 set_warning_issued ();
93 ERROR_MESSAGE (&loc, _("warning"), message);
94 }
95
96 void
97 warn (const char *message, ...)
98 {
99 set_warning_issued ();
100 ERROR_MESSAGE (NULL, _("warning"), message);
101 }
102
103
104 /*-----------------------------------------------------------.
105 | An error has occurred, but we can proceed, and die later. |
106 `-----------------------------------------------------------*/
107
108 void
109 complain_at (location loc, const char *message, ...)
110 {
111 ERROR_MESSAGE (&loc, NULL, message);
112 complaint_issued = true;
113 }
114
115 void
116 complain (const char *message, ...)
117 {
118 ERROR_MESSAGE (NULL, NULL, message);
119 complaint_issued = true;
120 }
121
122
123 /*-------------------------------------------------.
124 | A severe error has occurred, we cannot proceed. |
125 `-------------------------------------------------*/
126
127 void
128 fatal_at (location loc, const char *message, ...)
129 {
130 ERROR_MESSAGE (&loc, _("fatal error"), message);
131 exit (EXIT_FAILURE);
132 }
133
134 void
135 fatal (const char *message, ...)
136 {
137 ERROR_MESSAGE (NULL, _("fatal error"), message);
138 exit (EXIT_FAILURE);
139 }