8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / troff / n2.c
blob51803e7a02821eb5993c5089debe27c0c50076da
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * n2.c
45 * output, cleanup
48 #include <signal.h>
49 #include "tdef.h"
50 #ifdef NROFF
51 #include "tw.h"
52 #endif
53 #include <setjmp.h>
54 #include "ext.h"
55 #ifdef EUC
56 #ifdef NROFF
57 #include <stddef.h>
58 #include <widec.h>
59 #include <limits.h>
60 #include <ctype.h>
62 char mbobuf[MB_LEN_MAX] = {0};
63 wchar_t wchar;
64 int nmb1 = 0;
65 #endif /* NROFF */
66 #endif /* EUC */
68 extern jmp_buf sjbuf;
69 int toolate;
70 int error;
72 int
73 pchar(i)
74 tchar i;
76 int j;
77 static int hx = 0; /* records if have seen HX */
79 if (hx) {
80 hx = 0;
81 j = absmot(i);
82 if (isnmot(i)) {
83 if (j > dip->blss)
84 dip->blss = j;
85 } else {
86 if (j > dip->alss)
87 dip->alss = j;
88 ralss = dip->alss;
90 return (0);
92 if (ismot(i)) {
93 pchar1(i);
94 return (0);
96 switch (j = cbits(i)) {
97 case 0:
98 case IMP:
99 case RIGHT:
100 case LEFT:
101 return (0);
102 case HX:
103 hx = 1;
104 return (0);
105 case PRESC:
106 if (dip == &d[0])
107 j = eschar; /* fall through */
108 default:
109 #ifndef EUC
110 setcbits(i, trtab[j]);
111 #else
112 #ifndef NROFF
113 setcbits(i, trtab[j]);
114 #else
115 if (!multi_locale || (!(j & CSMASK) && !(j & MBMASK1)))
116 setcbits(i, trtab[j]);
117 #endif /* NROFF */
118 #endif /* EUC */
120 pchar1(i);
122 return (0);
127 pchar1(i)
128 tchar i;
130 int j;
132 j = cbits(i);
133 if (dip != &d[0]) {
134 wbf(i);
135 dip->op = offset;
136 return (0);
138 if (!tflg && !print) {
139 if (j == '\n')
140 dip->alss = dip->blss = 0;
141 return (0);
143 if (no_out || j == FILLER)
144 return (0);
145 if (tflg) { /* transparent mode, undiverted */
146 fdprintf(ptid, "%c", j);
147 return (0);
149 #ifndef NROFF
150 if (ascii)
151 outascii(i);
152 else
153 #endif
154 ptout(i);
156 return (0);
160 outascii(i) /* print i in best-guess ascii */
161 tchar i;
163 int j = cbits(i);
165 if (ismot(i)) {
166 oput(' ');
167 return (0);
169 if (j < 0177 && j >= ' ' || j == '\n') {
170 oput(j);
171 return (0);
173 if (j == DRAWFCN)
174 oputs("\\D");
175 else if (j == HYPHEN || j == MINUS)
176 oput('-');
177 else if (j == XON)
178 oputs("\\X");
179 else if (j == LIG_FI)
180 oputs("fi");
181 else if (j == LIG_FL)
182 oputs("fl");
183 else if (j == LIG_FF)
184 oputs("ff");
185 else if (j == LIG_FFI)
186 oputs("ffi");
187 else if (j == LIG_FFL)
188 oputs("ffl");
189 else if (j == WORDSP)
190 ; /* nothing at all */
191 else if (j > 0177) {
192 oput('\\');
193 oput('(');
194 oput(chname[chtab[j-128]]);
195 oput(chname[chtab[j-128]+1]);
198 return (0);
203 * now a macro
205 oput(i)
206 int i;
208 *obufp++ = i;
209 if (obufp >= &obuf[OBUFSZ])
210 flusho();
212 return (0);
217 oputs(i)
218 char *i;
220 while (*i != 0)
221 oput(*i++);
223 return (0);
228 flusho()
230 if (obufp == obuf)
231 return (0);
232 if (no_out == 0) {
233 if (!toolate) {
234 toolate++;
235 #ifdef NROFF
236 set_tty();
238 char *p = t.twinit;
239 while (*p++)
241 if (p - t.twinit > 1)
242 write(ptid, t.twinit, p - t.twinit - 1);
244 #endif
246 toolate += write(ptid, obuf, obufp - obuf);
248 obufp = obuf;
250 return (0);
255 done(x)
256 int x;
258 int i;
260 error |= x;
261 app = ds = lgf = 0;
262 if (i = em) {
263 donef = -1;
264 em = 0;
265 if (control(i, 0))
266 longjmp(sjbuf, 1);
268 if (!nfo)
269 done3(0);
270 mflg = 0;
271 dip = &d[0];
272 if (woff)
273 wbt((tchar)0);
274 if (pendw)
275 getword(1);
276 pendnf = 0;
277 if (donef == 1)
278 done1(0);
279 donef = 1;
280 ip = 0;
281 frame = stk;
282 nxf = frame + 1;
283 if (!ejf)
284 tbreak();
285 nflush++;
286 eject((struct s *)0);
287 longjmp(sjbuf, 1);
289 return (0);
294 done1(x)
295 int x;
297 error |= x;
298 if (numtab[NL].val) {
299 trap = 0;
300 eject((struct s *)0);
301 longjmp(sjbuf, 1);
303 if (nofeed) {
304 ptlead();
305 flusho();
306 done3(0);
307 } else {
308 if (!gflag)
309 pttrailer();
310 done2(0);
313 return (0);
318 done2(x)
319 int x;
321 ptlead();
322 #ifndef NROFF
323 if (!ascii)
324 ptstop();
325 #endif
326 flusho();
327 done3(x);
329 return (0);
333 done3(x)
334 int x;
336 error |= x;
337 signal(SIGINT, SIG_IGN);
338 signal(SIGTERM, SIG_IGN);
339 unlink(unlkp);
340 #ifdef NROFF
341 twdone();
342 #endif
343 if (ascii)
344 mesg(1);
345 exit(error);
347 return (0);
352 edone(x)
353 int x;
355 frame = stk;
356 nxf = frame + 1;
357 ip = 0;
358 done(x);
360 return (0);
365 casepi()
367 int i;
368 int id[2];
370 if (toolate || skip() || !getname() || pipe(id) == -1 || (i = fork()) == -1) {
371 errprint(gettext("Pipe not created."));
372 return (0);
374 ptid = id[1];
375 if (i > 0) {
376 close(id[0]);
377 toolate++;
378 pipeflg++;
379 return (0);
381 close(0);
382 dup(id[0]);
383 close(id[1]);
384 execl(nextf, nextf, 0);
385 errprint(gettext("Cannot exec %s"), nextf);
386 exit(-4);
388 return (0);