Pristine Ack-5.5
[Ack-5.5.git] / util / opt / main.c
1 #ifndef NORCSID
2 static char rcsid[] = "$Id: main.c,v 2.8 1994/06/24 10:40:17 ceriel Exp $";
3 #endif
4
5 #include <stdio.h>
6 #include "param.h"
7 #include "types.h"
8 #include "tes.h"
9 #include "alloc.h"
10 #include <em_spec.h>
11 #include "ext.h"
12
13 /*
14  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
15  * See the copyright notice in the ACK home directory, in the file "Copyright".
16  *
17  * Author: Hans van Staveren
18  */
19
20 /*
21  * Main program for EM optimizer
22  */
23
24 main(argc,argv) int argc; char *argv[]; {
25         int somespace[STACKROOM];
26
27         progname = argv[0];
28         while (argc-->1 && **++argv == '-')
29                 flags(*argv);
30         if (argc>1) {
31                 fprintf(stderr,"Usage: %s [-Ln] [-m<num>] [name]\n",progname);
32                 exit(-1);
33         }
34         if (argc)
35                 if (freopen(*argv,"r",stdin) == NULL)
36                         error("Cannot open %s",*argv);
37         fileinit();
38         coreinit((short *)somespace,(short *)(somespace+STACKROOM));
39         getlines();
40         cleanup();
41         return(0);
42 }
43
44 flags(s) register char *s; {
45
46         for (s++;*s;s++)
47                 switch(*s) {
48                 case 'L':       Lflag = TRUE; break;
49                 case 'n':       nflag = TRUE; break;
50                 case 'm':       if (*(s+1) == 'l') {
51                                         s++;
52                                         repl_longmuls = TRUE;
53                                 }
54                                 repl_muls = atoi(s+1); break;
55                 }
56 }
57
58 fileinit() {
59         char *mktemp();
60         short readshort();
61
62         if (readshort() != (short) sp_magic)
63                 error("wrong input file");
64         if (Lflag) {
65                 outfile = fopen(mktemp(template),"w");
66                 if (outfile == NULL)
67                         error("can't create %s",template);
68         } else {
69                 outfile = stdout;
70                 outshort(sp_magic);
71         }
72 }