chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / epp / 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 <stdio.h>
26 #include <stdlib.h>
27 #include "config.h"
28 #include "cpplib.h"
29
30 /* Print the file names and line numbers of the #include
31  * commands which led to the current file.  */
32
33 void
34 cpp_print_containing_files(cpp_reader * pfile)
35 {
36    cpp_buffer         *ip;
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
55         cpp_buf_line_and_col(ip, &line, &col);
56         if (ip->fname != NULL)
57           {
58              if (first)
59                {
60                   first = 0;
61                   fprintf(stderr, "In file included");
62                }
63              else
64                 fprintf(stderr, ",\n                ");
65           }
66      }
67    if (!first)
68       fprintf(stderr, ":\n");
69
70    /* Record we have printed the status as of this time.  */
71    pfile->input_stack_listing_current = 1;
72 }
73
74 void
75 cpp_file_line_for_message(cpp_reader * pfile, const char *filename,
76                           int line, int column)
77 {
78    pfile = NULL;
79    if (column > 0)
80      {
81         fprintf(stderr, "%s:%d:%d: ", filename, line, column);
82      }
83    else
84      {
85         fprintf(stderr, "%s:%d: ", filename, line);
86      }
87 }
88
89 /* IS_ERROR is 1 for error, 0 for warning */
90 void
91 cpp_message_v(cpp_reader * pfile, int is_error, const char *msg, va_list args)
92 {
93    if (is_error)
94       pfile->errors++;
95    else
96       fprintf(stderr, "warning: ");
97    vfprintf(stderr, msg, args);
98    fprintf(stderr, "\n");
99 }
100
101 void
102 cpp_message(cpp_reader * pfile, int is_error, const char *msg, ...)
103 {
104    va_list             args;
105
106    va_start(args, msg);
107
108    cpp_message_v(pfile, is_error, msg, args);
109
110    va_end(args);
111 }
112
113 static void
114 cpp_fatal_v(const char *msg, va_list args)
115 {
116    fprintf(stderr, "%s: ", progname);
117    vfprintf(stderr, msg, args);
118    fprintf(stderr, "\n");
119    exit(FATAL_EXIT_CODE);
120 }
121
122 void
123 cpp_fatal(const char *msg, ...)
124 {
125    va_list             args;
126
127    va_start(args, msg);
128
129    cpp_fatal_v(msg, args);
130
131    va_end(args);
132 }
133
134 void
135 cpp_pfatal_with_name(cpp_reader * pfile, const char *name)
136 {
137    cpp_perror_with_name(pfile, name);
138 #ifdef VMS
139    exit(vaxc$errno);
140 #else
141    exit(FATAL_EXIT_CODE);
142 #endif
143 }