1: #
   2: #include "0x.h"
   3: #include "opcode.h"
   4: 
   5: pwrite(opc, subopc, av)
   6: {
   7:     register char *ap, *cp;
   8:     register i;
   9:     int w, w1, sign, decpt;
  10:     char *acp;
  11:     long along;
  12:     double adouble;
  13:     int k2,k3;
  14: 
  15:     ap = &av;
  16:     if (opc == O_WRITLN || opc == O_PAGE)
  17:         opc = O_WRITC;
  18:     switch(opc) {
  19:         case O_WRIT2:
  20:             along = ap->pint;
  21:             ap += 2;
  22:             w = 10;
  23:             break;
  24:         case O_WRIT4:
  25:             along = ap->plong;
  26:             ap += 4;
  27:             w = 10;
  28:             break;
  29:         case O_WRITC:
  30:             acp = ap;
  31:             ap += 2;
  32:             w = 1;
  33:             break;
  34:         case O_WRITB:
  35:             i = ap->pint;
  36:             ap += 2;
  37:             w = 10;
  38:             break;
  39:         case O_WRITG:
  40:             w1 = ap->pint;
  41:             ap += 2;
  42:             acp = ap;
  43:             ap += (w1 + 1) & ~1;
  44:             w = 0;
  45:             break;
  46:         case O_WRIT8:
  47:         case O_WRIT82:
  48:             adouble = ap->pdouble;
  49:             ap += 8;
  50:             w = 22;
  51:             break;
  52:         case O_WRHEX2:
  53:         case O_WROCT2:
  54:             (&along)->pint = 0;
  55:             (&along)->p2int = ap->pint;
  56:             ap += 2;
  57:             w = opc == O_WROCT2 ? 11 : 8;
  58:             break;
  59:         case O_WRHEX2+1:    /* ugh, cc string table too small */
  60:         case O_WROCT2+1:    /* ugh, cc string table too small */
  61:             along = ap->plong;
  62:             ap += 4;
  63:             w = opc == O_WROCT2+1 ? 11 : 8;
  64:             break;
  65:     }
  66: again:
  67:     switch(subopc & 07) {
  68:         case 0:
  69:             break;
  70:         case 2:
  71:             w = ap->pint;
  72:             ap += 2;
  73:             break;
  74:         case 4:
  75:             w = ap->plong;
  76:             ap += 4;
  77:             break;
  78:     }
  79:     if (opc == O_WRIT82 && (i = (subopc >> 3) & 07) != 0) {
  80:         subopc = i;
  81:         w1 = w;
  82:         goto again;
  83:     }
  84:     switch(opc) {
  85:         case O_WROCT2+1:
  86:         case O_WROCT2:
  87:             while (w > 11) {
  88:                 pputch(' ');
  89:                 w--;
  90:             }
  91:             if (w > 0)
  92:                 wro(along, w);
  93:             break;
  94:         case O_WRHEX2:
  95:         case O_WRHEX2+1:
  96:             while (w > 8) {
  97:                 pputch(' ');
  98:                 w--;
  99:             }
 100:             if (w > 0)
 101:                 wrhex(along, w);
 102:             break;
 103:         case O_WRIT2:
 104:         case O_WRIT4:
 105:             pwril(w, along);
 106:             break;
 107:         case O_WRITC:
 108:             while (w > 1) {
 109:                 pputch(' ');
 110:                 w--;
 111:             }
 112:             pputch(*acp);
 113:             break;
 114:         case O_WRITB:
 115:             if (i) {
 116:                 acp = "true";
 117:                 w1 = 4;
 118:             } else {
 119:                 acp = "false";
 120:                 w1 = 5;
 121:             }
 122:         case O_WRITG:
 123:             cp = acp;
 124:             while (w > w1) {
 125:                 pputch(' ');
 126:                 w--;
 127:             }
 128:             while(w1 > 0) {
 129:                 pputch(*cp++);
 130:                 w1--;
 131:             }
 132:             break;
 133:         case O_WRIT8:
 134:             if (adouble == 0.0) {
 135:                 do
 136:                     pputch(' ');
 137:                 while (--w > 0);
 138:                 pputch('0');
 139:                 break;
 140:             }
 141:             if (w <= 9)
 142:                 w = 3;
 143:             else
 144:                 w -= 6;
 145:             do
 146:                 pputch(' ');
 147:             while (--w > 17);
 148:             cp = ecvt(adouble, w+1, &decpt, &sign);
 149:             pputch(sign ? '-' : ' ');
 150:             pputch(*cp++);
 151:             pputch('.');
 152:             do
 153:                 pputch(*cp++);
 154:             while (--w > 0);
 155:             pputch('e');
 156:             if (--decpt >= 0)
 157:                 pputch('+');
 158:             else {
 159:                 pputch('-');
 160:                 decpt = -decpt;
 161:             }
 162:             pputch(decpt / 10 + '0');
 163:             pputch(decpt % 10 + '0');
 164:             break;
 165:         case O_WRIT82:
 166:             if (adouble == 0.0) {
 167:                 do
 168:                     pputch(' ');
 169:                 while(--w1 > 1);
 170:                 pputch('0');
 171:                 break;
 172:             }
 173:             if (w < 0)
 174:                 w = 0;
 175:             cp = fcvt(adouble, w, &decpt, &sign);
 176:             cp[17] = '\0';
 177:             if (decpt > 0) {
 178:                 w1 = w1-w-decpt-2;
 179:                 k2 = decpt;
 180:                 k3 = 0;
 181:             } else {
 182:                 w1 = w1-w-3;
 183:                 k2 = 0;
 184:                 if (w+decpt >= 0)
 185:                     k3 = -decpt;
 186:                 else
 187:                     k3 = w;
 188:                 w -= k3;
 189:             }
 190:             while (w1 > 0) {
 191:                 pputch(' ');
 192:                 w1--;
 193:             }
 194:             pputch(sign ? '-' : ' ');
 195:             if (k2 <= 0)
 196:                 pputch('0');
 197:             else
 198:                 do
 199:                     pputch(*cp ? *cp++ : '0');
 200:                 while (--k2 > 0);
 201:             pputch('.');
 202:             if (k3 <= 0 && w <= 0) {
 203:                 pputch('0');
 204:                 break;
 205:             }
 206:             while(k3 > 0) {
 207:                 pputch('0');
 208:                 k3--;
 209:             }
 210:             while(w > 0) {
 211:                 pputch(*cp ? *cp++ : '0');
 212:                 w--;
 213:             }
 214:             break;
 215:     }
 216:     return(ap);
 217: }
 218: 
 219: wro(l, w)
 220: long l;
 221: {
 222:     register c;
 223: 
 224:     c = (&l)->p2int & 07;
 225:     l >>= 3;
 226:     (&l)->pint &= 017777;
 227:     if (w > 1 || l != 0)
 228:         wro(l, w-1);
 229:     pputch(c | '0');
 230: }
 231: 
 232: wrhex(l, w)
 233: long l;
 234: {
 235:     register c;
 236: 
 237:     c = (&l)->p2int & 017;
 238:     l >>= 4;
 239:     (&l)->pint &= 07777;
 240:     if (w > 1 || l != 0)
 241:         wrhex(l, w-1);
 242:     pputch(c <= 9 ? c | '0' : 'a' + (c - 10));
 243: }

Defined functions

wrhex defined in line 232; used 2 times
wro defined in line 219; used 2 times
Last modified: 1986-06-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1203
Valid CSS Valid XHTML 1.0 Strict