xref: /titanic_52/usr/src/cmd/sgs/error/common/error.h (revision 9fb1159054bb89619213a7b2be87ea3bca25fcce)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef  __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef	int	boolean;
37 
38 #define	TRUE	1
39 #define	FALSE	0
40 
41 #define	true	1
42 #define	false	0
43 /*
44  *	Descriptors for the various languages we know about.
45  *	If you touch these, also touch lang_table
46  */
47 #define	INUNKNOWN	0
48 #define	INCPP	1
49 #define	INCC	2
50 #define	INAS	3
51 #define	INLD	4
52 #define	INLINT	5
53 #define	INF77	6
54 #define	INPI	7
55 #define	INPC	8
56 #define	INFRANZ	9
57 #define	INLISP	10
58 #define	INVAXIMA	11
59 #define	INRATFOR	12
60 #define	INLEX	13
61 #define	INYACC	14
62 #define	INAPL	15
63 #define	INMAKE	16
64 #define	INRI	17
65 #define	INTROFF	18
66 #define	INMOD2	19
67 #define	INSUNF77 20
68 
69 extern	int	language;
70 
71 extern  boolean notouch;
72 
73 /*
74  *	We analyze each line in the error message file, and
75  *	attempt to categorize it by type, as well as language.
76  *	Here are the type descriptors.
77  */
78 typedef	int	Errorclass;
79 
80 #define	C_FIRST	0		/* first error category */
81 #define	C_UNKNOWN	0	/* must be zero */
82 #define	C_IGNORE	1	/* ignore the message; used for pi */
83 #define	C_SYNC		2	/* synchronization errors */
84 #define	C_DISCARD	3	/* touches dangerous files, so discard */
85 #define	C_NONSPEC	4	/* not specific to any file */
86 #define	C_THISFILE	5	/* specific to this file, but at no line */
87 #define	C_NULLED	6	/* refers to special func; so null */
88 #define	C_TRUE		7	/* fits into true error format */
89 #define	C_DUPL		8	/* sub class only; duplicated error message */
90 #define	C_LAST	9		/* last error category */
91 
92 #define	SORTABLE(x)	(!(NOTSORTABLE(x)))
93 #define	NOTSORTABLE(x)	(x <= C_NONSPEC)
94 /*
95  *	Resources to count and print out the error categories
96  */
97 extern	char		*class_table[];
98 extern	int		class_count[];
99 
100 #define	nunknown	class_count[C_UNKNOWN]
101 #define	nignore		class_count[C_IGNORE]
102 #define	nsyncerrors	class_count[C_SYNC]
103 #define	ndiscard	class_count[C_DISCARD]
104 #define	nnonspec	class_count[C_NONSPEC]
105 #define	nthisfile	class_count[C_THISFILE]
106 #define	nnulled		class_count[C_NULLED]
107 #define	ntrue		class_count[C_TRUE]
108 #define	ndupl		class_count[C_DUPL]
109 
110 /* places to put the error complaints */
111 
112 #define	TOTHEFILE	1	/* touch the file */
113 #define	TOSTDOUT	2	/* just print them out (ho-hum) */
114 
115 FILE	*errorfile;	/* where error file comes from */
116 FILE	*queryfile;	/* where the query responses from the user come from */
117 
118 extern	char	*currentfilename;
119 extern	char	*processname;
120 extern	char	*scriptname;
121 
122 extern	boolean	query;
123 extern	boolean	terse;
124 int	inquire(char *format, ...);			/* inquire for yes/no */
125 /*
126  *	codes for inquire() to return
127  */
128 #define	Q_NO	1			/* 'N' */
129 #define	Q_no	2			/* 'n' */
130 #define	Q_YES	3			/* 'Y' */
131 #define	Q_yes	4			/* 'y' */
132 
133 int	probethisfile(char *name);
134 /*
135  *	codes for probethisfile to return
136  */
137 #define	F_NOTEXIST	1
138 #define	F_NOTREAD	2
139 #define	F_NOTWRITE	3
140 #define	F_TOUCHIT	4
141 
142 /*
143  *	Describes attributes about a language
144  */
145 struct lang_desc {
146 	char	*lang_name;
147 	char	*lang_incomment;	/* one of the following defines */
148 	char	*lang_outcomment;	/* one of the following defines */
149 };
150 extern struct lang_desc lang_table[];
151 
152 #define	CINCOMMENT	"/*###"
153 #define	COUTCOMMENT	"%%%*/\n"
154 #define	FINCOMMENT	"C###"
155 #define	FOUTCOMMENT	"%%%\n"
156 #define	NEWLINE		"%%%\n"
157 #define	PIINCOMMENT	"(*###"
158 #define	PIOUTCOMMENT	"%%%*)\n"
159 #define	LISPINCOMMENT	";###"
160 #define	ASINCOMMENT	"####"
161 #define	RIINCOMMENT	CINCOMMENT
162 #define	RIOUTCOMMENT	COUTCOMMENT
163 #define	TROFFINCOMMENT	".\\\"###"
164 #define	TROFFOUTCOMMENT	NEWLINE
165 #define	MOD2INCOMMENT	"(*###"
166 #define	MOD2OUTCOMMENT	"%%%*)\n"
167 /*
168  *	Defines and resources for determing if a given line
169  *	is to be discarded because it refers to a file not to
170  *	be touched, or if the function reference is to a
171  *	function the user doesn't want recorded.
172  */
173 #define	IG_FILE1	"llib-lc"
174 #define	IG_FILE2	"llib-port"
175 #define	IG_FILE3	"/usr/lib/llib-lc"
176 #define	IG_FILE4	"/usr/lib/llib-port"
177 
178 #define	ERRORNAME	"/.errorrc"
179 int	nignored;
180 char	**names_ignored;
181 /*
182  *	Structure definition for a full error
183  */
184 typedef struct edesc	Edesc;
185 typedef	Edesc	*Eptr;
186 
187 struct edesc {
188 	Eptr	error_next;		/* linked together */
189 	int	error_lgtext;		/* how many on the right hand side */
190 	char	**error_text;		/* the right hand side proper */
191 	Errorclass	error_e_class;	/* error category of this error */
192 	Errorclass	error_s_class;	/* sub descriptor of error_e_class */
193 	int	error_language;		/* the language for this error */
194 	int	error_position;		/* oridinal position */
195 	int	error_line;		/* discovered line number */
196 	int	error_no;		/* sequence number on input */
197 };
198 /*
199  *	Resources for the true errors
200  */
201 extern	int	nerrors;
202 extern	Eptr	er_head;
203 extern	Eptr	*errors;
204 /*
205  *	Resources for each of the files mentioned
206  */
207 extern	int	nfiles;
208 extern	Eptr	**files;	/* array of pointers into errors */
209 boolean	*touchedfiles;			/* which files we touched */
210 /*
211  *	The langauge the compilation is in, as intuited from
212  *	the flavor of error messages analyzed.
213  */
214 extern	int	langauge;
215 extern	char	*currentfilename;
216 /*
217  *	Functional forwards
218  */
219 void	*Calloc(int nelements, int size);
220 char	*strsave(char *instring);
221 char	lastchar(char *string);
222 char	firstchar(char *string);
223 char	next_lastchar(char *string);
224 char	**wordvsplice(int emptyhead, int wordc, char **wordv);
225 int	wordvcmp(char **wordv1, int wordc, char **wordv2);
226 boolean	persperdexplode(char *string, char **r_perd, char **r_pers);
227 /*
228  *	Printing hacks
229  */
230 char	*plural(int n);
231 char	*verbform(int n);
232 
233 void erroradd(int errorlength, char **errorv, Errorclass errorclass,
234     Errorclass errorsubclass);
235 void eaterrors(int *r_errorc, Eptr **r_errorv);
236 void wordvbuild(char *string, int *r_wordc, char ***r_wordv);
237 void wordvprint(FILE *fyle, int wordc, char *wordv[]);
238 void printerrors(boolean look_at_subclass, int errorc, Eptr errorv[]);
239 void clob_last(char *string, char newstuff);
240 void arrayify(int *e_length, Eptr **e_array, Eptr header);
241 void getignored(char *auxname);
242 void filenames(int nfiles, Eptr **files);
243 void findfiles(int nerrors, Eptr *errors, int *r_nfiles, Eptr ***r_files);
244 void onintr(int sig);
245 boolean touchfiles(int nfiles, Eptr **files, int *r_edargc, char ***r_edargv);
246 Errorclass discardit(Eptr errorp);
247 char *substitute(char *string, char chold, char chnew);
248 int position(char *string, char ch);
249 
250 #ifdef  __cplusplus
251 }
252 #endif
253 
254 #endif /* _ERROR_H */
255