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