Tchar gettch(void) { extern int c_isalnum; Tchar i; int j; if (TROFF) return getch(); i = getch(); j = cbits(i); if (ismot(i) || fbits(i) != ulfont) return(i); if (cu) { if (trtab[j] == ' ') { setcbits(i, '_'); setfbits(i, FT); /* default */ } return(i); } /* should test here for characters that ought to be underlined */ /* in the old nroff, that was the 200 bit on the width! */ /* for now, just do letters, digits and certain special chars */ if (j <= 127) { if (!isalnum(j)) setfbits(i, FT); } else { if (j < c_isalnum) setfbits(i, FT); } return(i); }
void outascii ( /* print i in best-guess ascii */ tchar i ) { int j = cbits(i); int f = fbits(i); int k; if (j == FILLER) return; if (isadjspc(i)) return; if (ismot(i)) { oput(' '); return; } if ((j < 0177 && j >= ' ') || j == '\n') { oput(j); return; } if (f == 0) f = xfont; if (j == DRAWFCN) oputs("\\D"); else if (j == HYPHEN || j == MINUS) oput('-'); else if (j == XON) oputs("\\X"); else if (islig(i) && lgrevtab && lgrevtab[f] && lgrevtab[f][j]) { for (k = 0; lgrevtab[f][j][k]; k++) outmb(sfmask(i) | lgrevtab[f][j][k]); } else if (j == WORDSP) ; /* nothing at all */ else if (j > 0177) outmb(i); }
static void outmb(tchar i) { extern int nchtab; int j = cbits(i); #ifdef EUC wchar_t wc; char mb[MB_LEN_MAX+1]; int n; int f; #endif /* EUC */ if (j < 0177) { oput(j); return; } #ifdef EUC if (iscopy(i)) wc = cbits(i); else { if ((f = fbits(i)) == 0) f = font; wc = tr2un(j, f); } if (wc != -1 && (n = wctomb(mb, wc)) > 0) { mb[n] = 0; oputs(mb); } else #endif /* EUC */ if (j < 128 + nchtab) { oput('\\'); oput('('); oput(chname[chtab[j-128]]); oput(chname[chtab[j-128]+1]); } }
void ptout1(void) { int k; char *codep; int w, j, phyw; Tchar *q, i; static int oxfont = FT; /* start off in roman */ for (q = oline; q < olinep; q++) { i = *q; if (ismot(i)) { j = absmot(i); if (isnmot(i)) j = -j; if (isvmot(i)) lead += j; else esc += j; continue; } if ((k = cbits(i)) <= ' ') { switch (k) { case ' ': /*space*/ esc += t.Char; break; case '\033': case '\007': case '\016': case '\017': oput(k); break; } continue; } phyw = w = t.Char * t.tfont.wp[k].wid; if (iszbit(i)) w = 0; if (esc || lead) move(); esct += w; xfont = fbits(i); if (xfont != oxfont) { switch (oxfont) { case ULFONT: oputs(t.itoff); break; case BDFONT: oputs(t.bdoff); break; case BIFONT: oputs(t.itoff); oputs(t.bdoff); break; } switch (xfont) { case ULFONT: if (*t.iton & 0377) oputs(t.iton); break; case BDFONT: if (*t.bdon & 0377) oputs(t.bdon); break; case BIFONT: if (*t.bdon & 0377) oputs(t.bdon); if (*t.iton & 0377) oputs(t.iton); break; } oxfont = xfont; } if ((xfont == ulfont || xfont == BIFONT) && !(*t.iton & 0377)) { for (j = w / t.Char; j > 0; j--) oput('_'); for (j = w / t.Char; j > 0; j--) oput('\b'); } if (!(*t.bdon & 0377) && ((j = bdtab[xfont]) || xfont == BDFONT || xfont == BIFONT)) j++; else j = 1; /* number of overstrikes for bold */ if (k < ALPHABET) { /* ordinary ascii */ oput(k); while (--j > 0) { oput('\b'); oput(k); } } else if (k >= t.tfont.nchars) { /* BUG -- not really understood */ /* fprintf(stderr, "big char %d, name %s\n", k, chname(k)); /* */ oputs(chname(k)+1); /* BUG: should separate Troffchar and MBchar... */ } else if (t.tfont.wp[k].str == 0) { /* fprintf(stderr, "nostr char %d, name %s\n", k, chname(k)); /* */ oputs(chname(k)+1); /* BUG: should separate Troffchar and MBchar... */ } else if (t.tfont.wp[k].str[0] == MBchar) { /* parse() puts this on */ /* fprintf(stderr, "MBstr char %d, name %s\n", k, chname(k)); /* */ oputs(t.tfont.wp[k].str+1); } else { int oj = j; /* fprintf(stderr, "str char %d, name %s\n", k, chname(k)); /* */ codep = t.tfont.wp[k].str+1; /* Troffchar by default */ while (*codep != 0) { if (*codep & 0200) { codep = plot(codep); oput(' '); } else { if (*codep == '%') /* escape */ codep++; oput(*codep); if (*codep == '\033') oput(*++codep); else if (*codep != '\b') for (j = oj; --j > 0; ) { oput('\b'); oput(*codep); } codep++; } } } if (!w) for (j = phyw / t.Char; j > 0; j--) oput('\b'); } }
static void tmtmcwr(int ab, int tmc, int wr, int ep, int tmm) { const char tmtab[] = { 'a',000,000,000,000,000,000,000, 000,000,000,000,000,000,000,000, '{','}','&',000,'%','c','e',' ', '!',000,000,000,000,000,000,'~', 000 }; struct contab *cp; register int i, j; tchar c; char tmbuf[NTM]; filep savip = ip; int discard = 0; lgf++; if (tmm) { if (skip(1) || (i = getrq(0)) == 0) return; if ((cp = findmn(i)) == NULL || !cp->mx) { nosuch(i); return; } savip = ip; ip = (filep)cp->mx; app++; copyf++; } else { copyf++; if (skip(0) && ab) errprint("User Abort"); } loop: for (i = 0; i < NTM - 5 - mb_cur_max; ) { if (tmm) { if ((c = rbf()) == 0) { ip = savip; tmm = 0; app--; break; } } else c = getch(); if (discard) { discard--; continue; } if (c == '\n') { tmbuf[i++] = '\n'; break; } c: j = cbits(c); if (iscopy(c)) { int n; if ((n = wctomb(&tmbuf[i], j)) > 0) { i += n; continue; } } if (xflag == 0) { tmbuf[i++] = c; continue; } if (ismot(c)) continue; tmbuf[i++] = '\\'; if (c == (OHC|BLBIT)) j = ':'; else if (istrans(c)) j = ')'; else if (j >= 0 && j < sizeof tmtab && tmtab[j]) j = tmtab[j]; else if (j == ACUTE) j = '\''; else if (j == GRAVE) j = '`'; else if (j == UNDERLINE) j = '_'; else if (j == MINUS) j = '-'; else { i--; if (c == WORDSP) j = ' '; else if (j == WORDSP) continue; else if (j == FLSS) { discard++; continue; } } if (j == XFUNC) switch (fbits(c)) { case CHAR: c = charout[sbits(c)].ch; goto c; default: continue; } tmbuf[i++] = j; } if (i == NTM - 2) tmbuf[i++] = '\n'; if (tmc) i--; tmbuf[i] = 0; if (ab) /* truncate output */ obufp = obuf; /* should be a function in n2.c */ if (ep) { flusho(); errprint("%s", tmbuf); } else if (wr < 0) { flusho(); fdprintf(stderr, "%s", tmbuf); } else if (i) write(wr, tmbuf, i); if (tmm) goto loop; copyf--; lgf--; }
int pchar(register tchar i) { register int j; static int hx = 0; /* records if have seen HX */ static int xon = 0; /* records if have seen XON */ static int drawfcn = 0; /* records if have seen DRAWFCN */ if (hx) { hx = 0; j = absmot(i); if (isnmot(i)) { if (j > dip->blss) dip->blss = j; } else { if (j > dip->alss) dip->alss = j; ralss = dip->alss; } return 1; } if (ismot(i)) { pchar1(i); return 1; } switch (j = cbits(i)) { case 0: case IMP: case RIGHT: case LEFT: if (xflag) { i = j = FILLER; /* avoid kerning in output routine */ goto dfl; } return 1; case HX: hx = 1; if (xflag) { i = j = FILLER; /* avoid kerning in output routine */ goto dfl; } return 1; case XON: xon = 1; goto dfl; case XOFF: xon = 0; goto dfl; case DRAWFCN: drawfcn = !drawfcn; goto dfl; case PRESC: if (dip == &d[0]) j = eschar; /* fall through */ default: dfl: #ifndef NROFF if (html) { if (!xflag || !isdi(i)) { setcbits(i, j >= NCHARS ? j : tflg ? trnttab[j] : trtab[j]); if (xon == 0 && drawfcn == 0 && i < NCHARS) setcbits(i, ftrans(fbits(i), cbits(i))); } } else #endif if (!xflag || !isdi(i)) { setcbits(i, tflg ? trnttab[j] : trtab[j]); if (xon == 0 && drawfcn == 0) setcbits(i, ftrans(fbits(i), cbits(i))); } } #ifdef NROFF if (xon && xflag) return 1; #endif /* NROFF */ pchar1(i); return 1; }
void pchar1(register tchar i) { static int _olt; tchar _olp[1]; register int j; filep savip; extern void ptout(tchar); j = cbits(i); if (dip != &d[0]) { if (i == FLSS) dip->flss++; else if (dip->flss > 0) dip->flss--; else if (!ismot(i) && (cbits(i) > 32 || cbits(i) == XFUNC) && !tflg) i |= DIBIT; wbf(i); dip->op = offset; return; } if (!tflg && !print) { if (j == '\n') dip->alss = dip->blss = 0; return; } if (no_out) return; if (tflg) { /* transparent mode, undiverted */ outtp(i); return; } if (cbits(i) == XFUNC) { switch (fbits(i)) { case OLT: olt = realloc(olt, (nolt + 1) * sizeof *olt); _olt = 1; return; case CHAR: #ifndef NROFF if (!ascii) break; #endif /* !NROFF */ savip = ip; ip = charout[sbits(i)].op; app++; fmtchar++; while ((i = rbf()) != 0 && cbits(i) != '\n' && cbits(i) != FLSS) pchar(i); fmtchar--; app--; ip = savip; return; } } if (cbits(i) == 'x') fmtchar = fmtchar; if (_olt) { _olp[0] = i; olt[nolt++] = fetchrq(_olp); _olt = 0; } #ifndef NROFF if (ascii) outascii(i); else #endif ptout(i); }