Commit | Line | Data |
---|---|---|
84ef74c0 | 1 | static char *sccsid = "@(#)yymain.c 1.2 (Berkeley) %G%"; |
b78d4950 PK |
2 | /* Copyright (c) 1979 Regents of the University of California */ |
3 | # | |
4 | /* | |
5 | * pi - Pascal interpreter code translator | |
6 | * | |
7 | * Charles Haley, Bill Joy UCB | |
8 | * Version 1.2 November 1978 | |
9 | * | |
10 | * | |
11 | * pxp - Pascal execution profiler | |
12 | * | |
13 | * Bill Joy UCB | |
14 | * Version 1.2 November 1978 | |
15 | */ | |
16 | ||
84ef74c0 | 17 | #include "whoami.h" |
b78d4950 PK |
18 | #include "0.h" |
19 | #include "yy.h" | |
20 | ||
21 | int line = 1; | |
22 | ||
23 | /* | |
24 | * Yymain initializes each of the utility | |
25 | * clusters and then starts the processing | |
26 | * by calling yyparse. | |
27 | */ | |
28 | yymain() | |
29 | { | |
30 | ||
31 | /* | |
32 | * Initialize the scanner | |
33 | */ | |
34 | #ifdef PXP | |
35 | if (bracket == 0) { | |
36 | #endif | |
37 | if (getline() == -1) { | |
38 | Perror(filename, "No lines in file"); | |
39 | pexit(NOSTART); | |
40 | } | |
41 | #ifdef PXP | |
42 | } else | |
43 | yyline = 0; | |
44 | #endif | |
45 | ||
46 | #ifdef PI | |
47 | magic(); | |
48 | ||
49 | #endif | |
50 | /* | |
51 | * Initialize the clusters | |
52 | * | |
53 | initstring(); | |
54 | */ | |
55 | inithash(); | |
56 | inittree(); | |
57 | #ifdef PI | |
58 | initnl(); | |
59 | #endif | |
60 | ||
61 | /* | |
62 | * Process the input | |
63 | */ | |
64 | yyparse(); | |
65 | #ifdef PI | |
66 | magic2(); | |
67 | #ifdef DEBUG | |
68 | dumpnl(0); | |
69 | #endif | |
70 | #endif | |
71 | #ifdef PXP | |
72 | prttab(); | |
73 | if (onefile) { | |
74 | extern int outcol; | |
75 | ||
76 | if (outcol) | |
77 | putchar('\n'); | |
78 | flush(); | |
79 | if (eflg) { | |
80 | writef(2, "File not rewritten because of errors\n"); | |
81 | pexit(ERRS); | |
82 | } | |
83 | signal(1, 1); | |
84 | signal(2, 1); | |
85 | copyfile(); | |
86 | } | |
87 | #endif | |
88 | pexit(eflg ? ERRS : AOK); | |
89 | } | |
90 | ||
91 | #ifdef PXP | |
92 | copyfile() | |
93 | { | |
94 | register int c; | |
95 | char buf[BUFSIZ]; | |
96 | ||
97 | if (freopen(stdoutn, "r", stdin) == NULL) { | |
98 | perror(stdoutn); | |
99 | pexit(ERRS); | |
100 | } | |
101 | if (freopen(firstname, "w", stdout) == NULL) { | |
102 | perror(firstname); | |
103 | pexit(ERRS); | |
104 | } | |
105 | while ((c = getchar()) > 0) | |
106 | putchar(c); | |
107 | if (ferror(stdout)) | |
108 | perror(stdout); | |
109 | } | |
110 | #endif | |
111 | ||
112 | static | |
113 | struct { | |
114 | int magic; | |
115 | unsigned txt_size; | |
116 | unsigned data_size; | |
117 | unsigned bss_size; | |
118 | unsigned syms_size; | |
119 | unsigned entry_point; | |
120 | unsigned tr_size; | |
121 | unsigned dr_size; | |
122 | } header; | |
123 | ||
124 | #ifdef PI | |
125 | magic() | |
126 | { | |
127 | ||
128 | /* | |
129 | * this is the size of /usr/lib/npxheader | |
130 | */ | |
131 | #define HEAD_BYTES 1024 | |
132 | short buf[HEAD_BYTES / sizeof ( short )]; | |
133 | unsigned *ubuf = buf; | |
134 | register int hf, i; | |
135 | ||
136 | hf = open("/usr/lib/npx_header", 0); | |
137 | if (hf >= 0 && read(hf, buf, HEAD_BYTES) > sizeof header) { | |
138 | header.magic = ubuf[0]; | |
139 | header.txt_size = ubuf[1]; | |
140 | header.data_size = ubuf[2]; | |
141 | header.bss_size = ubuf[3]; | |
142 | header.syms_size = ubuf[4]; | |
143 | header.entry_point = ubuf[5]; | |
144 | header.tr_size = ubuf[6]; | |
145 | header.dr_size = ubuf[7]; | |
146 | for (i = 0; i < HEAD_BYTES / sizeof ( short ); i++) | |
147 | word(buf[i]); | |
148 | } | |
149 | close(hf); | |
150 | word(0404); | |
151 | } | |
152 | ||
153 | magic2() | |
154 | { | |
155 | short i; | |
156 | ||
157 | if (header.magic != 0407) | |
158 | panic ( "magic2" ); | |
159 | pflush(); | |
160 | lseek(ofil, 0l, 0); | |
161 | header.data_size = ( unsigned ) lc - header.txt_size; | |
162 | header.data_size =- sizeof header; | |
163 | write(ofil, &header, sizeof header); | |
164 | lseek(ofil, ( long ) ( HEAD_BYTES - sizeof ( short ) ) , 0); | |
165 | i = ( ( unsigned ) lc) - HEAD_BYTES; | |
166 | write(ofil, &i, 2); | |
167 | } | |
168 | #endif | |
169 | ||
170 | #ifdef PXP | |
171 | writef(i, cp) | |
172 | { | |
173 | ||
174 | write(i, cp, strlen(cp)); | |
175 | } | |
176 | #endif |