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