1: #ifndef lint
   2: static char sccsid[] = "@(#)t10.c	4.1	(Berkeley)	82/12/03";
   3: #endif
   4: 
   5: #include "tdef.h"
   6: extern
   7: #include "d.h"
   8: extern
   9: #include "v.h"
  10: /*
  11: troff10.c
  12: 
  13: CAT interface
  14: */
  15: 
  16: extern int *olinep;
  17: extern int oline[];
  18: extern int *pslp;
  19: extern int back;
  20: extern int xpts;
  21: extern int mpts;
  22: extern int po;
  23: extern int xflg;
  24: extern int line[];
  25: extern int lss;
  26: extern int xbitf;
  27: extern char obuf[];
  28: extern char *obufp;
  29: extern int esct;
  30: extern int trflg;
  31: extern int cs;
  32: extern int smnt;
  33: extern int mfont;
  34: extern int xfont;
  35: extern int code;
  36: extern int mcase;
  37: extern int esc;
  38: extern int lead;
  39: extern int paper;
  40: extern int cps;
  41: extern int psflg;
  42: extern int ptid;
  43: extern int verm;
  44: extern int escm;
  45: extern char pstab[], psctab[];
  46: extern int dpn;
  47: extern int ascii;
  48: int mrail = 0; /*0=LR,1=UR*/
  49: int mmag = 1; /*0=UM,1=LM*/
  50: extern int nofeed;
  51: extern int gflag;
  52: extern int fontlab[];
  53: int papflg;
  54: extern int pfont;
  55: extern int ppts;
  56: extern int oldbits;
  57: extern int bd;
  58: extern int vflag;
  59: extern int stopmesg;
  60: extern int xxx;
  61: 
  62: ptinit(){
  63: 
  64:     if(ascii || gflag)return;
  65:     oput(T_INIT);
  66:     esc = T_IESC;
  67:     ptesc();
  68:     esct = 0;
  69:     esc = po;
  70:     oput(0140); /*some initial lead*/
  71: }
  72: ptout(i)
  73: int i;
  74: {
  75:     register *k, lw, *j;
  76:     int ds, de, inith, temp, *slp, dv;
  77:     int psl[16];
  78: 
  79:     if((i & CMASK) != '\n'){
  80:         *olinep++ = i;
  81:         return;
  82:     }
  83:     if(olinep == oline){
  84:         lead += lss;
  85:         return;
  86:     }
  87:     pslp = psl;
  88:     *pslp = lw = inith = dv = 0;
  89:     for(k=oline; k<olinep; k++){
  90:         trflg++;
  91:         xbitf = 1;
  92:         lw += width(*k);
  93:         if((*k & (MOT | VMOT)) == (MOT | VMOT)){
  94:             temp = *k & ~MOTV;
  95:             if(*k & NMOT)temp = -temp;
  96:             dv += temp;
  97:         }
  98:         if(!(*k & MOT) && xflg)for(j=psl; j<=pslp; j++){
  99:             if(xpts == *j)break;
 100:             if(j == pslp){
 101:                 *j = xpts;
 102:                 *++pslp = 0;
 103:                 break;
 104:             }
 105:         }
 106:     }
 107:     if(dv){
 108:         vflag++;
 109:         *olinep++ = makem(-dv);
 110:         vflag = 0;
 111:     }
 112:     if(xflg){
 113:     --pslp;
 114:         for(j=psl; j<=pslp; j++){
 115:             if(*j == mpts){
 116:                 temp = *j;
 117:                 *j = *pslp;
 118:                 *pslp = temp;
 119:                 break;
 120:             }
 121:         }
 122:     }
 123:     for(k=oline; k<olinep; k++){
 124:         if(!(*k & MOT) || (*k & VMOT))break;
 125:         *k &= ~MOT;
 126:         if(*k & NMOT){
 127:             *k &= ~NMOT;
 128:             *k = -*k;
 129:         }
 130:         inith += *k;
 131:     }
 132:     lead += dip->blss + lss;
 133:     dip->blss = 0;
 134:     slp = k;
 135: scan:
 136:     temp = esct - po;
 137:     if(mpts & DBL)temp -= 55;
 138:     ds = temp - inith;
 139:     de = lw - temp;
 140:     if(de >= ds){
 141:         back = 0;
 142:         esc = -ds;
 143:         for(k=slp; k<olinep; k++)ptout0(*k);
 144:     }else{
 145:         back = 1;
 146:         esc = de;
 147:         for(k = olinep-1; k>=slp; --k)ptout0(*k);
 148:     }
 149:     if(xflg && (--pslp >= psl))goto scan;
 150:     olinep = oline;
 151:     lead += dip->alss;
 152:     dip->alss = 0;
 153: }
 154: ptout0(i)
 155: int i;
 156: {
 157:     register j, k, w;
 158:     int z;
 159: 
 160:     if(i & MOT){
 161:         j = i & ~MOTV;
 162:         if(i & NMOT)j = -j;
 163:         if(back)j = -j;
 164:         if(i & VMOT)lead += j;
 165:         else esc += j;
 166:         return;
 167:     }
 168:     xbitf = 2;
 169:     if((i>>BYTE) == oldbits){
 170:         xfont = pfont;
 171:         xpts = ppts;
 172:         xbitf = 0;
 173:     }else xbits(i);
 174:     if((k = (i & CMASK)) < 040){
 175:         return;
 176:     }
 177:     w = getcw(k-32);
 178:     if(cs){
 179:         if(bd)w += bd - 1;
 180:         j = (cs-w)/2;
 181:         w = cs - j;
 182:         if(bd)w -= bd - 1;
 183:     }else j = 0;
 184:     if(i & ZBIT){
 185:         if(cs)w = -j; else w = 0;
 186:         z = 1;
 187:     }else z = 0;
 188:     if(back){
 189:         k = j;
 190:         j = -w;
 191:         w = -k;
 192:     }
 193:     esc += j;
 194:     if((!xflg || (xpts == *pslp)) && (code & 077)){
 195:         if(code & 0200){
 196:             if(smnt)xfont = smnt -1;
 197:             else goto p1;
 198:         }
 199:         if((k=(code>>6)&01)^mcase)oput((mcase=k)+0105);
 200:         if(xfont != mfont){
 201:             mfont = xfont;
 202:             if(mrail != (xfont&01))
 203:                 oput(0101 + (mrail=xfont&01));
 204:             if(mmag != (xfont<2))
 205:                 oput(0103 + (mmag=(xfont<2)));
 206:         }
 207:         if(xpts != mpts)ptps();
 208:         if(lead)ptlead();
 209:         if(esc)ptesc();
 210: /*
 211: 		oput(code & 077);
 212: */
 213:         *obufp++ = code & 077;
 214:         if(obufp == (obuf + OBUFSZ + ascii - 1))flusho();
 215:         if(bd){
 216:             bd -= 1;
 217:             if(back && !z)bd = -bd;
 218:             if(esc += bd)ptesc();
 219:             oput(code & 077);
 220:             if(z)esc -= bd;
 221:         }
 222:     }else if(bd && !z){
 223:         bd -= 1;
 224:         if(back)bd = -bd;
 225:         esc += bd;
 226:     }
 227: p1:
 228:     esc += w;
 229:     return;
 230: }
 231: ptps(){
 232:     register i, j, k;
 233: 
 234:     if(psflg)return;
 235:     if(cps){
 236:         psflg++;
 237:         i = findps(cps);
 238:     }else i = xpts;
 239:     for(j=0; (i&077) > (k = pstab[j]);j++)if(!k){k=pstab[--j];break;}
 240:     j = psctab[j];
 241:     oput((j & ~0200) | 0120);
 242:     if((!(mpts & DBL))^(!(j & 0200))){
 243:         if(j & 0200)k = 55;
 244:             else k = -55;
 245:         esc += k;
 246:     }
 247:     mpts = i;
 248: }
 249: ptlead(){
 250:     register i, k;
 251: 
 252:     if(k = lead < 0)lead = -lead;
 253:     if(k^verm)oput(0112 + ((verm=k)<<1));
 254:     if(((k=lead)%3) == 2)k++;
 255:     k /= 3;
 256:     while(k > 0){
 257:         if((i=31) > k)i = k;
 258:         if(verm)paper -= i;
 259:             else paper += i;
 260:         oput(((~i) & 037) | 0140);
 261:         if((paper > (11*144*15)) && !papflg && ptid != 1){
 262:             prstr("Excessive paper use.\n");
 263:             papflg++;
 264:             if(ptid != 1){
 265:                 lead = 0;
 266:                 done2(0200);
 267:             }
 268:         }
 269:         k -= i;
 270:     }
 271:     lead = 0;
 272: }
 273: ptesc(){
 274:     register i, j, k;
 275: 
 276:     if(k = esc < 0)esc = -esc;
 277:     if(k^escm)oput(0107 + (escm=k));
 278:     k = esc;
 279:     while(k > 0){
 280:         if((i=127) > k)i = k;
 281:         if(((j = (esct + i*(1-2*escm))) > (46*72+18-T_IESC)) ||
 282:            (j < 0))break;
 283: /*
 284: 		oput(~i);
 285: */
 286:         *obufp++ = ~i;
 287:         if(obufp == (obuf + OBUFSZ + ascii - 1))flusho();
 288:         esct = j;
 289:         k -= i;
 290:     }
 291:     esc = 0;
 292: }
 293: dostop(){
 294:     register i;
 295: 
 296:     if(ascii)return;
 297:     if(!nofeed && !gflag)lead += TRAILER;
 298:     ptlead();
 299:     flusho();
 300:     oput(T_INIT);
 301:     oput(T_STOP);
 302:     if(gflag){
 303:         oput('f');
 304:         for(i=0; i<4; i++){
 305:             oput(fontlab[i] & BMASK);
 306:             oput((fontlab[i]>>BYTE) & BMASK);
 307:         }
 308:     }else for(i=8; i>0; i--)oput(T_PAD);
 309:     flusho();
 310:     if(stopmesg)prstr("Pages finished.\n");
 311:     mcase = mpts = mfont = mrail = verm = escm = 0;
 312:     mmag = 1;
 313:     report();
 314:     paper = 0;
 315:     esc = T_IESC;
 316:     ptesc();
 317:     esct = 0;
 318:     esc = po;
 319: }

Defined functions

dostop defined in line 293; never used
ptesc defined in line 273; used 4 times
ptinit defined in line 62; never used
ptlead defined in line 249; used 2 times
ptout defined in line 72; never used
ptout0 defined in line 154; used 2 times
ptps defined in line 231; used 1 times

Defined variables

mmag defined in line 49; used 3 times
mrail defined in line 48; used 3 times
papflg defined in line 53; used 2 times
sccsid defined in line 2; never used
Last modified: 1982-12-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3403
Valid CSS Valid XHTML 1.0 Strict