changed "source file %s.c" to "... %s.f"
[unix-history] / usr / src / old / roff / nroff / n10.c
CommitLineData
5816430b
RH
1#ifndef lint
2static char sccsid[] = "@(#)n10.c 4.1 %G%";
3#endif lint
4
5#include "tdef.h"
6#include <sgtty.h>
7extern
8#include "d.h"
9extern
10#include "v.h"
11extern
12#include "tw.h"
13/*
14nroff10.c
15
16Device interfaces
17*/
18
19extern int lss;
20extern char obuf[];
21extern char *obufp;
22extern int xfont;
23extern int esc;
24extern int lead;
25extern int oline[];
26extern int *olinep;
27extern int ulfont;
28extern int esct;
29extern int sps;
30extern int ics;
31extern int ttysave;
32extern struct sgttyb ttys;
33extern char termtab[];
34extern int ptid;
35extern int waitf;
36extern int pipeflg;
37extern int eqflg;
38extern int hflg;
39extern int tabtab[];
40extern int ascii;
41extern int xxx;
42int dtab;
43int bdmode;
44int plotmode;
45
46ptinit(){
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}
75twdone(){
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}
88ptout(i)
89int 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}
110ptout1()
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 if(xfont == ulfont){
151 for(k=w/t.Char;k>0;k--)oput('_');
152 for(k=w/t.Char;k>0;k--)oput('\b');
153 }
154 while(*codep != 0){
155 if(*codep & 0200){
156 codep = plot(codep);
157 oputs(t.plotoff);
158 oput(' ');
159 }else{
160 if(plotmode)oputs(t.plotoff);
161 *obufp++ = *codep++;
162 if(obufp == (obuf + OBUFSZ + ascii - 1))flusho();
163/* oput(*codep++);*/
164 }
165 }
166 if(!w)for(k=phyw/t.Char;k>0;k--)oput('\b');
167 }
168}
169char *plot(x)
170char *x;
171{
172 register int i;
173 register char *j, *k;
174
175 if(!plotmode)oputs(t.ploton);
176 k = x;
177 if((*k & 0377) == 0200)k++;
178 for(; *k; k++){
179 if(*k & 0200){
180 if(*k & 0100){
181 if(*k & 040)j = t.up; else j = t.down;
182 }else{
183 if(*k & 040)j = t.left; else j = t.right;
184 }
185 if(!(i = *k & 037))return(++k);
186 while(i--)oputs(j);
187 }else oput(*k);
188 }
189 return(k);
190}
191move(){
192 register k;
193 register char *i, *j;
194 char *p, *q;
195 int iesct, dt;
196
197 iesct = esct;
198 if(esct += esc)i = "\0"; else i = "\n\0";
199 j = t.hlf;
200 p = t.right;
201 q = t.down;
202 if(lead){
203 if(lead < 0){
204 lead = -lead;
205 i = t.flr;
206 /* if(!esct)i = t.flr; else i = "\0";*/
207 j = t.hlr;
208 q = t.up;
209 }
210 if(*i & 0377){
211 k = lead/t.Newline;
212 lead = lead%t.Newline;
213 while(k--)oputs(i);
214 }
215 if(*j & 0377){
216 k = lead/t.Halfline;
217 lead = lead%t.Halfline;
218 while(k--)oputs(j);
219 }
220 else { /* no half-line forward, not at line begining */
221 k = lead/t.Newline;
222 lead = lead%t.Newline;
223 if (k>0) esc=esct;
224 i = "\n";
225 while (k--) oputs(i);
226 }
227 }
228 if(esc){
229 if(esc < 0){
230 esc = -esc;
231 j = "\b";
232 p = t.left;
233 }else{
234 j = " ";
235 if(hflg)while((dt = dtab - (iesct%dtab)) <= esc){
236 if(dt%t.Em)break;
237 oput(TAB);
238 esc -= dt;
239 iesct += dt;
240 }
241 }
242 k = esc/t.Em;
243 esc = esc%t.Em;
244 while(k--)oputs(j);
245 }
246 if((*t.ploton & 0377) && (esc || lead)){
247 if(!plotmode)oputs(t.ploton);
248 esc /= t.Hor;
249 lead /= t.Vert;
250 while(esc--)oputs(p);
251 while(lead--)oputs(q);
252 oputs(t.plotoff);
253 }
254 esc = lead = 0;
255}
256ptlead(){move();}
257dostop(){
258 char junk;
259
260 flusho();
261 read(2,&junk,1);
262}