error.h revision 1.14 1 /* $NetBSD: error.h,v 1.14 2009/08/13 05:53:58 dholland 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 char *class_table[];
89 extern int class_count[];
90
91 #define nunknown class_count[C_UNKNOWN]
92 #define nignore class_count[C_IGNORE]
93 #define nsyncerrors class_count[C_SYNC]
94 #define ndiscard class_count[C_DISCARD]
95 #define nnonspec class_count[C_NONSPEC]
96 #define nthisfile class_count[C_THISFILE]
97 #define nnulled class_count[C_NULLED]
98 #define ntrue class_count[C_TRUE]
99 #define ndupl class_count[C_DUPL]
100
101 /* places to put the error complaints */
102
103 #define TOTHEFILE 1 /* touch the file */
104 #define TOSTDOUT 2 /* just print them out (ho-hum) */
105
106 extern FILE *errorfile; /* where error file comes from */
107 extern FILE *queryfile; /* where the query responses from the user come from*/
108
109 extern char *processname;
110 extern char *scriptname;
111
112 extern char *suffixlist;
113
114 extern boolean query;
115 extern boolean terse;
116 int inquire(const char *, ...); /* inquire for yes/no */
117
118 /*
119 * codes for inquire() to return
120 */
121 #define Q_error -1 /* an error occurred */
122 #define Q_NO 1 /* 'N' */
123 #define Q_no 2 /* 'n' */
124 #define Q_YES 3 /* 'Y' */
125 #define Q_yes 4 /* 'y' */
126
127 /*
128 * Describes attributes about a language
129 */
130 struct lang_desc {
131 char *lang_name;
132 const char *lang_incomment; /* one of the following defines */
133 const char *lang_outcomment; /* one of the following defines */
134 };
135 extern struct lang_desc lang_table[];
136
137 #define CINCOMMENT "/*###"
138 #define COUTCOMMENT "%%%*/\n"
139 #define FINCOMMENT "C###"
140 #define FOUTCOMMENT "%%%\n"
141 #define NEWLINE "%%%\n"
142 #define PIINCOMMENT "(*###"
143 #define PIOUTCOMMENT "%%%*)\n"
144 #define LISPINCOMMENT ";###"
145 #define ASINCOMMENT "####"
146 #define RIINCOMMENT CINCOMMENT
147 #define RIOUTCOMMENT COUTCOMMENT
148 #define TROFFINCOMMENT ".\\\"###"
149 #define TROFFOUTCOMMENT NEWLINE
150 #define MOD2INCOMMENT "(*###"
151 #define MOD2OUTCOMMENT "%%%*)\n"
152
153 /*
154 * Defines and resources for determing if a given line
155 * is to be discarded because it refers to a file not to
156 * be touched, or if the function reference is to a
157 * function the user doesn't want recorded.
158 */
159
160 #define ERRORNAME "/.errorrc"
161 extern int nignored;
162 extern char **names_ignored;
163
164 /*
165 * Structure definition for a full error
166 */
167 typedef struct edesc Edesc;
168 typedef Edesc *Eptr;
169
170 struct edesc {
171 Eptr error_next; /* linked together */
172 int error_lgtext; /* how many on the right hand side */
173 char **error_text; /* the right hand side proper */
174 Errorclass error_e_class; /* error category of this error */
175 Errorclass error_s_class; /* sub descriptor of error_e_class */
176 int error_language; /* the language for this error */
177 int error_position; /* oridinal position */
178 int error_line; /* discovered line number */
179 int error_no; /* sequence number on input */
180 };
181
182 /*
183 * Resources for the true errors
184 */
185 extern int nerrors;
186 extern Eptr er_head;
187
188 extern int cur_wordc;
189 extern char **cur_wordv;
190
191
192 /*
193 * Resources for each of the files mentioned
194 */
195 extern int nfiles;
196 extern Eptr **files; /* array of pointers into errors */
197 extern boolean *touchedfiles; /* which files we touched */
198
199 /*
200 * The language the compilation is in, as intuited from
201 * the flavor of error messages analyzed.
202 */
203 extern int language;
204 extern char *currentfilename;
205
206 /*
207 * Functional forwards
208 */
209 void arrayify(int *, Eptr **, Eptr);
210 void *Calloc(size_t, size_t);
211 void clob_last(char *, char);
212 Errorclass discardit(Eptr);
213 void eaterrors(int *, Eptr **);
214 void erroradd(int, char **, Errorclass, Errorclass);
215 void filenames(int, Eptr **);
216 void findfiles(int, Eptr *, int *, Eptr ***);
217 char firstchar(const char *);
218 void getignored(const char *);
219 char lastchar(const char *);
220 char next_lastchar(const char *);
221 void onintr(int);
222 bool persperdexplode(char *, char **, char **);
223 Errorclass pi(void);
224 int position(const char *, char);
225 void printerrors(bool, int, Eptr []);
226 const char *plural(int);
227 char *substitute(char *, char, char);
228 bool touchfiles(int, Eptr **, int *, char ***);
229 const char *verbform(int);
230 void wordvbuild(char *, int*, char ***);
231 int wordvcmp(char **, int, char **);
232 void wordvprint(FILE *, int, char **);
233 char **wordvsplice(int, int, char **);
234