Pristine Ack-5.5
[Ack-5.5.git] / util / ncgg / main.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 #ifndef NORCSID
6 static char rcsid[]= "$Id: main.c,v 0.6 1994/06/24 10:37:46 ceriel Exp $";
7 #endif
8
9 #include <stdio.h>
10
11 char *filename;
12 char *beg_sbrk;
13 extern char *sbrk();
14
15 main(argc,argv) char **argv; {
16         extern int nerrors;
17         extern int code_in_c;
18         extern int tabledebug;
19         extern int verbose;
20
21         beg_sbrk = sbrk(0);
22
23         while (argc >1 && argv[1][0]=='-') {
24                 switch(argv[1][1]) {
25                 case 'c':
26                         code_in_c = 0;
27                         break;
28                 case 'd':
29                         tabledebug++;
30                         break;
31                 case 'v':
32                         verbose++;
33                         break;
34                 default:
35                         error("Unknown flag -%c",argv[1][1]);
36                 }
37                 argc--; argv++;
38         }
39         if (argc==2) {
40                 if (freopen(argv[1],"r",stdin)==NULL) {
41                         error("Can't open %s",argv[1]);
42                         exit(-1);
43                 }
44                 filename = argv[1];
45         }
46         else if (argc == 1) {
47                 filename = "";
48         } else
49                 error("Usage: %s [-c] [-d] [-v] [table]",argv[0]);
50         initemhash();
51         enterkeyw();
52         initnodes();
53         initio();
54         yyparse();
55         if (nerrors==0) {
56                 finishio();
57                 statistics();
58                 if (verbose)
59                         hallverbose();
60         } else {
61                 errorexit();
62         }
63         exit(nerrors==0 ? 0 : -1);
64 }