# 2.11BSD#431 - /usr/src/ucb/pascal/pxp/main.c

##### Functions

    header            X
    main              X
    onintr            X
    pexit             X
    puthedr           X

##### Variables

    how_file          X
    how_pathlen       X
    stdoutn           X
    ugh               X
    unit              X
    usagestr          X

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

#### Defined functions

header defined in line 206; used 2 times

- in /usr/src/ucb/pascal/pxp/pmon.c line 211
- in /usr/src/ucb/pascal/pxp/yyput.c line 254

main defined in line 50; never used
onintr defined in line 249; used 2 times

- in line 178-181(2)

pexit defined in line 233; used 34 times

- in line 82, 176, 252
- in /usr/src/ucb/pascal/pxp/error.c line 48
- in /usr/src/ucb/pascal/pxp/hash.c line 149, 187
- in /usr/src/ucb/pascal/pxp/nl.c line 604-609(2)
- in /usr/src/ucb/pascal/pxp/pmon.c line 72, 88, 118, 347
- in /usr/src/ucb/pascal/pxp/pp.c line 390
- in /usr/src/ucb/pascal/pxp/string.c line 43
- in /usr/src/ucb/pascal/pxp/tree.c line 120, 126
- in /usr/src/ucb/pascal/pxp/yycomm.c line 217
- in /usr/src/ucb/pascal/pxp/yyerror.c line 80
- in /usr/src/ucb/pascal/pxp/yyget.c line 146, 202, 208, 234, 242-246(2)
- in /usr/src/ucb/pascal/pxp/yylex.c line 264
- in /usr/src/ucb/pascal/pxp/yymain.c line 39, 81, 88, 100, 106
- in /usr/src/ucb/pascal/pxp/yyparse.c line 70
- in /usr/src/ucb/pascal/pxp/yyput.c line 154
- in /usr/src/ucb/pascal/pxp/yyrecover.c line 503, 510

puthedr defined in line 255; used 6 times

- in /usr/src/ucb/pascal/pxp/const.c line 24
- in /usr/src/ucb/pascal/pxp/fdec.c line 38, 192
- in /usr/src/ucb/pascal/pxp/lab.c line 21
- in /usr/src/ucb/pascal/pxp/type.c line 23
- in /usr/src/ucb/pascal/pxp/var.c line 23

#### Defined variables

how_file defined in line 35; used 2 times

- in line 58-61(2)

how_pathlen defined in line 36; used 1 times

- in line 58

stdoutn defined in line 38; used 6 times

- in line 180-188(4), 239-240(2)

ugh defined in line 225; used 2 times

- in line 245(2)

unit defined in line 40; used 1 times

- in line 141

usagestr defined in line 32; used 1 times

- in line 145

Last modified: 1996-10-24 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1101 |