#include <stdio.h>
#include <string.h>
#ifdef sun
#include <stdlib.h>
#else
#include <getopt.h>
#endif
#include "out.h"
#include "alloc.h"
#include "stats.h"
#include "stable.h"
#include "literals.h"
#include "lut.h"
#include "esclex.h"
#include "ptree.h"
#include "tree.h"
#include "check.h"
#include "version.h"
#include "eftread.h"
extern void yyparse(void);
extern int yydebug;
extern void literals_init(void);
static const char *Usage = "[-DEPghpqvw] eft-files...";
static const char *Help =
"\t-D Print dictionaries EFT references.\n"
"\t-E Print ereports EFT will consume.\n"
"\t-P Print problems EFT can diagnose.\n"
"\t-g Print generated iterators (use with -p)\n"
"\t-h Print this help message\n"
"\t-p Print complete propagation tree\n"
"\t-q Quiet mode, no header info printed\n"
"\t-v Enable verbose output\n"
"\t-w Enable language warnings";
int Debug;
int Verbose;
int Warn;
extern int Pchildgen;
extern struct lut *Dicts;
static void
dictprint(const char *s, void *rhs, void *arg)
{
static char *sep = "";
out(O_OK|O_NONL, "%s%s", sep, s);
sep = ":";
}
int
main(int argc, char *argv[])
{
int c;
int count;
int Dflag = 0;
int Eflag = 0;
int yflag = 0;
int Pflag = 0;
int Sflag = 0;
int pflag = 0;
int qflag = 0;
alloc_init();
out_init(argv[0]);
stats_init(1);
stable_init(0);
literals_init();
lut_init();
tree_init();
while ((c = getopt(argc, argv, "DEPSYdghpqvwy")) != EOF) {
switch (c) {
case 'D':
Dflag++;
break;
case 'E':
Eflag++;
break;
case 'y':
yflag++;
break;
case 'P':
Pflag++;
break;
case 'S':
Sflag++;
break;
case 'Y':
yydebug++;
break;
case 'd':
Debug++;
break;
case 'g':
Pchildgen++;
break;
case 'h':
case '?':
out(O_PROG, "version %d.%d",
VERSION_MAJOR, VERSION_MINOR);
out(O_DIE|O_USAGE, "%s\n%s", Usage, Help);
break;
case 'p':
pflag++;
break;
case 'q':
qflag++;
break;
case 'v':
Verbose++;
break;
case 'w':
Warn++;
break;
default:
out(O_DIE|O_USAGE, Usage);
}
}
out(O_PROG|O_VERB, "version %d.%d",
VERSION_MAJOR, VERSION_MINOR);
argc -= optind;
if (argc < 1)
out(O_DIE|O_USAGE, Usage);
if (!qflag)
eftread_showheader(1);
lex_init(&argv[optind], NULL, yflag);
check_init();
yyparse();
(void) lex_fini();
tree_report();
if (count = out_errcount())
out(O_DIE, "%d error%s encountered, exiting.", OUTS(count));
if (Dflag) {
out(O_OK|O_NONL, "Dictionaries: ");
lut_walk(Dicts, (lut_cb)dictprint, (void *)0);
out(O_OK, NULL);
}
if (Eflag)
ptree_ereport(O_OK, NULL);
if (Pflag) {
ptree_fault(O_OK, NULL);
ptree_upset(O_OK, NULL);
ptree_defect(O_OK, NULL);
}
if (pflag)
ptree_name_iter(O_OK, tree_root(NULL));
if (Sflag) {
out(O_OK, "Stats:");
stats_publish();
}
out_exit(0);
return (0);
}