OSDN Git Service

Moved 'high-level' error functions from cpperror.c to cpplib.c.
[pf3gnuchains/gcc-fork.git] / gcc / cpperror.c
1 /* Default error handlers for CPP Library.
2    Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 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
6
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.
11
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.
16
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, 675 Mass Ave, Cambridge, MA 02139, USA.
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
25 #include "cpplib.h"
26 #include <stdio.h>
27
28 /* Print the file names and line numbers of the #include
29    commands which led to the current file.  */
30
31 void
32 cpp_print_containing_files (pfile)
33      cpp_reader *pfile;
34 {
35   cpp_buffer *ip;
36   int i;
37   int first = 1;
38
39   /* If stack of files hasn't changed since we last printed
40      this info, don't repeat it.  */
41   if (pfile->input_stack_listing_current)
42     return;
43
44   ip = cpp_file_buffer (pfile);
45
46   /* Give up if we don't find a source file.  */
47   if (ip == NULL)
48     return;
49
50   /* Find the other, outer source files.  */
51   while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
52     {
53       long line, col;
54       cpp_buf_line_and_col (ip, &line, &col);
55       if (ip->fname != NULL)
56         {
57           if (first)
58             {
59               first = 0;
60               fprintf (stderr, "In file included");
61             }
62           else
63             fprintf (stderr, ",\n                ");
64         }
65
66 /* start-sanitize-mpw */
67 #ifdef MPW
68       fprintf (stderr, " File \"%s\"; Line %d  # ", ip->nominal_fname, line);
69 #else
70 /* end-sanitize-mpw */
71       fprintf (stderr, " from %s:%d", ip->nominal_fname, line);
72 /* start-sanitize-mpw */
73 #endif /* MPW */
74 /* end-sanitize-mpw */
75     }
76   if (! first)
77     fprintf (stderr, ":\n");
78
79   /* Record we have printed the status as of this time.  */
80   pfile->input_stack_listing_current = 1;
81 }
82
83 void
84 cpp_file_line_for_message (pfile, filename, line, column)
85      cpp_reader *pfile;
86      char *filename;
87      int line, column;
88 {
89   if (column > 0)
90     fprintf (stderr, "%s:%d:%d: ", filename, line, column);
91   else
92     fprintf (stderr, "%s:%d: ", filename, line);
93 }
94
95 /* IS_ERROR is 1 for error, 0 for warning */
96 void cpp_message (pfile, is_error, msg, arg1, arg2, arg3)
97      int is_error;
98      cpp_reader *pfile;
99      char *msg;
100      char *arg1, *arg2, *arg3;
101 {
102   if (is_error)
103     pfile->errors++;
104   else
105     fprintf (stderr, "warning: ");
106   fprintf (stderr, msg, arg1, arg2, arg3);
107   fprintf (stderr, "\n");
108 }
109
110 void
111 fatal (str, arg)
112      char *str, *arg;
113 {
114   fprintf (stderr, "%s: ", progname);
115   fprintf (stderr, str, arg);
116   fprintf (stderr, "\n");
117   exit (FAILURE_EXIT_CODE);
118 }
119
120 \f
121 void
122 cpp_pfatal_with_name (pfile, name)
123      cpp_reader *pfile;
124      char *name;
125 {
126   cpp_perror_with_name (pfile, name);
127 #ifdef VMS
128   exit (vaxc$errno);
129 #else
130   exit (FAILURE_EXIT_CODE);
131 #endif
132 }