Annotation of 41BSD/cmd/px/int.c, revision 1.1.1.1

1.1       root        1: /* Copyright (c) 1979 Regents of the University of California */
                      2: 
                      3: static char sccsid[] = "@(#)int.c 4.1 10/10/80";
                      4: 
                      5: /*
                      6:  * px - interpreter for Berkeley Pascal
                      7:  * Version 2.0 Winter 1979
                      8:  *
                      9:  * Original version for the PDP 11/70 authored by:
                     10:  * Bill Joy, Charles Haley, Ken Thompson
                     11:  *
                     12:  * Rewritten for VAX 11/780 by Kirk McKusick
                     13:  */
                     14: 
                     15: #include       "stdio.h"
                     16: #include       "signal.h"
                     17: #include       "h00vars.h"
                     18: #include       "objfmt.h"
                     19: 
                     20: main(ac,av)
                     21: 
                     22: long   ac;
                     23: char   **av;
                     24: 
                     25: {
                     26: extern  intr();
                     27: extern  memsize();
                     28: extern  except();
                     29: extern  syserr();
                     30: extern  char *malloc();
                     31: extern   long createtime;
                     32: struct  pxhdr pxhd;
                     33: register long bytesread, block;
                     34: register char *objprog;
                     35: register FILE *prog;
                     36: #define         pipe 3
                     37: #define         pipesize 4096
                     38: 
                     39: /*
                     40:  * Initialize everything
                     41:  */
                     42: argc = ac;
                     43: argv = av;
                     44: stcnt = 0;
                     45: stlim = 500000;
                     46: llimit = 0x7fffffff;   /* set to unlimited */
                     47: nodump = 0;
                     48: 
                     49: /*
                     50:  * Determine how PX was invoked, and how to process the program 
                     51:  */
                     52: if (argv[0][0] == '-' && argv[0][1] == 'o')
                     53:        {
                     54:        file = &argv[0][2];
                     55:        mode = PIX;
                     56:        }
                     57: else if (argc <= 1)
                     58:        {
                     59:        file = "obj";
                     60:        mode = PX;
                     61:        }
                     62: else if (argv[1][0] != '-')
                     63:        {
                     64:        file = argv[1];
                     65:        mode = PX;
                     66:        }
                     67: else if (argv[1][1] == 0)
                     68:        {
                     69:        file = argv[0];
                     70:        mode = PIPE;
                     71:        argc -= 1;
                     72:        argv[1] = argv[0];
                     73:        argv = &argv[1];
                     74:        }
                     75: else
                     76:        {
                     77:        fputs("Improper specification of object file to PX\n",stderr);
                     78:        exit(1);
                     79:        }
                     80: 
                     81: /*
                     82:  * Process program header information
                     83:  */
                     84: if (mode == PIPE)
                     85:        read(pipe,&pxhd,sizeof(struct pxhdr));
                     86: else
                     87:        {
                     88:        prog = fopen(file,"r");
                     89:        if (prog == NULL)
                     90:                {
                     91:                perror(file);
                     92:                exit(1);
                     93:                }
                     94:        fseek(prog,HEADER_BYTES-sizeof(struct pxhdr),0);
                     95:        fread(&pxhd,sizeof(struct pxhdr),1,prog);
                     96:        }
                     97: if (pxhd.maketime < createtime)
                     98:        {
                     99:        fprintf(stderr,"%s is obsolete and must be recompiled\n",file);
                    100:        exit(1);
                    101:        }
                    102: if (pxhd.magicnum != 0403)
                    103:        {
                    104:        fprintf(stderr,"%s is not a Pascal program\n",file);
                    105:        exit(1);
                    106:        }
                    107: 
                    108: /*
                    109:  * Load program into memory
                    110:  */
                    111: objprog = malloc(pxhd.objsize);
                    112: if (mode == PIPE)
                    113:        {
                    114:        bytesread = 0;
                    115:        do
                    116:                {
                    117:                block = read(pipe,objprog+bytesread,pipesize);
                    118:                bytesread += block;
                    119:                }
                    120:                while (block);
                    121:        }
                    122: else
                    123:        {
                    124:        bytesread = fread(objprog,1,pxhd.objsize,prog);
                    125:        fclose(prog);
                    126:        if (mode == PIX)
                    127:                unlink(file);
                    128:        }
                    129: if (bytesread != pxhd.objsize)
                    130:        {
                    131:        fprintf(stderr,"Read error occurred while loading %s\n",file);
                    132:        exit(1);
                    133:        }
                    134: if (mode == PIX)
                    135:        fputs("Execution begins...\n",stderr);
                    136: /*
                    137:  * set interpreter to catch expected signals and begin interpretation
                    138:  */
                    139: signal(SIGILL,syserr);
                    140: signal(SIGBUS,syserr);
                    141: signal(SIGSYS,syserr);
                    142: if (signal(SIGINT,SIG_IGN) != SIG_IGN)
                    143:        signal(SIGINT,intr);
                    144: signal(SIGSEGV,memsize);
                    145: signal(SIGFPE,except);
                    146: #ifdef profile
                    147: interpret(objprog,1);
                    148: #else
                    149: interpret(objprog,0);
                    150: #endif
                    151: /*
                    152:  * reset signals, deallocate memory, and exit normally
                    153:  */
                    154: signal(SIGINT,SIG_IGN);
                    155: signal(SIGSEGV,SIG_DFL);
                    156: signal(SIGFPE,SIG_DFL);
                    157: pflush();
                    158: /* pfree(objprog); */
                    159: psexit(0);
                    160: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.