OSDN Git Service

* system.h: Include stdarg.h/varargs.h, make sure they are ordered
[pf3gnuchains/gcc-fork.git] / gcc / cpperror.c
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 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 #ifndef EMACS
26 #include "config.h"
27 #include "system.h"
28 #include "gansidecl.h"
29 #else
30 #include <stdio.h>
31 #endif /* not EMACS */
32
33 #include "cpplib.h"
34
35 /* Print the file names and line numbers of the #include
36    commands which led to the current file.  */
37
38 void
39 cpp_print_containing_files (pfile)
40      cpp_reader *pfile;
41 {
42   cpp_buffer *ip;
43   int first = 1;
44
45   /* If stack of files hasn't changed since we last printed
46      this info, don't repeat it.  */
47   if (pfile->input_stack_listing_current)
48     return;
49
50   ip = cpp_file_buffer (pfile);
51
52   /* Give up if we don't find a source file.  */
53   if (ip == NULL)
54     return;
55
56   /* Find the other, outer source files.  */
57   while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
58     {
59       long line, col;
60       cpp_buf_line_and_col (ip, &line, &col);
61       if (ip->fname != NULL)
62         {
63           if (first)
64             {
65               first = 0;
66               fprintf (stderr, "In file included");
67             }
68           else
69             fprintf (stderr, ",\n                ");
70         }
71
72       fprintf (stderr, " from %s:%ld", ip->nominal_fname, line);
73     }
74   if (! first)
75     fprintf (stderr, ":\n");
76
77   /* Record we have printed the status as of this time.  */
78   pfile->input_stack_listing_current = 1;
79 }
80
81 void
82 cpp_file_line_for_message (pfile, filename, line, column)
83      cpp_reader *pfile ATTRIBUTE_UNUSED;
84      char *filename;
85      int line, column;
86 {
87   if (column > 0)
88     fprintf (stderr, "%s:%d:%d: ", filename, line, column);
89   else
90     fprintf (stderr, "%s:%d: ", filename, line);
91 }
92
93 /* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning */
94
95 void
96 v_cpp_message (pfile, is_error, msg, ap)
97   cpp_reader * pfile;
98   int is_error;
99   const char *msg;
100   va_list ap;
101 {
102   if (!is_error)
103     fprintf (stderr, "warning: ");
104   else if (is_error == 2)
105     pfile->errors = CPP_FATAL_LIMIT;
106   else if (pfile->errors < CPP_FATAL_LIMIT)
107     pfile->errors++;
108   vfprintf (stderr, msg, ap);
109   fprintf (stderr, "\n");
110 }
111
112 void
113 cpp_message VPROTO ((cpp_reader *pfile, int is_error, const char *msg, ...))
114 {
115 #ifndef __STDC__
116   cpp_reader *pfile;
117   int is_error;
118   const char *msg;
119 #endif
120   va_list ap;
121   
122   VA_START (ap, msg);
123   
124 #ifndef __STDC__
125   pfile = va_arg (ap, cpp_reader *);
126   is_error = va_arg (ap, int);
127   msg = va_arg (ap, const char *);
128 #endif
129
130   v_cpp_message(pfile, is_error, msg, ap);
131   va_end(ap);
132 }
133
134 /* Same as cpp_error, except we consider the error to be "fatal",
135    such as inconsistent options.  I.e. there is little point in continuing.
136    (We do not exit, to support use of cpplib as a library.
137    Instead, it is the caller's responsibility to check
138    CPP_FATAL_ERRORS.  */
139
140 void
141 cpp_fatal VPROTO ((cpp_reader *pfile, const char *str, ...))
142 {  
143 #ifndef __STDC__
144   cpp_reader *pfile;
145   const char *str;
146 #endif
147   va_list ap;
148   
149   VA_START (ap, str);
150   
151 #ifndef __STDC__
152   pfile = va_arg (ap, cpp_reader *);
153   str = va_arg (ap, const char *);
154 #endif
155
156   fprintf (stderr, "%s: ", progname);
157   v_cpp_message (pfile, 2, str, ap);
158   va_end(ap);
159 }
160 \f
161 void
162 cpp_pfatal_with_name (pfile, name)
163      cpp_reader *pfile;
164      const char *name;
165 {
166   cpp_perror_with_name (pfile, name);
167 #ifdef VMS
168   exit (vaxc$errno);
169 #else
170   exit (FATAL_EXIT_CODE);
171 #endif
172 }