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

Defined functions

dashes defined in line 218; used 2 times
indent1 defined in line 227; used 4 times
indentlab defined in line 258; used 1 times
linopr defined in line 246; used 2 times
outerr defined in line 387; used 2 times
pplab defined in line 320; used 3 times
pppay defined in line 166; used 1 times
ppsnl defined in line 158; used 1 times
ppsnlb defined in line 150; used 1 times
pptab defined in line 369; used 1 times
ppunspac defined in line 121; used 1 times
printon defined in line 38; used 2 times
putchar defined in line 334; never used
setprint defined in line 25; used 3 times

Defined variables

killsp defined in line 119; used 3 times
nopflg defined in line 23; used 10 times
outcol defined in line 331; used 7 times
owenl defined in line 148; used 3 times
owenlb defined in line 148; used 4 times
pplev defined in line 22; used 11 times
sccsid defined in line 8; never used

Defined macros

noprint defined in line 20; used 16 times
Last modified: 1985-06-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 4649
Valid CSS Valid XHTML 1.0 Strict