8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / fm / eversholt / eftinfo / common / eftinfo.c
blob68332725d6b34827ee3d0b545f10a4152cc6144b
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * eftinfo.c -- main routine for eftinfo command
28 * argument processing and the general flow through all the other
29 * modules is driven by this file.
32 #pragma ident "%Z%%M% %I% %E% SMI"
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"
54 /* stuff exported by yacc-generated parsers */
55 extern void yyparse(void);
56 extern int yydebug;
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.
63 extern void literals_init(void);
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";
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"
85 int Debug;
86 int Verbose;
87 int Warn;
89 extern int Pchildgen; /* flag to ptree for printing generated interators */
91 extern struct lut *Dicts;
93 /*ARGSUSED*/
94 static void
95 dictprint(const char *s, void *rhs, void *arg)
97 static char *sep = "";
99 out(O_OK|O_NONL, "%s%s", sep, s);
100 sep = ":";
104 main(int argc, char *argv[])
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;
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();
124 while ((c = getopt(argc, argv, "DEPSYdghpqvwy")) != EOF) {
125 switch (c) {
126 case 'D':
127 Dflag++;
128 break;
130 case 'E':
131 Eflag++;
132 break;
134 case 'y':
135 yflag++;
136 break;
138 case 'P':
139 Pflag++;
140 break;
142 case 'S':
143 Sflag++;
144 break;
146 case 'Y':
147 yydebug++;
148 break;
150 case 'd':
151 Debug++;
152 break;
154 case 'g':
155 Pchildgen++;
156 break;
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*/
165 case 'p':
166 pflag++;
167 break;
169 case 'q':
170 qflag++;
171 break;
173 case 'v':
174 Verbose++;
175 break;
177 case 'w':
178 Warn++;
179 break;
181 default:
182 out(O_DIE|O_USAGE, Usage);
183 /*NOTREACHED*/
187 out(O_PROG|O_VERB, "version %d.%d",
188 VERSION_MAJOR, VERSION_MINOR);
189 argc -= optind;
191 if (argc < 1)
192 out(O_DIE|O_USAGE, Usage);
194 if (!qflag)
195 eftread_showheader(1);
197 lex_init(&argv[optind], NULL, yflag);
198 check_init();
199 yyparse();
200 (void) lex_fini();
202 tree_report();
204 if (count = out_errcount())
205 out(O_DIE, "%d error%s encountered, exiting.", OUTS(count));
207 if (Dflag) {
208 out(O_OK|O_NONL, "Dictionaries: ");
209 lut_walk(Dicts, (lut_cb)dictprint, (void *)0);
210 out(O_OK, NULL);
213 if (Eflag)
214 ptree_ereport(O_OK, NULL);
216 if (Pflag) {
217 ptree_fault(O_OK, NULL);
218 ptree_upset(O_OK, NULL);
219 ptree_defect(O_OK, NULL);
222 if (pflag)
223 ptree_name_iter(O_OK, tree_root(NULL));
225 if (Sflag) {
226 out(O_OK, "Stats:");
227 stats_publish();
230 out_exit(0);
231 /*NOTREACHED*/
232 return (0);