Bell 32V release
[unix-history] / usr / src / cmd / f77 / main.c
CommitLineData
0d57d6f5
TL
1char *xxxvers[] = "\nFORTRAN 77 PASS 1, VERSION 1.16, 3 NOVEMBER 1978\n";
2
3#include "defs"
4
5
6main(argc, argv)
7int argc;
8char **argv;
9{
10char *s;
11int k, retcode;
12FILEP opf();
13
14#define DONE(c) { retcode = c; goto finis; }
15
16--argc;
17++argv;
18
19while(argc>0 && argv[0][0]=='-')
20 {
21 for(s = argv[0]+1 ; *s ; ++s) switch(*s)
22 {
23 case 'w':
24 if(s[1]=='6' && s[2]=='6')
25 {
26 ftn66flag = YES;
27 s += 2;
28 }
29 else
30 nowarnflag = YES;
31 break;
32
33 case 'U':
34 shiftcase = NO;
35 break;
36
37 case 'u':
38 undeftype = YES;
39 break;
40
41 case 'O':
42 optimflag = YES;
43 if( isdigit(s[1]) )
44 {
45 k = *++s - '0';
46 if(k > MAXREGVAR)
47 {
48 warn1("-O%d: too many register variables", k);
49 maxregvar = MAXREGVAR;
50 }
51 else
52 maxregvar = k;
53 }
54 break;
55
56 case 'd':
57 debugflag = YES;
58 break;
59
60 case 'p':
61 profileflag = YES;
62 break;
63
64 case 'C':
65 checksubs = YES;
66 break;
67
68 case '1':
69 onetripflag = YES;
70 break;
71
72 case 'I':
73 if(*++s == '2')
74 tyint = TYSHORT;
75 else if(*s == '4')
76 {
77 shortsubs = NO;
78 tyint = TYLONG;
79 }
80 else if(*s == 's')
81 shortsubs = YES;
82 else
83 fatal1("invalid flag -I%c\n", *s);
84 tylogical = tyint;
85 break;
86
87 default:
88 fatal1("invalid flag %c\n", *s);
89 }
90 --argc;
91 ++argv;
92 }
93
94if(argc != 4)
95 fatal1("arg count %d", argc);
96asmfile = opf(argv[1]);
97initfile = opf(argv[2]);
98textfile = opf(argv[3]);
99
100initkey();
101if(inilex( copys(argv[0]) ))
102 DONE(1);
103fprintf(diagfile, "%s:\n", argv[0]);
104fileinit();
105procinit();
106if(k = yyparse())
107 {
108 fprintf(diagfile, "Bad parse, return code %d\n", k);
109 DONE(1);
110 }
111if(nerr > 0)
112 DONE(1);
113if(parstate != OUTSIDE)
114 {
115 warn("missing END statement");
116 endproc();
117 }
118doext();
119preven(ALIDOUBLE);
120prtail();
121#if FAMILY==SCJ
122 puteof();
123#endif
124DONE(0);
125
126
127finis:
128 done(retcode);
129 return(retcode);
130}
131
132
133
134done(k)
135int k;
136{
137static int recurs = NO;
138
139if(recurs == NO)
140 {
141 recurs = YES;
142 clfiles();
143 }
144exit(k);
145}
146
147
148LOCAL FILEP opf(fn)
149char *fn;
150{
151FILEP fp;
152if( fp = fopen(fn, "w") )
153 return(fp);
154
155fatal1("cannot open intermediate file %s", fn);
156/* NOTREACHED */
157}
158
159
160
161LOCAL clfiles()
162{
163clf(&textfile);
164clf(&asmfile);
165clf(&initfile);
166}
167
168
169clf(p)
170FILEP *p;
171{
172if(p!=NULL && *p!=NULL && *p!=stdout)
173 {
174 if(ferror(*p))
175 fatal("writing error");
176 fclose(*p);
177 }
178*p = NULL;
179}
180