17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
580ab886dSwesolows  * Common Development and Distribution License (the "License").
680ab886dSwesolows  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2180ab886dSwesolows 
227c478bd9Sstevel@tonic-gate /*
2380ab886dSwesolows  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  * eftinfo.c -- main routine for eftinfo command
277c478bd9Sstevel@tonic-gate  *
287c478bd9Sstevel@tonic-gate  * argument processing and the general flow through all the other
297c478bd9Sstevel@tonic-gate  * modules is driven by this file.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <stdio.h>
337c478bd9Sstevel@tonic-gate #include <string.h>
347c478bd9Sstevel@tonic-gate #ifdef sun
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #else
377c478bd9Sstevel@tonic-gate #include <getopt.h>
387c478bd9Sstevel@tonic-gate #endif /* sun */
397c478bd9Sstevel@tonic-gate #include "out.h"
407c478bd9Sstevel@tonic-gate #include "alloc.h"
417c478bd9Sstevel@tonic-gate #include "stats.h"
427c478bd9Sstevel@tonic-gate #include "stable.h"
437c478bd9Sstevel@tonic-gate #include "literals.h"
447c478bd9Sstevel@tonic-gate #include "lut.h"
457c478bd9Sstevel@tonic-gate #include "esclex.h"
467c478bd9Sstevel@tonic-gate #include "ptree.h"
477c478bd9Sstevel@tonic-gate #include "tree.h"
487c478bd9Sstevel@tonic-gate #include "check.h"
497c478bd9Sstevel@tonic-gate #include "version.h"
507c478bd9Sstevel@tonic-gate #include "eftread.h"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /* stuff exported by yacc-generated parsers */
537c478bd9Sstevel@tonic-gate extern void yyparse(void);
547c478bd9Sstevel@tonic-gate extern int yydebug;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * This external definition has to be here.  If we put it in literals.h
587c478bd9Sstevel@tonic-gate  * lint complains about the declaration not being used within the block
597c478bd9Sstevel@tonic-gate  * when compiling literals.c.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate extern void literals_init(void);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static const char *Usage = "[-DEPghpqvw] eft-files...";
647c478bd9Sstevel@tonic-gate static const char *Help =
657c478bd9Sstevel@tonic-gate "\t-D            Print dictionaries EFT references.\n"
667c478bd9Sstevel@tonic-gate "\t-E            Print ereports EFT will consume.\n"
677c478bd9Sstevel@tonic-gate "\t-P            Print problems EFT can diagnose.\n"
687c478bd9Sstevel@tonic-gate "\t-g            Print generated iterators (use with -p)\n"
697c478bd9Sstevel@tonic-gate "\t-h            Print this help message\n"
707c478bd9Sstevel@tonic-gate "\t-p            Print complete propagation tree\n"
717c478bd9Sstevel@tonic-gate "\t-q            Quiet mode, no header info printed\n"
727c478bd9Sstevel@tonic-gate "\t-v            Enable verbose output\n"
737c478bd9Sstevel@tonic-gate "\t-w            Enable language warnings";
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * and some undocumented extras...
767c478bd9Sstevel@tonic-gate  *	"\t-S            Print stats for compiler memory usage, etc.\n"
777c478bd9Sstevel@tonic-gate  *	"\t-Y            Enable parser debug output\n"
787c478bd9Sstevel@tonic-gate  *	"\t-d            Enable general debug output\n"
797c478bd9Sstevel@tonic-gate  *	"\t-y            Enable lexer debug output\n"
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate int Debug;
847c478bd9Sstevel@tonic-gate int Verbose;
857c478bd9Sstevel@tonic-gate int Warn;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate extern int Pchildgen;	/* flag to ptree for printing generated interators */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate extern struct lut *Dicts;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*ARGSUSED*/
927c478bd9Sstevel@tonic-gate static void
dictprint(const char * s,void * rhs,void * arg)937c478bd9Sstevel@tonic-gate dictprint(const char *s, void *rhs, void *arg)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	static char *sep = "";
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	out(O_OK|O_NONL, "%s%s", sep, s);
987c478bd9Sstevel@tonic-gate 	sep = ":";
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate 
10180ab886dSwesolows int
main(int argc,char * argv[])1027c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
1037c478bd9Sstevel@tonic-gate {
1047c478bd9Sstevel@tonic-gate 	int c;
1057c478bd9Sstevel@tonic-gate 	int count;
1067c478bd9Sstevel@tonic-gate 	int Dflag = 0;
1077c478bd9Sstevel@tonic-gate 	int Eflag = 0;
1087c478bd9Sstevel@tonic-gate 	int yflag = 0;
1097c478bd9Sstevel@tonic-gate 	int Pflag = 0;
1107c478bd9Sstevel@tonic-gate 	int Sflag = 0;
1117c478bd9Sstevel@tonic-gate 	int pflag = 0;
1127c478bd9Sstevel@tonic-gate 	int qflag = 0;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	alloc_init();
1157c478bd9Sstevel@tonic-gate 	out_init(argv[0]);
1167c478bd9Sstevel@tonic-gate 	stats_init(1);		/* extended stats always enabled for eftinfo */
1177c478bd9Sstevel@tonic-gate 	stable_init(0);
1187c478bd9Sstevel@tonic-gate 	literals_init();
1197c478bd9Sstevel@tonic-gate 	lut_init();
1207c478bd9Sstevel@tonic-gate 	tree_init();
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "DEPSYdghpqvwy")) != EOF) {
1237c478bd9Sstevel@tonic-gate 		switch (c) {
1247c478bd9Sstevel@tonic-gate 		case 'D':
1257c478bd9Sstevel@tonic-gate 			Dflag++;
1267c478bd9Sstevel@tonic-gate 			break;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 		case 'E':
1297c478bd9Sstevel@tonic-gate 			Eflag++;
1307c478bd9Sstevel@tonic-gate 			break;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 		case 'y':
1337c478bd9Sstevel@tonic-gate 			yflag++;
1347c478bd9Sstevel@tonic-gate 			break;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 		case 'P':
1377c478bd9Sstevel@tonic-gate 			Pflag++;
1387c478bd9Sstevel@tonic-gate 			break;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 		case 'S':
1417c478bd9Sstevel@tonic-gate 			Sflag++;
1427c478bd9Sstevel@tonic-gate 			break;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 		case 'Y':
1457c478bd9Sstevel@tonic-gate 			yydebug++;
1467c478bd9Sstevel@tonic-gate 			break;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 		case 'd':
1497c478bd9Sstevel@tonic-gate 			Debug++;
1507c478bd9Sstevel@tonic-gate 			break;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 		case 'g':
1537c478bd9Sstevel@tonic-gate 			Pchildgen++;
1547c478bd9Sstevel@tonic-gate 			break;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 		case 'h':
1577c478bd9Sstevel@tonic-gate 		case '?':
1587c478bd9Sstevel@tonic-gate 			out(O_PROG, "version %d.%d",
1597c478bd9Sstevel@tonic-gate 			    VERSION_MAJOR, VERSION_MINOR);
1607c478bd9Sstevel@tonic-gate 			out(O_DIE|O_USAGE, "%s\n%s", Usage, Help);
1617c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
162*586c519fSToomas Soome 			break;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 		case 'p':
1657c478bd9Sstevel@tonic-gate 			pflag++;
1667c478bd9Sstevel@tonic-gate 			break;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 		case 'q':
1697c478bd9Sstevel@tonic-gate 			qflag++;
1707c478bd9Sstevel@tonic-gate 			break;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 		case 'v':
1737c478bd9Sstevel@tonic-gate 			Verbose++;
1747c478bd9Sstevel@tonic-gate 			break;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 		case 'w':
1777c478bd9Sstevel@tonic-gate 			Warn++;
1787c478bd9Sstevel@tonic-gate 			break;
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 		default:
1817c478bd9Sstevel@tonic-gate 			out(O_DIE|O_USAGE, Usage);
1827c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
1837c478bd9Sstevel@tonic-gate 		}
1847c478bd9Sstevel@tonic-gate 	}
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	out(O_PROG|O_VERB, "version %d.%d",
1877c478bd9Sstevel@tonic-gate 	    VERSION_MAJOR, VERSION_MINOR);
1887c478bd9Sstevel@tonic-gate 	argc -= optind;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	if (argc < 1)
1917c478bd9Sstevel@tonic-gate 		out(O_DIE|O_USAGE, Usage);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	if (!qflag)
1947c478bd9Sstevel@tonic-gate 		eftread_showheader(1);
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	lex_init(&argv[optind], NULL, yflag);
1977c478bd9Sstevel@tonic-gate 	check_init();
1987c478bd9Sstevel@tonic-gate 	yyparse();
1997c478bd9Sstevel@tonic-gate 	(void) lex_fini();
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	tree_report();
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (count = out_errcount())
2047c478bd9Sstevel@tonic-gate 		out(O_DIE, "%d error%s encountered, exiting.", OUTS(count));
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	if (Dflag) {
2077c478bd9Sstevel@tonic-gate 		out(O_OK|O_NONL, "Dictionaries: ");
2087c478bd9Sstevel@tonic-gate 		lut_walk(Dicts, (lut_cb)dictprint, (void *)0);
2097c478bd9Sstevel@tonic-gate 		out(O_OK, NULL);
2107c478bd9Sstevel@tonic-gate 	}
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	if (Eflag)
2137c478bd9Sstevel@tonic-gate 		ptree_ereport(O_OK, NULL);
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	if (Pflag) {
2167c478bd9Sstevel@tonic-gate 		ptree_fault(O_OK, NULL);
2177c478bd9Sstevel@tonic-gate 		ptree_upset(O_OK, NULL);
2187c478bd9Sstevel@tonic-gate 		ptree_defect(O_OK, NULL);
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	if (pflag)
2227c478bd9Sstevel@tonic-gate 		ptree_name_iter(O_OK, tree_root(NULL));
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	if (Sflag) {
2257c478bd9Sstevel@tonic-gate 		out(O_OK, "Stats:");
2267c478bd9Sstevel@tonic-gate 		stats_publish();
2277c478bd9Sstevel@tonic-gate 	}
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	out_exit(0);
2307c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
23180ab886dSwesolows 	return (0);
2327c478bd9Sstevel@tonic-gate }
233