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

Defined functions

copyfile defined in line 96; used 1 times
  • in line 89
magic defined in line 129; used 4 times
magic2 defined in line 157; used 1 times
  • in line 70
writef defined in line 175; used 1 times
  • in line 84
yymain defined in line 32; used 1 times

Defined variables

line defined in line 25; never used

Defined macros

HEAD_BYTES defined in line 135; used 5 times
Last modified: 1996-10-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2833
Valid CSS Valid XHTML 1.0 Strict