# 2.11BSD#431 - /usr/src/bin/adb/output.c

##### Functions

    convert           X
    endline           X
    flushbuf          X
    iclose            X
    oclose            X
    printc            X
    printdate         X
    printdbl          X
    printf            X
    printnum          X
    printoct          X

##### Variables

    TOODEEP           X
    digitptr          X
    ifiledepth        X
    infile            X
    maxpos            X
    mkfault           X
    outfile           X
    printbuf          X
    printptr          X
    var               X

##### Macros

    MAXIFD            X

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

#### Defined functions

convert defined in line 187; used 2 times

- in line 79, 88

endline defined in line 319; used 2 times

- in /usr/src/bin/adb/format.c line 151, 222

flushbuf defined in line 51; used 6 times

- in line 315
- in /usr/src/bin/adb/command.c line 214
- in /usr/src/bin/adb/main.c line 126
- in /usr/src/bin/adb/print.c line 180, 289
- in /usr/src/bin/adb/runpcs.c line 260

iclose defined in line 278; used 4 times

- in /usr/src/bin/adb/main.c line 58, 143
- in /usr/src/bin/adb/print.c line 115, 135

oclose defined in line 312; used 3 times

- in /usr/src/bin/adb/main.c line 58
- in /usr/src/bin/adb/print.c line 129, 136

printc defined in line 13; used 38 times

- in line 53, 77, 122, 155, 166-169(3), 322
- in /usr/src/bin/adb/command.c line 152
- in /usr/src/bin/adb/format.c line 136, 149, 179, 199-204(2), 243, 253
- in /usr/src/bin/adb/main.c line 133
- in /usr/src/bin/adb/opset.c line 324, 337, 394-403(4), 425, 434, 443-448(2)
- in /usr/src/bin/adb/print.c line 164, 221, 277-284(4), 303, 332, 368-373(2), 409

printdate defined in line 175; used 1 times

- in line 111

printdbl defined in line 241; used 3 times

- in line 109-114(2), 120

printf defined in line 58; used 95 times

- in /usr/src/bin/adb/command.c line 151, 208
- in /usr/src/bin/adb/format.c line 32, 108, 116-119(2), 128-131(2), 141, 156-176(7), 182-195(4), 252
- in /usr/src/bin/adb/main.c line 128, 134
- in /usr/src/bin/adb/opset.c line 314, 355-357(2), 363, 377, 392, 415-420(2), 429, 438, 453
- in /usr/src/bin/adb/pcs.c line 87, 119-120(2)
- in /usr/src/bin/adb/print.c line 161-165(2), 177-178(2), 197-206(4), 213, 226-227(3), 247, 260, 269-274(3), 281-283(2), 295-299(2), 320-331(10), 350, 356, 366-371(2), 378, 417-419(2)
- in /usr/src/bin/adb/runpcs.c line 48-53(2), 103, 114, 145, 151, 201, 226, 249
- in /usr/src/bin/adb/setup.c line 212
- in /usr/src/bin/adb/sym.c line 48-50(2), 85-89(4), 180, 205, 229-232(2)

printnum defined in line 198; used 2 times

- in line 103, 137

printoct defined in line 218; used 4 times

- in line 105-107(2), 116-118(2)

#### Defined variables

TOODEEP defined in line 10; used 1 times

- in line 296

digitptr defined in line 9; used 21 times

- in line 97, 129-137(8), 159, 170, 183-184(2), 206, 214, 228-229(2), 238, 254-256(2), 266

ifiledepth defined in line 276; used 11 times

- in line 284-289(4), 295-307(7)

infile defined in line 4; used 13 times

- in line 281-292(7), 298-306(6)

maxpos defined in line 6; used 1 times

- in line 321

mkfault defined in line 3; used 1 times

- in line 20

outfile defined in line 5; used 5 times

- in line 37, 46, 314-315(3)

printbuf defined in line 7; used 15 times

- in line 8, 23-25(3), 37-52(9), 151, 321

printptr defined in line 8; used 13 times

- in line 22-24(2), 38-52(9), 151, 321

var defined in line 11; used 2 times

- in line 299, 307

#### Defined macros

MAXIFD defined in line 270; used 2 times

- in line 274, 295

Last modified: 1994-01-13 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 836 |