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