error.h revision 1.18 1 /* $NetBSD: error.h,v 1.18 2011/08/17 13:11:22 christos Exp $ */
2
3 /*
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)error.h 8.1 (Berkeley) 6/6/93
32 */
33
34 #include <stdbool.h>
35
36 typedef int boolean;
37
38 /*
39 * Descriptors for the various languages we know about.
40 * If you touch these, also touch lang_table
41 */
42 #define INUNKNOWN 0
43 #define INCPP 1
44 #define INCC 2
45 #define INAS 3
46 #define INLD 4
47 #define INLINT 5
48 #define INF77 6
49 #define INPI 7
50 #define INPC 8
51 #define INFRANZ 9
52 #define INLISP 10
53 #define INVAXIMA 11
54 #define INRATFOR 12
55 #define INLEX 13
56 #define INYACC 14
57 #define INAPL 15
58 #define INMAKE 16
59 #define INRI 17
60 #define INTROFF 18
61 #define INMOD2 19
62
63 /*
64 * We analyze each line in the error message file, and
65 * attempt to categorize it by type, as well as language.
66 * Here are the type descriptors.
67 */
68 typedef int Errorclass;
69
70 #define C_FIRST 0 /* first error category */
71 #define C_UNKNOWN 0 /* must be zero */
72 #define C_IGNORE 1 /* ignore the message; used for pi */
73 #define C_SYNC 2 /* synchronization errors */
74 #define C_DISCARD 3 /* touches dangerous files, so discard */
75 #define C_NONSPEC 4 /* not specific to any file */
76 #define C_THISFILE 5 /* specific to this file, but at no line */
77 #define C_NULLED 6 /* refers to special func; so null */
78 #define C_TRUE 7 /* fits into true error format */
79 #define C_DUPL 8 /* sub class only; duplicated error message */
80 #define C_LAST 9 /* last error category */
81
82 #define SORTABLE(x) (!(NOTSORTABLE(x)))
83 #define NOTSORTABLE(x) (x <= C_NONSPEC)
84
85 /*
86 * Resources to count and print out the error categories
87 */
88 extern const char *class_table[];
89 extern int class_count[];
90
91 extern size_t filelevel;
92
93 #define nunknown class_count[C_UNKNOWN]
94 #define nignore class_count[C_IGNORE]
95 #define nsyncerrors class_count[C_SYNC]
96 #define ndiscard class_count[C_DISCARD]
97 #define nnonspec class_count[C_NONSPEC]
98 #define nthisfile class_count[C_THISFILE]
99 #define nnulled class_count[C_NULLED]
100 #define ntrue class_count[C_TRUE]
101 #define ndupl class_count[C_DUPL]
102
103 /* places to put the error complaints */
104
105 #define TOTHEFILE 1 /* touch the file */
106 #define TOSTDOUT 2 /* just print them out (ho-hum) */
107
108 extern FILE *errorfile; /* where error file comes from */
109 extern FILE *queryfile; /* where the query responses from the user come from*/
110
111 extern char *scriptname;
112
113 extern const char *suffixlist;
114
115 extern boolean query;
116 extern boolean terse;
117 int inquire(const char *, ...); /* inquire for yes/no */
118
119 /*
120 * codes for inquire() to return
121 */
122 #define Q_error -1 /* an error occurred */
123 #define Q_NO 1 /* 'N' */
124 #define Q_no 2 /* 'n' */
125 #define Q_YES 3 /* 'Y' */
126 #define Q_yes 4 /* 'y' */
127
128 /*
129 * Describes attributes about a language
130 */
131 struct lang_desc {
132 const char *lang_name;
133 const char *lang_incomment; /* one of the following defines */
134 const char *lang_outcomment; /* one of the following defines */
135 };
136 extern struct lang_desc lang_table[];
137
138 #define CINCOMMENT "/*###"
139 #define COUTCOMMENT "%%%*/\n"
140 #define FINCOMMENT "C###"
141 #define FOUTCOMMENT "%%%\n"
142 #define NEWLINE "%%%\n"
143 #define PIINCOMMENT "(*###"
144 #define PIOUTCOMMENT "%%%*)\n"
145 #define LISPINCOMMENT ";###"
146 #define ASINCOMMENT "####"
147 #define RIINCOMMENT CINCOMMENT
148 #define RIOUTCOMMENT COUTCOMMENT
149 #define TROFFINCOMMENT ".\\\"###"
150 #define TROFFOUTCOMMENT NEWLINE
151 #define MOD2INCOMMENT "(*###"
152 #define MOD2OUTCOMMENT "%%%*)\n"
153
154 /*
155 * Defines and resources for determing if a given line
156 * is to be discarded because it refers to a file not to
157 * be touched, or if the function reference is to a
158 * function the user doesn't want recorded.
159 */
160
161 #define ERRORNAME "/.errorrc"
162 extern int nignored;
163 extern char **names_ignored;
164
165 /*
166 * Structure definition for a full error
167 */
168 typedef struct edesc Edesc;
169 typedef Edesc *Eptr;
170
171 struct edesc {
172 Eptr error_next; /* linked together */
173 int error_lgtext; /* how many on the right hand side */
174 char **error_text; /* the right hand side proper */
175 Errorclass error_e_class; /* error category of this error */
176 Errorclass error_s_class; /* sub descriptor of error_e_class */
177 int error_language; /* the language for this error */
178 int error_position; /* oridinal position */
179 int error_line; /* discovered line number */
180 int error_no; /* sequence number on input */
181 };
182
183 /*
184 * Resources for the true errors
185 */
186 extern int nerrors;
187 extern Eptr er_head;
188
189 extern int cur_wordc;
190 extern char **cur_wordv;
191
192
193 /*
194 * Resources for each of the files mentioned
195 */
196 extern int nfiles;
197 extern Eptr **files; /* array of pointers into errors */
198 extern boolean *touchedfiles; /* which files we touched */
199
200 /*
201 * The language the compilation is in, as intuited from
202 * the flavor of error messages analyzed.
203 */
204 extern int language;
205 extern char *currentfilename;
206 extern char default_currentfilename[];
207
208 /*
209 * Macros for initializing arrays of string constants.
210 * This is a fairly gross set of preprocessor hacks; the idea is
211 * that instead of
212 * static char *foo[4] = { "alpha", "beta", "gamma", "delta" };
213 * you do
214 * DECL_STRINGS_4(static, foo, "alpha", "beta", "gamma", "delta");
215 *
216 * and it comes out as
217 * static char foo_0[] = "delta";
218 * static char foo_1[] = "gamma";
219 * static char foo_2[] = "beta";
220 * static char foo_3[] = "alpha";
221 * static char *foo[4] = { foo_3, foo_2, foo_1, foo_0 };
222 *
223 * none of which is const.
224 *
225 * Unfortunately, the string arrays this program slings around freely
226 * can't be all const (because it munges some of them) and can't be
227 * all non-const without something like this to initialize the ones
228 * that need to contain string constants. Unfortunately you can't
229 * mix (const char *const *) and (char **) in C, only in C++.
230 */
231
232 #define DECL_STR(sym, num, str) static char sym##_##num[] = str
233
234 #define DECL_S1(sym, s, ...) __VA_ARGS__ DECL_STR(sym, 0, s)
235 #define DECL_S2(sym, s, ...) DECL_STR(sym, 1, s); DECL_S1(sym, __VA_ARGS__)
236 #define DECL_S3(sym, s, ...) DECL_STR(sym, 2, s); DECL_S2(sym, __VA_ARGS__)
237 #define DECL_S4(sym, s, ...) DECL_STR(sym, 3, s); DECL_S3(sym, __VA_ARGS__)
238 #define DECL_S5(sym, s, ...) DECL_STR(sym, 4, s); DECL_S4(sym, __VA_ARGS__)
239 #define DECL_S6(sym, s, ...) DECL_STR(sym, 5, s); DECL_S5(sym, __VA_ARGS__)
240
241 #define USE_S1(sym) sym##_0
242 #define USE_S2(sym) sym##_1, USE_S1(sym)
243 #define USE_S3(sym) sym##_2, USE_S2(sym)
244 #define USE_S4(sym) sym##_3, USE_S3(sym)
245 #define USE_S5(sym) sym##_4, USE_S4(sym)
246 #define USE_S6(sym) sym##_5, USE_S5(sym)
247
248 #define DECL_STRS(num, class, sym, ...) \
249 DECL_S##num(sym, __VA_ARGS__); \
250 class char *sym[num] = { USE_S##num(sym) }
251
252 #define DECL_STRINGS_1(class, sym, ...) DECL_STRS(1, class, sym, __VA_ARGS__)
253 #define DECL_STRINGS_2(class, sym, ...) DECL_STRS(2, class, sym, __VA_ARGS__)
254 #define DECL_STRINGS_3(class, sym, ...) DECL_STRS(3, class, sym, __VA_ARGS__)
255 #define DECL_STRINGS_4(class, sym, ...) DECL_STRS(4, class, sym, __VA_ARGS__)
256 #define DECL_STRINGS_5(class, sym, ...) DECL_STRS(5, class, sym, __VA_ARGS__)
257 #define DECL_STRINGS_6(class, sym, ...) DECL_STRS(6, class, sym, __VA_ARGS__)
258
259
260 /*
261 * Functional forwards
262 */
263 void arrayify(int *, Eptr **, Eptr);
264 void *Calloc(size_t, size_t);
265 void clob_last(char *, char);
266 Errorclass discardit(Eptr);
267 void eaterrors(int *, Eptr **);
268 void erroradd(int, char **, Errorclass, Errorclass);
269 void filenames(int, Eptr **);
270 void findfiles(int, Eptr *, int *, Eptr ***);
271 char firstchar(const char *);
272 void getignored(const char *);
273 char lastchar(const char *);
274 char next_lastchar(const char *);
275 void onintr(int);
276 bool persperdexplode(char *, char **, char **);
277 Errorclass pi(void);
278 int position(const char *, char);
279 void printerrors(bool, int, Eptr []);
280 const char *plural(int);
281 char *Strdup(const char *);
282 char *substitute(char *, char, char);
283 bool touchfiles(int, Eptr **, int *, char ***);
284 const char *verbform(int);
285 void wordvbuild(char *, int*, char ***);
286 int wordvcmp(char **, int, char **);
287 void wordvprint(FILE *, int, char **);
288 char **wordvsplice(int, int, char **);
289