Annotation of cci/usr/src/bin/adb/main.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * adb - main command loop and error/interrupt handling
                      3:  */
                      4: #include "defs.h"
                      5: 
                      6: MSG            NOEOR;
                      7: 
                      8: INT            mkfault;
                      9: INT            executing;
                     10: INT            infile;
                     11: CHAR           *lp;
                     12: L_INT          maxoff;
                     13: L_INT          maxpos;
                     14: SIG            sigint;
                     15: SIG            sigqit;
                     16: INT            wtflag;
                     17: STRING         errflg;
                     18: L_INT          exitflg;
                     19: 
                     20: CHAR           lastc;
                     21: INT            eof;
                     22: 
                     23: INT            lastcom;
                     24: 
                     25: L_INT  maxoff = MAXOFF;
                     26: L_INT  maxpos = MAXPOS;
                     27: 
                     28: main(argc, argv)
                     29:        register char **argv;
                     30:        int argc;
                     31: {
                     32: 
                     33:        mkioptab();
                     34:        while (argc>1 && !strcmp("-w", argv[1])) {
                     35:                wtflag = 2;             /* suitable for open() */
                     36:                argc--, argv++;
                     37:        }
                     38:        while (argc>1 && !strcmp("-k", argv[1])) {
                     39:                kernel = 1;
                     40:                argc--, argv++;
                     41:        }
                     42:        if (argc > 1)
                     43:                symfil = argv[1];
                     44:        if (argc > 2)
                     45:                corfil = argv[2];
                     46:        xargc = argc;
                     47:        setsym(); setcor(); setvar();
                     48: 
                     49:        if ((sigint=signal(SIGINT,SIG_IGN)) != SIG_IGN) {
                     50:                sigint = fault;
                     51:                signal(SIGINT, fault);
                     52:        }
                     53:        sigqit = signal(SIGQUIT, SIG_IGN);
                     54:        setexit();
                     55:        if (executing)
                     56:                delbp();
                     57:        executing = 0;
                     58:        for (;;) {
                     59:                flushbuf();
                     60:                if (errflg) {
                     61:                        printf("%s\n", errflg);
                     62:                        exitflg = 1;
                     63:                        errflg = 0;
                     64:                }
                     65:                if (mkfault) {
                     66:                        mkfault=0;
                     67:                        printc('\n');
                     68:                        printf(DBNAME);
                     69:                }
                     70:                lp=0; rdc(); lp--;
                     71:                if (eof) {
                     72:                        if (infile) {
                     73:                                iclose(); eof=0; reset();
                     74:                        } else
                     75:                                done();
                     76:                } else
                     77:                        exitflg = 0;
                     78:                command(0, lastcom);
                     79:                if (lp && lastc!='\n')
                     80:                        error(NOEOR);
                     81:        }
                     82: }
                     83: 
                     84: done()
                     85: {
                     86:        endpcs();
                     87:        exit(exitflg);
                     88: }
                     89: 
                     90: L_INT
                     91: round(a,b)
                     92: REG L_INT a, b;
                     93: {
                     94:        REG L_INT w;
                     95:        w = (a/b)*b;
                     96:        IF a!=w THEN w += b; FI
                     97:        return(w);
                     98: }
                     99: 
                    100: /*
                    101:  * If there has been an error or a fault, take the error.
                    102:  */
                    103: chkerr()
                    104: {
                    105:        if (errflg || mkfault)
                    106:                error(errflg);
                    107: }
                    108: 
                    109: /*
                    110:  * An error occurred; save the message for later printing,
                    111:  * close open files, and reset to main command loop.
                    112:  */
                    113: error(n)
                    114:        char *n;
                    115: {
                    116:        errflg = n;
                    117:        iclose(); oclose();
                    118:        reset();
                    119: }
                    120: 
                    121: /*
                    122:  * An interrupt occurred; reset the interrupt
                    123:  * catch, seek to the end of the current file
                    124:  * and remember that there was a fault.
                    125:  */
                    126: fault(a)
                    127: {
                    128:        signal(a, fault);
                    129:        lseek(infile, 0L, 2);
                    130:        mkfault++;
                    131: }

unix.superglobalmegacorp.com

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