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