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