]> git.saurik.com Git - bison.git/blame - src/complain.c
Fix typo: "&" should be "&&". Problem reported
[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"
a0f6b076 31
a0f6b076
AD
32/* The calling program should define program_name and set it to the
33 name of the executing program. */
34extern char *program_name;
8f13fe33 35
0ae6073a 36bool complaint_issued;
a0f6b076 37
a0f6b076 38\f
a0f6b076 39
23eb2a69
AD
40/** Report an error message.
41 *
42 * \param loc the location, defaulting to the current file,
43 * or the program name.
44 * \param prefix put before the message (e.g., "warning").
45 * \param message the error message, a printf format string.
46 * \param args the arguments of the format string.
47 */
48static
e9955c83 49void
23eb2a69
AD
50error_message (location *loc,
51 const char *prefix,
52 const char *message, va_list args)
e9955c83 53{
23eb2a69
AD
54 if (loc)
55 location_print (stderr, *loc);
56 else
57 fputs (current_file ? current_file : program_name, stderr);
ee000ba4 58 fputs (": ", stderr);
e9955c83 59
23eb2a69
AD
60 if (prefix)
61 fprintf (stderr, "%s: ", prefix);
62
52489d44
AD
63 vfprintf (stderr, message, args);
64 va_end (args);
52489d44 65 putc ('\n', stderr);
23eb2a69
AD
66 fflush (stderr);
67}
68
69/** Wrap error_message() with varargs handling. */
70#define ERROR_MESSAGE(Loc, Prefix, Message) \
71{ \
72 va_list args; \
73 va_start (args, Message); \
74 error_message (Loc, Prefix, Message, args); \
75}
76
77
78/*--------------------------------.
79| Report a warning, and proceed. |
80`--------------------------------*/
81
82void
83warn_at (location loc, const char *message, ...)
84{
85 ERROR_MESSAGE (&loc, _("warning"), message);
52489d44
AD
86}
87
88void
52489d44 89warn (const char *message, ...)
52489d44 90{
23eb2a69
AD
91 ERROR_MESSAGE (NULL, _("warning"), message);
92}
52489d44 93
e9955c83 94
a0f6b076
AD
95/*-----------------------------------------------------------.
96| An error has occurred, but we can proceed, and die later. |
97`-----------------------------------------------------------*/
98
e9955c83 99void
41f83caf 100complain_at (location loc, const char *message, ...)
e9955c83 101{
23eb2a69 102 ERROR_MESSAGE (&loc, NULL, message);
0ae6073a 103 complaint_issued = true;
52489d44
AD
104}
105
106void
52489d44 107complain (const char *message, ...)
52489d44 108{
23eb2a69 109 ERROR_MESSAGE (NULL, NULL, message);
0ae6073a 110 complaint_issued = true;
e9955c83 111}
23eb2a69
AD
112
113
a0f6b076
AD
114/*-------------------------------------------------.
115| A severe error has occurred, we cannot proceed. |
116`-------------------------------------------------*/
117
e9955c83 118void
41f83caf 119fatal_at (location loc, const char *message, ...)
e9955c83 120{
23eb2a69 121 ERROR_MESSAGE (&loc, _("fatal error"), message);
0ae6073a 122 exit (EXIT_FAILURE);
e9955c83
AD
123}
124
a0f6b076 125void
a0f6b076 126fatal (const char *message, ...)
a0f6b076 127{
23eb2a69 128 ERROR_MESSAGE (NULL, _("fatal error"), message);
0ae6073a 129 exit (EXIT_FAILURE);
a0f6b076 130}