]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cpperror.c
Wed May 6 22:32:37 CDT 1998 Robert Lipe <robertl@dgii.com>
[thirdparty/gcc.git] / gcc / cpperror.c
CommitLineData
7f2935c7 1/* Default error handlers for CPP Library.
51723711 2 Copyright (C) 1986, 87, 89, 92 - 95, 1998 Free Software Foundation, Inc.
7f2935c7
PB
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
6
7This program is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by the
9Free Software Foundation; either version 2, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
940d9d63 19Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7f2935c7
PB
20
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! */
24
84ee6fd4
RK
25#ifndef EMACS
26#include "config.h"
b04cd507
KG
27#include "system.h"
28#else
29#include <stdio.h>
84ee6fd4
RK
30#endif /* not EMACS */
31
f32da1f6 32#include "cpplib.h"
f32da1f6 33
7f2935c7
PB
34/* Print the file names and line numbers of the #include
35 commands which led to the current file. */
36
37void
38cpp_print_containing_files (pfile)
39 cpp_reader *pfile;
40{
41 cpp_buffer *ip;
7f2935c7
PB
42 int first = 1;
43
44 /* If stack of files hasn't changed since we last printed
45 this info, don't repeat it. */
46 if (pfile->input_stack_listing_current)
47 return;
48
49 ip = cpp_file_buffer (pfile);
50
51 /* Give up if we don't find a source file. */
52 if (ip == NULL)
53 return;
54
55 /* Find the other, outer source files. */
56 while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
57 {
58 long line, col;
59 cpp_buf_line_and_col (ip, &line, &col);
60 if (ip->fname != NULL)
61 {
62 if (first)
63 {
64 first = 0;
65 fprintf (stderr, "In file included");
66 }
67 else
68 fprintf (stderr, ",\n ");
69 }
70
51723711 71 fprintf (stderr, " from %s:%ld", ip->nominal_fname, line);
7f2935c7
PB
72 }
73 if (! first)
74 fprintf (stderr, ":\n");
75
76 /* Record we have printed the status as of this time. */
77 pfile->input_stack_listing_current = 1;
78}
79
80void
355142da 81cpp_file_line_for_message (pfile, filename, line, column)
7f2935c7 82 cpp_reader *pfile;
355142da
PB
83 char *filename;
84 int line, column;
7f2935c7 85{
355142da
PB
86 if (column > 0)
87 fprintf (stderr, "%s:%d:%d: ", filename, line, column);
7f2935c7 88 else
355142da 89 fprintf (stderr, "%s:%d: ", filename, line);
7f2935c7
PB
90}
91
05a2b36f 92/* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning */
0f41302f
MS
93
94void
95cpp_message (pfile, is_error, msg, arg1, arg2, arg3)
355142da 96 int is_error;
7f2935c7 97 cpp_reader *pfile;
7f2935c7
PB
98 char *msg;
99 char *arg1, *arg2, *arg3;
100{
05a2b36f 101 if (!is_error)
7f2935c7 102 fprintf (stderr, "warning: ");
05a2b36f
PB
103 else if (is_error == 2)
104 pfile->errors = CPP_FATAL_LIMIT;
105 else if (pfile->errors < CPP_FATAL_LIMIT)
106 pfile->errors++;
7f2935c7
PB
107 fprintf (stderr, msg, arg1, arg2, arg3);
108 fprintf (stderr, "\n");
109}
110
05a2b36f
PB
111/* Same as cpp_error, except we consider the error to be "fatal",
112 such as inconsistent options. I.e. there is little point in continuing.
113 (We do not exit, to support use of cpplib as a library.
114 Instead, it is the caller's responsibility to check
115 CPP_FATAL_ERRORS. */
116
117void
118cpp_fatal (pfile, str, arg)
119 cpp_reader *pfile;
120 char *str, *arg;
121{
122 fprintf (stderr, "%s: ", progname);
123 cpp_message (pfile, 2, str, arg);
124}
7f2935c7 125\f
7f2935c7
PB
126void
127cpp_pfatal_with_name (pfile, name)
128 cpp_reader *pfile;
129 char *name;
130{
131 cpp_perror_with_name (pfile, name);
132#ifdef VMS
133 exit (vaxc$errno);
134#else
84ee6fd4 135 exit (FATAL_EXIT_CODE);
7f2935c7
PB
136#endif
137}