1 #ifndef lint
2 /*
3 static char sccsid[] = "@(#)n2.c 2.1 (CWI) 85/07/18";
4 */
5 static char sccsid[] = "@(#)n2.c 2.2 (Berkeley) 07/27/93";
6 #endif lint
7 /*
8 * n2.c
9 *
10 * output, cleanup
11 */
12
13 #include "tdef.h"
14 #include <sgtty.h>
15 #include <signal.h>
16 #ifdef NROFF
17 #include "tw.h"
18 #endif
19 #include <setjmp.h>
20 #include "ext.h"
21
22 extern jmp_buf sjbuf;
23 int toolate;
24 int error;
25
pchar(i)26 pchar(i)
27 register tchar i;
28 {
29 register int j;
30 static int hx = 0; /* records if have seen HX */
31
32 if (hx) {
33 hx = 0;
34 j = absmot(i);
35 if (isnmot(i)) {
36 if (j > dip->blss)
37 dip->blss = j;
38 } else {
39 if (j > dip->alss)
40 dip->alss = j;
41 ralss = dip->alss;
42 }
43 return;
44 }
45 if (ismot(i)) {
46 pchar1(i);
47 return;
48 }
49 switch (j = cbits(i)) {
50 case 0:
51 case IMP:
52 case RIGHT:
53 case LEFT:
54 return;
55 case HX:
56 hx = 1;
57 return;
58 case PRESC:
59 if (dip == &d[0])
60 j = eschar; /* fall through */
61 default:
62 setcbits(i, trtab[j]);
63 }
64 pchar1(i);
65 }
66
67
pchar1(i)68 pchar1(i)
69 register tchar i;
70 {
71 register j;
72
73 j = cbits(i);
74 if (dip != &d[0]) {
75 wbf(i);
76 dip->op = offset;
77 return;
78 }
79 if (!tflg && !print) {
80 if (j == '\n')
81 dip->alss = dip->blss = 0;
82 return;
83 }
84 if (no_out || j == FILLER)
85 return;
86 if (tflg) { /* transparent mode, undiverted */
87 fdprintf(ptid, "%c", j);
88 return;
89 }
90 #ifndef NROFF
91 if (ascii)
92 outascii(i);
93 else
94 #endif
95 ptout(i);
96 }
97
outascii(i)98 outascii(i) /* print i in best-guess ascii */
99 tchar i;
100 {
101 static int seendraw;
102 int j = cbits(i);
103
104 if (ismot(i)) {
105 if(!seendraw) {
106 oput(' ');
107 }
108 return;
109 }
110 if (j < 0177 && j >= 040) {
111 if(!seendraw) {
112 oput(j);
113 return;
114 } else {
115 switch(j) {
116 case DRAWCIRCLE: oputs("CIRCLE ");
117 break;
118 case DRAWELLIPSE: oputs("ELLIPSE ");
119 break;
120 case DRAWLINE: oputs("LINE ");
121 break;
122 case DRAWSPLINE: oputs("SPLINE ");
123 break;
124 case DRAWARC: oputs("ARC ");
125 break;
126 case '.':oputs(".");
127 /*
128 if(seendraw == 2)
129 seendraw = 0;
130 else
131 seendraw++;
132 */
133 break;
134 default: oputs("UNKNOWN "); flusho();
135 errprint("Unknown 0%o %c function", j,j);
136 break;
137 }
138 return;
139 }
140 }
141 if( j < 040) {
142 switch(j) {
143 case SLANT:
144 case CHARHT:
145 case WORDSP:
146 case HX:
147 return;
148 case DRAWFCN:
149 if(seendraw == 1){
150 seendraw = 0;
151 } else {
152 oputs("DRAWFUNCTION ");flusho();
153 seendraw++;
154 }
155 /*
156 errprint("Seendraw %d", seendraw);
157 */
158 return;
159 case '\n':
160 oput(j);
161 return;
162 default:
163 errprint("Unknown (2) 0%o function", j);
164 return;
165 }
166 }
167 if (j == HYPHEN || j == MINUS)
168 oput('-');
169 else if (j == LIG_FI)
170 oputs("fi");
171 else if (j == LIG_FL)
172 oputs("fl");
173 else if (j == LIG_FF)
174 oputs("ff");
175 else if (j == LIG_FFI)
176 oputs("ffi");
177 else if (j == LIG_FFL)
178 oputs("ffl");
179 else {
180 oput('\\');
181 oput('(');
182 oput(chname[chtab[j-128]]);
183 oput(chname[chtab[j-128]+1]);
184 }
185 }
186
oputs(i)187 oputs(i)
188 register char *i;
189 {
190 while (*i != 0)
191 oput(*i++);
192 }
193
done(x)194 done(x)
195 int x;
196 {
197 register i;
198
199 error |= x;
200 app = ds = lgf = 0;
201 if (i = em) {
202 donef = -1;
203 em = 0;
204 if (control(i, 0))
205 longjmp(sjbuf, 1);
206 }
207 if (!nfo)
208 done3(0);
209 mflg = 0;
210 dip = &d[0];
211 if (woff)
212 wbt((tchar)0);
213 if (pendw)
214 getword(1);
215 pendnf = 0;
216 if (donef == 1)
217 done1(0);
218 donef = 1;
219 ip = 0;
220 frame = stk;
221 nxf = frame + 1;
222 if (!ejf)
223 tbreak();
224 nflush++;
225 eject((struct s *)0);
226 longjmp(sjbuf, 1);
227 }
228
229
done1(x)230 done1(x)
231 int x;
232 {
233 error |= x;
234 if (numtab[NL].val) {
235 trap = 0;
236 eject((struct s *)0);
237 longjmp(sjbuf, 1);
238 }
239 if (nofeed) {
240 ptlead();
241 flusho();
242 done3(0);
243 } else {
244 if (!gflag)
245 pttrailer();
246 done2(0);
247 }
248 }
249
250
done2(x)251 done2(x)
252 int x;
253 {
254 ptlead();
255 #ifndef NROFF
256 if (!ascii)
257 ptstop();
258 #endif
259 flusho();
260 done3(x);
261 }
262
done3(x)263 done3(x)
264 int x;
265 {
266 error |= x;
267 signal(SIGINT, SIG_IGN);
268 signal(SIGTERM, SIG_IGN);
269 #ifdef NROFF
270 twdone();
271 #endif
272 if (quiet) {
273 ttys.sg_flags |= ECHO;
274 stty(0, &ttys);
275 }
276 if (ascii)
277 mesg(1);
278 exit(error);
279 }
280
281
edone(x)282 edone(x)
283 int x;
284 {
285 frame = stk;
286 nxf = frame + 1;
287 ip = 0;
288 done(x);
289 }
290
291
292
casepi()293 casepi()
294 {
295 register i;
296 int id[2];
297
298 if (toolate || skip() || !getname() || pipe(id) == -1 || (i = fork()) == -1) {
299 errprint("Pipe not created.");
300 return;
301 }
302 ptid = fdopen(id[1], "w");
303 if (i > 0) {
304 close(id[0]);
305 toolate++;
306 pipeflg++;
307 return;
308 }
309 close(0);
310 dup(id[0]);
311 close(id[1]);
312 execl(nextf, nextf, 0);
313 errprint("Cannot exec %s", nextf);
314 exit(-4);
315 }
316