1: #ifndef lint
   2: static  char sccsid[] = "@(#)output.c	4.4 4/26/85";
   3: #endif
   4: /*
   5:  *
   6:  *	UNIX debugger
   7:  *
   8:  */
   9: 
  10: #include "defs.h"
  11: #include <stdio.h>
  12: 
  13: 
  14: INT     mkfault;
  15: INT     infile;
  16: INT     outfile = 1;
  17: L_INT       maxpos;
  18: L_INT       maxoff;
  19: INT     radix = 16;
  20: 
  21: CHAR        printbuf[MAXLIN];
  22: CHAR        *printptr = printbuf;
  23: CHAR        *digitptr;
  24: MSG     TOODEEP;
  25: 
  26: 
  27: eqstr(s1, s2)
  28:     REG STRING  s1, s2;
  29: {
  30:     REG STRING   es1;
  31:     WHILE *s1++ == *s2
  32:     DO IF *s2++ == 0
  33:        THEN return(1);
  34:        FI
  35:     OD
  36:     return(0);
  37: }
  38: 
  39: length(s)
  40:     REG STRING      s;
  41: {
  42:     INT     n = 0;
  43:     WHILE *s++ DO n++; OD
  44:     return(n);
  45: }
  46: 
  47: printc(c)
  48:     CHAR        c;
  49: {
  50:     CHAR        d;
  51:     STRING      q;
  52:     INT     posn, tabs, p;
  53: 
  54:     IF mkfault
  55:     THEN    return;
  56:     ELIF (*printptr=c)==EOR
  57:     THEN tabs=0; posn=0; q=printbuf;
  58:          FOR p=0; p<printptr-printbuf; p++
  59:          DO d=printbuf[p];
  60:         IF (p&7)==0 ANDF posn
  61:         THEN tabs++; posn=0;
  62:         FI
  63:         IF d==SP
  64:         THEN posn++;
  65:         ELSE WHILE tabs>0 DO *q++=TB; tabs--; OD
  66:              WHILE posn>0 DO *q++=SP; posn--; OD
  67:              *q++=d;
  68:         FI
  69:          OD
  70:          *q++=EOR;
  71: #ifdef EDDT
  72:         printptr=printbuf; do putchar(*printptr++); while (printptr<q);
  73: #else
  74:          write(outfile,printbuf,q-printbuf);
  75: #endif
  76:          printptr=printbuf;
  77:     ELIF c==TB
  78:     THEN *printptr++=SP;
  79:          WHILE (printptr-printbuf)&7 DO *printptr++=SP; OD
  80:     ELIF c
  81:     THEN printptr++;
  82:     FI
  83:     IF printptr >= &printbuf[MAXLIN-9] THEN
  84:         write(outfile, printbuf, printptr - printbuf);
  85:         printptr = printbuf;
  86:     FI
  87: }
  88: 
  89: charpos()
  90: {   return(printptr-printbuf);
  91: }
  92: 
  93: flushbuf()
  94: {   IF printptr!=printbuf
  95:     THEN printc(EOR);
  96:     FI
  97: }
  98: 
  99: printf(fmat,a1)
 100:     STRING      fmat;
 101:     STRING      *a1;
 102: {
 103:     STRING      fptr, s;
 104:     INT     *vptr;
 105:     L_INT       *dptr;
 106:     L_REAL      *rptr;
 107:     INT     width, prec;
 108:     CHAR        c, adj;
 109:     INT     x, decpt, n;
 110:     L_INT       lx;
 111:     CHAR        digits[64];
 112: 
 113:     fptr = fmat; dptr = vptr = &a1;
 114: 
 115:     WHILE c = *fptr++
 116:     DO  IF c!='%'
 117:         THEN printc(c);
 118:         ELSE IF *fptr=='-' THEN adj='l'; fptr++; ELSE adj='r'; FI
 119:          width=convert(&fptr);
 120:          IF *fptr=='.' THEN fptr++; prec=convert(&fptr); ELSE prec = -1; FI
 121:          digitptr=digits;
 122: #ifndef vax
 123:          dptr=rptr=vptr; lx = *dptr; x = *vptr++;
 124: #else
 125:          rptr=dptr; x = shorten(lx = *dptr++);
 126: #endif
 127:          s=0;
 128:          switch (c = *fptr++) {
 129: 
 130:             case 'd':
 131:             case 'u':
 132:             printnum(x,c,10); break;
 133:             case 'o':
 134: #ifndef vax
 135:             printoct(0,x,0); break;
 136: #else
 137:             printoct(itol(0,x),0); break;
 138: #endif
 139:             case 'q':
 140:             lx=x; printoct(lx,-1); break;
 141:             case 'x':
 142: #ifndef vax
 143:             printdbl(0,x,c,16); break;
 144: #else
 145:             printdbl(itol(0,x),c,16); break;
 146: #endif
 147:             case 'r':
 148:             printdbl(lx=x,c,radix); break;
 149:             case 'R':
 150:             printdbl(lx,c,radix); vptr++; break;
 151:             case 'Y':
 152:             printdate(lx); vptr++; break;
 153:             case 'D':
 154:             case 'U':
 155:             printdbl(lx,c,10); vptr++; break;
 156:             case 'O':
 157:             printoct(lx,0); vptr++; break;
 158:             case 'Q':
 159:             printoct(lx,-1); vptr++; break;
 160:             case 'X':
 161:             printdbl(lx,'x',16); vptr++; break;
 162:             case 'c':
 163:             printc(x); break;
 164:             case 's':
 165: #ifndef vax
 166:             s=x; break;
 167: #else
 168:             s=lx; break;
 169: #endif
 170: #ifndef EDDT
 171:             case 'f':
 172:             case 'F':
 173: #ifdef vax
 174:             dptr++;
 175:             sprintf(s=digits,"%+.16e",*rptr,*(rptr+4)); prec= -1; break;
 176: #else
 177:             vptr += 7;
 178:             s=ecvt(*rptr, prec, &decpt, &n);
 179:             *digitptr++=(n?'-':'+');
 180:             *digitptr++ = (decpt<=0 ? '0' : *s++);
 181:             IF decpt>0 THEN decpt--; FI
 182:             *digitptr++ = '.';
 183:             WHILE *s ANDF prec-- DO *digitptr++ = *s++; OD
 184:             WHILE *--digitptr=='0' DONE
 185:             digitptr += (digitptr-digits>=3 ? 1 : 2);
 186:             IF decpt
 187:             THEN *digitptr++ = 'e'; printnum(decpt,'d',10);
 188:             FI
 189:             s=0; prec = -1; break;
 190: #endif
 191: #endif
 192:             case 'm':
 193:             vptr--; break;
 194:             case 'M':
 195:             width=x; break;
 196:             case 'T':
 197:             case 't':
 198:             IF c=='T'
 199:             THEN width=x;
 200: #ifndef vax
 201:             ELSE vptr--;
 202: #else
 203:             ELSE dptr--;
 204: #endif
 205:             FI
 206:             IF width
 207:             THEN width -= charpos()%width;
 208:             FI
 209:             break;
 210:             default:
 211: #ifndef vax
 212:             printc(c); vptr--;
 213: #else
 214:             printc(c); dptr--;
 215: #endif
 216:         }
 217: 
 218:         IF s==0
 219:         THEN *digitptr=0; s=digits;
 220:         FI
 221:         n=length(s);
 222:         n=(prec<n ANDF prec>=0 ? prec : n);
 223:         width -= n;
 224:         IF adj=='r'
 225:         THEN WHILE width-- > 0
 226:              DO printc(SP); OD
 227:         FI
 228:         WHILE n-- DO printc(*s++); OD
 229:         WHILE width-- > 0 DO printc(SP); OD
 230:         digitptr=digits;
 231:         FI
 232:     OD
 233: }
 234: 
 235: printdate(tvec)
 236:     L_INT       tvec;
 237: {
 238:     REG INT     i;
 239:     REG STRING  timeptr;
 240: #ifndef EDDT
 241:     timeptr = ctime(&tvec);
 242: #else
 243:     timeptr="????????????????????????";
 244: #endif
 245:     FOR i=20; i<24; i++ DO *digitptr++ = *(timeptr+i); OD
 246:     FOR i=3; i<19; i++ DO *digitptr++ = *(timeptr+i); OD
 247: } /*printdate*/
 248: 
 249: prints(s)
 250: char *s;
 251: {   printf("%s",s);
 252: }
 253: 
 254: newline()
 255: {
 256:     printc(EOR);
 257: }
 258: 
 259: convert(cp)
 260: REG STRING  *cp;
 261: {
 262:     REG CHAR    c;
 263:     INT     n;
 264:     n=0;
 265:     WHILE ((c = *(*cp)++)>='0') ANDF (c<='9') DO n=n*10+c-'0'; OD
 266:     (*cp)--;
 267:     return(n);
 268: }
 269: 
 270: printnum(n,fmat,base)
 271:     REG INT     n;
 272: {
 273:     REG CHAR    k;
 274:     REG INT     *dptr;
 275:     INT     digs[15];
 276:     dptr=digs;
 277:     IF n<0 ANDF fmat=='d' THEN n = -n; *digitptr++ = '-'; FI
 278:     n &= 0xffff;
 279:     WHILE n
 280:     DO  *dptr++ = ((POS)(n&0xffff))%base;
 281:         n=((POS)(n&0xffff))/base;
 282:     OD
 283:     IF dptr==digs THEN *dptr++=0; FI
 284:     WHILE dptr!=digs
 285:     DO  k = *--dptr;
 286:         *digitptr++ = (k+(k<=9 ? '0' : 'a'-10));
 287:     OD
 288: }
 289: 
 290: printoct(o,s)
 291:     L_INT       o;
 292:     INT     s;
 293: {
 294:     INT     i;
 295:     L_INT       po = o;
 296:     CHAR        digs[12];
 297: 
 298:     IF s
 299:     THEN IF po<0
 300:          THEN po = -po; *digitptr++='-';
 301:          ELSE IF s>0 THEN *digitptr++='+'; FI
 302:          FI
 303:     FI
 304:     FOR i=0;i<=11;i++
 305:     DO digs[i] = po&7; po >>= 3; OD
 306:     digs[10] &= 03; digs[11]=0;
 307:     FOR i=11;i>=0;i--
 308:     DO IF digs[i] THEN break; FI OD
 309:     FOR i++;i>=0;i--
 310:     DO *digitptr++=digs[i]+'0'; OD
 311: }
 312: 
 313: #ifndef vax
 314: printdbl(lx,ly,fmat,base)
 315: INT lx, ly; char fmat; int base;
 316: #else
 317: printdbl(lxy,fmat,base)
 318: L_INT lxy; char fmat; int base;
 319: #endif
 320: {   int digs[20]; int *dptr; char k;
 321: #ifndef MULD2
 322:     register char *cp1;
 323:     cp1=digs; if ((lxy&0xFFFF0000L)==0xFFFF0000L) {*cp1++='-'; lxy= -lxy;}
 324:     sprintf(cp1,base==16 ? "%x" : "%D",lxy);
 325:     cp1=digs; while (*digitptr++= *cp1++); --digitptr;
 326: #else
 327:     L_REAL f ,g; long q;
 328: #ifdef vax
 329:     INT lx,ly;
 330:     ly=lxy; lx=(lxy>>16)&0xFFFF;
 331: #endif
 332:     dptr=digs;
 333:     IF fmat=='D' ORF fmat=='r'
 334:     THEN    f=itol(lx,ly);
 335:         IF f<0 THEN *digitptr++='-'; f = -f; FI
 336:     ELSE
 337:         IF lx==-1
 338:         THEN *digitptr++='-'; f=leng(-ly);
 339:         ELSE f=leng(lx); f *= itol(1,0); f += leng(ly);
 340:         FI
 341:         IF fmat=='x' THEN *digitptr++='#'; FI
 342:     FI
 343:     WHILE f
 344:     DO  q=f/base; g=q;
 345:         *dptr++ = f-g*base;
 346:         f=q;
 347:     OD
 348:     IF dptr==digs ORF dptr[-1]>9 THEN *dptr++=0; FI
 349:     WHILE dptr!=digs
 350:     DO  k = *--dptr;
 351:         *digitptr++ = (k+(k<=9 ? '0' : 'a'-10));
 352:     OD
 353: #endif
 354: }
 355: 
 356: #define MAXIFD  5
 357: struct {
 358:     int fd;
 359:     int r9;
 360: } istack[MAXIFD];
 361: int ifiledepth;
 362: 
 363: iclose(stack, err)
 364: {
 365:     IF err
 366:     THEN    IF infile
 367:         THEN    close(infile); infile=0;
 368:         FI
 369:         WHILE --ifiledepth >= 0
 370:         DO  IF istack[ifiledepth].fd
 371:             THEN    close(istack[ifiledepth].fd);
 372:             FI
 373:         OD
 374:         ifiledepth = 0;
 375:     ELIF stack == 0
 376:     THEN    IF infile
 377:         THEN    close(infile); infile=0;
 378:         FI
 379:     ELIF stack > 0
 380:     THEN    IF ifiledepth >= MAXIFD
 381:         THEN    error(TOODEEP);
 382:         FI
 383:         istack[ifiledepth].fd = infile;
 384:         istack[ifiledepth].r9 = var[9];
 385:         ifiledepth++;
 386:         infile = 0;
 387:     ELSE    IF infile
 388:         THEN    close(infile); infile=0;
 389:         FI
 390:         IF ifiledepth > 0
 391:         THEN    infile = istack[--ifiledepth].fd;
 392:             var[9] = istack[ifiledepth].r9;
 393:         FI
 394:     FI
 395: }
 396: 
 397: oclose()
 398: {
 399:     IF outfile!=1
 400:     THEN    flushbuf(); close(outfile); outfile=1;
 401:     FI
 402: }
 403: 
 404: endline()
 405: {
 406: 
 407:     if (maxpos <= charpos())
 408:         printf("\n");
 409: }

Defined functions

charpos defined in line 89; used 3 times
convert defined in line 259; used 2 times
endline defined in line 404; used 2 times
eqstr defined in line 27; used 3 times
iclose defined in line 363; used 4 times
length defined in line 39; used 1 times
newline defined in line 254; used 1 times
oclose defined in line 397; used 3 times
printc defined in line 47; used 23 times
printdate defined in line 235; used 1 times
printdbl defined in line 317; used 6 times
printf defined in line 99; used 98 times
printnum defined in line 270; used 2 times
printoct defined in line 290; used 5 times

Defined variables

ifiledepth defined in line 361; used 11 times
sccsid defined in line 2; never used

Defined macros

MAXIFD defined in line 356; used 2 times
Last modified: 1985-04-27
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1597
Valid CSS Valid XHTML 1.0 Strict