|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)n10.c 4.3 4/27/88"; ! 3: #endif lint ! 4: ! 5: #include "tdef.h" ! 6: #include <sgtty.h> ! 7: extern ! 8: #include "d.h" ! 9: extern ! 10: #include "v.h" ! 11: extern ! 12: #include "tw.h" ! 13: /* ! 14: nroff10.c ! 15: ! 16: Device interfaces ! 17: */ ! 18: ! 19: extern int lss; ! 20: extern char obuf[]; ! 21: extern char *obufp; ! 22: extern int xfont; ! 23: extern int esc; ! 24: extern int lead; ! 25: extern int oline[]; ! 26: extern int *olinep; ! 27: extern int ulfont; ! 28: extern int esct; ! 29: extern int sps; ! 30: extern int ics; ! 31: extern int ttysave; ! 32: extern struct sgttyb ttys; ! 33: extern char termtab[]; ! 34: extern int ptid; ! 35: extern int waitf; ! 36: extern int pipeflg; ! 37: extern int eqflg; ! 38: extern int hflg; ! 39: extern int tabtab[]; ! 40: extern int ascii; ! 41: extern int xxx; ! 42: int dtab; ! 43: int bdmode; ! 44: int plotmode; ! 45: ! 46: ptinit(){ ! 47: register i, j; ! 48: register char **p; ! 49: char *q; ! 50: int x[8]; ! 51: extern char *setbrk(); ! 52: ! 53: if(((i=open(termtab,0)) < 0) && (i=open("/usr/lib/term/tablpr",0)) < 0){ ! 54: prstr("Cannot open "); ! 55: prstr(termtab); ! 56: prstr("\n"); ! 57: exit(-1); ! 58: } ! 59: read(i,(char *)x,8*sizeof(int)); ! 60: read(i,(char *)&t.bset,j = sizeof(int)*((int *)&t.zzz - &t.bset)); ! 61: x[2] -= j; ! 62: q = setbrk(x[2]); ! 63: lseek(i,(long)t.twinit+8*sizeof(int),0); ! 64: i = read(i,q,x[2]); ! 65: j = q - t.twinit; ! 66: for(p = &t.twinit; p < &t.zzz; p++){ ! 67: if(*p)*p += j;else *p = ""; ! 68: } ! 69: sps = EM; ! 70: ics = EM*2; ! 71: dtab = 8 * t.Em; ! 72: for(i=0; i<16; i++)tabtab[i] = dtab * (i+1); ! 73: if(eqflg)t.Adj = t.Hor; ! 74: } ! 75: twdone(){ ! 76: obufp = obuf; ! 77: oputs(t.twrest); ! 78: flusho(); ! 79: if(pipeflg){ ! 80: close(ptid); ! 81: wait(&waitf); ! 82: } ! 83: if(ttysave != -1) { ! 84: ttys.sg_flags = ttysave; ! 85: stty(1, &ttys); ! 86: } ! 87: } ! 88: ptout(i) ! 89: int i; ! 90: { ! 91: *olinep++ = i; ! 92: if(olinep >= &oline[LNSIZE])olinep--; ! 93: if((i&CMASK) != '\n')return; ! 94: olinep--; ! 95: lead += dip->blss + lss - t.Newline; ! 96: dip->blss = 0; ! 97: esct = esc = 0; ! 98: if(olinep>oline){ ! 99: move(); ! 100: ptout1(); ! 101: oputs(t.twnl); ! 102: }else{ ! 103: lead += t.Newline; ! 104: move(); ! 105: } ! 106: lead += dip->alss; ! 107: dip->alss = 0; ! 108: olinep = oline; ! 109: } ! 110: ptout1() ! 111: { ! 112: register i, k; ! 113: register char *codep; ! 114: extern char *plot(); ! 115: int *q, w, j, phyw; ! 116: ! 117: for(q=oline; q<olinep; q++){ ! 118: if((i = *q) & MOT){ ! 119: j = i & ~MOTV; ! 120: if(i & NMOT)j = -j; ! 121: if(i & VMOT)lead += j; ! 122: else esc += j; ! 123: continue; ! 124: } ! 125: if((k = (i & CMASK)) <= 040){ ! 126: switch(k){ ! 127: case ' ': /*space*/ ! 128: esc += t.Char; ! 129: break; ! 130: } ! 131: continue; ! 132: } ! 133: codep = t.codetab[k-32]; ! 134: w = t.Char * (*codep++ & 0177); ! 135: phyw = w; ! 136: if(i&ZBIT)w = 0; ! 137: if(*codep && (esc || lead))move(); ! 138: esct += w; ! 139: if(i&074000)xfont = (i>>9) & 03; ! 140: if(*t.bdon & 0377){ ! 141: if(!bdmode && (xfont == 2)){ ! 142: oputs(t.bdon); ! 143: bdmode++; ! 144: } ! 145: if(bdmode && (xfont != 2)){ ! 146: oputs(t.bdoff); ! 147: bdmode = 0; ! 148: } ! 149: } ! 150: ! 151: if(xfont == ulfont){ ! 152: for(k=w/t.Char;k>0;k--)oput('_'); ! 153: for(k=w/t.Char;k>0;k--)oput('\b'); ! 154: } ! 155: while(*codep != 0){ ! 156: if(*codep & 0200){ ! 157: codep = plot(codep); ! 158: oputs(t.plotoff); ! 159: oput(' '); ! 160: }else{ ! 161: if(plotmode)oputs(t.plotoff); ! 162: /* ! 163: * simulate bold font as overstrike if no t.bdon ! 164: */ ! 165: if (xfont == 2 && !(*t.bdon & 0377)) { ! 166: oput(*codep); ! 167: oput('\b'); ! 168: } ! 169: *obufp++ = *codep++; ! 170: if(obufp == (obuf + OBUFSZ + ascii - 1))flusho(); ! 171: /* oput(*codep++);*/ ! 172: } ! 173: } ! 174: if(!w)for(k=phyw/t.Char;k>0;k--)oput('\b'); ! 175: } ! 176: } ! 177: char *plot(x) ! 178: char *x; ! 179: { ! 180: register int i; ! 181: register char *j, *k; ! 182: ! 183: if(!plotmode)oputs(t.ploton); ! 184: k = x; ! 185: if((*k & 0377) == 0200)k++; ! 186: for(; *k; k++){ ! 187: if(*k & 0200){ ! 188: if(*k & 0100){ ! 189: if(*k & 040)j = t.up; else j = t.down; ! 190: }else{ ! 191: if(*k & 040)j = t.left; else j = t.right; ! 192: } ! 193: if(!(i = *k & 037))return(++k); ! 194: while(i--)oputs(j); ! 195: }else oput(*k); ! 196: } ! 197: return(k); ! 198: } ! 199: move(){ ! 200: register k; ! 201: register char *i, *j; ! 202: char *p, *q; ! 203: int iesct, dt; ! 204: ! 205: iesct = esct; ! 206: if(esct += esc)i = "\0"; else i = "\n\0"; ! 207: j = t.hlf; ! 208: p = t.right; ! 209: q = t.down; ! 210: if(lead){ ! 211: if(lead < 0){ ! 212: lead = -lead; ! 213: i = t.flr; ! 214: /* if(!esct)i = t.flr; else i = "\0";*/ ! 215: j = t.hlr; ! 216: q = t.up; ! 217: } ! 218: if(*i & 0377){ ! 219: k = lead/t.Newline; ! 220: lead = lead%t.Newline; ! 221: while(k--)oputs(i); ! 222: } ! 223: if(*j & 0377){ ! 224: k = lead/t.Halfline; ! 225: lead = lead%t.Halfline; ! 226: while(k--)oputs(j); ! 227: } ! 228: else { /* no half-line forward, not at line begining */ ! 229: k = lead/t.Newline; ! 230: lead = lead%t.Newline; ! 231: if (k>0) esc=esct; ! 232: i = "\n"; ! 233: while (k--) oputs(i); ! 234: } ! 235: } ! 236: if(esc){ ! 237: if(esc < 0){ ! 238: esc = -esc; ! 239: j = "\b"; ! 240: p = t.left; ! 241: }else{ ! 242: j = " "; ! 243: if(hflg)while((dt = dtab - (iesct%dtab)) <= esc){ ! 244: if(dt%t.Em || dt==t.Em)break; ! 245: oput(TAB); ! 246: esc -= dt; ! 247: iesct += dt; ! 248: } ! 249: } ! 250: k = esc/t.Em; ! 251: esc = esc%t.Em; ! 252: while(k--)oputs(j); ! 253: } ! 254: if((*t.ploton & 0377) && (esc || lead)){ ! 255: if(!plotmode)oputs(t.ploton); ! 256: esc /= t.Hor; ! 257: lead /= t.Vert; ! 258: while(esc--)oputs(p); ! 259: while(lead--)oputs(q); ! 260: oputs(t.plotoff); ! 261: } ! 262: esc = lead = 0; ! 263: } ! 264: ptlead(){move();} ! 265: dostop(){ ! 266: char junk; ! 267: ! 268: flusho(); ! 269: read(2,&junk,1); ! 270: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.