Annotation of researchv8dc/cmd/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: #include <signal.h>
                      6: #include <setjmp.h>
                      7: 
                      8: MSG    NOEOR;
                      9: 
                     10: char *errflg;
                     11: BOOL wtflag;
                     12: 
                     13: BOOL mkfault;
                     14: ADDR maxoff;
                     15: 
                     16: int xargc;             /* bullshit */
                     17: 
                     18: BOOL   executing;
                     19: int    infile;
                     20: char   *lp;
                     21: static int     exitflg;
                     22: int    (*sigint)();
                     23: int    (*sigqit)();
                     24: 
                     25: char   lastc;
                     26: int    eof;
                     27: 
                     28: char   *Ipath = "/usr/lib/adb";
                     29: static jmp_buf env;
                     30: 
                     31: main(argc, argv)
                     32: register char **argv;
                     33: int argc;
                     34: {
                     35:        extern fault();
                     36: 
                     37:        mkioptab();
                     38:        maxoff = MAXOFF;
                     39: another:
                     40:        if (argc>1) {
                     41:                if (strcmp("-w", argv[1]) == 0) {
                     42:                        wtflag = 2;             /* suitable for open() */
                     43:                        argc--, argv++;
                     44:                        goto another;
                     45:                }
                     46:                if (argv[1][0] == '-' && argv[1][1] == 'I') {
                     47:                        Ipath = argv[1]+2;
                     48:                        argc--, argv++;
                     49:                }
                     50:        }
                     51:        if (argc > 1)
                     52:                symfil = argv[1];
                     53:        if (argc > 2)
                     54:                corfil = argv[2];
                     55:        xargc = argc;
                     56:        setsym();
                     57:        setcor();
                     58:        setvar();
                     59: 
                     60:        if ((sigint=signal(SIGINT,SIG_IGN)) != SIG_IGN) {
                     61:                sigint = fault;
                     62:                signal(SIGINT, fault);
                     63:        }
                     64:        sigqit = signal(SIGQUIT, SIG_IGN);
                     65:        setjmp(env);
                     66:        if (executing)
                     67:                delbp();
                     68:        executing = 0;
                     69:        for (;;) {
                     70:                flushbuf();
                     71:                if (errflg) {
                     72:                        printf("%s\n", errflg);
                     73:                        exitflg = 1;
                     74:                        errflg = 0;
                     75:                }
                     76:                if (mkfault) {
                     77:                        mkfault=0;
                     78:                        printc('\n');
                     79:                        prints(DBNAME);
                     80:                }
                     81:                clrinp();
                     82:                rdc();
                     83:                reread();
                     84:                if (eof) {
                     85:                        if (infile == STDIN)
                     86:                                done();
                     87:                        iclose(-1, 0);
                     88:                        eof = 0;
                     89:                        longjmp(env, 1);
                     90:                }
                     91:                exitflg = 0;
                     92:                command((char *)NULL, 0);
                     93:                reread();
                     94:                if (rdc() != '\n')
                     95:                        error(NOEOR);
                     96:        }
                     97: }
                     98: 
                     99: done()
                    100: {
                    101:        if (pid)
                    102:                endpcs();
                    103:        exit(exitflg);
                    104: }
                    105: 
                    106: WORD
                    107: round(a,b)
                    108: register WORD a, b;
                    109: {
                    110:        register WORD w;
                    111: 
                    112:        w = (a/b)*b;
                    113:        if (a!=w)
                    114:                w += b;
                    115:        return(w);
                    116: }
                    117: 
                    118: /*
                    119:  * If there has been an error or a fault, take the error.
                    120:  */
                    121: chkerr()
                    122: {
                    123:        if (errflg || mkfault)
                    124:                error(errflg);
                    125: }
                    126: 
                    127: /*
                    128:  * An error occurred; save the message for later printing,
                    129:  * close open files, and reset to main command loop.
                    130:  */
                    131: error(n)
                    132: char *n;
                    133: {
                    134:        errflg = n;
                    135:        iclose(0, 1);
                    136:        oclose();
                    137:        longjmp(env, 1);
                    138: }
                    139: 
                    140: /*
                    141:  * An interrupt occurred; reset the interrupt
                    142:  * catch, seek to the end of the current file
                    143:  * and remember that there was a fault.
                    144:  */
                    145: fault(a)
                    146: {
                    147:        signal(a, fault);
                    148:        lseek(infile, 0L, 2);
                    149:        mkfault++;
                    150: }

unix.superglobalmegacorp.com

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