|
|
1.1 ! root 1: /* ! 2: * n2.c ! 3: * ! 4: * output, cleanup ! 5: */ ! 6: ! 7: #include "tdef.h" ! 8: #include "fns.h" ! 9: #include "ext.h" ! 10: #include <setjmp.h> ! 11: ! 12: ! 13: extern jmp_buf sjbuf; ! 14: int toolate; ! 15: int error; ! 16: ! 17: char obuf[2*BUFSIZ]; ! 18: char *obufp = obuf; ! 19: ! 20: int xon = 0; /* records if in middle of \X */ ! 21: ! 22: int pchar(Tchar i) ! 23: { ! 24: int j; ! 25: static int hx = 0; /* records if have seen HX */ ! 26: ! 27: if (hx) { ! 28: hx = 0; ! 29: j = absmot(i); ! 30: if (isnmot(i)) { ! 31: if (j > dip->blss) ! 32: dip->blss = j; ! 33: } else { ! 34: if (j > dip->alss) ! 35: dip->alss = j; ! 36: ralss = dip->alss; ! 37: } ! 38: return 0; ! 39: } ! 40: if (ismot(i)) { ! 41: pchar1(i); ! 42: return 0; ! 43: } ! 44: switch (j = cbits(i)) { ! 45: case 0: ! 46: case IMP: ! 47: case RIGHT: ! 48: case LEFT: ! 49: return 0; ! 50: case HX: ! 51: hx = 1; ! 52: return 0; ! 53: case XON: ! 54: xon++; ! 55: break; ! 56: case XOFF: ! 57: xon--; ! 58: break; ! 59: case PRESC: ! 60: if (!xon && !tflg && dip == &d[0]) ! 61: j = eschar; /* fall through */ ! 62: default: ! 63: setcbits(i, trtab[j]); ! 64: } ! 65: pchar1(i); ! 66: return 0; ! 67: } ! 68: ! 69: ! 70: void pchar1(Tchar i) ! 71: { ! 72: int j; ! 73: ! 74: j = cbits(i); ! 75: if (dip != &d[0]) { ! 76: wbf(i); ! 77: dip->op = offset; ! 78: return; ! 79: } ! 80: if (!tflg && !print) { ! 81: if (j == '\n') ! 82: dip->alss = dip->blss = 0; ! 83: return; ! 84: } ! 85: if (j == FILLER && !xon) ! 86: return; ! 87: if (tflg) { /* transparent mode, undiverted */ ! 88: if (print) /* assumes that it's ok to print */ ! 89: /* OUT "%c", j PUT; /* i.e., is ascii */ ! 90: outascii(i); ! 91: return; ! 92: } ! 93: if (TROFF && ascii) ! 94: outascii(i); ! 95: else ! 96: ptout(i); ! 97: } ! 98: ! 99: ! 100: void outascii(Tchar i) /* print i in best-guess ascii */ ! 101: { ! 102: char *p; ! 103: int j = cbits(i); ! 104: ! 105: /* is this ever called with NROFF set? probably doesn't work at all. */ ! 106: ! 107: if (ismot(i)) ! 108: oput(' '); ! 109: else if (j < ALPHABET && j >= ' ' || j == '\n' || j == '\t') ! 110: oput(j); ! 111: else if (j == DRAWFCN) ! 112: oputs("\\D"); ! 113: else if (j == HYPHEN) ! 114: oput('-'); ! 115: else if (j == MINUS) /* special pleading for strange encodings */ ! 116: oputs("\\-"); ! 117: else if (j == PRESC) ! 118: oputs("\\e"); ! 119: else if (j == FILLER) ! 120: oputs("\\&"); ! 121: else if (j == UNPAD) ! 122: oputs("\\ "); ! 123: else if (j == OHC) /* this will never occur; stripped out earlier */ ! 124: oputs("\\%"); ! 125: else if (j == XON) ! 126: oputs("\\X"); ! 127: else if (j == XOFF) ! 128: oputs(" "); ! 129: else if (j == LIG_FI) ! 130: oputs("fi"); ! 131: else if (j == LIG_FL) ! 132: oputs("fl"); ! 133: else if (j == LIG_FF) ! 134: oputs("ff"); ! 135: else if (j == LIG_FFI) ! 136: oputs("ffi"); ! 137: else if (j == LIG_FFL) ! 138: oputs("ffl"); ! 139: else if (j == WORDSP) { /* nothing at all */ ! 140: if (xon) /* except in \X */ ! 141: oput(' '); ! 142: ! 143: } else if (j >= ALPHABET && j < nchnames + ALPHABET) { /* \N DOESN'T WORK YET */ ! 144: p = chname(j); ! 145: if (strlen(p) == 2) ! 146: OUT "\\(%s", p PUT; ! 147: else ! 148: OUT "\\C'%s'", p PUT; ! 149: } else { /* WEIRD CHARACTER NAME */ ! 150: OUT " %d? ", j PUT; ! 151: ! 152: } ! 153: } ! 154: ! 155: int flusho(void) ! 156: { ! 157: if (NROFF && !toolate && t.twinit) ! 158: fwrite(t.twinit, strlen(t.twinit), 1, ptid); ! 159: ! 160: if (obufp > obuf) { ! 161: *obufp = 0; ! 162: fputs(obuf, ptid); ! 163: fflush(ptid); ! 164: obufp = obuf; ! 165: } ! 166: toolate++; ! 167: return 1; ! 168: } ! 169: ! 170: ! 171: void caseex(void) ! 172: { ! 173: done(0); ! 174: } ! 175: ! 176: ! 177: void done(int x) ! 178: { ! 179: int i; ! 180: ! 181: error |= x; ! 182: app = ds = lgf = 0; ! 183: if (i = em) { ! 184: donef = -1; ! 185: em = 0; ! 186: if (control(i, 0)) ! 187: longjmp(sjbuf, 1); ! 188: } ! 189: if (!nfo) ! 190: done3(0); ! 191: mflg = 0; ! 192: dip = &d[0]; ! 193: if (woff) /* BUG!!! This isn't set anywhere */ ! 194: wbf((Tchar)0); ! 195: if (pendw) ! 196: getword(1); ! 197: pendnf = 0; ! 198: if (donef == 1) ! 199: done1(0); ! 200: donef = 1; ! 201: ip = 0; ! 202: frame = stk; ! 203: nxf = frame + 1; ! 204: if (!ejf) ! 205: tbreak(); ! 206: nflush++; ! 207: eject((Stack *)0); ! 208: longjmp(sjbuf, 1); ! 209: } ! 210: ! 211: ! 212: void done1(int x) ! 213: { ! 214: error |= x; ! 215: if (numtab[NL].val) { ! 216: trap = 0; ! 217: eject((Stack *)0); ! 218: longjmp(sjbuf, 1); ! 219: } ! 220: if (!ascii) ! 221: pttrailer(); ! 222: done2(0); ! 223: } ! 224: ! 225: ! 226: void done2(int x) ! 227: { ! 228: ptlead(); ! 229: if (TROFF && !ascii) ! 230: ptstop(); ! 231: flusho(); ! 232: done3(x); ! 233: } ! 234: ! 235: void done3(int x) ! 236: { ! 237: error |= x; ! 238: flusho(); ! 239: if (NROFF) ! 240: twdone(); ! 241: if (pipeflg) ! 242: pclose(ptid); ! 243: exit(error); ! 244: } ! 245: ! 246: ! 247: void edone(int x) ! 248: { ! 249: frame = stk; ! 250: nxf = frame + 1; ! 251: ip = 0; ! 252: done(x); ! 253: } ! 254: ! 255: ! 256: void casepi(void) ! 257: { ! 258: char buf[NTM]; ! 259: ! 260: getline(buf, NTM); ! 261: if (toolate || buf[0] == '\0' || (ptid = popen(buf, "w")) == NULL) { ! 262: ERROR "pipe %s not created.", buf WARN; ! 263: return; ! 264: } ! 265: toolate++; ! 266: pipeflg++; ! 267: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.