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