1: #include "sdef.h"
   2: #include "d.h"
   3: #include "v.h"
   4: #include "tw.h"
   5: /*
   6: sroff10.c
   7: 
   8: Device interfaces
   9: */
  10: 
  11: extern int lss;
  12: extern int nlss;
  13: extern char obuf[];
  14: extern char *obufp;
  15: extern int toolate;
  16: extern int xfont;
  17: extern int esc;
  18: extern int lead;
  19: extern int oline[];
  20: extern int *olinep;
  21: extern int sps;
  22: extern int Em;
  23: extern int ics;
  24: extern int ttysave;
  25: extern struct sgttyb ttys;
  26: extern char fontlib[];
  27: extern int ptid;
  28: extern int waitf;
  29: extern int rollpaper;
  30: extern int nroff;
  31: extern int draft;
  32: extern int pipeflg;
  33: extern int tabtab[];
  34: extern int xxx;
  35: extern int dotF;
  36: extern int physfont;
  37: #ifndef ADJ
  38: extern int spacesz; /* width of space in physfont */
  39: #endif
  40: extern int bdtab[];
  41: extern int smnt;
  42: extern int sbold;
  43: extern int chbits;
  44: extern int fontab[PFONT][0200-040];
  45: extern int fontabS[];
  46: extern char *codetab[];
  47: extern int ce;
  48: extern int ad;
  49: extern int pl;
  50: extern int ll;
  51: extern int brflg;
  52: int bdmode;
  53: int plotmode;
  54: int ulmode = 0; /* Underline toggle, stan */
  55: int lastwd; /* width of last printing character */
  56: ptinit(){
  57:     register i, j;
  58:     register char **p;
  59:     char *q;
  60:     struct fonts *fp;
  61:     extern char *setbrk();
  62: 
  63:     if (ptid)
  64: #ifdef  TIOCEXCL
  65:         ioctl(ptid,TIOCEXCL,(struct sgttyb *)0);
  66: #endif
  67:     if (dotF) {
  68:         if((i = open(fontlib,0)) < 0){
  69:             prstr("Cannot open ");
  70:             prstr(fontlib);
  71:             prstr("\n");
  72:             exit(-1);
  73:         }
  74:         lseek(i,(long)8*sizeof(int),0); /* past header */
  75:         read(i,(char *)&fonts[0],
  76:             sizeof(int) *
  77:             (int)((int *)&fontabS[MAXCHAR-0200]-
  78:                 (int *)&fonts[0]));
  79:     }
  80: 
  81:     mchbits();
  82: #ifndef ADJ
  83:     spacesz = getcw(' ');       /* font 0 space */
  84: #endif
  85:     ics = Em*2;
  86:     for(i=0; i<16; i++)tabtab[i] = (nroff?NDTAB:DTAB) * (i+1);
  87:     setpl();
  88: #ifdef PGOFF
  89:     setpo();
  90: #endif
  91:     setll(ll);
  92: #ifdef ADJ
  93:     setin();
  94:     setad();
  95: #endif
  96:     for (i=0; i<NFONTS; i++) {
  97:         fp = &fonts[i];
  98:         if (fp->mount[0]) {
  99:         oputs(SE_MOUNT);
 100:         oput(0100+(fp->phys & FONTMSK));
 101:         oputs(fp->mount);
 102:         }
 103:     }
 104:     if (draft)
 105:         oputs(SE_DRAFT);
 106: }
 107: twdone(){
 108:     if (toolate) {
 109:         obufp = obuf;
 110:         oputs(t.twrest);
 111:         flusho();
 112:     }
 113:     if(pipeflg){
 114:         close(ptid);
 115:         wait(&waitf);
 116:     }
 117:     if(ttysave != -1) {
 118:         ttys.sg_flags = ttysave;
 119:         stty(1, &ttys);
 120:     }
 121: }
 122: ptout(i)
 123: int i;
 124: {
 125:     register pos;
 126:     *olinep++ = i;
 127:     if(olinep >= &oline[LNSIZE])olinep--;
 128:     if((i&CMASK) != '\n')return;
 129:     olinep--;
 130:     lead += utos(dip->blss) + utos(lss) - utos(t.Newline);
 131:     pos = v.nl - nlss;
 132:     if ((pos < TOP_MARG) && (!rollpaper)) {
 133:         lead -= utos(TOP_MARG - pos);       /* already at margin */
 134:         if (olinep>oline && lead<0)
 135:             lead = 0;   /* ignore motion in margin */
 136:     }
 137:     dip->blss = 0;
 138:     esc = 0;
 139:     if(olinep>oline){
 140:         move();
 141:         ptout1();
 142: #ifdef ADJ
 143:         if (i & EBIT)
 144:             oputs(t.twfp);
 145:         else
 146: #endif
 147:         if(ulmode) {
 148:             ulmode = 0;
 149:             oputs(t.uloff);
 150:         }
 151:         oputs(t.twnl);
 152:     }else{
 153:         lead += utos(t.Newline);
 154:         if (pos<TOP_MARG && lead<0 && !rollpaper)
 155:             lead = 0;
 156:         move();
 157:     }
 158:     lead += utos(dip->alss);
 159:     dip->alss = 0;
 160:     olinep = oline;
 161: }
 162: ptout1()
 163: {
 164:     register i, k;
 165:     register char *codep;
 166:     register struct fonts *fp;
 167:     extern char *plot();
 168:     extern int oput();
 169:     int *q, w, j, phyw, bd;
 170: 
 171:     for(q=oline; q<olinep; q++){
 172:     if((i = *q) & MOT){
 173:         j = i & ~MOTV;
 174:         if(i & NMOT)j = -j;
 175:         if(i & VMOT)lead += utos(j);
 176:         else esc += j;
 177:         /*
 178: 		 * Save the width of the previous printing character
 179: 		 * so that move() will know if it needs to fake out
 180: 		 * the printer.
 181: 		 */
 182:         if (q>oline) {
 183:            if (!*(q-1)&MOT)
 184:             lastwd = getcw(*(q-1));
 185:         }
 186:         else lastwd = 0;
 187:         continue;
 188:     }
 189:     if((k = (i & CMASK)) < 040){
 190:         continue;
 191:     }
 192:     xfont = getfont(i);
 193:     fp = &fonts[xfont];
 194:     j = fp->phys & FONTMSK;
 195:     if (k > 0177) {
 196:         codep = codetab[k-0200];
 197:         if (*codep & 0100) j = *codep & 07;
 198:         bd = (xfont==sbold) ? bdtab[smnt] : 0;
 199:     } else {
 200:         codep = (char *) 0;
 201:         bd = (xfont==smnt) ? 0 : bdtab[xfont];
 202:     }
 203:     if(esc || lead) move();
 204:     if (j != physfont) {
 205:         oputs(SE_CHFONT);   /* change font */
 206:         oput(0100+j);
 207:         physfont = j;
 208: #ifndef ADJ
 209:         if (codep == 0)
 210:             spacesz = getcw(' '|(xfont<<FONTSHFT));
 211: #endif
 212:     }
 213:     if(bdmode && (bdmode != bd)){
 214:         oputs(t.bdoff);
 215:         bdmode = 0;
 216:     }
 217:     if(!bdmode && bd){
 218:         oputs(t.bdon);
 219:         oput((bdmode=bd) + 0140);
 220:     }
 221:     if ((i & ULMODE)  && !ulmode) {
 222:             oputs(t.ulon);
 223:         ulmode++;
 224:     }
 225:     else if (ulmode && !(i & ULMODE)) {
 226:         oputs(t.uloff);
 227:         ulmode = 0;
 228:     }
 229:     if (codep == (char *)0) {
 230:         *obufp++ = (char) k;
 231:         if(obufp == (obuf + OBUFSZ)) flusho();
 232:     } else {
 233:         if (*codep & 0100)
 234:         physfont = (*codep>>3) & 07;
 235:         codep++;
 236:         while(*codep != 0){
 237:         if(*codep & 0200){
 238:             codep = plot(codep);
 239:             oputs(t.plotoff);
 240:             oput(' ');
 241:         }else{
 242:             if(plotmode)oputs(t.plotoff);
 243:             *obufp++ = *codep++;
 244:             if(obufp == (obuf + OBUFSZ)) flusho();
 245:         }
 246:         }
 247:     }
 248:     if (i & ZBIT)
 249:         esc -= getcw(i);
 250:     }
 251: }
 252: char *plot(x)
 253: char *x;
 254: {
 255:     register int i;
 256:     register char *j, *k;
 257: 
 258:     if(!plotmode)oputs(t.ploton);
 259:     k = x;
 260:     if((*k & 0377) == 0200)k++;
 261:     for(; *k; k++){
 262:         if(*k & 0200){
 263:             if(*k & 0100){
 264:                 if(*k & 040)j = t.up; else j = t.down;
 265:             }else{
 266:                 if(*k & 040)j = t.left; else j = t.right;
 267:             }
 268:             if(!(i = *k & 037))return(++k);
 269:             while(i--)oputs(j);
 270:         }else oput(*k);
 271:     }
 272:     return(k);
 273: }
 274: move(){
 275:     /* lead is in chunks of SE_VBLOCK steps for vertical spacing */
 276:     /* esc is in chunks of SE_HBLOCK steps for reverse horizontal motion */
 277:     register k, steps;
 278:     int dt, DidLead;
 279:     DidLead = 0;
 280:     if(ulmode) {
 281:     ulmode = 0;
 282:     oputs(t.uloff);
 283:     }
 284:     if(lead){
 285:         if (v.nl >= pl) {
 286:         oput('\f');
 287:     } else {
 288:         DidLead++;      /* did vertical motion */
 289:         steps = lead;   /* 3.5 mil increments */
 290:         if (steps < 0) steps = -steps;
 291:         for (; steps > SE_VBLOCK; steps -= SE_VBLOCK)
 292:         oputs((lead < 0) ? SE_UPBL : SE_DOWNBL);
 293:         if (steps) {  /*travel rest of the way*/
 294:             oputs(SE_VMOT);
 295:         donum2(oput,(lead<0)?-steps:steps);
 296:         }
 297:     }
 298:     lead = 0;
 299:     }
 300:     if(esc > 0) {
 301: /*
 302: #ifndef ADJ	/* spaces get adjusted by the sanders */
 303: /*
 304:         k = esc/spacesz; esc = esc%spacesz;
 305:         while(k--)oput(' ');
 306: #else
 307: */
 308:         for( ; esc > SE_HBLOCK; esc -= SE_HBLOCK) oputs(SE_RIGHTBL);
 309: /* #endif */
 310:         if(esc > 0) {
 311:             oputs(SE_HMOT);
 312:         donum2(oput,esc);
 313:         }
 314:     }
 315:     if(esc < 0) {
 316:     /*
 317: 	 * If we just did vertical motion, or if the current backward
 318: 	 * motion is less than the width of the last printed character,
 319: 	 * things are fine.  Otherwise, we have to do fake vertical motion
 320: 	 * so the printer won't truncate our move.
 321: 	 */
 322:     if (-esc < lastwd)
 323:         DidLead++;
 324:     if (!DidLead)
 325:             oputs(SE_DOWN1);
 326:         for( ; esc <= -SE_HBLOCK;esc += SE_HBLOCK) oputs(SE_LEFTBL);
 327:     if (esc < 0) {
 328:             oputs(SE_HMOT);
 329:         donum2(oput,esc);
 330:     }
 331:     if (!DidLead)
 332:             oputs(SE_UP1);
 333:     }
 334:     esc = 0;
 335: }
 336: ptlead(){move();}
 337: 
 338: donum1(output,i)        /* output int in 1-byte sanders ascii */
 339: int (*output)();
 340: register i;
 341: {
 342:     if (i>=0)
 343:         (*output)((i+0100) | EBIT);
 344:     else
 345:         (*output)((64+i+0100) | EBIT);
 346: }
 347: 
 348: donum2(output,i)        /* output int in 2-byte sanders ascii */
 349: int (*output)();
 350: register i;
 351: {
 352:     if (i<0)
 353:         i = 4096 + i;
 354:     (*output)(((i/64) + 0100) | EBIT);
 355:     (*output)(((i%64) + 0100) | EBIT);
 356: }
 357: donum3(output,i)        /* output int in 3-byte sanders ascii */
 358: int (*output)();
 359: register i;
 360: {
 361:     long l;
 362:     if (i>=0)
 363:         l = i;
 364:     else
 365:         l = 65536L + (long)i;
 366:     (*output)(((int)(l/4096) + 0100) | EBIT);
 367:     donum2(output,(int)(l%4096));
 368: }

Defined functions

donum1 defined in line 338; used 1 times
donum2 defined in line 348; used 4 times
donum3 defined in line 357; used 5 times
move defined in line 274; used 4 times
plot defined in line 252; used 2 times
ptinit defined in line 56; used 1 times
ptlead defined in line 336; used 1 times
ptout defined in line 122; used 3 times
ptout1 defined in line 162; used 1 times
twdone defined in line 107; used 1 times

Defined variables

bdmode defined in line 52; used 5 times
lastwd defined in line 55; used 3 times
plotmode defined in line 53; used 2 times
ulmode defined in line 54; used 8 times
Last modified: 1982-07-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1378
Valid CSS Valid XHTML 1.0 Strict