|
|
1.1 root 1: /* Copyright (c) 1979 Regents of the University of California */
2:
3: static char sccsid[] = "@(#)yymain.c 1.4 5/6/82";
4:
5: #include "whoami.h"
6: #include "0.h"
7: #include "yy.h"
8: #include <a.out.h>
9: #include "objfmt.h"
10: #include <signal.h>
11: #include "config.h"
12:
13: /*
14: * Yymain initializes each of the utility
15: * clusters and then starts the processing
16: * by calling yyparse.
17: */
18: yymain()
19: {
20:
21: #ifdef OBJ
22: /*
23: * initialize symbol table temp files
24: */
25: startnlfile();
26: #endif
27: /*
28: * Initialize the scanner
29: */
30: #ifdef PXP
31: if (bracket == 0) {
32: #endif
33: if (getline() == -1) {
34: Perror(filename, "No lines in file");
35: pexit(NOSTART);
36: }
37: #ifdef PXP
38: } else
39: yyline = 0;
40: #endif
41:
42: #ifdef PI
43: # ifdef OBJ
44: magic();
45: # endif OBJ
46: #endif
47: line = 1;
48: errpfx = 'E';
49: /*
50: * Initialize the clusters
51: *
52: initstring();
53: */
54: inithash();
55: inittree();
56: #ifdef PI
57: initnl();
58: #endif
59:
60: /*
61: * Process the input
62: */
63: yyparse();
64: #ifdef PI
65: # ifdef OBJ
66:
67: /*
68: * save outermost block of namelist
69: */
70: savenl(0);
71:
72: magic2();
73: # endif OBJ
74: # ifdef DEBUG
75: dumpnl(0);
76: # endif
77: #endif
78:
79: #ifdef PXP
80: prttab();
81: if (onefile) {
82: extern int outcol;
83:
84: if (outcol)
85: pchr('\n');
86: flush();
87: if (eflg) {
88: writef(2, "File not rewritten because of errors\n");
89: pexit(ERRS);
90: }
91: signal(SIGHUP, SIG_IGN);
92: signal(SIGINT, SIG_IGN);
93: copyfile();
94: }
95: #endif
96: pexit(eflg ? ERRS : AOK);
97: }
98:
99: #ifdef PXP
100: copyfile()
101: {
102: extern int fout[];
103: register int c;
104:
105: close(1);
106: if (creat(firstname, 0644) != 1) {
107: perror(firstname);
108: pexit(ERRS);
109: }
110: lseek(fout[0], 0l, 0);
111: while ((c = read(fout[0], &fout[3], 512)) > 0) {
112: if (write(1, &fout[3], c) != c) {
113: perror(firstname);
114: pexit(ERRS);
115: }
116: }
117: }
118: #endif
119:
120: static
121: struct exec magichdr;
122:
123: #ifdef PI
124: #ifdef OBJ
125: magic()
126: {
127:
128: short buf[HEADER_BYTES / sizeof ( short )];
129: unsigned *ubuf = buf;
130: register int hf, i;
131:
132: hf = open(px_header,0);
133: if (hf >= 0 && read(hf, buf, HEADER_BYTES) > sizeof(struct exec)) {
134: magichdr.a_magic = ubuf[0];
135: magichdr.a_text = ubuf[1];
136: magichdr.a_data = ubuf[2];
137: magichdr.a_bss = ubuf[3];
138: magichdr.a_syms = ubuf[4];
139: magichdr.a_entry = ubuf[5];
140: magichdr.a_trsize = ubuf[6];
141: magichdr.a_drsize = ubuf[7];
142: for (i = 0; i < HEADER_BYTES / sizeof ( short ); i++)
143: word(buf[i]);
144: }
145: close(hf);
146: }
147: #endif OBJ
148:
149: #ifdef OBJ
150: magic2()
151: {
152: struct pxhdr pxhd;
153:
154: if (magichdr.a_magic != 0407)
155: panic ( "magic2" );
156: pflush();
157: magichdr.a_data = ( unsigned ) lc - magichdr.a_text;
158: magichdr.a_data -= sizeof (struct exec);
159: pxhd.objsize = ( ( unsigned ) lc) - HEADER_BYTES;
160: pxhd.symtabsize = nlhdrsize();
161: magichdr.a_data += pxhd.symtabsize;
162: time(&pxhd.maketime);
163: pxhd.magicnum = MAGICNUM;
164: lseek(ofil, 0l, 0);
165: write(ofil, &magichdr, sizeof(struct exec));
166: lseek(ofil, ( long ) ( HEADER_BYTES - sizeof ( pxhd ) ) , 0);
167: write(ofil, &pxhd, sizeof (pxhd));
168: }
169: #endif OBJ
170: #endif
171:
172: #ifdef PXP
173: writef(i, cp)
174: {
175:
176: write(i, cp, strlen(cp));
177: }
178: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.