xref: /netbsd-src/usr.bin/error/error.h (revision b5677b36047b601b9addaaa494a58ceae82c2a6c)
1 /*	$NetBSD: error.h,v 1.10 2007/07/19 05:43:23 lukem 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 typedef	int	boolean;
35 
36 #define	TRUE	1
37 #define	FALSE	0
38 
39 #define	true	1
40 #define	false	0
41 /*
42  *	Descriptors for the various languages we know about.
43  *	If you touch these, also touch lang_table
44  */
45 #define	INUNKNOWN	0
46 #define	INCPP	1
47 #define	INCC	2
48 #define	INAS	3
49 #define	INLD	4
50 #define	INLINT	5
51 #define	INF77	6
52 #define	INPI	7
53 #define	INPC	8
54 #define	INFRANZ	9
55 #define	INLISP	10
56 #define	INVAXIMA	11
57 #define	INRATFOR	12
58 #define	INLEX	13
59 #define	INYACC	14
60 #define	INAPL	15
61 #define	INMAKE	16
62 #define	INRI	17
63 #define	INTROFF	18
64 #define	INMOD2	19
65 
66 /*
67  *	We analyze each line in the error message file, and
68  *	attempt to categorize it by type, as well as language.
69  *	Here are the type descriptors.
70  */
71 typedef	int	Errorclass;
72 
73 #define	C_FIRST	0		/* first error category */
74 #define	C_UNKNOWN	0	/* must be zero */
75 #define	C_IGNORE	1	/* ignore the message; used for pi */
76 #define	C_SYNC		2	/* synchronization errors */
77 #define	C_DISCARD	3	/* touches dangerous files, so discard */
78 #define	C_NONSPEC	4	/* not specific to any file */
79 #define	C_THISFILE	5	/* specific to this file, but at no line */
80 #define	C_NULLED	6	/* refers to special func; so null */
81 #define	C_TRUE		7	/* fits into true error format */
82 #define	C_DUPL		8	/* sub class only; duplicated error message */
83 #define	C_LAST	9		/* last error category */
84 
85 #define	SORTABLE(x)	(!(NOTSORTABLE(x)))
86 #define	NOTSORTABLE(x)	(x <= C_NONSPEC)
87 /*
88  *	Resources to count and print out the error categories
89  */
90 extern	char		*class_table[];
91 extern	int		class_count[];
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	*processname;
112 extern	char	*scriptname;
113 
114 extern	boolean	query;
115 extern	boolean	terse;
116 int	inquire(char *, ...);	/* inquire for yes/no */
117 /*
118  *	codes for inquire() to return
119  */
120 #define	Q_error	-1			/* an error occurred */
121 #define	Q_NO	1			/* 'N' */
122 #define	Q_no	2			/* 'n' */
123 #define	Q_YES	3			/* 'Y' */
124 #define	Q_yes	4			/* 'y' */
125 
126 int	probethisfile(char *);
127 /*
128  *	codes for probethisfile to return
129  */
130 #define	F_NOTEXIST	1
131 #define	F_NOTREAD	2
132 #define	F_NOTWRITE	3
133 #define	F_TOUCHIT	4
134 
135 /*
136  *	Describes attributes about a language
137  */
138 struct lang_desc{
139 	char	*lang_name;
140 	char	*lang_incomment;	/* one of the following defines */
141 	char	*lang_outcomment;	/* one of the following defines */
142 };
143 extern struct lang_desc lang_table[];
144 
145 #define	CINCOMMENT	"/*###"
146 #define	COUTCOMMENT	"%%%*/\n"
147 #define	FINCOMMENT	"C###"
148 #define	FOUTCOMMENT	"%%%\n"
149 #define	NEWLINE		"%%%\n"
150 #define	PIINCOMMENT	"(*###"
151 #define	PIOUTCOMMENT	"%%%*)\n"
152 #define	LISPINCOMMENT	";###"
153 #define	ASINCOMMENT	"####"
154 #define	RIINCOMMENT	CINCOMMENT
155 #define	RIOUTCOMMENT	COUTCOMMENT
156 #define	TROFFINCOMMENT	".\\\"###"
157 #define	TROFFOUTCOMMENT	NEWLINE
158 #define	MOD2INCOMMENT	"(*###"
159 #define	MOD2OUTCOMMENT	"%%%*)\n"
160 /*
161  *	Defines and resources for determing if a given line
162  *	is to be discarded because it refers to a file not to
163  *	be touched, or if the function reference is to a
164  *	function the user doesn't want recorded.
165  */
166 
167 #define	ERRORNAME	"/.errorrc"
168 extern int	nignored;
169 extern char	**names_ignored;
170 /*
171  *	Structure definition for a full error
172  */
173 typedef struct edesc	Edesc;
174 typedef	Edesc	*Eptr;
175 
176 struct edesc{
177 	Eptr	error_next;		/*linked together*/
178 	int	error_lgtext;		/* how many on the right hand side*/
179 	char	**error_text;		/* the right hand side proper*/
180 	Errorclass	error_e_class;	/* error category of this error*/
181 	Errorclass	error_s_class;	/* sub descriptor of error_e_class*/
182 	int	error_language;		/* the language for this error*/
183 	int	error_position;		/* oridinal position */
184 	int	error_line;		/* discovered line number*/
185 	int	error_no;		/* sequence number on input */
186 };
187 /*
188  *	Resources for the true errors
189  */
190 extern	int	nerrors;
191 extern	Eptr	er_head;
192 extern	Eptr	*errors;
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 
207 /*
208  *	Functional forwards
209  */
210 void	arrayify(int *, Eptr **, Eptr);
211 char   *Calloc(int, int);
212 void	clob_last(char *,  char);
213 int	countfiles(Eptr *);
214 Errorclass discardit(Eptr);
215 void	diverterrors(char *, int, Eptr **, int, boolean,  int);
216 void	eaterrors(int *, Eptr **);
217 boolean	edit(char *);
218 void	erroradd(int, char **, Errorclass, Errorclass);
219 void	errorprint(FILE *, Eptr, boolean);
220 void	execvarg(int, int *, char ***);
221 void	filenames(int, Eptr **);
222 void	findfiles(int, Eptr *, int *, Eptr ***);
223 char	firstchar(char *);
224 void	getignored(char *);
225 void	hackfile(char *, Eptr **, int, int);
226 void	insert(int);
227 char	lastchar(char *);
228 int	mustoverwrite(FILE *, FILE *);
229 int	mustwrite(char *, int, FILE *);
230 char	next_lastchar(char *);
231 int	nopertain(Eptr **);
232 int	oktotouch(char *);
233 void	onintr(int);
234 boolean	persperdexplode(char *, char **, char **);
235 int	position(char *, char);
236 boolean	preview(char *,  int, Eptr **, int);
237 void	printerrors(boolean, int, Eptr []);
238 char   *plural(int);
239 boolean	qpersperdexplode(char *, char **, char **);
240 int	settotouch(char *);
241 char   *substitute(char *, char, char);
242 void	text(Eptr, boolean);
243 boolean	touchfiles(int, Eptr **, int *, char ***);
244 char   *verbform(int);
245 void	wordvbuild(char *, int*, char ***);
246 int	wordvcmp(char **, int, char **);
247 void	wordvprint(FILE *, int, char **);
248 char  **wordvsplice(int, int, char **);
249 boolean	writetouched(int);
250