10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*1717Swesolows * Common Development and Distribution License (the "License").
6*1717Swesolows * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*1717Swesolows
220Sstevel@tonic-gate /*
23*1717Swesolows * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate *
260Sstevel@tonic-gate * eftinfo.c -- main routine for eftinfo command
270Sstevel@tonic-gate *
280Sstevel@tonic-gate * argument processing and the general flow through all the other
290Sstevel@tonic-gate * modules is driven by this file.
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
330Sstevel@tonic-gate
340Sstevel@tonic-gate #include <stdio.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #ifdef sun
370Sstevel@tonic-gate #include <stdlib.h>
380Sstevel@tonic-gate #else
390Sstevel@tonic-gate #include <getopt.h>
400Sstevel@tonic-gate #endif /* sun */
410Sstevel@tonic-gate #include "out.h"
420Sstevel@tonic-gate #include "alloc.h"
430Sstevel@tonic-gate #include "stats.h"
440Sstevel@tonic-gate #include "stable.h"
450Sstevel@tonic-gate #include "literals.h"
460Sstevel@tonic-gate #include "lut.h"
470Sstevel@tonic-gate #include "esclex.h"
480Sstevel@tonic-gate #include "ptree.h"
490Sstevel@tonic-gate #include "tree.h"
500Sstevel@tonic-gate #include "check.h"
510Sstevel@tonic-gate #include "version.h"
520Sstevel@tonic-gate #include "eftread.h"
530Sstevel@tonic-gate
540Sstevel@tonic-gate /* stuff exported by yacc-generated parsers */
550Sstevel@tonic-gate extern void yyparse(void);
560Sstevel@tonic-gate extern int yydebug;
570Sstevel@tonic-gate
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate * This external definition has to be here. If we put it in literals.h
600Sstevel@tonic-gate * lint complains about the declaration not being used within the block
610Sstevel@tonic-gate * when compiling literals.c.
620Sstevel@tonic-gate */
630Sstevel@tonic-gate extern void literals_init(void);
640Sstevel@tonic-gate
650Sstevel@tonic-gate static const char *Usage = "[-DEPghpqvw] eft-files...";
660Sstevel@tonic-gate static const char *Help =
670Sstevel@tonic-gate "\t-D Print dictionaries EFT references.\n"
680Sstevel@tonic-gate "\t-E Print ereports EFT will consume.\n"
690Sstevel@tonic-gate "\t-P Print problems EFT can diagnose.\n"
700Sstevel@tonic-gate "\t-g Print generated iterators (use with -p)\n"
710Sstevel@tonic-gate "\t-h Print this help message\n"
720Sstevel@tonic-gate "\t-p Print complete propagation tree\n"
730Sstevel@tonic-gate "\t-q Quiet mode, no header info printed\n"
740Sstevel@tonic-gate "\t-v Enable verbose output\n"
750Sstevel@tonic-gate "\t-w Enable language warnings";
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * and some undocumented extras...
780Sstevel@tonic-gate * "\t-S Print stats for compiler memory usage, etc.\n"
790Sstevel@tonic-gate * "\t-Y Enable parser debug output\n"
800Sstevel@tonic-gate * "\t-d Enable general debug output\n"
810Sstevel@tonic-gate * "\t-y Enable lexer debug output\n"
820Sstevel@tonic-gate *
830Sstevel@tonic-gate */
840Sstevel@tonic-gate
850Sstevel@tonic-gate int Debug;
860Sstevel@tonic-gate int Verbose;
870Sstevel@tonic-gate int Warn;
880Sstevel@tonic-gate
890Sstevel@tonic-gate extern int Pchildgen; /* flag to ptree for printing generated interators */
900Sstevel@tonic-gate
910Sstevel@tonic-gate extern struct lut *Dicts;
920Sstevel@tonic-gate
930Sstevel@tonic-gate /*ARGSUSED*/
940Sstevel@tonic-gate static void
dictprint(const char * s,void * rhs,void * arg)950Sstevel@tonic-gate dictprint(const char *s, void *rhs, void *arg)
960Sstevel@tonic-gate {
970Sstevel@tonic-gate static char *sep = "";
980Sstevel@tonic-gate
990Sstevel@tonic-gate out(O_OK|O_NONL, "%s%s", sep, s);
1000Sstevel@tonic-gate sep = ":";
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate
103*1717Swesolows int
main(int argc,char * argv[])1040Sstevel@tonic-gate main(int argc, char *argv[])
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate int c;
1070Sstevel@tonic-gate int count;
1080Sstevel@tonic-gate int Dflag = 0;
1090Sstevel@tonic-gate int Eflag = 0;
1100Sstevel@tonic-gate int yflag = 0;
1110Sstevel@tonic-gate int Pflag = 0;
1120Sstevel@tonic-gate int Sflag = 0;
1130Sstevel@tonic-gate int pflag = 0;
1140Sstevel@tonic-gate int qflag = 0;
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate alloc_init();
1170Sstevel@tonic-gate out_init(argv[0]);
1180Sstevel@tonic-gate stats_init(1); /* extended stats always enabled for eftinfo */
1190Sstevel@tonic-gate stable_init(0);
1200Sstevel@tonic-gate literals_init();
1210Sstevel@tonic-gate lut_init();
1220Sstevel@tonic-gate tree_init();
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate while ((c = getopt(argc, argv, "DEPSYdghpqvwy")) != EOF) {
1250Sstevel@tonic-gate switch (c) {
1260Sstevel@tonic-gate case 'D':
1270Sstevel@tonic-gate Dflag++;
1280Sstevel@tonic-gate break;
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate case 'E':
1310Sstevel@tonic-gate Eflag++;
1320Sstevel@tonic-gate break;
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate case 'y':
1350Sstevel@tonic-gate yflag++;
1360Sstevel@tonic-gate break;
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate case 'P':
1390Sstevel@tonic-gate Pflag++;
1400Sstevel@tonic-gate break;
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate case 'S':
1430Sstevel@tonic-gate Sflag++;
1440Sstevel@tonic-gate break;
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate case 'Y':
1470Sstevel@tonic-gate yydebug++;
1480Sstevel@tonic-gate break;
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate case 'd':
1510Sstevel@tonic-gate Debug++;
1520Sstevel@tonic-gate break;
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate case 'g':
1550Sstevel@tonic-gate Pchildgen++;
1560Sstevel@tonic-gate break;
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate case 'h':
1590Sstevel@tonic-gate case '?':
1600Sstevel@tonic-gate out(O_PROG, "version %d.%d",
1610Sstevel@tonic-gate VERSION_MAJOR, VERSION_MINOR);
1620Sstevel@tonic-gate out(O_DIE|O_USAGE, "%s\n%s", Usage, Help);
1630Sstevel@tonic-gate /*NOTREACHED*/
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate case 'p':
1660Sstevel@tonic-gate pflag++;
1670Sstevel@tonic-gate break;
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate case 'q':
1700Sstevel@tonic-gate qflag++;
1710Sstevel@tonic-gate break;
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate case 'v':
1740Sstevel@tonic-gate Verbose++;
1750Sstevel@tonic-gate break;
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate case 'w':
1780Sstevel@tonic-gate Warn++;
1790Sstevel@tonic-gate break;
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate default:
1820Sstevel@tonic-gate out(O_DIE|O_USAGE, Usage);
1830Sstevel@tonic-gate /*NOTREACHED*/
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate out(O_PROG|O_VERB, "version %d.%d",
1880Sstevel@tonic-gate VERSION_MAJOR, VERSION_MINOR);
1890Sstevel@tonic-gate argc -= optind;
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate if (argc < 1)
1920Sstevel@tonic-gate out(O_DIE|O_USAGE, Usage);
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate if (!qflag)
1950Sstevel@tonic-gate eftread_showheader(1);
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate lex_init(&argv[optind], NULL, yflag);
1980Sstevel@tonic-gate check_init();
1990Sstevel@tonic-gate yyparse();
2000Sstevel@tonic-gate (void) lex_fini();
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate tree_report();
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate if (count = out_errcount())
2050Sstevel@tonic-gate out(O_DIE, "%d error%s encountered, exiting.", OUTS(count));
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate if (Dflag) {
2080Sstevel@tonic-gate out(O_OK|O_NONL, "Dictionaries: ");
2090Sstevel@tonic-gate lut_walk(Dicts, (lut_cb)dictprint, (void *)0);
2100Sstevel@tonic-gate out(O_OK, NULL);
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate if (Eflag)
2140Sstevel@tonic-gate ptree_ereport(O_OK, NULL);
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate if (Pflag) {
2170Sstevel@tonic-gate ptree_fault(O_OK, NULL);
2180Sstevel@tonic-gate ptree_upset(O_OK, NULL);
2190Sstevel@tonic-gate ptree_defect(O_OK, NULL);
2200Sstevel@tonic-gate }
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate if (pflag)
2230Sstevel@tonic-gate ptree_name_iter(O_OK, tree_root(NULL));
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate if (Sflag) {
2260Sstevel@tonic-gate out(O_OK, "Stats:");
2270Sstevel@tonic-gate stats_publish();
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate out_exit(0);
2310Sstevel@tonic-gate /*NOTREACHED*/
232*1717Swesolows return (0);
2330Sstevel@tonic-gate }
234