|
|
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: #include "whoami" ! 11: #include "0.h" ! 12: #include "yy.h" ! 13: ! 14: /* ! 15: * This version of pi has been in use at Berkeley since May 1977 ! 16: * and is very stable, except for the syntactic error recovery which ! 17: * has just been written. Please report any problems with the error ! 18: * recovery to the second author at the address given in the file ! 19: * READ_ME. The second author takes full responsibility for any bugs ! 20: * in the syntactic error recovery. ! 21: */ ! 22: ! 23: char piusage[] = "pi [ -blnpstuw ] [ -i file ... ] name.p"; ! 24: char pixusage[] = "pix [ -blnpstuw ] [ -i file ... ] name.p [ arg ... ]"; ! 25: ! 26: char *usageis = piusage; ! 27: char *obj = "obj"; ! 28: ! 29: #ifdef PPC ! 30: char *ppcname = "ppc.p1"; ! 31: # ifdef DEBUG ! 32: char *ppcdname = "ppcd.p1"; ! 33: # endif ! 34: #endif ! 35: #ifdef PTREE ! 36: char *pTreeName = "pi.pTree"; ! 37: #endif ! 38: ! 39: /* ! 40: * Be careful changing errfile and howfile. ! 41: * There are the "magic" constants 9 and 15 immediately below. ! 42: */ ! 43: char *errfile = "/usr/lib/pi1.2strings"; ! 44: char *howfile = "/usr/lib/how_pi\0"; ! 45: ! 46: int onintr(); ! 47: ! 48: extern char *lastname; ! 49: ! 50: FILE *ibuf; ! 51: ! 52: /* ! 53: * these are made real variables ! 54: * so they can be changed ! 55: * if you are compiling on a smaller machine ! 56: */ ! 57: double MAXINT = 2147483647.; ! 58: double MININT = -2147483648.; ! 59: ! 60: /* ! 61: * Main program for pi. ! 62: * Process options, then call yymain ! 63: * to do all the real work. ! 64: */ ! 65: main(argc, argv) ! 66: int argc; ! 67: char *argv[]; ! 68: { ! 69: register char *cp; ! 70: register c; ! 71: int i; ! 72: ! 73: if (argv[0][0] == 'a') ! 74: errfile += 9, howfile += 9; ! 75: if (argv[0][0] == '-' && argv[0][1] == 'o') { ! 76: obj = &argv[0][2]; ! 77: usageis = pixusage; ! 78: howfile[15] = 'x'; ! 79: ofil = 3; ! 80: } else { ! 81: ofil = creat(obj, 0755); ! 82: if (ofil < 0) { ! 83: perror(obj); ! 84: pexit(NOSTART); ! 85: } ! 86: } ! 87: argv++, argc--; ! 88: if (argc == 0) { ! 89: i = fork(); ! 90: if (i == -1) ! 91: goto usage; ! 92: if (i == 0) { ! 93: execl("/bin/cat", "cat", howfile, 0); ! 94: goto usage; ! 95: } ! 96: while (wait(&i) != -1) ! 97: continue; ! 98: pexit(NOSTART); ! 99: } ! 100: opt('p') = opt('t') = opt('b') = 1; ! 101: while (argc > 0) { ! 102: cp = argv[0]; ! 103: if (*cp++ != '-') ! 104: break; ! 105: while (c = *cp++) switch (c) { ! 106: #ifdef DEBUG ! 107: case 'c': ! 108: case 'r': ! 109: case 'y': ! 110: togopt(c); ! 111: continue; ! 112: case 'C': ! 113: yycosts(); ! 114: pexit(NOSTART); ! 115: case 'A': ! 116: testtrace++; ! 117: case 'F': ! 118: fulltrace++; ! 119: case 'E': ! 120: errtrace++; ! 121: opt('r')++; ! 122: continue; ! 123: case 'U': ! 124: yyunique = 0; ! 125: continue; ! 126: # ifdef PPC ! 127: case 'P': ! 128: ppcdebug++; ! 129: continue; ! 130: # endif ! 131: #endif ! 132: case 'b': ! 133: opt('b') = 2; ! 134: continue; ! 135: case 'i': ! 136: pflist = argv + 1; ! 137: pflstc = 0; ! 138: while (argc > 1) { ! 139: if (dotted(argv[1], 'p')) ! 140: break; ! 141: pflstc++, argc--, argv++; ! 142: } ! 143: if (pflstc == 0) ! 144: goto usage; ! 145: continue; ! 146: case 'l': ! 147: case 'n': ! 148: case 'p': ! 149: case 's': ! 150: case 't': ! 151: case 'u': ! 152: case 'w': ! 153: togopt(c); ! 154: continue; ! 155: case 'z': ! 156: monflg++; ! 157: continue; ! 158: default: ! 159: usage: ! 160: Perror( "Usage", usageis); ! 161: pexit(NOSTART); ! 162: } ! 163: argc--, argv++; ! 164: } ! 165: if (argc != 1) ! 166: goto usage; ! 167: efil = open ( errfile, 0 ); ! 168: if ( efil < 0 ) ! 169: perror(errfile), pexit(NOSTART); ! 170: filename = argv[0]; ! 171: if (!dotted(filename, 'p')) { ! 172: Perror(filename, "Name must end in '.p'"); ! 173: pexit(NOSTART); ! 174: } ! 175: close(0); ! 176: if ( ( ibuf = fopen ( filename , "r" ) ) == NULL ) ! 177: perror(filename), pexit(NOSTART); ! 178: ibp = ibuf; ! 179: # ifdef PPC ! 180: if ( ( ppcstream = fopen( ppcname , "w" ) ) == NULL ) { ! 181: perror( ppcname ); ! 182: pexit( NOSTART ); ! 183: } ! 184: # ifdef DEBUG ! 185: if ( ppcdebug ) { ! 186: if ( ( ppcdstream = fopen( ppcdname , "w" ) ) == NULL ) { ! 187: perror( ppcdname ); ! 188: pexit( NOSTART ); ! 189: } ! 190: } ! 191: # endif ! 192: putprintf( "# compilation of %s" , filename ); ! 193: # endif ! 194: # ifdef PTREE ! 195: # define MAXpPAGES 16 ! 196: if ( ! pCreate( pTreeName , MAXpPAGES ) ) { ! 197: perror( pTreeName ); ! 198: pexit( NOSTART ); ! 199: } ! 200: # endif ! 201: if ((signal(2, 1) & 01) == 0) ! 202: signal(2, onintr); ! 203: if (opt('l')) { ! 204: opt('n')++; ! 205: yysetfile(filename); ! 206: opt('n')--; ! 207: } else ! 208: lastname = filename; ! 209: yymain(); ! 210: /* No return */ ! 211: } ! 212: ! 213: pchr(c) ! 214: char c; ! 215: { ! 216: ! 217: putc ( c , stdout ); ! 218: } ! 219: ! 220: char ugh[] = "Fatal error in pi\n"; ! 221: /* ! 222: * Exit from the Pascal system. ! 223: * We throw in an ungraceful termination ! 224: * message if c > 1 indicating a severe ! 225: * error such as running out of memory ! 226: * or an internal inconsistency. ! 227: */ ! 228: pexit(c) ! 229: int c; ! 230: { ! 231: ! 232: if (opt('l') && c != DIED && c != NOSTART) ! 233: while (getline() != -1) ! 234: continue; ! 235: yyflush(); ! 236: switch (c) { ! 237: case DIED: ! 238: write(2, ugh, sizeof ugh); ! 239: case NOSTART: ! 240: case ERRS: ! 241: if (ofil > 0) ! 242: unlink(obj); ! 243: break; ! 244: case AOK: ! 245: pflush(); ! 246: break; ! 247: } ! 248: /* ! 249: * this to gather statistics on programs being compiled ! 250: * taken 20 june 79 ... peter ! 251: * ! 252: * if (fork() == 0) { ! 253: * char *cp = "-0"; ! 254: * cp[1] += c; ! 255: * execl("/usr/lib/gather", "gather", cp, filename, 0); ! 256: * exit(1); ! 257: * } ! 258: */ ! 259: # ifdef PTREE ! 260: pFinish(); ! 261: # endif ! 262: exit(c); ! 263: } ! 264: ! 265: onintr() ! 266: { ! 267: ! 268: signal(2, 1); ! 269: pexit(NOSTART); ! 270: } ! 271: ! 272: /* ! 273: * Get an error message from the error message file ! 274: */ ! 275: geterr(seekpt, buf) ! 276: int seekpt; ! 277: char *buf; ! 278: { ! 279: ! 280: lseek(efil, (long) seekpt, 0); ! 281: if (read(efil, buf, 256) <= 0) ! 282: perror(errfile), pexit(DIED); ! 283: } ! 284: ! 285: header() ! 286: { ! 287: extern char version[]; ! 288: static char anyheaders; ! 289: ! 290: gettime( filename ); ! 291: if (anyheaders && opt('n')) ! 292: putc( '\f' , stdout ); ! 293: anyheaders++; ! 294: printf("Berkeley Pascal PI -- Version 1.2 (%s)\n\n%s %s\n\n", ! 295: version, myctime(&tvec), filename); ! 296: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.