]> git.saurik.com Git - bison.git/blame - src/complain.c
* src/reader.c (grammar_current_rule_check): Also check that $$
[bison.git] / src / complain.c
CommitLineData
a0f6b076 1/* Declaration for error-reporting function for Bison.
2cec9080
PE
2
3 Copyright (C) 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
a0f6b076
AD
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
8 later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
0fb669f9 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
a0f6b076
AD
18 USA. */
19
20/* Based on error.c and error.h,
21 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
22
2cec9080 23#include <config.h>
342b8b6e 24#include "system.h"
a0f6b076 25
21184140 26#include <stdarg.h>
a0f6b076 27
a0f6b076 28#include "complain.h"
4b68955b 29#include "files.h"
a0f6b076 30
a0f6b076
AD
31/* The calling program should define program_name and set it to the
32 name of the executing program. */
33extern char *program_name;
8f13fe33 34
0ae6073a
PE
35/* This variable is set each time `warn' is called. */
36bool warning_issued;
a0f6b076 37
0ae6073a
PE
38/* This variable is set each time `complain' is called. */
39bool complaint_issued;
a0f6b076 40
a0f6b076
AD
41\f
42/*--------------------------------.
43| Report a warning, and proceed. |
44`--------------------------------*/
45
e9955c83 46void
41f83caf 47warn_at (location loc, const char *message, ...)
e9955c83 48{
e9955c83 49 va_list args;
e9955c83 50
41f83caf 51 location_print (stderr, loc);
ee000ba4 52 fputs (": ", stderr);
e9955c83
AD
53 fputs (_("warning: "), stderr);
54
21184140 55 va_start (args, message);
52489d44
AD
56 vfprintf (stderr, message, args);
57 va_end (args);
52489d44 58
0ae6073a 59 warning_issued = true;
52489d44 60 putc ('\n', stderr);
52489d44
AD
61}
62
63void
52489d44 64warn (const char *message, ...)
52489d44 65{
52489d44 66 va_list args;
52489d44 67
95612cfa 68 fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: "));
52489d44 69
21184140 70 va_start (args, message);
e9955c83
AD
71 vfprintf (stderr, message, args);
72 va_end (args);
e9955c83 73
0ae6073a 74 warning_issued = true;
e9955c83 75 putc ('\n', stderr);
e9955c83 76}
a0f6b076
AD
77\f
78/*-----------------------------------------------------------.
79| An error has occurred, but we can proceed, and die later. |
80`-----------------------------------------------------------*/
81
e9955c83 82void
41f83caf 83complain_at (location loc, const char *message, ...)
e9955c83 84{
e9955c83 85 va_list args;
e9955c83 86
41f83caf 87 location_print (stderr, loc);
ee000ba4 88 fputs (": ", stderr);
e9955c83 89
21184140 90 va_start (args, message);
52489d44
AD
91 vfprintf (stderr, message, args);
92 va_end (args);
52489d44 93
0ae6073a 94 complaint_issued = true;
52489d44 95 putc ('\n', stderr);
52489d44
AD
96}
97
98void
52489d44 99complain (const char *message, ...)
52489d44 100{
52489d44 101 va_list args;
52489d44 102
95612cfa 103 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
52489d44 104
21184140 105 va_start (args, message);
e9955c83
AD
106 vfprintf (stderr, message, args);
107 va_end (args);
e9955c83 108
0ae6073a 109 complaint_issued = true;
e9955c83 110 putc ('\n', stderr);
e9955c83 111}
a0f6b076
AD
112\f
113/*-------------------------------------------------.
114| A severe error has occurred, we cannot proceed. |
115`-------------------------------------------------*/
116
e9955c83 117void
41f83caf 118fatal_at (location loc, const char *message, ...)
e9955c83 119{
e9955c83 120 va_list args;
e9955c83 121
41f83caf 122 location_print (stderr, loc);
ee000ba4 123 fputs (": ", stderr);
e9955c83
AD
124 fputs (_("fatal error: "), stderr);
125
21184140 126 va_start (args, message);
e9955c83
AD
127 vfprintf (stderr, message, args);
128 va_end (args);
e9955c83 129 putc ('\n', stderr);
0ae6073a 130 exit (EXIT_FAILURE);
e9955c83
AD
131}
132
a0f6b076 133void
a0f6b076 134fatal (const char *message, ...)
a0f6b076 135{
a0f6b076 136 va_list args;
a0f6b076 137
95612cfa 138 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
a0f6b076
AD
139
140 fputs (_("fatal error: "), stderr);
141
21184140 142 va_start (args, message);
a0f6b076
AD
143 vfprintf (stderr, message, args);
144 va_end (args);
a0f6b076 145 putc ('\n', stderr);
0ae6073a 146 exit (EXIT_FAILURE);
a0f6b076 147}