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
endline defined in line 319; used 2 times
iclose defined in line 278; used 4 times
oclose defined in line 312; used 3 times
printc defined in line 13; used 38 times
printdate defined in line 175; used 1 times
printdbl defined in line 241; used 3 times
printf defined in line 58; used 95 times
printnum defined in line 198; used 2 times
printoct defined in line 218; used 4 times

Defined variables

TOODEEP defined in line 10; used 1 times
digitptr defined in line 9; used 21 times
ifiledepth defined in line 276; used 11 times
infile defined in line 4; used 13 times
maxpos defined in line 6; used 1 times
mkfault defined in line 3; used 1 times
  • in line 20
outfile defined in line 5; used 5 times
printbuf defined in line 7; used 15 times
printptr defined in line 8; used 13 times
var defined in line 11; used 2 times

Defined macros

MAXIFD defined in line 270; used 2 times
Last modified: 1994-01-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3343
Valid CSS Valid XHTML 1.0 Strict