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

Defined functions

done defined in line 96; used 2 times
fault defined in line 138; used 4 times
main defined in line 31; never used
round defined in line 102; used 4 times

Defined variables

Ipath defined in line 29; used 1 times
  • in line 50
maxoff defined in line 27; used 1 times
  • in line 13
maxpos defined in line 28; used 1 times
  • in line 14
sccsid defined in line 1; never used
Last modified: 1982-10-27
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1070
Valid CSS Valid XHTML 1.0 Strict