1 #ifndef lint 2 static char sccsid[] = "@(#)n2.c 2.1 (CWI) 85/07/18"; 3 #endif lint 4 /* 5 * n2.c 6 * 7 * output, cleanup 8 */ 9 10 #include "tdef.h" 11 #include <sgtty.h> 12 #include <signal.h> 13 #ifdef NROFF 14 #include "tw.h" 15 #endif 16 #include <setjmp.h> 17 #include "ext.h" 18 19 extern jmp_buf sjbuf; 20 int toolate; 21 int error; 22 23 pchar(i) 24 register tchar i; 25 { 26 register int j; 27 static int hx = 0; /* records if have seen HX */ 28 29 if (hx) { 30 hx = 0; 31 j = absmot(i); 32 if (isnmot(i)) { 33 if (j > dip->blss) 34 dip->blss = j; 35 } else { 36 if (j > dip->alss) 37 dip->alss = j; 38 ralss = dip->alss; 39 } 40 return; 41 } 42 if (ismot(i)) { 43 pchar1(i); 44 return; 45 } 46 switch (j = cbits(i)) { 47 case 0: 48 case IMP: 49 case RIGHT: 50 case LEFT: 51 return; 52 case HX: 53 hx = 1; 54 return; 55 case PRESC: 56 if (dip == &d[0]) 57 j = eschar; /* fall through */ 58 default: 59 setcbits(i, trtab[j]); 60 } 61 pchar1(i); 62 } 63 64 65 pchar1(i) 66 register tchar i; 67 { 68 register j; 69 70 j = cbits(i); 71 if (dip != &d[0]) { 72 wbf(i); 73 dip->op = offset; 74 return; 75 } 76 if (!tflg && !print) { 77 if (j == '\n') 78 dip->alss = dip->blss = 0; 79 return; 80 } 81 if (no_out || j == FILLER) 82 return; 83 if (tflg) { /* transparent mode, undiverted */ 84 fdprintf(ptid, "%c", j); 85 return; 86 } 87 #ifndef NROFF 88 if (ascii) 89 outascii(i); 90 else 91 #endif 92 ptout(i); 93 } 94 95 outascii(i) /* print i in best-guess ascii */ 96 tchar i; 97 { 98 static int seendraw; 99 int j = cbits(i); 100 101 if (ismot(i)) { 102 if(!seendraw) { 103 oput(' '); 104 } 105 return; 106 } 107 if (j < 0177 && j >= 040) { 108 if(!seendraw) { 109 oput(j); 110 return; 111 } else { 112 switch(j) { 113 case DRAWCIRCLE: oputs("CIRCLE "); 114 break; 115 case DRAWELLIPSE: oputs("ELLIPSE "); 116 break; 117 case DRAWLINE: oputs("LINE "); 118 break; 119 case DRAWSPLINE: oputs("SPLINE "); 120 break; 121 case DRAWARC: oputs("ARC "); 122 break; 123 case '.':oputs("."); 124 /* 125 if(seendraw == 2) 126 seendraw = 0; 127 else 128 seendraw++; 129 */ 130 break; 131 default: oputs("UNKNOWN "); flusho(); 132 errprint("Unknown 0%o %c function", j,j); 133 break; 134 } 135 return; 136 } 137 } 138 if( j < 040) { 139 switch(j) { 140 case SLANT: 141 case CHARHT: 142 case WORDSP: 143 case HX: 144 return; 145 case DRAWFCN: 146 if(seendraw == 1){ 147 seendraw = 0; 148 } else { 149 oputs("DRAWFUNCTION ");flusho(); 150 seendraw++; 151 } 152 /* 153 errprint("Seendraw %d", seendraw); 154 */ 155 return; 156 case '\n': 157 oput(j); 158 return; 159 default: 160 errprint("Unknown (2) 0%o function", j); 161 return; 162 } 163 } 164 if (j == HYPHEN || j == MINUS) 165 oput('-'); 166 else if (j == LIG_FI) 167 oputs("fi"); 168 else if (j == LIG_FL) 169 oputs("fl"); 170 else if (j == LIG_FF) 171 oputs("ff"); 172 else if (j == LIG_FFI) 173 oputs("ffi"); 174 else if (j == LIG_FFL) 175 oputs("ffl"); 176 else { 177 oput('\\'); 178 oput('('); 179 oput(chname[chtab[j-128]]); 180 oput(chname[chtab[j-128]+1]); 181 } 182 } 183 184 185 /* 186 * now a macro 187 oput(i) 188 register int i; 189 { 190 *obufp++ = i; 191 if (obufp >= &obuf[OBUFSZ]) 192 flusho(); 193 } 194 */ 195 196 oputs(i) 197 register char *i; 198 { 199 while (*i != 0) 200 oput(*i++); 201 } 202 203 204 flusho() 205 { 206 if (obufp == obuf) 207 return; 208 if (no_out == 0) { 209 if (!toolate) { 210 toolate++; 211 #ifdef NROFF 212 if (t.bset || t.breset) { 213 if (ttysave == -1) { 214 gtty(1, &ttys); 215 ttysave = ttys.sg_flags; 216 } 217 ttys.sg_flags &= ~t.breset; 218 ttys.sg_flags |= t.bset; 219 stty(1, &ttys); 220 } 221 { 222 char *p = t.twinit; 223 while (*p++) 224 ; 225 if (p - t.twinit > 1) 226 write(ptid, t.twinit, p - t.twinit - 1); 227 } 228 #endif 229 } 230 toolate += write(ptid, obuf, obufp - obuf); 231 } 232 obufp = obuf; 233 } 234 235 236 done(x) 237 int x; 238 { 239 register i; 240 241 error |= x; 242 app = ds = lgf = 0; 243 if (i = em) { 244 donef = -1; 245 em = 0; 246 if (control(i, 0)) 247 longjmp(sjbuf, 1); 248 } 249 if (!nfo) 250 done3(0); 251 mflg = 0; 252 dip = &d[0]; 253 if (woff) 254 wbt((tchar)0); 255 if (pendw) 256 getword(1); 257 pendnf = 0; 258 if (donef == 1) 259 done1(0); 260 donef = 1; 261 ip = 0; 262 frame = stk; 263 nxf = frame + 1; 264 if (!ejf) 265 tbreak(); 266 nflush++; 267 eject((struct s *)0); 268 longjmp(sjbuf, 1); 269 } 270 271 272 done1(x) 273 int x; 274 { 275 error |= x; 276 if (numtab[NL].val) { 277 trap = 0; 278 eject((struct s *)0); 279 longjmp(sjbuf, 1); 280 } 281 if (nofeed) { 282 ptlead(); 283 flusho(); 284 done3(0); 285 } else { 286 if (!gflag) 287 pttrailer(); 288 done2(0); 289 } 290 } 291 292 293 done2(x) 294 int x; 295 { 296 ptlead(); 297 #ifndef NROFF 298 if (!ascii) 299 ptstop(); 300 #endif 301 flusho(); 302 done3(x); 303 } 304 305 done3(x) 306 int x; 307 { 308 error |= x; 309 signal(SIGINT, SIG_IGN); 310 signal(SIGTERM, SIG_IGN); 311 unlink(unlkp); 312 #ifdef NROFF 313 twdone(); 314 #endif 315 if (quiet) { 316 ttys.sg_flags |= ECHO; 317 stty(0, &ttys); 318 } 319 if (ascii) 320 mesg(1); 321 exit(error); 322 } 323 324 325 edone(x) 326 int x; 327 { 328 frame = stk; 329 nxf = frame + 1; 330 ip = 0; 331 done(x); 332 } 333 334 335 336 casepi() 337 { 338 register i; 339 int id[2]; 340 341 if (toolate || skip() || !getname() || pipe(id) == -1 || (i = fork()) == -1) { 342 errprint("Pipe not created."); 343 return; 344 } 345 ptid = id[1]; 346 if (i > 0) { 347 close(id[0]); 348 toolate++; 349 pipeflg++; 350 return; 351 } 352 close(0); 353 dup(id[0]); 354 close(id[1]); 355 execl(nextf, nextf, 0); 356 errprint("Cannot exec %s", nextf); 357 exit(-4); 358 } 359