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

Defined functions

copyfile defined in line 99; used 1 times
  • in line 92
magic defined in line 132; used 4 times
magic2 defined in line 160; used 1 times
  • in line 73
writef defined in line 178; used 1 times
  • in line 87
yymain defined in line 35; used 1 times

Defined variables

line defined in line 28; never used
sccsid defined in line 8; never used

Defined macros

HEAD_BYTES defined in line 138; used 5 times
Last modified: 1985-06-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3036
Valid CSS Valid XHTML 1.0 Strict