Import final gcc2 snapshot (990109)
[official-gcc.git] / gcc / cpperror.c
blob0a5241fd4cda677562fa00a888d406cd2fe23cf9
1 /* Default error handlers for CPP Library.
2 Copyright (C) 1986, 87, 89, 92-95, 1998 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994.
4 Based on CCCP program by by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding! */
25 #ifndef EMACS
26 #include "config.h"
27 #endif /* not EMACS */
29 #ifdef IN_GCC
30 #include "system.h"
31 #else
32 #include <stdio.h>
33 #include <errno.h>
34 #endif
36 #include "cpplib.h"
37 #include "intl.h"
39 /* Print the file names and line numbers of the #include
40 commands which led to the current file. */
42 void
43 cpp_print_containing_files (pfile)
44 cpp_reader *pfile;
46 cpp_buffer *ip;
47 int i;
48 int first = 1;
50 /* If stack of files hasn't changed since we last printed
51 this info, don't repeat it. */
52 if (pfile->input_stack_listing_current)
53 return;
55 ip = cpp_file_buffer (pfile);
57 /* Give up if we don't find a source file. */
58 if (ip == NULL)
59 return;
61 /* Find the other, outer source files. */
62 while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
64 long line, col;
65 cpp_buf_line_and_col (ip, &line, &col);
66 if (ip->fname != NULL)
68 if (first)
70 first = 0;
71 cpp_notice ("In file included from ");
73 else
74 cpp_notice (",\n from ");
77 fprintf (stderr, "%s:%d", ip->nominal_fname, line);
79 if (! first)
80 fprintf (stderr, ":\n");
82 /* Record we have printed the status as of this time. */
83 pfile->input_stack_listing_current = 1;
86 void
87 cpp_file_line_for_message (pfile, filename, line, column)
88 cpp_reader *pfile;
89 char *filename;
90 int line, column;
92 if (column > 0)
93 fprintf (stderr, "%s:%d:%d: ", filename, line, column);
94 else
95 fprintf (stderr, "%s:%d: ", filename, line);
98 /* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning, -1 for notice */
100 void
101 cpp_message (pfile, is_error, format, arg1, arg2, arg3)
102 int is_error;
103 cpp_reader *pfile;
104 char *format;
105 char *arg1, *arg2, *arg3;
107 switch (is_error)
109 case -1:
110 break;
111 case 0:
112 fprintf (stderr, _("warning: "));
113 break;
114 case 1:
115 if (pfile->errors < CPP_FATAL_LIMIT)
116 pfile->errors++;
117 break;
118 case 2:
119 pfile->errors = CPP_FATAL_LIMIT;
120 break;
121 default:
122 abort ();
125 fprintf (stderr, format, arg1, arg2, arg3);
127 if (0 <= is_error)
128 fprintf (stderr, "\n");
131 /* Same as cpp_error, except we consider the error to be "fatal",
132 such as inconsistent options. I.e. there is little point in continuing.
133 (We do not exit, to support use of cpplib as a library.
134 Instead, it is the caller's responsibility to check
135 CPP_FATAL_ERRORS. */
137 void
138 cpp_fatal (pfile, msgid, arg)
139 cpp_reader *pfile;
140 char *msgid, *arg;
142 fprintf (stderr, "%s: ", progname);
143 cpp_message (pfile, 2, _(msgid), arg);
146 void
147 cpp_pfatal_with_name (pfile, name)
148 cpp_reader *pfile;
149 char *name;
151 cpp_perror_with_name (pfile, name);
152 #ifdef VMS
153 exit (vaxc$errno);
154 #else
155 exit (FATAL_EXIT_CODE);
156 #endif