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