]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cpperror.c
cpplib.c (copy_rest_of_line): Revert previous change: don't bail out early if we...
[thirdparty/gcc.git] / gcc / cpperror.c
CommitLineData
7f2935c7 1/* Default error handlers for CPP Library.
40ea76de
ZW
2 Copyright (C) 1986, 87, 89, 92-95, 98, 99, 2000
3 Free Software Foundation, Inc.
7f2935c7 4 Written by Per Bothner, 1994.
38e01259 5 Based on CCCP program by Paul Rubin, June 1986
7f2935c7
PB
6 Adapted to ANSI C, Richard Stallman, Jan 1987
7
8This program is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License as published by the
10Free Software Foundation; either version 2, or (at your option) any
11later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
940d9d63 20Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7f2935c7
PB
21
22 In other words, you are welcome to use, share and improve this program.
23 You are forbidden to forbid anyone else to use, share and improve
24 what you give them. Help stamp out software-hoarding! */
25
84ee6fd4 26#include "config.h"
b04cd507 27#include "system.h"
f32da1f6 28#include "cpplib.h"
ab87f8c8 29#include "intl.h"
f32da1f6 30
7f2935c7
PB
31/* Print the file names and line numbers of the #include
32 commands which led to the current file. */
33
34void
35cpp_print_containing_files (pfile)
36 cpp_reader *pfile;
37{
38 cpp_buffer *ip;
7f2935c7
PB
39 int first = 1;
40
41 /* If stack of files hasn't changed since we last printed
42 this info, don't repeat it. */
43 if (pfile->input_stack_listing_current)
44 return;
45
46 ip = cpp_file_buffer (pfile);
47
48 /* Give up if we don't find a source file. */
49 if (ip == NULL)
50 return;
51
52 /* Find the other, outer source files. */
53 while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
54 {
55 long line, col;
56 cpp_buf_line_and_col (ip, &line, &col);
57 if (ip->fname != NULL)
58 {
59 if (first)
60 {
61 first = 0;
6ee2c979
ZW
62 cpp_message (pfile, -1, "In file included from %s:%ld",
63 ip->nominal_fname, line);
7f2935c7
PB
64 }
65 else
74c9467a
ZW
66 cpp_message (pfile, -1, ",\n from %s:%ld",
67 ip->nominal_fname, line);
7f2935c7 68 }
7f2935c7
PB
69 }
70 if (! first)
74c9467a 71 fputs (":\n", stderr);
7f2935c7
PB
72
73 /* Record we have printed the status as of this time. */
74 pfile->input_stack_listing_current = 1;
75}
76
77void
355142da 78cpp_file_line_for_message (pfile, filename, line, column)
487a6e06 79 cpp_reader *pfile ATTRIBUTE_UNUSED;
bcc5cac9 80 const char *filename;
355142da 81 int line, column;
7f2935c7 82{
59495f38
ZW
83 if (filename == 0 || *filename == '\0')
84 filename = "<stdin>";
85 if (line == 0)
86 fputs (_("<command line>: "), stderr);
87 else if (column > 0)
355142da 88 fprintf (stderr, "%s:%d:%d: ", filename, line, column);
7f2935c7 89 else
355142da 90 fprintf (stderr, "%s:%d: ", filename, line);
7f2935c7
PB
91}
92
ab87f8c8 93/* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning, -1 for notice */
0f41302f
MS
94
95void
ab87f8c8 96v_cpp_message (pfile, is_error, msgid, ap)
487a6e06
KG
97 cpp_reader * pfile;
98 int is_error;
ab87f8c8 99 const char *msgid;
487a6e06 100 va_list ap;
7f2935c7 101{
ab87f8c8
JL
102 switch (is_error)
103 {
104 case -1:
105 break;
106 case 0:
107 fprintf (stderr, _("warning: "));
108 break;
109 case 1:
110 if (pfile->errors < CPP_FATAL_LIMIT)
111 pfile->errors++;
112 break;
113 case 2:
114 pfile->errors = CPP_FATAL_LIMIT;
115 break;
116 default:
34ca9541 117 cpp_fatal (pfile, "internal error: bad is_error(%d) in v_cpp_message", is_error);
ab87f8c8
JL
118 }
119
120 vfprintf (stderr, _(msgid), ap);
121
122 if (0 <= is_error)
123 fprintf (stderr, "\n");
7f2935c7
PB
124}
125
487a6e06 126void
f84c2018 127cpp_message VPARAMS ((cpp_reader *pfile, int is_error, const char *msgid, ...))
487a6e06 128{
5148a72b 129#ifndef ANSI_PROTOTYPES
487a6e06
KG
130 cpp_reader *pfile;
131 int is_error;
1c5d09e4 132 const char *msgid;
487a6e06
KG
133#endif
134 va_list ap;
135
ab87f8c8 136 VA_START (ap, msgid);
487a6e06 137
5148a72b 138#ifndef ANSI_PROTOTYPES
487a6e06
KG
139 pfile = va_arg (ap, cpp_reader *);
140 is_error = va_arg (ap, int);
ab87f8c8 141 msgid = va_arg (ap, const char *);
487a6e06
KG
142#endif
143
ab87f8c8 144 v_cpp_message(pfile, is_error, msgid, ap);
487a6e06
KG
145 va_end(ap);
146}
147
05a2b36f
PB
148/* Same as cpp_error, except we consider the error to be "fatal",
149 such as inconsistent options. I.e. there is little point in continuing.
150 (We do not exit, to support use of cpplib as a library.
151 Instead, it is the caller's responsibility to check
152 CPP_FATAL_ERRORS. */
153
154void
f84c2018 155cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
487a6e06 156{
5148a72b 157#ifndef ANSI_PROTOTYPES
487a6e06 158 cpp_reader *pfile;
ab87f8c8 159 const char *msgid;
487a6e06
KG
160#endif
161 va_list ap;
162
ab87f8c8 163 VA_START (ap, msgid);
487a6e06 164
5148a72b 165#ifndef ANSI_PROTOTYPES
487a6e06 166 pfile = va_arg (ap, cpp_reader *);
ab87f8c8 167 msgid = va_arg (ap, const char *);
487a6e06
KG
168#endif
169
05a2b36f 170 fprintf (stderr, "%s: ", progname);
ab87f8c8 171 v_cpp_message (pfile, 2, msgid, ap);
487a6e06 172 va_end(ap);
05a2b36f 173}
7f2935c7 174\f
7f2935c7
PB
175void
176cpp_pfatal_with_name (pfile, name)
177 cpp_reader *pfile;
487a6e06 178 const char *name;
7f2935c7
PB
179{
180 cpp_perror_with_name (pfile, name);
181#ifdef VMS
182 exit (vaxc$errno);
183#else
84ee6fd4 184 exit (FATAL_EXIT_CODE);
7f2935c7
PB
185#endif
186}
ab87f8c8
JL
187
188/* Print an error message. */
189
190void
f84c2018 191cpp_notice VPARAMS ((const char *msgid, ...))
ab87f8c8
JL
192{
193#ifndef ANSI_PROTOTYPES
194 const char *msgid;
195#endif
196 va_list ap;
197
198 VA_START (ap, msgid);
199
200#ifndef ANSI_PROTOTYPES
201 msgid = va_arg (ap, const char *);
202#endif
203
204 fprintf (stderr, "%s: ", progname);
205 v_cpp_message ((cpp_reader *) 0, -1, msgid, ap);
206 va_end(ap);
207}
208\f