17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate * n2.c
427c478bd9Sstevel@tonic-gate *
437c478bd9Sstevel@tonic-gate * output, cleanup
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #include <signal.h>
477c478bd9Sstevel@tonic-gate #include "tdef.h"
487c478bd9Sstevel@tonic-gate #ifdef NROFF
497c478bd9Sstevel@tonic-gate #include "tw.h"
507c478bd9Sstevel@tonic-gate #endif
517c478bd9Sstevel@tonic-gate #include <setjmp.h>
527c478bd9Sstevel@tonic-gate #include "ext.h"
537c478bd9Sstevel@tonic-gate #ifdef EUC
547c478bd9Sstevel@tonic-gate #ifdef NROFF
557c478bd9Sstevel@tonic-gate #include <stddef.h>
567c478bd9Sstevel@tonic-gate #include <widec.h>
577c478bd9Sstevel@tonic-gate #include <limits.h>
587c478bd9Sstevel@tonic-gate #include <ctype.h>
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate char mbobuf[MB_LEN_MAX] = {0};
617c478bd9Sstevel@tonic-gate wchar_t wchar;
627c478bd9Sstevel@tonic-gate int nmb1 = 0;
637c478bd9Sstevel@tonic-gate #endif /* NROFF */
647c478bd9Sstevel@tonic-gate #endif /* EUC */
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate extern jmp_buf sjbuf;
677c478bd9Sstevel@tonic-gate int toolate;
687c478bd9Sstevel@tonic-gate int error;
697c478bd9Sstevel@tonic-gate
70e5190c10Smuffin int
pchar(i)717c478bd9Sstevel@tonic-gate pchar(i)
72e5190c10Smuffin tchar i;
737c478bd9Sstevel@tonic-gate {
74e5190c10Smuffin int j;
757c478bd9Sstevel@tonic-gate static int hx = 0; /* records if have seen HX */
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate if (hx) {
787c478bd9Sstevel@tonic-gate hx = 0;
797c478bd9Sstevel@tonic-gate j = absmot(i);
807c478bd9Sstevel@tonic-gate if (isnmot(i)) {
817c478bd9Sstevel@tonic-gate if (j > dip->blss)
827c478bd9Sstevel@tonic-gate dip->blss = j;
837c478bd9Sstevel@tonic-gate } else {
847c478bd9Sstevel@tonic-gate if (j > dip->alss)
857c478bd9Sstevel@tonic-gate dip->alss = j;
867c478bd9Sstevel@tonic-gate ralss = dip->alss;
877c478bd9Sstevel@tonic-gate }
88e5190c10Smuffin return (0);
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate if (ismot(i)) {
91*2a8bcb4eSToomas Soome pchar1(i);
92e5190c10Smuffin return (0);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate switch (j = cbits(i)) {
957c478bd9Sstevel@tonic-gate case 0:
967c478bd9Sstevel@tonic-gate case IMP:
977c478bd9Sstevel@tonic-gate case RIGHT:
987c478bd9Sstevel@tonic-gate case LEFT:
99e5190c10Smuffin return (0);
1007c478bd9Sstevel@tonic-gate case HX:
1017c478bd9Sstevel@tonic-gate hx = 1;
102e5190c10Smuffin return (0);
1037c478bd9Sstevel@tonic-gate case PRESC:
1047c478bd9Sstevel@tonic-gate if (dip == &d[0])
1057c478bd9Sstevel@tonic-gate j = eschar; /* fall through */
1067c478bd9Sstevel@tonic-gate default:
1077c478bd9Sstevel@tonic-gate #ifndef EUC
1087c478bd9Sstevel@tonic-gate setcbits(i, trtab[j]);
1097c478bd9Sstevel@tonic-gate #else
1107c478bd9Sstevel@tonic-gate #ifndef NROFF
1117c478bd9Sstevel@tonic-gate setcbits(i, trtab[j]);
1127c478bd9Sstevel@tonic-gate #else
1137c478bd9Sstevel@tonic-gate if (!multi_locale || (!(j & CSMASK) && !(j & MBMASK1)))
1147c478bd9Sstevel@tonic-gate setcbits(i, trtab[j]);
1157c478bd9Sstevel@tonic-gate #endif /* NROFF */
1167c478bd9Sstevel@tonic-gate #endif /* EUC */
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate pchar1(i);
119e5190c10Smuffin
120e5190c10Smuffin return (0);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate
124e5190c10Smuffin int
pchar1(i)1257c478bd9Sstevel@tonic-gate pchar1(i)
126e5190c10Smuffin tchar i;
1277c478bd9Sstevel@tonic-gate {
128e5190c10Smuffin int j;
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate j = cbits(i);
1317c478bd9Sstevel@tonic-gate if (dip != &d[0]) {
1327c478bd9Sstevel@tonic-gate wbf(i);
1337c478bd9Sstevel@tonic-gate dip->op = offset;
134e5190c10Smuffin return (0);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate if (!tflg && !print) {
1377c478bd9Sstevel@tonic-gate if (j == '\n')
1387c478bd9Sstevel@tonic-gate dip->alss = dip->blss = 0;
139e5190c10Smuffin return (0);
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate if (no_out || j == FILLER)
142e5190c10Smuffin return (0);
1437c478bd9Sstevel@tonic-gate if (tflg) { /* transparent mode, undiverted */
1447c478bd9Sstevel@tonic-gate fdprintf(ptid, "%c", j);
145e5190c10Smuffin return (0);
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate #ifndef NROFF
1487c478bd9Sstevel@tonic-gate if (ascii)
1497c478bd9Sstevel@tonic-gate outascii(i);
1507c478bd9Sstevel@tonic-gate else
1517c478bd9Sstevel@tonic-gate #endif
1527c478bd9Sstevel@tonic-gate ptout(i);
153e5190c10Smuffin
154e5190c10Smuffin return (0);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate
157e5190c10Smuffin int
outascii(i)1587c478bd9Sstevel@tonic-gate outascii(i) /* print i in best-guess ascii */
1597c478bd9Sstevel@tonic-gate tchar i;
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate int j = cbits(i);
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate if (ismot(i)) {
1647c478bd9Sstevel@tonic-gate oput(' ');
165e5190c10Smuffin return (0);
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate if (j < 0177 && j >= ' ' || j == '\n') {
1687c478bd9Sstevel@tonic-gate oput(j);
169e5190c10Smuffin return (0);
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate if (j == DRAWFCN)
1727c478bd9Sstevel@tonic-gate oputs("\\D");
1737c478bd9Sstevel@tonic-gate else if (j == HYPHEN || j == MINUS)
1747c478bd9Sstevel@tonic-gate oput('-');
1757c478bd9Sstevel@tonic-gate else if (j == XON)
1767c478bd9Sstevel@tonic-gate oputs("\\X");
1777c478bd9Sstevel@tonic-gate else if (j == LIG_FI)
1787c478bd9Sstevel@tonic-gate oputs("fi");
1797c478bd9Sstevel@tonic-gate else if (j == LIG_FL)
1807c478bd9Sstevel@tonic-gate oputs("fl");
1817c478bd9Sstevel@tonic-gate else if (j == LIG_FF)
1827c478bd9Sstevel@tonic-gate oputs("ff");
1837c478bd9Sstevel@tonic-gate else if (j == LIG_FFI)
1847c478bd9Sstevel@tonic-gate oputs("ffi");
1857c478bd9Sstevel@tonic-gate else if (j == LIG_FFL)
1867c478bd9Sstevel@tonic-gate oputs("ffl");
1877c478bd9Sstevel@tonic-gate else if (j == WORDSP)
1887c478bd9Sstevel@tonic-gate ; /* nothing at all */
1897c478bd9Sstevel@tonic-gate else if (j > 0177) {
1907c478bd9Sstevel@tonic-gate oput('\\');
1917c478bd9Sstevel@tonic-gate oput('(');
1927c478bd9Sstevel@tonic-gate oput(chname[chtab[j-128]]);
1937c478bd9Sstevel@tonic-gate oput(chname[chtab[j-128]+1]);
1947c478bd9Sstevel@tonic-gate }
195e5190c10Smuffin
196e5190c10Smuffin return (0);
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate * now a macro
202e5190c10Smuffin int
2037c478bd9Sstevel@tonic-gate oput(i)
204e5190c10Smuffin int i;
2057c478bd9Sstevel@tonic-gate {
2067c478bd9Sstevel@tonic-gate *obufp++ = i;
2077c478bd9Sstevel@tonic-gate if (obufp >= &obuf[OBUFSZ])
2087c478bd9Sstevel@tonic-gate flusho();
209e5190c10Smuffin
210e5190c10Smuffin return (0);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate */
2137c478bd9Sstevel@tonic-gate
214e5190c10Smuffin int
oputs(i)2157c478bd9Sstevel@tonic-gate oputs(i)
216e5190c10Smuffin char *i;
2177c478bd9Sstevel@tonic-gate {
2187c478bd9Sstevel@tonic-gate while (*i != 0)
2197c478bd9Sstevel@tonic-gate oput(*i++);
220e5190c10Smuffin
221e5190c10Smuffin return (0);
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate
225e5190c10Smuffin int
flusho()2267c478bd9Sstevel@tonic-gate flusho()
2277c478bd9Sstevel@tonic-gate {
2287c478bd9Sstevel@tonic-gate if (obufp == obuf)
229e5190c10Smuffin return (0);
2307c478bd9Sstevel@tonic-gate if (no_out == 0) {
2317c478bd9Sstevel@tonic-gate if (!toolate) {
2327c478bd9Sstevel@tonic-gate toolate++;
2337c478bd9Sstevel@tonic-gate #ifdef NROFF
2347c478bd9Sstevel@tonic-gate set_tty();
2357c478bd9Sstevel@tonic-gate {
2367c478bd9Sstevel@tonic-gate char *p = t.twinit;
2377c478bd9Sstevel@tonic-gate while (*p++)
2387c478bd9Sstevel@tonic-gate ;
2397c478bd9Sstevel@tonic-gate if (p - t.twinit > 1)
2407c478bd9Sstevel@tonic-gate write(ptid, t.twinit, p - t.twinit - 1);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate #endif
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate toolate += write(ptid, obuf, obufp - obuf);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate obufp = obuf;
247e5190c10Smuffin
248e5190c10Smuffin return (0);
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate
252e5190c10Smuffin int
done(x)253*2a8bcb4eSToomas Soome done(x)
2547c478bd9Sstevel@tonic-gate int x;
2557c478bd9Sstevel@tonic-gate {
256e5190c10Smuffin int i;
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate error |= x;
2597c478bd9Sstevel@tonic-gate app = ds = lgf = 0;
2607c478bd9Sstevel@tonic-gate if (i = em) {
2617c478bd9Sstevel@tonic-gate donef = -1;
2627c478bd9Sstevel@tonic-gate em = 0;
2637c478bd9Sstevel@tonic-gate if (control(i, 0))
2647c478bd9Sstevel@tonic-gate longjmp(sjbuf, 1);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate if (!nfo)
2677c478bd9Sstevel@tonic-gate done3(0);
2687c478bd9Sstevel@tonic-gate mflg = 0;
2697c478bd9Sstevel@tonic-gate dip = &d[0];
2707c478bd9Sstevel@tonic-gate if (woff)
2717c478bd9Sstevel@tonic-gate wbt((tchar)0);
2727c478bd9Sstevel@tonic-gate if (pendw)
2737c478bd9Sstevel@tonic-gate getword(1);
2747c478bd9Sstevel@tonic-gate pendnf = 0;
2757c478bd9Sstevel@tonic-gate if (donef == 1)
2767c478bd9Sstevel@tonic-gate done1(0);
2777c478bd9Sstevel@tonic-gate donef = 1;
2787c478bd9Sstevel@tonic-gate ip = 0;
2797c478bd9Sstevel@tonic-gate frame = stk;
2807c478bd9Sstevel@tonic-gate nxf = frame + 1;
2817c478bd9Sstevel@tonic-gate if (!ejf)
2827c478bd9Sstevel@tonic-gate tbreak();
2837c478bd9Sstevel@tonic-gate nflush++;
2847c478bd9Sstevel@tonic-gate eject((struct s *)0);
2857c478bd9Sstevel@tonic-gate longjmp(sjbuf, 1);
286e5190c10Smuffin
287e5190c10Smuffin return (0);
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate
291e5190c10Smuffin int
done1(x)292*2a8bcb4eSToomas Soome done1(x)
293*2a8bcb4eSToomas Soome int x;
2947c478bd9Sstevel@tonic-gate {
2957c478bd9Sstevel@tonic-gate error |= x;
2967c478bd9Sstevel@tonic-gate if (numtab[NL].val) {
2977c478bd9Sstevel@tonic-gate trap = 0;
2987c478bd9Sstevel@tonic-gate eject((struct s *)0);
2997c478bd9Sstevel@tonic-gate longjmp(sjbuf, 1);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate if (nofeed) {
3027c478bd9Sstevel@tonic-gate ptlead();
3037c478bd9Sstevel@tonic-gate flusho();
3047c478bd9Sstevel@tonic-gate done3(0);
3057c478bd9Sstevel@tonic-gate } else {
3067c478bd9Sstevel@tonic-gate if (!gflag)
3077c478bd9Sstevel@tonic-gate pttrailer();
3087c478bd9Sstevel@tonic-gate done2(0);
3097c478bd9Sstevel@tonic-gate }
310e5190c10Smuffin
311e5190c10Smuffin return (0);
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate
315e5190c10Smuffin int
done2(x)316*2a8bcb4eSToomas Soome done2(x)
317*2a8bcb4eSToomas Soome int x;
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate ptlead();
3207c478bd9Sstevel@tonic-gate #ifndef NROFF
3217c478bd9Sstevel@tonic-gate if (!ascii)
3227c478bd9Sstevel@tonic-gate ptstop();
3237c478bd9Sstevel@tonic-gate #endif
3247c478bd9Sstevel@tonic-gate flusho();
3257c478bd9Sstevel@tonic-gate done3(x);
326e5190c10Smuffin
327e5190c10Smuffin return (0);
3287c478bd9Sstevel@tonic-gate }
3297c478bd9Sstevel@tonic-gate
330e5190c10Smuffin int
done3(x)331*2a8bcb4eSToomas Soome done3(x)
3327c478bd9Sstevel@tonic-gate int x;
3337c478bd9Sstevel@tonic-gate {
3347c478bd9Sstevel@tonic-gate error |= x;
3357c478bd9Sstevel@tonic-gate signal(SIGINT, SIG_IGN);
3367c478bd9Sstevel@tonic-gate signal(SIGTERM, SIG_IGN);
3377c478bd9Sstevel@tonic-gate unlink(unlkp);
3387c478bd9Sstevel@tonic-gate #ifdef NROFF
3397c478bd9Sstevel@tonic-gate twdone();
3407c478bd9Sstevel@tonic-gate #endif
3417c478bd9Sstevel@tonic-gate if (ascii)
3427c478bd9Sstevel@tonic-gate mesg(1);
3437c478bd9Sstevel@tonic-gate exit(error);
344e5190c10Smuffin
345e5190c10Smuffin return (0);
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate
349e5190c10Smuffin int
edone(x)350*2a8bcb4eSToomas Soome edone(x)
3517c478bd9Sstevel@tonic-gate int x;
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate frame = stk;
3547c478bd9Sstevel@tonic-gate nxf = frame + 1;
3557c478bd9Sstevel@tonic-gate ip = 0;
3567c478bd9Sstevel@tonic-gate done(x);
3577c478bd9Sstevel@tonic-gate
358e5190c10Smuffin return (0);
359e5190c10Smuffin }
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate
362e5190c10Smuffin int
casepi()3637c478bd9Sstevel@tonic-gate casepi()
3647c478bd9Sstevel@tonic-gate {
365e5190c10Smuffin int i;
3667c478bd9Sstevel@tonic-gate int id[2];
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate if (toolate || skip() || !getname() || pipe(id) == -1 || (i = fork()) == -1) {
3697c478bd9Sstevel@tonic-gate errprint(gettext("Pipe not created."));
370e5190c10Smuffin return (0);
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate ptid = id[1];
3737c478bd9Sstevel@tonic-gate if (i > 0) {
3747c478bd9Sstevel@tonic-gate close(id[0]);
3757c478bd9Sstevel@tonic-gate toolate++;
3767c478bd9Sstevel@tonic-gate pipeflg++;
377e5190c10Smuffin return (0);
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate close(0);
3807c478bd9Sstevel@tonic-gate dup(id[0]);
3817c478bd9Sstevel@tonic-gate close(id[1]);
3827c478bd9Sstevel@tonic-gate execl(nextf, nextf, 0);
3837c478bd9Sstevel@tonic-gate errprint(gettext("Cannot exec %s"), nextf);
3847c478bd9Sstevel@tonic-gate exit(-4);
385e5190c10Smuffin
386e5190c10Smuffin return (0);
3877c478bd9Sstevel@tonic-gate }
388