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