Commit | Line | Data |
---|---|---|
4a9bdf3d BJ |
1 | # |
2 | /* | |
3 | * pxp - Pascal execution profiler | |
4 | * | |
5 | * Bill Joy UCB | |
6 | * Version 1.0 August 1977 | |
7 | */ | |
8 | ||
9 | #include "whoami" | |
10 | #include "0.h" | |
11 | ||
12 | #define noprint() nopflg | |
13 | ||
14 | int pplev[3]; /* STAT, DECL, PRFN */ | |
15 | int nopflg; | |
16 | ||
17 | setprint() | |
18 | { | |
19 | ||
20 | if (profile == 0) { | |
21 | if (table) | |
22 | nopflg = 1; | |
23 | else | |
24 | nopflg = 0; | |
25 | return; | |
26 | } | |
27 | nopflg = !all && nowcnt() == 0 || !opt('z'); | |
28 | } | |
29 | ||
30 | printon() | |
31 | { | |
32 | ||
33 | if (profile == 0) { | |
34 | if (table) | |
35 | nopflg = 1; | |
36 | return; | |
37 | } | |
38 | nopflg = 0; | |
39 | } | |
40 | ||
41 | printoff() | |
42 | { | |
43 | ||
44 | nopflg = 1; | |
45 | } | |
46 | ||
47 | ppkw(s) | |
48 | char *s; | |
49 | { | |
50 | register char *cp, i; | |
51 | ||
52 | if (noprint()) | |
53 | return; | |
54 | /* | |
55 | * First real thing printed | |
56 | * is always a keyword | |
57 | * or includes an "id" (if a comment) | |
58 | * (See ppnl below) | |
59 | */ | |
60 | hadsome = 1; | |
61 | if (underline) { | |
62 | for (cp = s; *cp; cp++) | |
63 | putchar('_'); | |
64 | for (cp = s; *cp; cp++) | |
65 | putchar('\b'); | |
66 | } | |
67 | printf(s); | |
68 | } | |
69 | ||
70 | ppid(s) | |
71 | char *s; | |
72 | { | |
73 | ||
74 | if (noprint()) | |
75 | return; | |
76 | hadsome = 1; | |
77 | if (s == NIL) | |
78 | s = "{identifier}"; | |
79 | printf(s); | |
80 | } | |
81 | ||
82 | ppbra(s) | |
83 | char *s; | |
84 | { | |
85 | ||
86 | if (noprint()) | |
87 | return; | |
88 | if (s != NIL) | |
89 | printf(s); | |
90 | } | |
91 | ||
92 | ppsep(s) | |
93 | char *s; | |
94 | { | |
95 | ||
96 | if (noprint()) | |
97 | return; | |
98 | printf(s); | |
99 | } | |
100 | ||
101 | ppket(s) | |
102 | char *s; | |
103 | { | |
104 | ||
105 | if (noprint()) | |
106 | return; | |
107 | if (s != NIL) | |
108 | printf(s); | |
109 | } | |
110 | ||
111 | char killsp; | |
112 | ||
113 | ppunspac() | |
114 | { | |
115 | ||
116 | killsp = 1; | |
117 | } | |
118 | ||
119 | ppspac() | |
120 | { | |
121 | ||
122 | if (killsp) { | |
123 | killsp = 0; | |
124 | return; | |
125 | } | |
126 | if (noprint()) | |
127 | return; | |
128 | putchar(' '); | |
129 | } | |
130 | ||
131 | ppitem() | |
132 | { | |
133 | ||
134 | if (noprint()) | |
135 | return; | |
136 | ppnl(); | |
137 | indent(); | |
138 | } | |
139 | ||
140 | int owenl, owenlb; | |
141 | ||
142 | ppsnlb() | |
143 | { | |
144 | ||
145 | if (nopflg) | |
146 | return; | |
147 | owenlb++; | |
148 | } | |
149 | ||
150 | ppsnl() | |
151 | { | |
152 | ||
153 | if (nopflg) | |
154 | return; | |
155 | owenl++; | |
156 | } | |
157 | ||
158 | pppay() | |
159 | { | |
160 | ||
161 | while (owenl || owenlb) { | |
162 | putchar('\n'); | |
163 | if (owenlb) | |
164 | putchar(' '); | |
165 | owenlb ? owenlb-- : owenl--; | |
166 | } | |
167 | } | |
168 | ||
169 | ppnl() | |
170 | { | |
171 | ||
172 | if (noprint()) | |
173 | return; | |
174 | if (hadsome == 0) | |
175 | return; | |
176 | pppay(); | |
177 | putchar('\n'); | |
178 | } | |
179 | ||
180 | indent() | |
181 | { | |
182 | register i; | |
183 | ||
184 | if (noprint()) | |
185 | return; | |
186 | linopr(); | |
187 | if (profile == 0) { | |
188 | indent1(pplev[PRFN] + pplev[DECL] + pplev[STAT]); | |
189 | return; | |
190 | } | |
191 | indent1(pplev[PRFN] + pplev[STAT]); | |
192 | switch (i = shudpcnt()) { | |
193 | case 1: | |
194 | printf("%7.7ld.", nowcnt()); | |
195 | dashes('-'); | |
196 | putchar('|'); | |
197 | break; | |
198 | case 0: | |
199 | case -1: | |
200 | printf(" "); | |
201 | dashes(' '); | |
202 | putchar(i == 0 ? '|' : ' '); | |
203 | break; | |
204 | } | |
205 | indent1(pplev[DECL]); | |
206 | } | |
207 | ||
208 | dashes(c) | |
209 | char c; | |
210 | { | |
211 | register i; | |
212 | ||
213 | for (i = unit - 1; i != 0; i--) | |
214 | putchar(c); | |
215 | } | |
216 | ||
217 | indent1(in) | |
218 | int in; | |
219 | { | |
220 | register i; | |
221 | ||
222 | if (noprint()) | |
223 | return; | |
224 | i = in; | |
225 | if (profile == 0) | |
226 | while (i >= 8) { | |
227 | putchar('\t'); | |
228 | i =- 8; | |
229 | } | |
230 | while (i > 0) { | |
231 | putchar(' '); | |
232 | i--; | |
233 | } | |
234 | } | |
235 | ||
236 | linopr() | |
237 | { | |
238 | ||
239 | if (noprint()) | |
240 | return; | |
241 | if (profile) { | |
242 | if (line < 0) | |
243 | line = -line; | |
244 | printf("%6d ", line); | |
245 | } | |
246 | } | |
247 | ||
248 | indentlab() | |
249 | { | |
250 | ||
251 | indent1(pplev[PRFN]); | |
252 | } | |
253 | ||
254 | ppop(s) | |
255 | char *s; | |
256 | { | |
257 | ||
258 | if (noprint()) | |
259 | return; | |
260 | printf(s); | |
261 | } | |
262 | ||
263 | ppnumb(s) | |
264 | char *s; | |
265 | { | |
266 | ||
267 | if (noprint()) | |
268 | return; | |
269 | if (s == NIL) | |
270 | s = "{number}"; | |
271 | printf(s); | |
272 | } | |
273 | ||
274 | ppgoin(lv) | |
275 | { | |
276 | ||
277 | pplev[lv] =+ unit; | |
278 | } | |
279 | ||
280 | ppgoout(lv) | |
281 | { | |
282 | ||
283 | pplev[lv] =- unit; | |
284 | if (pplev[lv] < 0) | |
285 | panic("pplev"); | |
286 | } | |
287 | ||
288 | ppstr(s) | |
289 | char *s; | |
290 | { | |
291 | register char *cp; | |
292 | ||
293 | if (noprint()) | |
294 | return; | |
295 | if (s == NIL) { | |
296 | printf("{string}"); | |
297 | return; | |
298 | } | |
299 | putchar('\''); | |
300 | cp = s; | |
301 | while (*cp) { | |
302 | putchar(*cp); | |
303 | if (*cp == '\'') | |
304 | putchar('\''); | |
305 | cp++; | |
306 | } | |
307 | putchar('\''); | |
308 | } | |
309 | ||
310 | pplab(s) | |
311 | char *s; | |
312 | { | |
313 | ||
314 | if (noprint()) | |
315 | return; | |
316 | if (s == NIL) | |
317 | s = "{integer label}"; | |
318 | printf(s); | |
319 | } | |
320 | ||
321 | int fout[259]; | |
322 | extern int putchar(), flush(); | |
323 | ||
324 | int outcol; | |
325 | ||
326 | putchar(c) | |
327 | char c; | |
328 | { | |
329 | ||
330 | putc(c, fout); | |
331 | switch (c) { | |
332 | case '\n': | |
333 | outcol = 0; | |
334 | fflush(); | |
335 | break; | |
336 | case '\t': | |
337 | outcol =+ 8; | |
338 | outcol =& ~07; | |
339 | break; | |
340 | case '\b': | |
341 | if (outcol) | |
342 | outcol--; | |
343 | break; | |
344 | default: | |
345 | outcol++; | |
346 | case '\f': | |
347 | break; | |
348 | } | |
349 | } | |
350 | ||
351 | flush() | |
352 | { | |
353 | ||
354 | fflush(fout); | |
355 | } | |
356 | ||
357 | pptab() | |
358 | { | |
359 | register int i; | |
360 | ||
361 | if (noprint()) | |
362 | return; | |
363 | i = pplev[PRFN] + profile ? 44 + unit : 28; | |
364 | if (outcol > i + 8) | |
365 | ppnl(); | |
366 | do | |
367 | putchar('\t'); | |
368 | while (outcol < i); | |
369 | } |