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
40*e5190c10Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
41*e5190c10Smuffin
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * n2.c
447c478bd9Sstevel@tonic-gate *
457c478bd9Sstevel@tonic-gate * output, cleanup
467c478bd9Sstevel@tonic-gate */
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate #include <signal.h>
497c478bd9Sstevel@tonic-gate #include "tdef.h"
507c478bd9Sstevel@tonic-gate #ifdef NROFF
517c478bd9Sstevel@tonic-gate #include "tw.h"
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate #include <setjmp.h>
547c478bd9Sstevel@tonic-gate #include "ext.h"
557c478bd9Sstevel@tonic-gate #ifdef EUC
567c478bd9Sstevel@tonic-gate #ifdef NROFF
577c478bd9Sstevel@tonic-gate #include <stddef.h>
587c478bd9Sstevel@tonic-gate #include <widec.h>
597c478bd9Sstevel@tonic-gate #include <limits.h>
607c478bd9Sstevel@tonic-gate #include <ctype.h>
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate char mbobuf[MB_LEN_MAX] = {0};
637c478bd9Sstevel@tonic-gate wchar_t wchar;
647c478bd9Sstevel@tonic-gate int nmb1 = 0;
657c478bd9Sstevel@tonic-gate #endif /* NROFF */
667c478bd9Sstevel@tonic-gate #endif /* EUC */
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate extern jmp_buf sjbuf;
697c478bd9Sstevel@tonic-gate int toolate;
707c478bd9Sstevel@tonic-gate int error;
717c478bd9Sstevel@tonic-gate
72*e5190c10Smuffin int
pchar(i)737c478bd9Sstevel@tonic-gate pchar(i)
74*e5190c10Smuffin tchar i;
757c478bd9Sstevel@tonic-gate {
76*e5190c10Smuffin int j;
777c478bd9Sstevel@tonic-gate static int hx = 0; /* records if have seen HX */
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate if (hx) {
807c478bd9Sstevel@tonic-gate hx = 0;
817c478bd9Sstevel@tonic-gate j = absmot(i);
827c478bd9Sstevel@tonic-gate if (isnmot(i)) {
837c478bd9Sstevel@tonic-gate if (j > dip->blss)
847c478bd9Sstevel@tonic-gate dip->blss = j;
857c478bd9Sstevel@tonic-gate } else {
867c478bd9Sstevel@tonic-gate if (j > dip->alss)
877c478bd9Sstevel@tonic-gate dip->alss = j;
887c478bd9Sstevel@tonic-gate ralss = dip->alss;
897c478bd9Sstevel@tonic-gate }
90*e5190c10Smuffin return (0);
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate if (ismot(i)) {
937c478bd9Sstevel@tonic-gate pchar1(i);
94*e5190c10Smuffin return (0);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate switch (j = cbits(i)) {
977c478bd9Sstevel@tonic-gate case 0:
987c478bd9Sstevel@tonic-gate case IMP:
997c478bd9Sstevel@tonic-gate case RIGHT:
1007c478bd9Sstevel@tonic-gate case LEFT:
101*e5190c10Smuffin return (0);
1027c478bd9Sstevel@tonic-gate case HX:
1037c478bd9Sstevel@tonic-gate hx = 1;
104*e5190c10Smuffin return (0);
1057c478bd9Sstevel@tonic-gate case PRESC:
1067c478bd9Sstevel@tonic-gate if (dip == &d[0])
1077c478bd9Sstevel@tonic-gate j = eschar; /* fall through */
1087c478bd9Sstevel@tonic-gate default:
1097c478bd9Sstevel@tonic-gate #ifndef EUC
1107c478bd9Sstevel@tonic-gate setcbits(i, trtab[j]);
1117c478bd9Sstevel@tonic-gate #else
1127c478bd9Sstevel@tonic-gate #ifndef NROFF
1137c478bd9Sstevel@tonic-gate setcbits(i, trtab[j]);
1147c478bd9Sstevel@tonic-gate #else
1157c478bd9Sstevel@tonic-gate if (!multi_locale || (!(j & CSMASK) && !(j & MBMASK1)))
1167c478bd9Sstevel@tonic-gate setcbits(i, trtab[j]);
1177c478bd9Sstevel@tonic-gate #endif /* NROFF */
1187c478bd9Sstevel@tonic-gate #endif /* EUC */
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate pchar1(i);
121*e5190c10Smuffin
122*e5190c10Smuffin return (0);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate
126*e5190c10Smuffin int
pchar1(i)1277c478bd9Sstevel@tonic-gate pchar1(i)
128*e5190c10Smuffin tchar i;
1297c478bd9Sstevel@tonic-gate {
130*e5190c10Smuffin int j;
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate j = cbits(i);
1337c478bd9Sstevel@tonic-gate if (dip != &d[0]) {
1347c478bd9Sstevel@tonic-gate wbf(i);
1357c478bd9Sstevel@tonic-gate dip->op = offset;
136*e5190c10Smuffin return (0);
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate if (!tflg && !print) {
1397c478bd9Sstevel@tonic-gate if (j == '\n')
1407c478bd9Sstevel@tonic-gate dip->alss = dip->blss = 0;
141*e5190c10Smuffin return (0);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate if (no_out || j == FILLER)
144*e5190c10Smuffin return (0);
1457c478bd9Sstevel@tonic-gate if (tflg) { /* transparent mode, undiverted */
1467c478bd9Sstevel@tonic-gate fdprintf(ptid, "%c", j);
147*e5190c10Smuffin return (0);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate #ifndef NROFF
1507c478bd9Sstevel@tonic-gate if (ascii)
1517c478bd9Sstevel@tonic-gate outascii(i);
1527c478bd9Sstevel@tonic-gate else
1537c478bd9Sstevel@tonic-gate #endif
1547c478bd9Sstevel@tonic-gate ptout(i);
155*e5190c10Smuffin
156*e5190c10Smuffin return (0);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
159*e5190c10Smuffin int
outascii(i)1607c478bd9Sstevel@tonic-gate outascii(i) /* print i in best-guess ascii */
1617c478bd9Sstevel@tonic-gate tchar i;
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate int j = cbits(i);
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate if (ismot(i)) {
1667c478bd9Sstevel@tonic-gate oput(' ');
167*e5190c10Smuffin return (0);
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate if (j < 0177 && j >= ' ' || j == '\n') {
1707c478bd9Sstevel@tonic-gate oput(j);
171*e5190c10Smuffin return (0);
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate if (j == DRAWFCN)
1747c478bd9Sstevel@tonic-gate oputs("\\D");
1757c478bd9Sstevel@tonic-gate else if (j == HYPHEN || j == MINUS)
1767c478bd9Sstevel@tonic-gate oput('-');
1777c478bd9Sstevel@tonic-gate else if (j == XON)
1787c478bd9Sstevel@tonic-gate oputs("\\X");
1797c478bd9Sstevel@tonic-gate else if (j == LIG_FI)
1807c478bd9Sstevel@tonic-gate oputs("fi");
1817c478bd9Sstevel@tonic-gate else if (j == LIG_FL)
1827c478bd9Sstevel@tonic-gate oputs("fl");
1837c478bd9Sstevel@tonic-gate else if (j == LIG_FF)
1847c478bd9Sstevel@tonic-gate oputs("ff");
1857c478bd9Sstevel@tonic-gate else if (j == LIG_FFI)
1867c478bd9Sstevel@tonic-gate oputs("ffi");
1877c478bd9Sstevel@tonic-gate else if (j == LIG_FFL)
1887c478bd9Sstevel@tonic-gate oputs("ffl");
1897c478bd9Sstevel@tonic-gate else if (j == WORDSP)
1907c478bd9Sstevel@tonic-gate ; /* nothing at all */
1917c478bd9Sstevel@tonic-gate else if (j > 0177) {
1927c478bd9Sstevel@tonic-gate oput('\\');
1937c478bd9Sstevel@tonic-gate oput('(');
1947c478bd9Sstevel@tonic-gate oput(chname[chtab[j-128]]);
1957c478bd9Sstevel@tonic-gate oput(chname[chtab[j-128]+1]);
1967c478bd9Sstevel@tonic-gate }
197*e5190c10Smuffin
198*e5190c10Smuffin return (0);
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate * now a macro
204*e5190c10Smuffin int
2057c478bd9Sstevel@tonic-gate oput(i)
206*e5190c10Smuffin int i;
2077c478bd9Sstevel@tonic-gate {
2087c478bd9Sstevel@tonic-gate *obufp++ = i;
2097c478bd9Sstevel@tonic-gate if (obufp >= &obuf[OBUFSZ])
2107c478bd9Sstevel@tonic-gate flusho();
211*e5190c10Smuffin
212*e5190c10Smuffin return (0);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate */
2157c478bd9Sstevel@tonic-gate
216*e5190c10Smuffin int
oputs(i)2177c478bd9Sstevel@tonic-gate oputs(i)
218*e5190c10Smuffin char *i;
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate while (*i != 0)
2217c478bd9Sstevel@tonic-gate oput(*i++);
222*e5190c10Smuffin
223*e5190c10Smuffin return (0);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate
227*e5190c10Smuffin int
flusho()2287c478bd9Sstevel@tonic-gate flusho()
2297c478bd9Sstevel@tonic-gate {
2307c478bd9Sstevel@tonic-gate if (obufp == obuf)
231*e5190c10Smuffin return (0);
2327c478bd9Sstevel@tonic-gate if (no_out == 0) {
2337c478bd9Sstevel@tonic-gate if (!toolate) {
2347c478bd9Sstevel@tonic-gate toolate++;
2357c478bd9Sstevel@tonic-gate #ifdef NROFF
2367c478bd9Sstevel@tonic-gate set_tty();
2377c478bd9Sstevel@tonic-gate {
2387c478bd9Sstevel@tonic-gate char *p = t.twinit;
2397c478bd9Sstevel@tonic-gate while (*p++)
2407c478bd9Sstevel@tonic-gate ;
2417c478bd9Sstevel@tonic-gate if (p - t.twinit > 1)
2427c478bd9Sstevel@tonic-gate write(ptid, t.twinit, p - t.twinit - 1);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate #endif
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate toolate += write(ptid, obuf, obufp - obuf);
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate obufp = obuf;
249*e5190c10Smuffin
250*e5190c10Smuffin return (0);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate
254*e5190c10Smuffin int
done(x)2557c478bd9Sstevel@tonic-gate done(x)
2567c478bd9Sstevel@tonic-gate int x;
2577c478bd9Sstevel@tonic-gate {
258*e5190c10Smuffin int i;
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate error |= x;
2617c478bd9Sstevel@tonic-gate app = ds = lgf = 0;
2627c478bd9Sstevel@tonic-gate if (i = em) {
2637c478bd9Sstevel@tonic-gate donef = -1;
2647c478bd9Sstevel@tonic-gate em = 0;
2657c478bd9Sstevel@tonic-gate if (control(i, 0))
2667c478bd9Sstevel@tonic-gate longjmp(sjbuf, 1);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate if (!nfo)
2697c478bd9Sstevel@tonic-gate done3(0);
2707c478bd9Sstevel@tonic-gate mflg = 0;
2717c478bd9Sstevel@tonic-gate dip = &d[0];
2727c478bd9Sstevel@tonic-gate if (woff)
2737c478bd9Sstevel@tonic-gate wbt((tchar)0);
2747c478bd9Sstevel@tonic-gate if (pendw)
2757c478bd9Sstevel@tonic-gate getword(1);
2767c478bd9Sstevel@tonic-gate pendnf = 0;
2777c478bd9Sstevel@tonic-gate if (donef == 1)
2787c478bd9Sstevel@tonic-gate done1(0);
2797c478bd9Sstevel@tonic-gate donef = 1;
2807c478bd9Sstevel@tonic-gate ip = 0;
2817c478bd9Sstevel@tonic-gate frame = stk;
2827c478bd9Sstevel@tonic-gate nxf = frame + 1;
2837c478bd9Sstevel@tonic-gate if (!ejf)
2847c478bd9Sstevel@tonic-gate tbreak();
2857c478bd9Sstevel@tonic-gate nflush++;
2867c478bd9Sstevel@tonic-gate eject((struct s *)0);
2877c478bd9Sstevel@tonic-gate longjmp(sjbuf, 1);
288*e5190c10Smuffin
289*e5190c10Smuffin return (0);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate
293*e5190c10Smuffin int
done1(x)2947c478bd9Sstevel@tonic-gate done1(x)
2957c478bd9Sstevel@tonic-gate int x;
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate error |= x;
2987c478bd9Sstevel@tonic-gate if (numtab[NL].val) {
2997c478bd9Sstevel@tonic-gate trap = 0;
3007c478bd9Sstevel@tonic-gate eject((struct s *)0);
3017c478bd9Sstevel@tonic-gate longjmp(sjbuf, 1);
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate if (nofeed) {
3047c478bd9Sstevel@tonic-gate ptlead();
3057c478bd9Sstevel@tonic-gate flusho();
3067c478bd9Sstevel@tonic-gate done3(0);
3077c478bd9Sstevel@tonic-gate } else {
3087c478bd9Sstevel@tonic-gate if (!gflag)
3097c478bd9Sstevel@tonic-gate pttrailer();
3107c478bd9Sstevel@tonic-gate done2(0);
3117c478bd9Sstevel@tonic-gate }
312*e5190c10Smuffin
313*e5190c10Smuffin return (0);
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate
317*e5190c10Smuffin int
done2(x)3187c478bd9Sstevel@tonic-gate done2(x)
3197c478bd9Sstevel@tonic-gate int x;
3207c478bd9Sstevel@tonic-gate {
3217c478bd9Sstevel@tonic-gate ptlead();
3227c478bd9Sstevel@tonic-gate #ifndef NROFF
3237c478bd9Sstevel@tonic-gate if (!ascii)
3247c478bd9Sstevel@tonic-gate ptstop();
3257c478bd9Sstevel@tonic-gate #endif
3267c478bd9Sstevel@tonic-gate flusho();
3277c478bd9Sstevel@tonic-gate done3(x);
328*e5190c10Smuffin
329*e5190c10Smuffin return (0);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate
332*e5190c10Smuffin int
done3(x)3337c478bd9Sstevel@tonic-gate done3(x)
3347c478bd9Sstevel@tonic-gate int x;
3357c478bd9Sstevel@tonic-gate {
3367c478bd9Sstevel@tonic-gate error |= x;
3377c478bd9Sstevel@tonic-gate signal(SIGINT, SIG_IGN);
3387c478bd9Sstevel@tonic-gate signal(SIGTERM, SIG_IGN);
3397c478bd9Sstevel@tonic-gate unlink(unlkp);
3407c478bd9Sstevel@tonic-gate #ifdef NROFF
3417c478bd9Sstevel@tonic-gate twdone();
3427c478bd9Sstevel@tonic-gate #endif
3437c478bd9Sstevel@tonic-gate if (ascii)
3447c478bd9Sstevel@tonic-gate mesg(1);
3457c478bd9Sstevel@tonic-gate exit(error);
346*e5190c10Smuffin
347*e5190c10Smuffin return (0);
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate
351*e5190c10Smuffin int
edone(x)3527c478bd9Sstevel@tonic-gate edone(x)
3537c478bd9Sstevel@tonic-gate int x;
3547c478bd9Sstevel@tonic-gate {
3557c478bd9Sstevel@tonic-gate frame = stk;
3567c478bd9Sstevel@tonic-gate nxf = frame + 1;
3577c478bd9Sstevel@tonic-gate ip = 0;
3587c478bd9Sstevel@tonic-gate done(x);
3597c478bd9Sstevel@tonic-gate
360*e5190c10Smuffin return (0);
361*e5190c10Smuffin }
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate
364*e5190c10Smuffin int
casepi()3657c478bd9Sstevel@tonic-gate casepi()
3667c478bd9Sstevel@tonic-gate {
367*e5190c10Smuffin int i;
3687c478bd9Sstevel@tonic-gate int id[2];
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate if (toolate || skip() || !getname() || pipe(id) == -1 || (i = fork()) == -1) {
3717c478bd9Sstevel@tonic-gate errprint(gettext("Pipe not created."));
372*e5190c10Smuffin return (0);
3737c478bd9Sstevel@tonic-gate }
3747c478bd9Sstevel@tonic-gate ptid = id[1];
3757c478bd9Sstevel@tonic-gate if (i > 0) {
3767c478bd9Sstevel@tonic-gate close(id[0]);
3777c478bd9Sstevel@tonic-gate toolate++;
3787c478bd9Sstevel@tonic-gate pipeflg++;
379*e5190c10Smuffin return (0);
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate close(0);
3827c478bd9Sstevel@tonic-gate dup(id[0]);
3837c478bd9Sstevel@tonic-gate close(id[1]);
3847c478bd9Sstevel@tonic-gate execl(nextf, nextf, 0);
3857c478bd9Sstevel@tonic-gate errprint(gettext("Cannot exec %s"), nextf);
3867c478bd9Sstevel@tonic-gate exit(-4);
387*e5190c10Smuffin
388*e5190c10Smuffin return (0);
3897c478bd9Sstevel@tonic-gate }
390