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