xref: /titanic_44/usr/src/cmd/fm/eversholt/eftinfo/common/eftinfo.c (revision 5151fb1220e0ceafdc172203863c73da4285c170)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * eftinfo.c -- main routine for eftinfo command
27  *
28  * argument processing and the general flow through all the other
29  * modules is driven by this file.
30  */
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include <stdio.h>
35 #include <string.h>
36 #ifdef sun
37 #include <stdlib.h>
38 #else
39 #include <getopt.h>
40 #endif /* sun */
41 #include "out.h"
42 #include "alloc.h"
43 #include "stats.h"
44 #include "stable.h"
45 #include "literals.h"
46 #include "lut.h"
47 #include "esclex.h"
48 #include "ptree.h"
49 #include "tree.h"
50 #include "check.h"
51 #include "version.h"
52 #include "eftread.h"
53 
54 /* stuff exported by yacc-generated parsers */
55 extern void yyparse(void);
56 extern int yydebug;
57 
58 /*
59  * This external definition has to be here.  If we put it in literals.h
60  * lint complains about the declaration not being used within the block
61  * when compiling literals.c.
62  */
63 extern void literals_init(void);
64 
65 static const char *Usage = "[-DEPghpqvw] eft-files...";
66 static const char *Help =
67 "\t-D            Print dictionaries EFT references.\n"
68 "\t-E            Print ereports EFT will consume.\n"
69 "\t-P            Print problems EFT can diagnose.\n"
70 "\t-g            Print generated iterators (use with -p)\n"
71 "\t-h            Print this help message\n"
72 "\t-p            Print complete propagation tree\n"
73 "\t-q            Quiet mode, no header info printed\n"
74 "\t-v            Enable verbose output\n"
75 "\t-w            Enable language warnings";
76 /*
77  * and some undocumented extras...
78  *	"\t-S            Print stats for compiler memory usage, etc.\n"
79  *	"\t-Y            Enable parser debug output\n"
80  *	"\t-d            Enable general debug output\n"
81  *	"\t-y            Enable lexer debug output\n"
82  *
83  */
84 
85 int Debug;
86 int Verbose;
87 int Warn;
88 
89 extern int Pchildgen;	/* flag to ptree for printing generated interators */
90 
91 extern struct lut *Dicts;
92 
93 /*ARGSUSED*/
94 static void
95 dictprint(const char *s, void *rhs, void *arg)
96 {
97 	static char *sep = "";
98 
99 	out(O_OK|O_NONL, "%s%s", sep, s);
100 	sep = ":";
101 }
102 
103 int
104 main(int argc, char *argv[])
105 {
106 	int c;
107 	int count;
108 	int Dflag = 0;
109 	int Eflag = 0;
110 	int yflag = 0;
111 	int Pflag = 0;
112 	int Sflag = 0;
113 	int pflag = 0;
114 	int qflag = 0;
115 
116 	alloc_init();
117 	out_init(argv[0]);
118 	stats_init(1);		/* extended stats always enabled for eftinfo */
119 	stable_init(0);
120 	literals_init();
121 	lut_init();
122 	tree_init();
123 
124 	while ((c = getopt(argc, argv, "DEPSYdghpqvwy")) != EOF) {
125 		switch (c) {
126 		case 'D':
127 			Dflag++;
128 			break;
129 
130 		case 'E':
131 			Eflag++;
132 			break;
133 
134 		case 'y':
135 			yflag++;
136 			break;
137 
138 		case 'P':
139 			Pflag++;
140 			break;
141 
142 		case 'S':
143 			Sflag++;
144 			break;
145 
146 		case 'Y':
147 			yydebug++;
148 			break;
149 
150 		case 'd':
151 			Debug++;
152 			break;
153 
154 		case 'g':
155 			Pchildgen++;
156 			break;
157 
158 		case 'h':
159 		case '?':
160 			out(O_PROG, "version %d.%d",
161 			    VERSION_MAJOR, VERSION_MINOR);
162 			out(O_DIE|O_USAGE, "%s\n%s", Usage, Help);
163 			/*NOTREACHED*/
164 
165 		case 'p':
166 			pflag++;
167 			break;
168 
169 		case 'q':
170 			qflag++;
171 			break;
172 
173 		case 'v':
174 			Verbose++;
175 			break;
176 
177 		case 'w':
178 			Warn++;
179 			break;
180 
181 		default:
182 			out(O_DIE|O_USAGE, Usage);
183 			/*NOTREACHED*/
184 		}
185 	}
186 
187 	out(O_PROG|O_VERB, "version %d.%d",
188 	    VERSION_MAJOR, VERSION_MINOR);
189 	argc -= optind;
190 
191 	if (argc < 1)
192 		out(O_DIE|O_USAGE, Usage);
193 
194 	if (!qflag)
195 		eftread_showheader(1);
196 
197 	lex_init(&argv[optind], NULL, yflag);
198 	check_init();
199 	yyparse();
200 	(void) lex_fini();
201 
202 	tree_report();
203 
204 	if (count = out_errcount())
205 		out(O_DIE, "%d error%s encountered, exiting.", OUTS(count));
206 
207 	if (Dflag) {
208 		out(O_OK|O_NONL, "Dictionaries: ");
209 		lut_walk(Dicts, (lut_cb)dictprint, (void *)0);
210 		out(O_OK, NULL);
211 	}
212 
213 	if (Eflag)
214 		ptree_ereport(O_OK, NULL);
215 
216 	if (Pflag) {
217 		ptree_fault(O_OK, NULL);
218 		ptree_upset(O_OK, NULL);
219 		ptree_defect(O_OK, NULL);
220 	}
221 
222 	if (pflag)
223 		ptree_name_iter(O_OK, tree_root(NULL));
224 
225 	if (Sflag) {
226 		out(O_OK, "Stats:");
227 		stats_publish();
228 	}
229 
230 	out_exit(0);
231 	/*NOTREACHED*/
232 	return (0);
233 }
234