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