]> git.saurik.com Git - bison.git/blob - src/complain.c
* src/getargs.c (usage): Back out yesterday's modification of the
[bison.git] / src / complain.c
1 /* Declaration for error-reporting function for Bison.
2
3 Copyright (C) 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
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
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 USA. */
19
20 /* Based on error.c and error.h,
21 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
22
23 #include <config.h>
24 #include "system.h"
25
26 #include <stdarg.h>
27
28 #include "complain.h"
29 #include "files.h"
30
31 /* The calling program should define program_name and set it to the
32 name of the executing program. */
33 extern char *program_name;
34
35 /* This variable is set each time `warn' is called. */
36 bool warning_issued;
37
38 /* This variable is set each time `complain' is called. */
39 bool complaint_issued;
40
41 \f
42 /*--------------------------------.
43 | Report a warning, and proceed. |
44 `--------------------------------*/
45
46 void
47 warn_at (location loc, const char *message, ...)
48 {
49 va_list args;
50
51 location_print (stderr, loc);
52 fputs (": ", stderr);
53 fputs (_("warning: "), stderr);
54
55 va_start (args, message);
56 vfprintf (stderr, message, args);
57 va_end (args);
58
59 warning_issued = true;
60 putc ('\n', stderr);
61 }
62
63 void
64 warn (const char *message, ...)
65 {
66 va_list args;
67
68 fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: "));
69
70 va_start (args, message);
71 vfprintf (stderr, message, args);
72 va_end (args);
73
74 warning_issued = true;
75 putc ('\n', stderr);
76 }
77 \f
78 /*-----------------------------------------------------------.
79 | An error has occurred, but we can proceed, and die later. |
80 `-----------------------------------------------------------*/
81
82 void
83 complain_at (location loc, const char *message, ...)
84 {
85 va_list args;
86
87 location_print (stderr, loc);
88 fputs (": ", stderr);
89
90 va_start (args, message);
91 vfprintf (stderr, message, args);
92 va_end (args);
93
94 complaint_issued = true;
95 putc ('\n', stderr);
96 }
97
98 void
99 complain (const char *message, ...)
100 {
101 va_list args;
102
103 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
104
105 va_start (args, message);
106 vfprintf (stderr, message, args);
107 va_end (args);
108
109 complaint_issued = true;
110 putc ('\n', stderr);
111 }
112 \f
113 /*-------------------------------------------------.
114 | A severe error has occurred, we cannot proceed. |
115 `-------------------------------------------------*/
116
117 void
118 fatal_at (location loc, const char *message, ...)
119 {
120 va_list args;
121
122 location_print (stderr, loc);
123 fputs (": ", stderr);
124 fputs (_("fatal error: "), stderr);
125
126 va_start (args, message);
127 vfprintf (stderr, message, args);
128 va_end (args);
129 putc ('\n', stderr);
130 exit (EXIT_FAILURE);
131 }
132
133 void
134 fatal (const char *message, ...)
135 {
136 va_list args;
137
138 fprintf (stderr, "%s: ", current_file ? current_file : program_name);
139
140 fputs (_("fatal error: "), stderr);
141
142 va_start (args, message);
143 vfprintf (stderr, message, args);
144 va_end (args);
145 putc ('\n', stderr);
146 exit (EXIT_FAILURE);
147 }