* doc/gcc.texi, doc/install.texi, doc/invoke.texi: Remove trailing
[official-gcc.git] / gcc / errors.c
blobe1a3f13a8fd4c912f9b22fe22828cc6113666d37
1 /* Basic error reporting routines.
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* warning, error, and fatal. These definitions are suitable for use
22 in the generator programs; eventually we would like to use them in
23 cc1 too, but that's a longer term project. */
25 #include "config.h"
26 #include "system.h"
27 #include "errors.h"
29 /* Set this to argv[0] at the beginning of main. */
31 const char *progname;
33 /* Starts out 0, set to 1 if error is called. */
35 int have_error = 0;
37 /* Print a warning message - output produced, but there may be problems. */
39 void
40 warning VPARAMS ((const char *format, ...))
42 #ifndef ANSI_PROTOTYPES
43 const char *format;
44 #endif
45 va_list ap;
47 VA_START (ap, format);
49 #ifndef ANSI_PROTOTYPES
50 format = va_arg (ap, const char *);
51 #endif
53 fprintf (stderr, "%s: warning: ", progname);
54 vfprintf (stderr, format, ap);
55 va_end (ap);
56 fputc('\n', stderr);
60 /* Print an error message - we keep going but the output is unusable. */
62 void
63 error VPARAMS ((const char *format, ...))
65 #ifndef ANSI_PROTOTYPES
66 const char *format;
67 #endif
68 va_list ap;
70 VA_START (ap, format);
72 #ifndef ANSI_PROTOTYPES
73 format = va_arg (ap, const char *);
74 #endif
76 fprintf (stderr, "%s: ", progname);
77 vfprintf (stderr, format, ap);
78 va_end (ap);
79 fputc('\n', stderr);
81 have_error = 1;
85 /* Fatal error - terminate execution immediately. Does not return. */
87 void
88 fatal VPARAMS ((const char *format, ...))
90 #ifndef ANSI_PROTOTYPES
91 const char *format;
92 #endif
93 va_list ap;
95 VA_START (ap, format);
97 #ifndef ANSI_PROTOTYPES
98 format = va_arg (ap, const char *);
99 #endif
101 fprintf (stderr, "%s: ", progname);
102 vfprintf (stderr, format, ap);
103 va_end (ap);
104 fputc('\n', stderr);
105 exit (FATAL_EXIT_CODE);
108 /* Similar, but say we got an internal error. */
110 void
111 internal_error VPARAMS ((const char *format, ...))
113 #ifndef ANSI_PROTOTYPES
114 const char *format;
115 #endif
116 va_list ap;
118 VA_START (ap, format);
120 #ifndef ANSI_PROTOTYPES
121 format = va_arg (ap, const char *);
122 #endif
124 fprintf (stderr, "%s: Internal error", progname);
125 vfprintf (stderr, format, ap);
126 va_end (ap);
127 fputc ('\n', stderr);
128 exit (FATAL_EXIT_CODE);
131 /* Given a partial pathname as input, return another pathname that
132 shares no directory elements with the pathname of __FILE__. This
133 is used by fancy_abort() to print `Internal compiler error in expr.c'
134 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. This
135 version if for the gen* programs and so neededn't handle subdirectories. */
137 const char *
138 trim_filename (name)
139 const char *name;
141 static const char this_file[] = __FILE__;
142 const char *p = name, *q = this_file;
144 /* Skip any parts the two filenames have in common. */
145 while (*p == *q && *p != 0 && *q != 0)
146 p++, q++;
148 /* Now go backwards until the previous directory separator. */
149 while (p > name && p[-1] != DIR_SEPARATOR
150 #ifdef DIR_SEPARATOR_2
151 && p[-1] != DIR_SEPARATOR_2
152 #endif
154 p--;
156 return p;
159 /* "Fancy" abort. Reports where in the compiler someone gave up.
160 This file is used only by build programs, so we're not as polite as
161 the version in diagnostic.c. */
162 void
163 fancy_abort (file, line, func)
164 const char *file;
165 int line;
166 const char *func;
168 internal_error ("abort in %s, at %s:%d", func, file, line);