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