1: #
   2: /*
   3:  * pxp - Pascal execution profiler
   4:  *
   5:  * Bill Joy UCB
   6:  * Version 1.2 January 1979
   7:  */
   8: 
   9: #include "0.h"
  10: 
  11: /*
  12:  * This program is described in detail in the "PXP 1.0 Implementation Notes"
  13:  *
  14:  * The structure of pxp is very similar to that of the compiler pc.
  15:  * The major new pieces here are a set of profile data maintenance
  16:  * routines in the file pmon.c and a set of pretty printing utility
  17:  * routines in the file pp.c.
  18:  * The semantic routines of pc have been rewritten to do a simple
  19:  * reformatting tree walk, the parsing and scanning remains
  20:  * the same.
  21:  *
  22:  * This version does not reformat comments, rather discards them.
  23:  * It also does not place more than one statement per line and
  24:  * is not very intelligent about folding long lines, with only
  25:  * an ad hoc way of folding case label list and enumerated type
  26:  * declarations being implemented.
  27:  */
  28: 
  29: char    usagestr[]
  30:     "pxp [ -acdefjntuw_ ] [ -23456789 ] [ -z [ name ... ] ] name.p";
  31: char    *howfile    "/usr/lib/how_pxp";
  32: char    *stdoutn    "Standard output";
  33: 
  34: int unit    4;
  35: 
  36: extern  int ibuf[259];
  37: extern  char errout;
  38: 
  39: /*
  40:  * Main program for pxp.
  41:  * Process options, then call yymain
  42:  * to do all the real work.
  43:  */
  44: main(argc, argv)
  45:     int argc;
  46:     char *argv[];
  47: {
  48:     register char *cp;
  49:     register c;
  50: 
  51:     if (argv[0][0] == 'a')
  52:         howfile =+ 9;
  53:     argc--, argv++;
  54:     if (argc == 0) {
  55:         execl("/bin/cat", "cat", howfile, 0);
  56:         goto usage;
  57:     }
  58:     while (argc > 0) {
  59:         cp = argv[0];
  60:         if (*cp++ != '-')
  61:             break;
  62:         while (c = *cp++) switch (c) {
  63: #ifdef DEBUG
  64:             case 'T':
  65:                 typetest++;
  66:                 continue;
  67:             case 'A':
  68:                 testtrace++;
  69:             case 'F':
  70:                 fulltrace++;
  71:             case 'E':
  72:                 errtrace++;
  73:                 continue;
  74:             case 'C':
  75:                 yycosts();
  76:                 pexit(NOSTART);
  77:             case 'U':
  78:                 yyunique++;
  79:                 continue;
  80: #endif
  81:             case 'a':
  82:                 all++;
  83:                 continue;
  84:             case 'c':
  85:                 core++;
  86:                 continue;
  87:             case 'd':
  88:                 nodecl++;
  89:                 continue;
  90:             case 'e':
  91:                 noinclude = -1;
  92:                 continue;
  93:             case 'f':
  94:                 full++;
  95:                 continue;
  96:             case 'j':
  97:                 justify++;
  98:                 continue;
  99:             case 'l':
 100:             case 'n':
 101:                 togopt(c);
 102:                 continue;
 103:             case 'o':
 104:                 onefile++;
 105:                 continue;
 106:             case 's':
 107:                 stripcomm++;
 108:                 continue;
 109:             case 't':
 110:                 table++;
 111:                 continue;
 112:             case 'u':
 113:             case 'w':
 114:                 togopt(c);
 115:                 continue;
 116:             case 'z':
 117:                 profile++;
 118:                 pflist = argv + 1;
 119:                 pflstc = 0;
 120:                 while (argc > 1) {
 121:                     if (dotted(argv[1], 'p'))
 122:                         break;
 123:                     pflstc++, argc--, argv++;
 124:                 }
 125:                 if (pflstc == 0)
 126:                     togopt(c);
 127:                 else
 128:                     nojunk++;
 129:                 continue;
 130:             case '_':
 131:                 underline++;
 132:                 continue;
 133:             default:
 134:                 if (c >= '2' && c <= '9') {
 135:                     unit = c - '0';
 136:                     continue;
 137:                 }
 138: usage:
 139:                 Perror("Usage", usagestr);
 140:                 exit(1);
 141:         }
 142:         argc--, argv++;
 143:     }
 144:     if (core && !profile && !table)
 145:         profile++;
 146:     if (argc == 0 || argc > 2)
 147:         goto usage;
 148:     if (profile || table) {
 149:         noinclude = 0;
 150:         if (argc == 2) {
 151:             argc--;
 152:             getit(argv[1]);
 153:         } else
 154:             getit(core ? "core" : "pmon.out");
 155:     } else
 156:         noinclude++;
 157:     if (argc != 1)
 158:         goto usage;
 159:     firstname = filename = argv[0];
 160:     if (dotted(filename, 'i')) {
 161:         if (profile || table)
 162:             goto usage;
 163:         noinclude = 1;
 164:         bracket++;
 165:     } else if (!dotted(filename, 'p')) {
 166:         Perror(filename, "Name must end in '.p'");
 167:         exit(1);
 168:     }
 169:     if (fopen(filename, ibuf) < 0)
 170:         perror(filename), pexit(NOSTART);
 171:     if (onefile) {
 172:         int onintr();
 173: 
 174:         cp = (stdoutn = "/tmp/pxp00000") + 13;
 175:         signal(2, onintr);
 176:         for (c = getpid(); c; c =/ 10)
 177:             *--cp =| (c % 10);
 178:         if (fcreat(stdoutn, fout) < 0)
 179: bad:
 180:             perror(stdoutn), exit(1);
 181:         close(fout[0]);
 182:         if (open(stdoutn, 2) != fout[0])
 183:             goto bad;
 184:     } else
 185:         fout[0] = dup(1);
 186:     if (profile || opt('l')) {
 187:         opt('n')++;
 188:         yysetfile(filename);
 189:         opt('n')--;
 190:     } else
 191:         lastname = filename;
 192:     errout = dup(2);
 193:     yymain();
 194:     /* No return */
 195: }
 196: 
 197: /*
 198:  * Put a header on a top of a page
 199:  */
 200: header()
 201: {
 202:     extern char version[];
 203:     static char reenter;
 204:     extern int outcol;
 205: 
 206:     gettime();
 207:     if (reenter) {
 208:         if (outcol)
 209:             putchar('\n');
 210:         putchar('\f');
 211:     }
 212:     reenter++;
 213:     if (profile || table) {
 214:         printf("Berkeley Pascal PXP -- Version 1.1 (%s)\n\n%s  %s\n\n", version, myctime(tvec), filename);
 215:         printf("Profiled %s\n\n", myctime(ptvec));
 216:     }
 217: }
 218: 
 219: char    ugh[]   "Fatal error in pxp\n";
 220: /*
 221:  * Exit from the Pascal system.
 222:  * We throw in an ungraceful termination
 223:  * message if c > 1 indicating a severe
 224:  * error such as running out of memory
 225:  * or an internal inconsistency.
 226:  */
 227: pexit(c)
 228:     int c;
 229: {
 230:     register char *cp;
 231:     extern int outcol;
 232: 
 233:     if (stdoutn[0] == '/')
 234:         unlink(stdoutn);
 235:     if (outcol)
 236:         putchar('\n');
 237:     flush();
 238:     if (c == DIED)
 239:         write(2, ugh, sizeof ugh);
 240:     exit(c);
 241: }
 242: 
 243: onintr()
 244: {
 245: 
 246:     pexit(DIED);
 247: }
 248: 
 249: puthedr()
 250: {
 251: 
 252:     yysetfile(filename);
 253: }

Defined functions

header defined in line 200; used 2 times
main defined in line 44; never used
onintr defined in line 243; used 2 times

Defined variables

howfile defined in line 31; used 2 times
stdoutn defined in line 32; used 6 times
ugh defined in line 219; used 2 times
  • in line 239(2)
unit defined in line 34; used 1 times
usagestr defined in line 29; used 1 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1028
Valid CSS Valid XHTML 1.0 Strict