1: /*	@(#)yymain.c	2.2	SCCS id keyword	*/
   2: /* Copyright (c) 1979 Regents of the University of California */
   3: #
   4: /*
   5:  * pi - Pascal interpreter code translator
   6:  *
   7:  * Charles Haley, Bill Joy UCB
   8:  * Version 1.2 November 1978
   9:  *
  10:  *
  11:  * pxp - Pascal execution profiler
  12:  *
  13:  * Bill Joy UCB
  14:  * Version 1.2 November 1978
  15:  */
  16: 
  17: #include "whoami"
  18: #include "0.h"
  19: #include "yy.h"
  20: 
  21: short   line = 1;
  22: 
  23: /*
  24:  * Yymain initializes each of the utility
  25:  * clusters and then starts the processing
  26:  * by calling yyparse.
  27:  */
  28: yymain()
  29: {
  30: 
  31:     /*
  32: 	 * Initialize the scanner
  33: 	 */
  34: #ifdef PXP
  35:     if (bracket == 0) {
  36: #endif
  37:         if (getline() == -1) {
  38:             Perror(filename, "No lines in file");
  39:             pexit(NOSTART);
  40:         }
  41: #ifdef PXP
  42:     } else
  43:         yyline = 0;
  44: #endif
  45: 
  46: #ifdef PI
  47:     magic();
  48: 
  49: #endif
  50:     /*
  51: 	 * Initialize the clusters
  52: 	 *
  53: 	initstring();
  54: 	 */
  55:     inithash();
  56:     inittree();
  57: #ifdef PI
  58:     initnl();
  59: #endif
  60: 
  61:     /*
  62: 	 * Process the input
  63: 	 */
  64:     yyparse();
  65: #ifdef PI
  66:     magic2();
  67: #ifdef DEBUG
  68:     dumpnl(0);
  69: #endif
  70: #endif
  71: #ifdef PXP
  72:     prttab();
  73:     if (onefile) {
  74:         extern int outcol;
  75: 
  76:         if (outcol)
  77:             pchr('\n');
  78:         flush();
  79:         if (eflg) {
  80:             writef(2, "File not rewritten because of errors\n");
  81:             pexit(ERRS);
  82:         }
  83:         signal(1, 1);
  84:         signal(2, 1);
  85:         copyfile();
  86:     }
  87: #endif
  88:     pexit(eflg ? ERRS : AOK);
  89: }
  90: 
  91: #ifdef PXP
  92: copyfile()
  93: {
  94:     extern int fout[];
  95:     register int c;
  96: 
  97:     close(1);
  98:     if (creat(firstname, 0644) != 1) {
  99:         perror(firstname);
 100:         pexit(ERRS);
 101:     }
 102:     lseek(fout[0], 0l, 0);
 103:     while ((c = read(fout[0], &fout[3], 512)) > 0) {
 104:         if (write(1, &fout[3], c) != c) {
 105:             perror(firstname);
 106:             pexit(ERRS);
 107:         }
 108:     }
 109: }
 110: #endif
 111: 
 112: static
 113: struct {
 114:     int     magic;
 115:     unsigned    txt_size;
 116:     unsigned    data_size;
 117:     unsigned    bss_size;
 118:     unsigned    syms_size;
 119:     unsigned    entry_point;
 120:     unsigned    tr_size;
 121:     unsigned    dr_size;
 122: } header;
 123: 
 124: #ifdef PI
 125: magic()
 126: {
 127: 
 128:     /*
 129:      *	this is the size of /usr/lib/npxheader
 130:      */
 131: #define HEAD_BYTES  1024
 132:     short       buf[HEAD_BYTES / sizeof ( short )];
 133:     unsigned    *ubuf = buf;
 134:     register int    hf, i;
 135: 
 136:     hf = open("/usr/lib/npx_header", 0);
 137:     if (hf >= 0 && read(hf, buf, HEAD_BYTES) > sizeof header) {
 138:         header.magic = ubuf[0];
 139:         header.txt_size = ubuf[1];
 140:         header.data_size = ubuf[2];
 141:         header.bss_size = ubuf[3];
 142:         header.syms_size = ubuf[4];
 143:         header.entry_point = ubuf[5];
 144:         header.tr_size = ubuf[6];
 145:         header.dr_size = ubuf[7];
 146:         for (i = 0; i < HEAD_BYTES / sizeof ( short ); i++)
 147:             word(buf[i]);
 148:     }
 149:     close(hf);
 150:     word(0404);
 151: }
 152: 
 153: magic2()
 154: {
 155:     short i;
 156: 
 157:     if  (header.magic != 0407)
 158:         panic ( "magic2" );
 159:     pflush();
 160:     lseek(ofil, 0l, 0);
 161:     header.data_size = ( unsigned ) lc - header.txt_size;
 162:     header.data_size =- sizeof header;
 163:     write(ofil, &header, sizeof header);
 164:     lseek(ofil, ( long ) ( HEAD_BYTES - sizeof ( short ) ) , 0);
 165:     i = ( ( unsigned ) lc) - HEAD_BYTES;
 166:     write(ofil, &i, 2);
 167: }
 168: #endif
 169: 
 170: #ifdef PXP
 171: writef(i, cp)
 172: {
 173: 
 174:     write(i, cp, strlen(cp));
 175: }
 176: #endif

Defined functions

copyfile defined in line 92; used 1 times
  • in line 85
magic defined in line 125; used 4 times
magic2 defined in line 153; used 1 times
  • in line 66
writef defined in line 171; used 1 times
  • in line 80
yymain defined in line 28; used 1 times

Defined variables

line defined in line 21; never used

Defined macros

HEAD_BYTES defined in line 131; used 5 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 967
Valid CSS Valid XHTML 1.0 Strict