]> git.saurik.com Git - bison.git/blame - src/complain.c
Get rid of broken %no-parser, -n, and --no-parser implementation and
[bison.git] / src / complain.c
CommitLineData
a0f6b076 1/* Declaration for error-reporting function for Bison.
2cec9080 2
23eb2a69
AD
3 Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006
4 Free Software Foundation, Inc.
a0f6b076
AD
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
0fb669f9 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
a0f6b076
AD
19 USA. */
20
21/* Based on error.c and error.h,
22 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
23
2cec9080 24#include <config.h>
342b8b6e 25#include "system.h"
a0f6b076 26
21184140 27#include <stdarg.h>
a0f6b076 28
a0f6b076 29#include "complain.h"
4b68955b 30#include "files.h"
89eb3c76 31#include "getargs.h"
a0f6b076 32
0ae6073a 33bool complaint_issued;
a0f6b076 34
a0f6b076 35\f
a0f6b076 36
23eb2a69
AD
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 */
45static
e9955c83 46void
23eb2a69
AD
47error_message (location *loc,
48 const char *prefix,
49 const char *message, va_list args)
e9955c83 50{
23eb2a69
AD
51 if (loc)
52 location_print (stderr, *loc);
53 else
54 fputs (current_file ? current_file : program_name, stderr);
ee000ba4 55 fputs (": ", stderr);
e9955c83 56
23eb2a69
AD
57 if (prefix)
58 fprintf (stderr, "%s: ", prefix);
59
52489d44
AD
60 vfprintf (stderr, message, args);
61 va_end (args);
52489d44 62 putc ('\n', stderr);
23eb2a69
AD
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
89eb3c76
JD
79static void
80set_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
23eb2a69
AD
91void
92warn_at (location loc, const char *message, ...)
93{
89eb3c76 94 set_warning_issued ();
23eb2a69 95 ERROR_MESSAGE (&loc, _("warning"), message);
52489d44
AD
96}
97
98void
52489d44 99warn (const char *message, ...)
52489d44 100{
89eb3c76 101 set_warning_issued ();
23eb2a69
AD
102 ERROR_MESSAGE (NULL, _("warning"), message);
103}
52489d44 104
e9955c83 105
a0f6b076
AD
106/*-----------------------------------------------------------.
107| An error has occurred, but we can proceed, and die later. |
108`-----------------------------------------------------------*/
109
e9955c83 110void
41f83caf 111complain_at (location loc, const char *message, ...)
e9955c83 112{
23eb2a69 113 ERROR_MESSAGE (&loc, NULL, message);
0ae6073a 114 complaint_issued = true;
52489d44
AD
115}
116
117void
52489d44 118complain (const char *message, ...)
52489d44 119{
23eb2a69 120 ERROR_MESSAGE (NULL, NULL, message);
0ae6073a 121 complaint_issued = true;
e9955c83 122}
23eb2a69
AD
123
124
a0f6b076
AD
125/*-------------------------------------------------.
126| A severe error has occurred, we cannot proceed. |
127`-------------------------------------------------*/
128
e9955c83 129void
41f83caf 130fatal_at (location loc, const char *message, ...)
e9955c83 131{
23eb2a69 132 ERROR_MESSAGE (&loc, _("fatal error"), message);
0ae6073a 133 exit (EXIT_FAILURE);
e9955c83
AD
134}
135
a0f6b076 136void
a0f6b076 137fatal (const char *message, ...)
a0f6b076 138{
23eb2a69 139 ERROR_MESSAGE (NULL, _("fatal error"), message);
0ae6073a 140 exit (EXIT_FAILURE);
a0f6b076 141}