]> git.saurik.com Git - bison.git/blob - src/complain.c
* tests/testsuite.at (AT_CHECK): When checking if $1 starts with
[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 /* The calling program should define program_name and set it to the
34 name of the executing program. */
35 extern char *program_name;
36
37 bool complaint_issued;
38
39 \f
40
41 /** Report an error message.
42 *
43 * \param loc the location, defaulting to the current file,
44 * or the program name.
45 * \param prefix put before the message (e.g., "warning").
46 * \param message the error message, a printf format string.
47 * \param args the arguments of the format string.
48 */
49 static
50 void
51 error_message (location *loc,
52 const char *prefix,
53 const char *message, va_list args)
54 {
55 if (loc)
56 location_print (stderr, *loc);
57 else
58 fputs (current_file ? current_file : program_name, stderr);
59 fputs (": ", stderr);
60
61 if (prefix)
62 fprintf (stderr, "%s: ", prefix);
63
64 vfprintf (stderr, message, args);
65 va_end (args);
66 putc ('\n', stderr);
67 fflush (stderr);
68 }
69
70 /** Wrap error_message() with varargs handling. */
71 #define ERROR_MESSAGE(Loc, Prefix, Message) \
72 { \
73 va_list args; \
74 va_start (args, Message); \
75 error_message (Loc, Prefix, Message, args); \
76 }
77
78
79 /*--------------------------------.
80 | Report a warning, and proceed. |
81 `--------------------------------*/
82
83 static void
84 set_warning_issued (void)
85 {
86 static bool warning_issued = false;
87 if (!warning_issued && (warnings_flag & warnings_error))
88 {
89 fprintf (stderr, "%s: warnings being treated as errors\n", program_name);
90 complaint_issued = true;
91 }
92 warning_issued = true;
93 }
94
95 void
96 warn_at (location loc, const char *message, ...)
97 {
98 set_warning_issued ();
99 ERROR_MESSAGE (&loc, _("warning"), message);
100 }
101
102 void
103 warn (const char *message, ...)
104 {
105 set_warning_issued ();
106 ERROR_MESSAGE (NULL, _("warning"), message);
107 }
108
109
110 /*-----------------------------------------------------------.
111 | An error has occurred, but we can proceed, and die later. |
112 `-----------------------------------------------------------*/
113
114 void
115 complain_at (location loc, const char *message, ...)
116 {
117 ERROR_MESSAGE (&loc, NULL, message);
118 complaint_issued = true;
119 }
120
121 void
122 complain (const char *message, ...)
123 {
124 ERROR_MESSAGE (NULL, NULL, message);
125 complaint_issued = true;
126 }
127
128
129 /*-------------------------------------------------.
130 | A severe error has occurred, we cannot proceed. |
131 `-------------------------------------------------*/
132
133 void
134 fatal_at (location loc, const char *message, ...)
135 {
136 ERROR_MESSAGE (&loc, _("fatal error"), message);
137 exit (EXIT_FAILURE);
138 }
139
140 void
141 fatal (const char *message, ...)
142 {
143 ERROR_MESSAGE (NULL, _("fatal error"), message);
144 exit (EXIT_FAILURE);
145 }