xref: /netbsd/usr.bin/error/error.h (revision bf9ec67e)
1 /*	$NetBSD: error.h,v 1.7 2002/05/26 22:41:20 wiz 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. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)error.h	8.1 (Berkeley) 6/6/93
36  */
37 
38 typedef	int	boolean;
39 
40 #define	TRUE	1
41 #define	FALSE	0
42 
43 #define	true	1
44 #define	false	0
45 /*
46  *	Descriptors for the various languages we know about.
47  *	If you touch these, also touch lang_table
48  */
49 #define	INUNKNOWN	0
50 #define	INCPP	1
51 #define	INCC	2
52 #define	INAS	3
53 #define	INLD	4
54 #define	INLINT	5
55 #define	INF77	6
56 #define	INPI	7
57 #define	INPC	8
58 #define	INFRANZ	9
59 #define	INLISP	10
60 #define	INVAXIMA	11
61 #define	INRATFOR	12
62 #define	INLEX	13
63 #define	INYACC	14
64 #define	INAPL	15
65 #define	INMAKE	16
66 #define	INRI	17
67 #define	INTROFF	18
68 #define	INMOD2	19
69 
70 /*
71  *	We analyze each line in the error message file, and
72  *	attempt to categorize it by type, as well as language.
73  *	Here are the type descriptors.
74  */
75 typedef	int	Errorclass;
76 
77 #define	C_FIRST	0		/* first error category */
78 #define	C_UNKNOWN	0	/* must be zero */
79 #define	C_IGNORE	1	/* ignore the message; used for pi */
80 #define	C_SYNC		2	/* synchronization errors */
81 #define	C_DISCARD	3	/* touches dangerous files, so discard */
82 #define	C_NONSPEC	4	/* not specific to any file */
83 #define	C_THISFILE	5	/* specific to this file, but at no line */
84 #define	C_NULLED	6	/* refers to special func; so null */
85 #define	C_TRUE		7	/* fits into true error format */
86 #define	C_DUPL		8	/* sub class only; duplicated error message */
87 #define	C_LAST	9		/* last error category */
88 
89 #define	SORTABLE(x)	(!(NOTSORTABLE(x)))
90 #define	NOTSORTABLE(x)	(x <= C_NONSPEC)
91 /*
92  *	Resources to count and print out the error categories
93  */
94 extern	char		*class_table[];
95 extern	int		class_count[];
96 
97 #define	nunknown	class_count[C_UNKNOWN]
98 #define	nignore		class_count[C_IGNORE]
99 #define	nsyncerrors	class_count[C_SYNC]
100 #define	ndiscard	class_count[C_DISCARD]
101 #define	nnonspec	class_count[C_NONSPEC]
102 #define	nthisfile	class_count[C_THISFILE]
103 #define	nnulled		class_count[C_NULLED]
104 #define	ntrue		class_count[C_TRUE]
105 #define	ndupl		class_count[C_DUPL]
106 
107 /* places to put the error complaints */
108 
109 #define	TOTHEFILE	1	/* touch the file */
110 #define	TOSTDOUT	2	/* just print them out (ho-hum) */
111 
112 extern FILE	*errorfile;	/* where error file comes from */
113 extern FILE	*queryfile;	/* where the query responses from the user come from*/
114 
115 extern	char	*processname;
116 extern	char	*scriptname;
117 
118 extern	boolean	query;
119 extern	boolean	terse;
120 int	inquire(char *, ...);	/* inquire for yes/no */
121 /*
122  *	codes for inquire() to return
123  */
124 #define	Q_NO	1			/* 'N' */
125 #define	Q_no	2			/* 'n' */
126 #define	Q_YES	3			/* 'Y' */
127 #define	Q_yes	4			/* 'y' */
128 
129 int	probethisfile(char *);
130 /*
131  *	codes for probethisfile to return
132  */
133 #define	F_NOTEXIST	1
134 #define	F_NOTREAD	2
135 #define	F_NOTWRITE	3
136 #define	F_TOUCHIT	4
137 
138 /*
139  *	Describes attributes about a language
140  */
141 struct lang_desc{
142 	char	*lang_name;
143 	char	*lang_incomment;	/* one of the following defines */
144 	char	*lang_outcomment;	/* one of the following defines */
145 };
146 extern struct lang_desc lang_table[];
147 
148 #define	CINCOMMENT	"/*###"
149 #define	COUTCOMMENT	"%%%*/\n"
150 #define	FINCOMMENT	"C###"
151 #define	FOUTCOMMENT	"%%%\n"
152 #define	NEWLINE		"%%%\n"
153 #define	PIINCOMMENT	"(*###"
154 #define	PIOUTCOMMENT	"%%%*)\n"
155 #define	LISPINCOMMENT	";###"
156 #define	ASINCOMMENT	"####"
157 #define	RIINCOMMENT	CINCOMMENT
158 #define	RIOUTCOMMENT	COUTCOMMENT
159 #define	TROFFINCOMMENT	".\\\"###"
160 #define	TROFFOUTCOMMENT	NEWLINE
161 #define	MOD2INCOMMENT	"(*###"
162 #define	MOD2OUTCOMMENT	"%%%*)\n"
163 /*
164  *	Defines and resources for determing if a given line
165  *	is to be discarded because it refers to a file not to
166  *	be touched, or if the function reference is to a
167  *	function the user doesn't want recorded.
168  */
169 
170 #define	ERRORNAME	"/.errorrc"
171 extern int	nignored;
172 extern char	**names_ignored;
173 /*
174  *	Structure definition for a full error
175  */
176 typedef struct edesc	Edesc;
177 typedef	Edesc	*Eptr;
178 
179 struct edesc{
180 	Eptr	error_next;		/*linked together*/
181 	int	error_lgtext;		/* how many on the right hand side*/
182 	char	**error_text;		/* the right hand side proper*/
183 	Errorclass	error_e_class;	/* error category of this error*/
184 	Errorclass	error_s_class;	/* sub descriptor of error_e_class*/
185 	int	error_language;		/* the language for this error*/
186 	int	error_position;		/* oridinal position */
187 	int	error_line;		/* discovered line number*/
188 	int	error_no;		/* sequence number on input */
189 };
190 /*
191  *	Resources for the true errors
192  */
193 extern	int	nerrors;
194 extern	Eptr	er_head;
195 extern	Eptr	*errors;
196 /*
197  *	Resources for each of the files mentioned
198  */
199 extern	int	nfiles;
200 extern	Eptr	**files;	/* array of pointers into errors*/
201 extern  boolean	*touchedfiles;			/* which files we touched */
202 
203 /*
204  *	The language the compilation is in, as intuited from
205  *	the flavor of error messages analyzed.
206  */
207 extern	int	language;
208 extern	char	*currentfilename;
209 
210 /*
211  *	Functional forwards
212  */
213 void	arrayify(int *, Eptr **, Eptr);
214 char   *Calloc(int, int);
215 void	clob_last(char *,  char);
216 int	countfiles(Eptr *);
217 Errorclass discardit(Eptr);
218 void	diverterrors(char *, int, Eptr **, int, boolean,  int);
219 void	eaterrors(int *, Eptr **);
220 boolean	edit(char *);
221 void	erroradd(int, char **, Errorclass, Errorclass);
222 void	errorprint(FILE *, Eptr, boolean);
223 void	execvarg(int, int *, char ***);
224 void	filenames(int, Eptr **);
225 void	findfiles(int, Eptr *, int *, Eptr ***);
226 char	firstchar(char *);
227 void	getignored(char *);
228 void	hackfile(char *, Eptr **, int, int);
229 void	insert(int);
230 char	lastchar(char *);
231 int	mustoverwrite(FILE *, FILE *);
232 int	mustwrite(char *, int, FILE *);
233 char	next_lastchar(char *);
234 int	nopertain(Eptr **);
235 int	oktotouch(char *);
236 void	onintr(int);
237 boolean	persperdexplode(char *, char **, char **);
238 int	position(char *, char);
239 boolean	preview(char *,  int, Eptr **, int);
240 void	printerrors(boolean, int, Eptr []);
241 char   *plural(int);
242 boolean	qpersperdexplode(char *, char **, char **);
243 int	settotouch(char *);
244 char   *strsave(char *);
245 char   *substitute(char *, char, char);
246 void	text(Eptr, boolean);
247 boolean	touchfiles(int, Eptr **, int *, char ***);
248 char   *verbform(int);
249 void	wordvbuild(char *, int*, char ***);
250 int	wordvcmp(char **, int, char **);
251 void	wordvprint(FILE *, int, char **);
252 char  **wordvsplice(int, int, char **);
253 boolean	writetouched(int);
254