6 char cs[CSSIZE+20]; /* text string converted into this */
7 char *csp; /* next spot in cs[] */
8 char *psp; /* next character in input token */
10 int lf, rf; /* temporary spots for left and right fonts */
11 int lastft; /* last \f added */
12 int nextft; /* next \f to be added */
14 int pclass; /* class of previous character */
15 int nclass; /* class of next character */
17 int class[LAST][LAST] ={ /* guesswork, tuned to times roman postscript */
19 /*OT OL IL DG LP RP SL PL IF IJ VB */
20 /*OT*/ { 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 0 }, /* OTHER */
21 /*OL*/ { 1, 0, 1, 1, 1, 1, 1, 2, 2, 2, 0 }, /* OLET */
22 /*IL*/ { 1, 1, 0, 1, 1, 1, 1, 3, 2, 1, 0 }, /* ILET */
23 /*DG*/ { 1, 1, 1, 0, 1, 1, 1, 2, 2, 2, 0 }, /* DIG */
24 /*LP*/ { 1, 1, 1, 1, 1, 2, 1, 2, 3, 3, 0 }, /* LPAR */
25 /*RP*/ { 2, 2, 2, 1, 1, 1, 1, 2, 3, 3, 0 }, /* RPAR */
26 /*SL*/ { 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 0 }, /* SLASH */
27 /*PL*/ { 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 0 }, /* PLUS */
28 /*IF*/ { 3, 3, 1, 2, 2, 3, 2, 3, 0, 1, 1 }, /* ILETF */
29 /*IJ*/ { 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 0 }, /* ILETJ */
30 /*VB*/ { 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 1 }, /* VBAR */
34 extern void shim(int, int);
35 extern void roman(int);
36 extern void sadd(char *);
37 extern void cadd(int);
38 extern int trans(int, char *);
40 int textc(void) /* read next UTF rune from psp */
45 w = mbtowc(&r, psp, 3);
52 return 0x80; /* Plan 9-ism */
58 void text(int t, char *p1) /* convert text string p1 of type t */
66 eht[yyval] = EM(1.0, ps); /* ht in ems of orig size */
67 lfont[yyval] = rfont[yyval] = ROM;
68 lclass[yyval] = rclass[yyval] = OTHER;
70 for (p = p1; *p; p++) /* scan for embedded \f's */
71 if (*p == '\\' && *(p+1) == 'f')
73 if (*p) /* if found \f, leave it alone and hope */
76 sprintf(cs, "\\f%s%s\\fP", ftp->name, p1);
79 } else if (t == SPACE)
85 else if ((tp = lookup(restbl, p1)) != NULL) {
90 nclass = NONE; /* get started with no class == no pad */
92 for (psp = p1; (c = textc()) != '\0'; ) {
97 lf = rf; /* left stuff is first found */
98 lclass[yyval] = nclass;
101 ERROR "converted token %.25s... too long", p1 FATAL ;
108 rclass[yyval] = nclass;
110 dprintf(".\t%dtext: S%d <- %s; b=%g,h=%g,lf=%c,rf=%c,ps=%d\n",
111 t, yyval, p, ebase[yyval], eht[yyval], lfont[yyval], rfont[yyval], ps);
112 printf(".ds %d \"%s\n", yyval, p);
115 int isalpharune(int c)
117 return ('a'<=c && c<='z') || ('A'<=c && c<='Z');
120 int isdigitrune(int c)
122 return ('0'<=c && c<='9');
126 trans(int c, char *p1)
130 if (isalpharune(c) && ft == ITAL && c != 'f' && c != 'j') { /* italic letter */
131 shim(pclass, nclass = ILET);
135 if (isalpharune(c) && ft != ITAL) { /* other letter */
136 shim(pclass, nclass = OLET);
140 if (isdigitrune(c)) {
141 shim(pclass, nclass = DIG);
143 return ROM; /* this is the right side font of this object */
148 case ':': case ';': case '!': case '%': case '?':
149 shim(pclass, nclass);
153 shim(pclass, nclass = LPAR);
157 shim(pclass, nclass = RPAR);
161 shim(pclass, nclass = OTHER);
170 case '|': /* postscript needs help with default width! */
171 shim(pclass, nclass = VBAR);
172 sadd("\\v'.17m'\\z|\\v'-.17m'\\|"); /* and height */
175 shim(pclass, nclass = PLUS);
179 shim(pclass, nclass = PLUS);
183 case '<': /* >, >=, >>, <, <-, <=, << */
184 shim(pclass, nclass = PLUS);
186 sadd(c == '<' ? "\\(<=" : "\\(>=");
188 } else if (c == '<' && *psp == '-') { /* <- only */
191 } else if (*psp == c) { /* << or >> */
200 shim(pclass, nclass = PLUS); /* probably too big for ->'s */
209 shim(pclass, nclass = SLASH);
219 case '\\': /* troff - pass only \(xx without comment */
220 shim(pclass, nclass);
223 if (c == '(' && *psp && *(psp+1)) {
227 fprintf(stderr, "eqn warning: unquoted troff command \\%c, file %s:%d\n",
228 c, curfile->fname, curfile->lineno);
231 shim(pclass, nclass);
237 shim(pclass, nclass = ILETF);
245 shim(pclass, nclass = ILETJ);
252 shim(pclass, nclass);
254 return ft==ITAL ? ITAL : ROM;
258 char *pad(int n) /* return the padding as a string */
264 sprintf(buf, "\\h'-%du*\\w'\\^'u'", -n);
267 for ( ; n > 1; n -= 2)
274 void shim(int lc, int rc) /* add padding space suitable to left and right classes */
276 sadd(pad(class[lc][rc]));
279 void roman(int c) /* add char c in "roman" font */
285 void sadd(char *s) /* add string s to cs */
291 void cadd(int c) /* add character c to end of cs */
296 if (lastft != nextft) {
304 if (ftp == ftstack) { /* bottom level */
305 if (ftp->ft == ITAL) /* usual case */
307 else /* gfont set, use it */
308 for (p = ftp->name; (*csp = *p++); )
310 } else { /* inside some kind of font ... */
311 for (p = ftp->name; (*csp = *p++); )
317 if(w > 0) /* ignore bad characters */