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 5*80ab886dSwesolows * Common Development and Distribution License (the "License"). 6*80ab886dSwesolows * 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 */ 21*80ab886dSwesolows 227c478bd9Sstevel@tonic-gate /* 23*80ab886dSwesolows * 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 #pragma ident "%Z%%M% %I% %E% SMI" 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <stdio.h> 357c478bd9Sstevel@tonic-gate #include <string.h> 367c478bd9Sstevel@tonic-gate #ifdef sun 377c478bd9Sstevel@tonic-gate #include <stdlib.h> 387c478bd9Sstevel@tonic-gate #else 397c478bd9Sstevel@tonic-gate #include <getopt.h> 407c478bd9Sstevel@tonic-gate #endif /* sun */ 417c478bd9Sstevel@tonic-gate #include "out.h" 427c478bd9Sstevel@tonic-gate #include "alloc.h" 437c478bd9Sstevel@tonic-gate #include "stats.h" 447c478bd9Sstevel@tonic-gate #include "stable.h" 457c478bd9Sstevel@tonic-gate #include "literals.h" 467c478bd9Sstevel@tonic-gate #include "lut.h" 477c478bd9Sstevel@tonic-gate #include "esclex.h" 487c478bd9Sstevel@tonic-gate #include "ptree.h" 497c478bd9Sstevel@tonic-gate #include "tree.h" 507c478bd9Sstevel@tonic-gate #include "check.h" 517c478bd9Sstevel@tonic-gate #include "version.h" 527c478bd9Sstevel@tonic-gate #include "eftread.h" 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* stuff exported by yacc-generated parsers */ 557c478bd9Sstevel@tonic-gate extern void yyparse(void); 567c478bd9Sstevel@tonic-gate extern int yydebug; 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * This external definition has to be here. If we put it in literals.h 607c478bd9Sstevel@tonic-gate * lint complains about the declaration not being used within the block 617c478bd9Sstevel@tonic-gate * when compiling literals.c. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate extern void literals_init(void); 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate static const char *Usage = "[-DEPghpqvw] eft-files..."; 667c478bd9Sstevel@tonic-gate static const char *Help = 677c478bd9Sstevel@tonic-gate "\t-D Print dictionaries EFT references.\n" 687c478bd9Sstevel@tonic-gate "\t-E Print ereports EFT will consume.\n" 697c478bd9Sstevel@tonic-gate "\t-P Print problems EFT can diagnose.\n" 707c478bd9Sstevel@tonic-gate "\t-g Print generated iterators (use with -p)\n" 717c478bd9Sstevel@tonic-gate "\t-h Print this help message\n" 727c478bd9Sstevel@tonic-gate "\t-p Print complete propagation tree\n" 737c478bd9Sstevel@tonic-gate "\t-q Quiet mode, no header info printed\n" 747c478bd9Sstevel@tonic-gate "\t-v Enable verbose output\n" 757c478bd9Sstevel@tonic-gate "\t-w Enable language warnings"; 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * and some undocumented extras... 787c478bd9Sstevel@tonic-gate * "\t-S Print stats for compiler memory usage, etc.\n" 797c478bd9Sstevel@tonic-gate * "\t-Y Enable parser debug output\n" 807c478bd9Sstevel@tonic-gate * "\t-d Enable general debug output\n" 817c478bd9Sstevel@tonic-gate * "\t-y Enable lexer debug output\n" 827c478bd9Sstevel@tonic-gate * 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate int Debug; 867c478bd9Sstevel@tonic-gate int Verbose; 877c478bd9Sstevel@tonic-gate int Warn; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate extern int Pchildgen; /* flag to ptree for printing generated interators */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate extern struct lut *Dicts; 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 947c478bd9Sstevel@tonic-gate static void 957c478bd9Sstevel@tonic-gate dictprint(const char *s, void *rhs, void *arg) 967c478bd9Sstevel@tonic-gate { 977c478bd9Sstevel@tonic-gate static char *sep = ""; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate out(O_OK|O_NONL, "%s%s", sep, s); 1007c478bd9Sstevel@tonic-gate sep = ":"; 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate 103*80ab886dSwesolows int 1047c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 1057c478bd9Sstevel@tonic-gate { 1067c478bd9Sstevel@tonic-gate int c; 1077c478bd9Sstevel@tonic-gate int count; 1087c478bd9Sstevel@tonic-gate int Dflag = 0; 1097c478bd9Sstevel@tonic-gate int Eflag = 0; 1107c478bd9Sstevel@tonic-gate int yflag = 0; 1117c478bd9Sstevel@tonic-gate int Pflag = 0; 1127c478bd9Sstevel@tonic-gate int Sflag = 0; 1137c478bd9Sstevel@tonic-gate int pflag = 0; 1147c478bd9Sstevel@tonic-gate int qflag = 0; 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate alloc_init(); 1177c478bd9Sstevel@tonic-gate out_init(argv[0]); 1187c478bd9Sstevel@tonic-gate stats_init(1); /* extended stats always enabled for eftinfo */ 1197c478bd9Sstevel@tonic-gate stable_init(0); 1207c478bd9Sstevel@tonic-gate literals_init(); 1217c478bd9Sstevel@tonic-gate lut_init(); 1227c478bd9Sstevel@tonic-gate tree_init(); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "DEPSYdghpqvwy")) != EOF) { 1257c478bd9Sstevel@tonic-gate switch (c) { 1267c478bd9Sstevel@tonic-gate case 'D': 1277c478bd9Sstevel@tonic-gate Dflag++; 1287c478bd9Sstevel@tonic-gate break; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate case 'E': 1317c478bd9Sstevel@tonic-gate Eflag++; 1327c478bd9Sstevel@tonic-gate break; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate case 'y': 1357c478bd9Sstevel@tonic-gate yflag++; 1367c478bd9Sstevel@tonic-gate break; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate case 'P': 1397c478bd9Sstevel@tonic-gate Pflag++; 1407c478bd9Sstevel@tonic-gate break; 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate case 'S': 1437c478bd9Sstevel@tonic-gate Sflag++; 1447c478bd9Sstevel@tonic-gate break; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate case 'Y': 1477c478bd9Sstevel@tonic-gate yydebug++; 1487c478bd9Sstevel@tonic-gate break; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate case 'd': 1517c478bd9Sstevel@tonic-gate Debug++; 1527c478bd9Sstevel@tonic-gate break; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate case 'g': 1557c478bd9Sstevel@tonic-gate Pchildgen++; 1567c478bd9Sstevel@tonic-gate break; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate case 'h': 1597c478bd9Sstevel@tonic-gate case '?': 1607c478bd9Sstevel@tonic-gate out(O_PROG, "version %d.%d", 1617c478bd9Sstevel@tonic-gate VERSION_MAJOR, VERSION_MINOR); 1627c478bd9Sstevel@tonic-gate out(O_DIE|O_USAGE, "%s\n%s", Usage, Help); 1637c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate case 'p': 1667c478bd9Sstevel@tonic-gate pflag++; 1677c478bd9Sstevel@tonic-gate break; 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate case 'q': 1707c478bd9Sstevel@tonic-gate qflag++; 1717c478bd9Sstevel@tonic-gate break; 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate case 'v': 1747c478bd9Sstevel@tonic-gate Verbose++; 1757c478bd9Sstevel@tonic-gate break; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate case 'w': 1787c478bd9Sstevel@tonic-gate Warn++; 1797c478bd9Sstevel@tonic-gate break; 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate default: 1827c478bd9Sstevel@tonic-gate out(O_DIE|O_USAGE, Usage); 1837c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate out(O_PROG|O_VERB, "version %d.%d", 1887c478bd9Sstevel@tonic-gate VERSION_MAJOR, VERSION_MINOR); 1897c478bd9Sstevel@tonic-gate argc -= optind; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate if (argc < 1) 1927c478bd9Sstevel@tonic-gate out(O_DIE|O_USAGE, Usage); 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate if (!qflag) 1957c478bd9Sstevel@tonic-gate eftread_showheader(1); 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate lex_init(&argv[optind], NULL, yflag); 1987c478bd9Sstevel@tonic-gate check_init(); 1997c478bd9Sstevel@tonic-gate yyparse(); 2007c478bd9Sstevel@tonic-gate (void) lex_fini(); 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate tree_report(); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate if (count = out_errcount()) 2057c478bd9Sstevel@tonic-gate out(O_DIE, "%d error%s encountered, exiting.", OUTS(count)); 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate if (Dflag) { 2087c478bd9Sstevel@tonic-gate out(O_OK|O_NONL, "Dictionaries: "); 2097c478bd9Sstevel@tonic-gate lut_walk(Dicts, (lut_cb)dictprint, (void *)0); 2107c478bd9Sstevel@tonic-gate out(O_OK, NULL); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate if (Eflag) 2147c478bd9Sstevel@tonic-gate ptree_ereport(O_OK, NULL); 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate if (Pflag) { 2177c478bd9Sstevel@tonic-gate ptree_fault(O_OK, NULL); 2187c478bd9Sstevel@tonic-gate ptree_upset(O_OK, NULL); 2197c478bd9Sstevel@tonic-gate ptree_defect(O_OK, NULL); 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate if (pflag) 2237c478bd9Sstevel@tonic-gate ptree_name_iter(O_OK, tree_root(NULL)); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate if (Sflag) { 2267c478bd9Sstevel@tonic-gate out(O_OK, "Stats:"); 2277c478bd9Sstevel@tonic-gate stats_publish(); 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate out_exit(0); 2317c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 232*80ab886dSwesolows return (0); 2337c478bd9Sstevel@tonic-gate } 234