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