Annotation of 43BSDTahoe/ucb/pascal/pdx/main/main.c, revision 1.1

1.1     ! root        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: char copyright[] =
        !             9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
        !            10:  All rights reserved.\n";
        !            11: #endif not lint
        !            12: 
        !            13: #ifndef lint
        !            14: static char sccsid[] = "@(#)main.c     5.2 (Berkeley) 4/7/87";
        !            15: #endif not lint
        !            16: 
        !            17: /*
        !            18:  * Debugger main routine.
        !            19:  */
        !            20: 
        !            21: #include "defs.h"
        !            22: #include <setjmp.h>
        !            23: #include <signal.h>
        !            24: #include "main.h"
        !            25: #include "command.h"
        !            26: #include "process.h"
        !            27: #include "object.h"
        !            28: 
        !            29: #define FIRST_TIME 0        /* initial value setjmp returns */
        !            30: 
        !            31: LOCAL int firstarg;
        !            32: LOCAL jmp_buf env;
        !            33: LOCAL catchintr();
        !            34: 
        !            35: main(argc, argv)
        !            36: int argc;
        !            37: char **argv;
        !            38: {
        !            39:     FILE *fp;
        !            40:     int i;
        !            41: 
        !            42: #ifdef lint
        !            43:     syserr();
        !            44: #endif
        !            45:     catchsigs();
        !            46:     scanargs(argc, argv);
        !            47:     cmdname = argv[0];
        !            48:     if ((fp = fopen(objname, "r")) == NIL) {
        !            49:        panic("can't read %s", objname);
        !            50:     } else {
        !            51:        fclose(fp);
        !            52:     }
        !            53:     if (option('r')) {
        !            54:        if (setjmp(env) == FIRST_TIME) {
        !            55:            arginit();
        !            56:            for (i = firstarg; i < argc; i++) {
        !            57:                newarg(argv[i]);
        !            58:            }
        !            59:            run();
        !            60:            /* NOTREACHED */
        !            61:        } else {
        !            62:            option('r') = FALSE;
        !            63:        }
        !            64:     } else {
        !            65:        initstart();
        !            66:        prompt();
        !            67:        init();
        !            68:     }
        !            69:     setjmp(env);
        !            70:     signal(SIGINT, catchintr);
        !            71:     yyparse();
        !            72:     putchar('\n');
        !            73:     quit(0);
        !            74: }
        !            75: 
        !            76: /*
        !            77:  * Initialize the world, including setting initial input file
        !            78:  * if the file exists.
        !            79:  */
        !            80: 
        !            81: init()
        !            82: {
        !            83:     initinput();
        !            84:     readobj(objname);
        !            85:     lexinit();
        !            86: }
        !            87: 
        !            88: /*
        !            89:  * After a non-fatal error we jump back to command parsing.
        !            90:  */
        !            91: 
        !            92: erecover()
        !            93: {
        !            94:     gobble();
        !            95:     prompt();
        !            96:     longjmp(env, 1);
        !            97: }
        !            98: 
        !            99: /*
        !           100:  * This routine is called when an interrupt occurs.
        !           101:  */
        !           102: 
        !           103: LOCAL catchintr()
        !           104: {
        !           105:     putchar('\n');
        !           106:     prompt();
        !           107:     longjmp(env, 1);
        !           108: }
        !           109: 
        !           110: /*
        !           111:  * scan the argument list
        !           112:  */
        !           113: 
        !           114: LOCAL scanargs(argc, argv)
        !           115: int argc;
        !           116: char **argv;
        !           117: {
        !           118:     register int i, j;
        !           119:     BOOLEAN done;
        !           120: 
        !           121:     if (streq(argv[0], "pxhdr") || streq(argv[0], "pix")) {
        !           122:        objname = argv[1];
        !           123:        option('r') = TRUE;
        !           124:        option('t') = TRUE;
        !           125:        if (streq(argv[0], "pxhdr")) {
        !           126:            setargs("pdx", argv[2]);
        !           127:            firstarg = 3;
        !           128:        } else {
        !           129:            setargs("pix", NIL);
        !           130:            firstarg = 2;
        !           131:        }
        !           132:        argv[0] = "pdx";
        !           133:     } else {
        !           134:        done = FALSE;
        !           135:        i = 1;
        !           136:        while (i < argc && !done) {
        !           137:            if (argv[i][0] == '-') {
        !           138:                for (j = 1; argv[i][j] != '\0'; j++) {
        !           139:                    switch (argv[i][j]) {
        !           140:                        case 'r':   /* run program before accepting commands */
        !           141:                        case 'i':   /* assume input is a terminal */
        !           142:                        case 'b':   /* (internal) trace breakpoints */
        !           143:                        case 'e':   /* (internal) trace execution */
        !           144:                        case 'h':   /* (internal) display header information */
        !           145:                            option(argv[i][j]) = TRUE;
        !           146:                            break;
        !           147: 
        !           148:                    default:
        !           149:                        panic("bad option \"%c\"", argv[i]);
        !           150:                    }
        !           151:                }
        !           152:            } else {
        !           153:                objname = argv[i];
        !           154:                done = TRUE;
        !           155:            }
        !           156:            i++;
        !           157:        }
        !           158:        firstarg = i;
        !           159:        setargs("pdx", objname);
        !           160:     }
        !           161: }
        !           162: 
        !           163: /*
        !           164:  * Terminate program.  In the case of the -t option, we must remove
        !           165:  * the object file because it's a tmp file.
        !           166:  */
        !           167: 
        !           168: quit(r)
        !           169: int r;
        !           170: {
        !           171:     if (option('t')) {
        !           172:        unlink(objname);
        !           173:     }
        !           174:     exit(r);
        !           175: }
        !           176: 
        !           177: LOCAL catchsigs()
        !           178: {
        !           179:     signal(SIGHUP, quit);
        !           180:     signal(SIGQUIT, quit);
        !           181: }

unix.superglobalmegacorp.com

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