* pi - Pascal interpreter code translator
* Charles Haley, Bill Joy UCB
* Version 1.0 August 1977
* This program is described in detail in the "PI 1.0 Implementation Notes"
* This version of pi has been in use at Berkeley since May 1977
* and is very stable, except for the syntactic error recovery which
* has just been written. Please report any problems with the error
* recovery to the second author at the address given in the file
* READ_ME. The second author takes full responsibility for any bugs
* in the syntactic error recovery.
char piusage
[] "pi [ -blnpstuw ] [ -i file ... ] name.p";
char pixusage
[] "pix [ -blnpstuw ] [ -i file ... ] name.p [ arg ... ]";
* Be careful changing errfile and howfile.
* There are the "magic" constants 9 and 15 immediately below.
char *errfile
"/usr/lib/pi_strings";
char *howfile
"/usr/lib/how_pi\0";
* Process options, then call yymain
* to do all the real work.
errfile
=+ 9, howfile
=+ 9;
if (argv
[0][0] == '-' && argv
[0][1] == 'o') {
execl("/bin/cat", "cat", howfile
, 0);
opt('p') = opt('t') = opt('b') = 1;
while (c
= *cp
++) switch (c
) {
if (dotted(argv
[1], 'p'))
pflstc
++, argc
--, argv
++;
Perror( "Usage", usageis
);
perror(errfile
), pexit(NOSTART
);
if (!dotted(filename
, 'p')) {
Perror(filename
, "Name must end in '.p'");
if (fopen(filename
, ibuf
) < 0)
perror(filename
), pexit(NOSTART
);
if ((signal(2, 1) & 01) == 0)
* Line buffered putchar for pi.
if (c
== '\n' || pcbp
== &pcbuf
[sizeof pcbuf
-1]) {
write(1, &pcbuf
, pcbp
-pcbuf
);
char ugh
[] "Fatal error in pi\n";
* Exit from the Pascal system.
* We throw in an ungraceful termination
* message if c > 1 indicating a severe
* error such as running out of memory
* or an internal inconsistency.
if (opt('l') && c
!= DIED
&& c
!= NOSTART
)
write(2, ugh
, sizeof ugh
);
* Get an error message from the error message file
if (seek(efil
, seekpt
, 0) || read(efil
, buf
, 256) <= 0)
perror(errfile
), pexit(DIED
);
if (anyheaders
&& opt('n'))
printf("UNIX Pascal PI -- Version 1.0 (%s)\n\n%s %s\n\n", version
, myctime(tvec
), filename
);