1779fc935Sceastha /*
2779fc935Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3779fc935Sceastha * Use is subject to license terms.
4779fc935Sceastha */
5779fc935Sceastha
67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
77c478bd9Sstevel@tonic-gate /* All Rights Reserved */
87c478bd9Sstevel@tonic-gate
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate */
147c478bd9Sstevel@tonic-gate
15779fc935Sceastha #pragma ident "%Z%%M% %I% %E% SMI"
167c478bd9Sstevel@tonic-gate
177c478bd9Sstevel@tonic-gate #include "e.h"
187c478bd9Sstevel@tonic-gate #include "e.def"
197c478bd9Sstevel@tonic-gate #include <locale.h>
207c478bd9Sstevel@tonic-gate
217c478bd9Sstevel@tonic-gate int csp;
227c478bd9Sstevel@tonic-gate int psp;
237c478bd9Sstevel@tonic-gate #define CSSIZE 400
247c478bd9Sstevel@tonic-gate char cs[420];
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate int lf, rf; /* temporary spots for left and right fonts */
277c478bd9Sstevel@tonic-gate
28779fc935Sceastha void name4(int, int);
29779fc935Sceastha void roman(int);
30779fc935Sceastha void shim(void);
31779fc935Sceastha int trans(int, char *);
32779fc935Sceastha
33779fc935Sceastha void
text(int t,char * p1)34779fc935Sceastha text(int t, char *p1)
35779fc935Sceastha {
367c478bd9Sstevel@tonic-gate int c;
377c478bd9Sstevel@tonic-gate char *p;
387c478bd9Sstevel@tonic-gate tbl *tp, *lookup();
39*b5cda42eSceastha extern tbl *restbl[];
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate yyval = oalloc();
427c478bd9Sstevel@tonic-gate ebase[yyval] = 0;
437c478bd9Sstevel@tonic-gate #ifndef NEQN
447c478bd9Sstevel@tonic-gate eht[yyval] = VERT(EM(1.0, EFFPS(ps))); /* ht in machine units */
45779fc935Sceastha #else /* NEQN */
467c478bd9Sstevel@tonic-gate eht[yyval] = VERT(2); /* 2 half-spaces */
47779fc935Sceastha #endif /* NEQN */
487c478bd9Sstevel@tonic-gate lfont[yyval] = rfont[yyval] = ROM;
497c478bd9Sstevel@tonic-gate if (t == QTEXT)
507c478bd9Sstevel@tonic-gate p = p1;
517c478bd9Sstevel@tonic-gate else if (t == SPACE)
527c478bd9Sstevel@tonic-gate p = "\\ ";
537c478bd9Sstevel@tonic-gate else if (t == THIN)
547c478bd9Sstevel@tonic-gate p = "\\|";
557c478bd9Sstevel@tonic-gate else if (t == TAB)
567c478bd9Sstevel@tonic-gate p = "\\t";
57*b5cda42eSceastha else if ((tp = lookup(restbl, p1, NULL)) != NULL)
587c478bd9Sstevel@tonic-gate p = tp->defn;
597c478bd9Sstevel@tonic-gate else {
607c478bd9Sstevel@tonic-gate lf = rf = 0;
617c478bd9Sstevel@tonic-gate for (csp = psp = 0; (c = p1[psp++]) != '\0'; ) {
627c478bd9Sstevel@tonic-gate rf = trans(c, p1);
637c478bd9Sstevel@tonic-gate if (lf == 0)
647c478bd9Sstevel@tonic-gate lf = rf; /* save first */
657c478bd9Sstevel@tonic-gate if (csp > CSSIZE)
66779fc935Sceastha error(FATAL, gettext(
67779fc935Sceastha "converted token %.25s... too long"), p1);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate cs[csp] = '\0';
707c478bd9Sstevel@tonic-gate p = cs;
717c478bd9Sstevel@tonic-gate lfont[yyval] = lf;
727c478bd9Sstevel@tonic-gate rfont[yyval] = rf;
737c478bd9Sstevel@tonic-gate }
74779fc935Sceastha if (dbg)
75779fc935Sceastha printf(".\t%dtext: S%d <- %s; b=%d,h=%d,lf=%c,rf=%c\n",
76779fc935Sceastha t, yyval, p, ebase[yyval], eht[yyval], lfont[yyval],
77779fc935Sceastha rfont[yyval]);
787c478bd9Sstevel@tonic-gate printf(".ds %d \"%s\n", yyval, p);
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate
81779fc935Sceastha int
trans(int c,char * p1)82779fc935Sceastha trans(int c, char *p1)
83779fc935Sceastha {
847c478bd9Sstevel@tonic-gate int f;
857c478bd9Sstevel@tonic-gate f = ROM;
867c478bd9Sstevel@tonic-gate switch (c) {
877c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4':
887c478bd9Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9':
897c478bd9Sstevel@tonic-gate case ':': case ';': case '!': case '%':
907c478bd9Sstevel@tonic-gate case '(': case '[': case ')': case ']':
917c478bd9Sstevel@tonic-gate case ',':
927c478bd9Sstevel@tonic-gate if (rf == ITAL)
937c478bd9Sstevel@tonic-gate shim();
947c478bd9Sstevel@tonic-gate roman(c); break;
957c478bd9Sstevel@tonic-gate case '.':
967c478bd9Sstevel@tonic-gate if (rf == ROM)
977c478bd9Sstevel@tonic-gate roman(c);
987c478bd9Sstevel@tonic-gate else
997c478bd9Sstevel@tonic-gate cs[csp++] = c;
1007c478bd9Sstevel@tonic-gate f = rf;
1017c478bd9Sstevel@tonic-gate break;
1027c478bd9Sstevel@tonic-gate case '|':
1037c478bd9Sstevel@tonic-gate if (rf == ITAL)
1047c478bd9Sstevel@tonic-gate shim();
1057c478bd9Sstevel@tonic-gate shim(); roman(c); shim(); break;
1067c478bd9Sstevel@tonic-gate case '=':
1077c478bd9Sstevel@tonic-gate if (rf == ITAL)
1087c478bd9Sstevel@tonic-gate shim();
1097c478bd9Sstevel@tonic-gate name4('e', 'q');
1107c478bd9Sstevel@tonic-gate break;
1117c478bd9Sstevel@tonic-gate case '+':
1127c478bd9Sstevel@tonic-gate if (rf == ITAL)
1137c478bd9Sstevel@tonic-gate shim();
1147c478bd9Sstevel@tonic-gate name4('p', 'l');
1157c478bd9Sstevel@tonic-gate break;
1167c478bd9Sstevel@tonic-gate case '>': case '<':
1177c478bd9Sstevel@tonic-gate if (rf == ITAL)
1187c478bd9Sstevel@tonic-gate shim();
1197c478bd9Sstevel@tonic-gate if (p1[psp] == '=') { /* look ahead for == <= >= */
1207c478bd9Sstevel@tonic-gate name4(c, '=');
1217c478bd9Sstevel@tonic-gate psp++;
1227c478bd9Sstevel@tonic-gate } else {
1237c478bd9Sstevel@tonic-gate cs[csp++] = c;
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate break;
1267c478bd9Sstevel@tonic-gate case '-':
1277c478bd9Sstevel@tonic-gate if (rf == ITAL)
1287c478bd9Sstevel@tonic-gate shim();
1297c478bd9Sstevel@tonic-gate if (p1[psp] == '>') {
1307c478bd9Sstevel@tonic-gate name4('-', '>'); psp++;
1317c478bd9Sstevel@tonic-gate } else {
1327c478bd9Sstevel@tonic-gate name4('m', 'i');
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate break;
1357c478bd9Sstevel@tonic-gate case '/':
1367c478bd9Sstevel@tonic-gate if (rf == ITAL)
1377c478bd9Sstevel@tonic-gate shim();
1387c478bd9Sstevel@tonic-gate name4('s', 'l');
1397c478bd9Sstevel@tonic-gate break;
1407c478bd9Sstevel@tonic-gate case '~': case ' ':
1417c478bd9Sstevel@tonic-gate shim(); shim(); break;
1427c478bd9Sstevel@tonic-gate case '^':
1437c478bd9Sstevel@tonic-gate shim(); break;
1447c478bd9Sstevel@tonic-gate case '\\': /* troff - pass 2 or 3 more chars */
1457c478bd9Sstevel@tonic-gate if (rf == ITAL)
1467c478bd9Sstevel@tonic-gate shim();
1477c478bd9Sstevel@tonic-gate cs[csp++] = c; cs[csp++] = c = p1[psp++]; cs[csp++] = p1[psp++];
1487c478bd9Sstevel@tonic-gate if (c == '(') cs[csp++] = p1[psp++];
1497c478bd9Sstevel@tonic-gate if (c == '*' && cs[csp-1] == '(') {
1507c478bd9Sstevel@tonic-gate cs[csp++] = p1[psp++];
1517c478bd9Sstevel@tonic-gate cs[csp++] = p1[psp++];
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate break;
1547c478bd9Sstevel@tonic-gate case '\'':
155779fc935Sceastha cs[csp++] = '\\';
156779fc935Sceastha cs[csp++] = 'f';
157779fc935Sceastha cs[csp++] = rf == ITAL ? ITAL : ROM;
1587c478bd9Sstevel@tonic-gate name4('f', 'm');
1597c478bd9Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = 'P';
1607c478bd9Sstevel@tonic-gate f = rf == ITAL ? ITAL : ROM;
1617c478bd9Sstevel@tonic-gate break;
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate case 'f':
1647c478bd9Sstevel@tonic-gate if (ft == ITAL) {
1657c478bd9Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '^';
1667c478bd9Sstevel@tonic-gate cs[csp++] = 'f';
167779fc935Sceastha
168779fc935Sceastha /* trying | instead of ^ */
169779fc935Sceastha cs[csp++] = '\\'; cs[csp++] = '|';
170779fc935Sceastha
1717c478bd9Sstevel@tonic-gate f = ITAL;
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate else
1747c478bd9Sstevel@tonic-gate cs[csp++] = 'f';
1757c478bd9Sstevel@tonic-gate break;
1767c478bd9Sstevel@tonic-gate case 'j':
1777c478bd9Sstevel@tonic-gate if (ft == ITAL) {
1787c478bd9Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '^';
1797c478bd9Sstevel@tonic-gate cs[csp++] = 'j';
1807c478bd9Sstevel@tonic-gate f = ITAL;
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate else
1837c478bd9Sstevel@tonic-gate cs[csp++] = 'j';
1847c478bd9Sstevel@tonic-gate break;
1857c478bd9Sstevel@tonic-gate default:
1867c478bd9Sstevel@tonic-gate cs[csp++] = c;
1877c478bd9Sstevel@tonic-gate f = ft == ITAL ? ITAL : ROM;
1887c478bd9Sstevel@tonic-gate break;
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate return (f);
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate
193779fc935Sceastha void
shim(void)194779fc935Sceastha shim(void)
195779fc935Sceastha {
1967c478bd9Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '|';
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
199779fc935Sceastha void
roman(int c)200779fc935Sceastha roman(int c)
201779fc935Sceastha {
2027c478bd9Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = ROM;
2037c478bd9Sstevel@tonic-gate cs[csp++] = c;
2047c478bd9Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = 'P';
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate
207779fc935Sceastha void
name4(int c1,int c2)208779fc935Sceastha name4(int c1, int c2)
209779fc935Sceastha {
2107c478bd9Sstevel@tonic-gate cs[csp++] = '\\';
2117c478bd9Sstevel@tonic-gate cs[csp++] = '(';
2127c478bd9Sstevel@tonic-gate cs[csp++] = c1;
2137c478bd9Sstevel@tonic-gate cs[csp++] = c2;
2147c478bd9Sstevel@tonic-gate }
215