xref: /illumos-gate/usr/src/cmd/sgs/error/common/error.h (revision 8a2b682e57a046b828f37bcde1776f131ef4629f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _ERROR_H
28 #define	_ERROR_H
29 
30 #ifdef  __cplusplus
31 extern "C" {
32 #endif
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 #define	INSUNF77 20
66 
67 extern	int	language;
68 
69 extern  boolean notouch;
70 
71 /*
72  *	We analyze each line in the error message file, and
73  *	attempt to categorize it by type, as well as language.
74  *	Here are the type descriptors.
75  */
76 typedef	int	Errorclass;
77 
78 #define	C_FIRST	0		/* first error category */
79 #define	C_UNKNOWN	0	/* must be zero */
80 #define	C_IGNORE	1	/* ignore the message; used for pi */
81 #define	C_SYNC		2	/* synchronization errors */
82 #define	C_DISCARD	3	/* touches dangerous files, so discard */
83 #define	C_NONSPEC	4	/* not specific to any file */
84 #define	C_THISFILE	5	/* specific to this file, but at no line */
85 #define	C_NULLED	6	/* refers to special func; so null */
86 #define	C_TRUE		7	/* fits into true error format */
87 #define	C_DUPL		8	/* sub class only; duplicated error message */
88 #define	C_LAST	9		/* last error category */
89 
90 #define	SORTABLE(x)	(!(NOTSORTABLE(x)))
91 #define	NOTSORTABLE(x)	(x <= C_NONSPEC)
92 /*
93  *	Resources to count and print out the error categories
94  */
95 extern	char		*class_table[];
96 extern	int		class_count[];
97 
98 #define	nunknown	class_count[C_UNKNOWN]
99 #define	nignore		class_count[C_IGNORE]
100 #define	nsyncerrors	class_count[C_SYNC]
101 #define	ndiscard	class_count[C_DISCARD]
102 #define	nnonspec	class_count[C_NONSPEC]
103 #define	nthisfile	class_count[C_THISFILE]
104 #define	nnulled		class_count[C_NULLED]
105 #define	ntrue		class_count[C_TRUE]
106 #define	ndupl		class_count[C_DUPL]
107 
108 /* places to put the error complaints */
109 
110 #define	TOTHEFILE	1	/* touch the file */
111 #define	TOSTDOUT	2	/* just print them out (ho-hum) */
112 
113 FILE	*errorfile;	/* where error file comes from */
114 FILE	*queryfile;	/* where the query responses from the user come from */
115 
116 extern	char	*currentfilename;
117 extern	char	*processname;
118 extern	char	*scriptname;
119 
120 extern	boolean	query;
121 extern	boolean	terse;
122 int	inquire(char *format, ...);			/* inquire for yes/no */
123 /*
124  *	codes for inquire() to return
125  */
126 #define	Q_NO	1			/* 'N' */
127 #define	Q_no	2			/* 'n' */
128 #define	Q_YES	3			/* 'Y' */
129 #define	Q_yes	4			/* 'y' */
130 
131 int	probethisfile(char *name);
132 /*
133  *	codes for probethisfile to return
134  */
135 #define	F_NOTEXIST	1
136 #define	F_NOTREAD	2
137 #define	F_NOTWRITE	3
138 #define	F_TOUCHIT	4
139 
140 /*
141  *	Describes attributes about a language
142  */
143 struct lang_desc {
144 	char	*lang_name;
145 	char	*lang_incomment;	/* one of the following defines */
146 	char	*lang_outcomment;	/* one of the following defines */
147 };
148 extern struct lang_desc lang_table[];
149 
150 #define	CINCOMMENT	"/*###"
151 #define	COUTCOMMENT	"%%%*/\n"
152 #define	FINCOMMENT	"C###"
153 #define	FOUTCOMMENT	"%%%\n"
154 #define	NEWLINE		"%%%\n"
155 #define	PIINCOMMENT	"(*###"
156 #define	PIOUTCOMMENT	"%%%*)\n"
157 #define	LISPINCOMMENT	";###"
158 #define	ASINCOMMENT	"####"
159 #define	RIINCOMMENT	CINCOMMENT
160 #define	RIOUTCOMMENT	COUTCOMMENT
161 #define	TROFFINCOMMENT	".\\\"###"
162 #define	TROFFOUTCOMMENT	NEWLINE
163 #define	MOD2INCOMMENT	"(*###"
164 #define	MOD2OUTCOMMENT	"%%%*)\n"
165 /*
166  *	Defines and resources for determing if a given line
167  *	is to be discarded because it refers to a file not to
168  *	be touched, or if the function reference is to a
169  *	function the user doesn't want recorded.
170  */
171 #define	IG_FILE1	"llib-port"
172 #define	IG_FILE2	"/usr/lib/llib-port"
173 
174 #define	ERRORNAME	"/.errorrc"
175 int	nignored;
176 char	**names_ignored;
177 /*
178  *	Structure definition for a full error
179  */
180 typedef struct edesc	Edesc;
181 typedef	Edesc	*Eptr;
182 
183 struct edesc {
184 	Eptr	error_next;		/* linked together */
185 	int	error_lgtext;		/* how many on the right hand side */
186 	char	**error_text;		/* the right hand side proper */
187 	Errorclass	error_e_class;	/* error category of this error */
188 	Errorclass	error_s_class;	/* sub descriptor of error_e_class */
189 	int	error_language;		/* the language for this error */
190 	int	error_position;		/* oridinal position */
191 	int	error_line;		/* discovered line number */
192 	int	error_no;		/* sequence number on input */
193 };
194 /*
195  *	Resources for the true errors
196  */
197 extern	int	nerrors;
198 extern	Eptr	er_head;
199 extern	Eptr	*errors;
200 /*
201  *	Resources for each of the files mentioned
202  */
203 extern	int	nfiles;
204 extern	Eptr	**files;	/* array of pointers into errors */
205 boolean	*touchedfiles;			/* which files we touched */
206 /*
207  *	The langauge the compilation is in, as intuited from
208  *	the flavor of error messages analyzed.
209  */
210 extern	int	langauge;
211 extern	char	*currentfilename;
212 /*
213  *	Functional forwards
214  */
215 void	*Calloc(int nelements, int size);
216 char	*strsave(char *instring);
217 char	lastchar(char *string);
218 char	firstchar(char *string);
219 char	next_lastchar(char *string);
220 char	**wordvsplice(int emptyhead, int wordc, char **wordv);
221 int	wordvcmp(char **wordv1, int wordc, char **wordv2);
222 boolean	persperdexplode(char *string, char **r_perd, char **r_pers);
223 /*
224  *	Printing hacks
225  */
226 char	*plural(int n);
227 char	*verbform(int n);
228 
229 void erroradd(int errorlength, char **errorv, Errorclass errorclass,
230     Errorclass errorsubclass);
231 void eaterrors(int *r_errorc, Eptr **r_errorv);
232 void wordvbuild(char *string, int *r_wordc, char ***r_wordv);
233 void wordvprint(FILE *fyle, int wordc, char *wordv[]);
234 void printerrors(boolean look_at_subclass, int errorc, Eptr errorv[]);
235 void clob_last(char *string, char newstuff);
236 void arrayify(int *e_length, Eptr **e_array, Eptr header);
237 void getignored(char *auxname);
238 void filenames(int nfiles, Eptr **files);
239 void findfiles(int nerrors, Eptr *errors, int *r_nfiles, Eptr ***r_files);
240 void onintr(int sig);
241 boolean touchfiles(int nfiles, Eptr **files, int *r_edargc, char ***r_edargv);
242 Errorclass discardit(Eptr errorp);
243 char *substitute(char *string, char chold, char chnew);
244 int position(char *string, char ch);
245 
246 #ifdef  __cplusplus
247 }
248 #endif
249 
250 #endif /* _ERROR_H */
251