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