get Borland makefiles working yet again
[fw/sdcc] / support / cpp / 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, 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 #define EMACS
26 #define FATAL_EXIT_CODE 33
27 #ifndef EMACS
28 #include "config.h"
29 #endif /* not EMACS */
30
31 #include "cpplib.h"
32 #include <stdio.h>
33 #include <stdlib.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 (
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:%d", 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 (
83      cpp_reader *pfile,
84      char *filename ,
85      int line, int 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 1 for error, 0 for warning */
94 void cpp_message (
95      cpp_reader *pfile,
96      int is_error,
97      char *msg,
98      char *arg1, char *arg2, char *arg3)
99 {
100         if (is_error) {
101                 pfile->errors++;
102                 fprintf (stderr,"error:");
103         }
104         else {
105                 fprintf (stderr, "warning: ");
106         }
107   fprintf (stderr, msg, arg1, arg2, arg3);
108   fprintf (stderr, "\n");
109 }
110
111 void
112 fatal (char *str,char *arg)
113 {
114   fprintf (stderr, "%s: ", progname);
115   fprintf (stderr, str, arg);
116   fprintf (stderr, "\n");
117   exit (FATAL_EXIT_CODE);
118 }
119
120 \f
121 void
122 cpp_pfatal_with_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 (FATAL_EXIT_CODE);
131 #endif
132 }