1: #
   2: /*
   3:  *
   4:  *	UNIX debugger
   5:  *
   6:  */
   7: 
   8: #include "defs.h"
   9: 
  10: 
  11: INT     mkfault;
  12: INT     infile;
  13: INT     outfile 1;
  14: INT     maxpos;
  15: 
  16: CHAR        printbuf[MAXLIN];
  17: CHAR        *printptr printbuf;
  18: CHAR        *digitptr;
  19: 
  20: 
  21: eqstr(s1, s2)
  22:     REG STRING  s1, s2;
  23: {
  24:     REG STRING   es1;
  25:     es1 = s1+8;
  26:     WHILE *s1++ == *s2
  27:     DO IF *s2++ == 0 ORF s1>=es1
  28:        THEN return(1);
  29:        FI
  30:     OD
  31:     return(0);
  32: }
  33: 
  34: length(s)
  35:     STRING      s;
  36: {
  37:     INT     n 0;
  38:     WHILE *s++ DO n++; OD
  39:     return(n);
  40: }
  41: 
  42: printc(c)
  43:     CHAR        c;
  44: {
  45:     CHAR        d;
  46:     STRING      q;
  47:     INT     posn, tabs, p;
  48: 
  49:     IF mkfault
  50:     THEN    return;
  51:     ELIF (*printptr=c)==EOR
  52:     THEN tabs=0; posn=0; q=printbuf;
  53:          FOR p=0; p<printptr-printbuf; p++
  54:          DO d=printbuf[p];
  55:         IF (p&7)==0 ANDF posn
  56:         THEN tabs++; posn=0;
  57:         FI
  58:         IF d==SP
  59:         THEN posn++;
  60:         ELSE WHILE tabs>0 DO *q++=TB; tabs--; OD
  61:              WHILE posn>0 DO *q++=SP; posn--; OD
  62:              *q++=d;
  63:         FI
  64:          OD
  65:          *q++=EOR;
  66:          write(outfile,printbuf,q-printbuf);
  67:          printptr=printbuf;
  68:     ELIF c==TB
  69:     THEN *printptr++=SP;
  70:          WHILE (printptr-printbuf)&7 DO *printptr++=SP; OD
  71:     ELIF c
  72:     THEN printptr++;
  73:     FI
  74: }
  75: 
  76: charpos()
  77: {   return(printptr-printbuf);
  78: }
  79: 
  80: flushbuf()
  81: {   IF printptr!=printbuf
  82:     THEN printc(EOR);
  83:     FI
  84: }
  85: 
  86: printf(fmat,a1)
  87:     STRING      fmat;
  88:     STRING      *a1;
  89: {
  90:     STRING      fptr, s;
  91:     INT     *vptr;
  92:     L_INT       *dptr;
  93:     L_REAL      *rptr;
  94:     INT     width, prec;
  95:     CHAR        c, adj;
  96:     INT     x, decpt, n;
  97:     L_INT       lx;
  98:     CHAR        digits[64];
  99: 
 100:     fptr = fmat; vptr = &a1;
 101: 
 102:     WHILE c = *fptr++
 103:     DO  IF c!='%'
 104:         THEN printc(c);
 105:         ELSE IF *fptr=='-' THEN adj='l'; fptr++; ELSE adj='r'; FI
 106:          width=convert(&fptr);
 107:          IF *fptr=='.' THEN fptr++; prec=convert(&fptr); ELSE prec = -1; FI
 108:          digitptr=digits;
 109:          dptr=rptr=vptr; lx = *dptr; x = *vptr++;
 110:          s=0;
 111:          switch (c = *fptr++) {
 112: 
 113:             case 'd':
 114:             case 'u':
 115:             printnum(x,c,10); break;
 116:             case 'o':
 117:             printoct(0,x,0); break;
 118:             case 'q':
 119:             lx=x; printoct(lx,-1); break;
 120:             case 'x':
 121:             printdbl(0,x,c,16); break;
 122:             case 'Y':
 123:             printdate(lx); vptr++; break;
 124:             case 'D':
 125:             case 'U':
 126:             printdbl(lx,c,10); vptr++; break;
 127:             case 'O':
 128:             printoct(lx,0); vptr++; break;
 129:             case 'Q':
 130:             printoct(lx,-1); vptr++; break;
 131:             case 'X':
 132:             printdbl(lx,'x',16); vptr++; break;
 133:             case 'c':
 134:             printc(x); break;
 135:             case 's':
 136:             s=x; break;
 137:             case 'f':
 138:             case 'F':
 139:             vptr += 7;
 140:             s=ecvt(*rptr, prec, &decpt, &n);
 141:             *digitptr++=(n?'-':'+');
 142:             *digitptr++ = (decpt<=0 ? '0' : *s++);
 143:             IF decpt>0 THEN decpt--; FI
 144:             *digitptr++ = '.';
 145:             WHILE *s ANDF prec-- DO *digitptr++ = *s++; OD
 146:             WHILE *--digitptr=='0' DONE
 147:             digitptr += (digitptr-digits>=3 ? 1 : 2);
 148:             IF decpt
 149:             THEN *digitptr++ = 'e'; printnum(decpt,'d',10);
 150:             FI
 151:             s=0; prec = -1; break;
 152:             case 'm':
 153:             vptr--; break;
 154:             case 'M':
 155:             width=x; break;
 156:             case 'T':
 157:             case 't':
 158:             IF c=='T'
 159:             THEN width=x;
 160:             ELSE vptr--;
 161:             FI
 162:             IF width
 163:             THEN width -= charpos()%width;
 164:             FI
 165:             break;
 166:             default:
 167:             printc(c); vptr--;
 168:         }
 169: 
 170:         IF s==0
 171:         THEN *digitptr=0; s=digits;
 172:         FI
 173:         n=length(s);
 174:         n=(prec<n ANDF prec>=0 ? prec : n);
 175:         width -= n;
 176:         IF adj=='r'
 177:         THEN WHILE width-- > 0
 178:              DO printc(SP); OD
 179:         FI
 180:         WHILE n-- DO printc(*s++); OD
 181:         WHILE width-- > 0 DO printc(SP); OD
 182:         digitptr=digits;
 183:         FI
 184:     OD
 185: }
 186: 
 187: printdate(tvec)
 188:     L_INT       tvec;
 189: {
 190:     REG INT     i;
 191:     REG STRING  timeptr;
 192:     timeptr = ctime(&tvec);
 193:     FOR i=20; i<24; i++ DO *digitptr++ = *(timeptr+i); OD
 194:     FOR i=3; i<19; i++ DO *digitptr++ = *(timeptr+i); OD
 195: } /*printdate*/
 196: 
 197: prints(s)
 198: char *s;
 199: {   printf("%s",s);
 200: }
 201: 
 202: newline()
 203: {
 204:     printc(EOR);
 205: }
 206: 
 207: convert(cp)
 208: REG STRING  *cp;
 209: {
 210:     REG CHAR    c;
 211:     INT     n;
 212:     n=0;
 213:     WHILE ((c = *(*cp)++)>='0') ANDF (c<='9') DO n=n*10+c-'0'; OD
 214:     (*cp)--;
 215:     return(n);
 216: }
 217: 
 218: printnum(n,fmat,base)
 219:     REG INT     n;
 220: {
 221:     REG CHAR    k;
 222:     REG INT     *dptr;
 223:     INT     digs[15];
 224:     dptr=digs;
 225:     IF n<0 ANDF fmat=='d' THEN n = -n; *digitptr++ = '-'; FI
 226:     WHILE n
 227:     DO  *dptr++ = ((POS)n)%base;
 228:         n=((POS)n)/base;
 229:     OD
 230:     IF dptr==digs THEN *dptr++=0; FI
 231:     WHILE dptr!=digs
 232:     DO  k = *--dptr;
 233:         *digitptr++ = (k+(k<=9 ? '0' : 'a'-10));
 234:     OD
 235: }
 236: 
 237: printoct(o,s)
 238:     L_INT       o;
 239:     INT     s;
 240: {
 241:     INT     i;
 242:     L_INT       po = o;
 243:     CHAR        digs[12];
 244: 
 245:     IF s
 246:     THEN IF po<0
 247:          THEN po = -po; *digitptr++='-';
 248:          ELSE IF s>0 THEN *digitptr++='+'; FI
 249:          FI
 250:     FI
 251:     FOR i=0;i<=11;i++
 252:     DO digs[i] = po&7; po =>> 3; OD
 253:     digs[10] &= 03; digs[11]=0;
 254:     FOR i=11;i>=0;i--
 255:     DO IF digs[i] THEN break; FI OD
 256:     FOR i++;i>=0;i--
 257:     DO *digitptr++=digs[i]+'0'; OD
 258: }
 259: 
 260: printdbl(lx,ly,fmat,base)
 261: INT lx, ly; char fmat; int base;
 262: {   int digs[20]; int *dptr; char k;
 263:     L_REAL f ,g; long q;
 264:     dptr=digs;
 265:     IF fmat!='D'
 266:     THEN    f=leng(lx); f *= itol(1,0); f += leng(ly);
 267:         IF fmat=='x' THEN *digitptr++='#'; FI
 268:     ELSE    f=itol(lx,ly);
 269:         IF f<0 THEN *digitptr++='-'; f = -f; FI
 270:     FI
 271:     WHILE f
 272:     DO  q=f/base; g=q;
 273:         *dptr++ = f-g*base;
 274:         f=q;
 275:     OD
 276:     IF dptr==digs THEN *dptr++=0; FI
 277:     WHILE dptr!=digs
 278:     DO  k = *--dptr;
 279:         *digitptr++ = (k+(k<=9 ? '0' : 'a'-10));
 280:     OD
 281: }
 282: 
 283: iclose()
 284: {
 285:     IF infile
 286:     THEN    close(infile); infile=0;
 287:     FI
 288: }
 289: 
 290: oclose()
 291: {
 292:     IF outfile!=1
 293:     THEN    flushbuf(); close(outfile); outfile=1;
 294:     FI
 295: }
 296: 
 297: endline()
 298: {
 299:     IF charpos()>=maxpos
 300:     THEN printf("\n");
 301:     FI
 302: }

Defined functions

charpos defined in line 76; used 3 times
convert defined in line 207; used 2 times
endline defined in line 297; used 2 times
eqstr defined in line 21; used 5 times
iclose defined in line 283; used 3 times
length defined in line 34; used 1 times
newline defined in line 202; used 1 times
oclose defined in line 290; used 2 times
printc defined in line 42; used 39 times
printdate defined in line 187; used 1 times
printdbl defined in line 260; used 3 times
printf defined in line 86; used 82 times
printnum defined in line 218; used 2 times
printoct defined in line 237; used 4 times
Last modified: 1982-02-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1153
Valid CSS Valid XHTML 1.0 Strict