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