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