ptinit(){ if(ascii || gflag)return; oput(T_INIT); esc = T_IESC; ptesc(); esct = 0; esc = po; oput(0140); /*some initial lead*/ }
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); }
char *plot(char *x) { int i; char *j, *k; oputs(t.ploton); k = x; if ((*k & 0377) == 0200) k++; for (; *k; k++) { if (*k == '%') { /* quote char within plot mode */ oput(*++k); } else if (*k & 0200) { if (*k & 0100) { if (*k & 040) j = t.up; else j = t.down; } else { if (*k & 040) j = t.left; else j = t.right; } if ((i = *k & 037) == 0) { /* 2nd 0200 turns it off */ ++k; break; } while (i--) oputs(j); } else oput(*k); } oputs(t.plotoff); return(k); }
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]); } }
static void text(void) { int ch; /* next input character */ /* * * Translates the next input file into PostScript. The redirect(-1) call forces * the initial output to go to /dev/null - so the stuff formfeed() does at the * end of each page doesn't go to stdout. * */ redirect(-1); /* get ready for the first page */ formfeed(); /* force PAGE comment etc. */ inittabs(); while ( (ch = getc(fp_in)) != EOF ) switch ( ch ) { case '\010': /* backspace */ backspace(); break; case '\011': /* horizontal tab */ htab(); break; case '\012': /* new line */ linefeed(); break; case '\013': /* vertical tab */ vtab(); break; case '\014': /* form feed */ formfeed(); break; case '\015': /* carriage return */ carriage(); break; case '\016': /* extended character set - SO */ break; case '\017': /* extended character set - SI */ break; case '\031': /* next char from supplementary set */ break; case '\033': /* 2 or 3 byte escape sequence */ escape(); break; default: oput(ch); break; } /* End switch */ formfeed(); /* next file starts on a new page? */ } /* End of text */
void move(void) { int k; char *i, *j; char *p, *q; int iesct, dt; iesct = esct; if (esct += esc) i = "\0"; else i = "\n\0"; j = t.hlf; p = t.right; q = t.down; if (lead) { if (lead < 0) { lead = -lead; i = t.flr; /* if(!esct)i = t.flr; else i = "\0";*/ j = t.hlr; q = t.up; } if (*i & 0377) { k = lead / t.Newline; lead = lead % t.Newline; while (k--) oputs(i); } if (*j & 0377) { k = lead / t.Halfline; lead = lead % t.Halfline; while (k--) oputs(j); } else { /* no half-line forward, not at line begining */ k = lead / t.Newline; lead = lead % t.Newline; if (k > 0) esc = esct; i = "\n"; while (k--) oputs(i); } } if (esc) { if (esc < 0) { esc = -esc; j = "\b"; p = t.left; } else { j = " "; if (hflg) while ((dt = dtab - (iesct % dtab)) <= esc) { if (dt % t.Em) break; oput(TAB); esc -= dt; iesct += dt; } } k = esc / t.Em; esc = esc % t.Em; while (k--) oputs(j); } if ((*t.ploton & 0377) && (esc || lead)) { oputs(t.ploton); esc /= t.Hor; lead /= t.Vert; while (esc--) oputs(p); while (lead--) oputs(q); oputs(t.plotoff); } esc = lead = 0; }
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'); } }
void oputs(register char *i) { while (*i != 0) oput(*i++&0377); }