1*364Sceastha /* 2*364Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*364Sceastha * Use is subject to license terms. 4*364Sceastha */ 5*364Sceastha 60Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 70Sstevel@tonic-gate /* All Rights Reserved */ 80Sstevel@tonic-gate 90Sstevel@tonic-gate /* 100Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 110Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 120Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 130Sstevel@tonic-gate */ 14*364Sceastha 15*364Sceastha #pragma ident "%Z%%M% %I% %E% SMI" 160Sstevel@tonic-gate 17*364Sceastha #include "e.h" 18*364Sceastha #include "e.def" 190Sstevel@tonic-gate #include <locale.h> 200Sstevel@tonic-gate 210Sstevel@tonic-gate int csp; 220Sstevel@tonic-gate int psp; 230Sstevel@tonic-gate #define CSSIZE 400 240Sstevel@tonic-gate char cs[420]; 250Sstevel@tonic-gate 260Sstevel@tonic-gate int lf, rf; /* temporary spots for left and right fonts */ 270Sstevel@tonic-gate 28*364Sceastha void name4(int, int); 29*364Sceastha void roman(int); 30*364Sceastha void shim(void); 31*364Sceastha int trans(int, char *); 32*364Sceastha 33*364Sceastha void 34*364Sceastha text(int t, char *p1) 35*364Sceastha { 360Sstevel@tonic-gate int c; 370Sstevel@tonic-gate char *p; 380Sstevel@tonic-gate tbl *tp, *lookup(); 390Sstevel@tonic-gate extern tbl *restbl; 400Sstevel@tonic-gate 410Sstevel@tonic-gate yyval = oalloc(); 420Sstevel@tonic-gate ebase[yyval] = 0; 430Sstevel@tonic-gate #ifndef NEQN 440Sstevel@tonic-gate eht[yyval] = VERT(EM(1.0, EFFPS(ps))); /* ht in machine units */ 45*364Sceastha #else /* NEQN */ 460Sstevel@tonic-gate eht[yyval] = VERT(2); /* 2 half-spaces */ 47*364Sceastha #endif /* NEQN */ 480Sstevel@tonic-gate lfont[yyval] = rfont[yyval] = ROM; 490Sstevel@tonic-gate if (t == QTEXT) 500Sstevel@tonic-gate p = p1; 51*364Sceastha else if (t == SPACE) 520Sstevel@tonic-gate p = "\\ "; 53*364Sceastha else if (t == THIN) 540Sstevel@tonic-gate p = "\\|"; 55*364Sceastha else if (t == TAB) 560Sstevel@tonic-gate p = "\\t"; 570Sstevel@tonic-gate else if ((tp = lookup(&restbl, p1, NULL)) != NULL) 580Sstevel@tonic-gate p = tp->defn; 590Sstevel@tonic-gate else { 600Sstevel@tonic-gate lf = rf = 0; 61*364Sceastha for (csp = psp = 0; (c = p1[psp++]) != '\0'; ) { 620Sstevel@tonic-gate rf = trans(c, p1); 630Sstevel@tonic-gate if (lf == 0) 640Sstevel@tonic-gate lf = rf; /* save first */ 65*364Sceastha if (csp > CSSIZE) 66*364Sceastha error(FATAL, gettext( 67*364Sceastha "converted token %.25s... too long"), p1); 680Sstevel@tonic-gate } 690Sstevel@tonic-gate cs[csp] = '\0'; 700Sstevel@tonic-gate p = cs; 710Sstevel@tonic-gate lfont[yyval] = lf; 720Sstevel@tonic-gate rfont[yyval] = rf; 730Sstevel@tonic-gate } 74*364Sceastha if (dbg) 75*364Sceastha printf(".\t%dtext: S%d <- %s; b=%d,h=%d,lf=%c,rf=%c\n", 76*364Sceastha t, yyval, p, ebase[yyval], eht[yyval], lfont[yyval], 77*364Sceastha rfont[yyval]); 780Sstevel@tonic-gate printf(".ds %d \"%s\n", yyval, p); 790Sstevel@tonic-gate } 800Sstevel@tonic-gate 81*364Sceastha int 82*364Sceastha trans(int c, char *p1) 83*364Sceastha { 840Sstevel@tonic-gate int f; 850Sstevel@tonic-gate f = ROM; 86*364Sceastha switch (c) { 870Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4': 880Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9': 890Sstevel@tonic-gate case ':': case ';': case '!': case '%': 900Sstevel@tonic-gate case '(': case '[': case ')': case ']': 910Sstevel@tonic-gate case ',': 920Sstevel@tonic-gate if (rf == ITAL) 930Sstevel@tonic-gate shim(); 940Sstevel@tonic-gate roman(c); break; 950Sstevel@tonic-gate case '.': 960Sstevel@tonic-gate if (rf == ROM) 970Sstevel@tonic-gate roman(c); 980Sstevel@tonic-gate else 990Sstevel@tonic-gate cs[csp++] = c; 1000Sstevel@tonic-gate f = rf; 1010Sstevel@tonic-gate break; 1020Sstevel@tonic-gate case '|': 1030Sstevel@tonic-gate if (rf == ITAL) 1040Sstevel@tonic-gate shim(); 1050Sstevel@tonic-gate shim(); roman(c); shim(); break; 1060Sstevel@tonic-gate case '=': 1070Sstevel@tonic-gate if (rf == ITAL) 1080Sstevel@tonic-gate shim(); 109*364Sceastha name4('e', 'q'); 1100Sstevel@tonic-gate break; 1110Sstevel@tonic-gate case '+': 1120Sstevel@tonic-gate if (rf == ITAL) 1130Sstevel@tonic-gate shim(); 1140Sstevel@tonic-gate name4('p', 'l'); 1150Sstevel@tonic-gate break; 1160Sstevel@tonic-gate case '>': case '<': 1170Sstevel@tonic-gate if (rf == ITAL) 1180Sstevel@tonic-gate shim(); 119*364Sceastha if (p1[psp] == '=') { /* look ahead for == <= >= */ 120*364Sceastha name4(c, '='); 1210Sstevel@tonic-gate psp++; 1220Sstevel@tonic-gate } else { 123*364Sceastha cs[csp++] = c; 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate break; 1260Sstevel@tonic-gate case '-': 1270Sstevel@tonic-gate if (rf == ITAL) 1280Sstevel@tonic-gate shim(); 129*364Sceastha if (p1[psp] == '>') { 130*364Sceastha name4('-', '>'); psp++; 1310Sstevel@tonic-gate } else { 132*364Sceastha name4('m', 'i'); 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate break; 1350Sstevel@tonic-gate case '/': 1360Sstevel@tonic-gate if (rf == ITAL) 1370Sstevel@tonic-gate shim(); 138*364Sceastha name4('s', 'l'); 1390Sstevel@tonic-gate break; 1400Sstevel@tonic-gate case '~': case ' ': 1410Sstevel@tonic-gate shim(); shim(); break; 1420Sstevel@tonic-gate case '^': 1430Sstevel@tonic-gate shim(); break; 1440Sstevel@tonic-gate case '\\': /* troff - pass 2 or 3 more chars */ 1450Sstevel@tonic-gate if (rf == ITAL) 1460Sstevel@tonic-gate shim(); 1470Sstevel@tonic-gate cs[csp++] = c; cs[csp++] = c = p1[psp++]; cs[csp++] = p1[psp++]; 148*364Sceastha if (c == '(') cs[csp++] = p1[psp++]; 149*364Sceastha if (c == '*' && cs[csp-1] == '(') { 1500Sstevel@tonic-gate cs[csp++] = p1[psp++]; 1510Sstevel@tonic-gate cs[csp++] = p1[psp++]; 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate break; 1540Sstevel@tonic-gate case '\'': 155*364Sceastha cs[csp++] = '\\'; 156*364Sceastha cs[csp++] = 'f'; 157*364Sceastha cs[csp++] = rf == ITAL ? ITAL : ROM; 158*364Sceastha name4('f', 'm'); 1590Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = 'P'; 160*364Sceastha f = rf == ITAL ? ITAL : ROM; 1610Sstevel@tonic-gate break; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate case 'f': 1640Sstevel@tonic-gate if (ft == ITAL) { 1650Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '^'; 1660Sstevel@tonic-gate cs[csp++] = 'f'; 167*364Sceastha 168*364Sceastha /* trying | instead of ^ */ 169*364Sceastha cs[csp++] = '\\'; cs[csp++] = '|'; 170*364Sceastha 1710Sstevel@tonic-gate f = ITAL; 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate else 1740Sstevel@tonic-gate cs[csp++] = 'f'; 1750Sstevel@tonic-gate break; 1760Sstevel@tonic-gate case 'j': 1770Sstevel@tonic-gate if (ft == ITAL) { 1780Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '^'; 1790Sstevel@tonic-gate cs[csp++] = 'j'; 1800Sstevel@tonic-gate f = ITAL; 1810Sstevel@tonic-gate } 1820Sstevel@tonic-gate else 1830Sstevel@tonic-gate cs[csp++] = 'j'; 1840Sstevel@tonic-gate break; 1850Sstevel@tonic-gate default: 1860Sstevel@tonic-gate cs[csp++] = c; 187*364Sceastha f = ft == ITAL ? ITAL : ROM; 1880Sstevel@tonic-gate break; 1890Sstevel@tonic-gate } 190*364Sceastha return (f); 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate 193*364Sceastha void 194*364Sceastha shim(void) 195*364Sceastha { 1960Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '|'; 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate 199*364Sceastha void 200*364Sceastha roman(int c) 201*364Sceastha { 2020Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = ROM; 2030Sstevel@tonic-gate cs[csp++] = c; 2040Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = 'P'; 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate 207*364Sceastha void 208*364Sceastha name4(int c1, int c2) 209*364Sceastha { 2100Sstevel@tonic-gate cs[csp++] = '\\'; 2110Sstevel@tonic-gate cs[csp++] = '('; 2120Sstevel@tonic-gate cs[csp++] = c1; 2130Sstevel@tonic-gate cs[csp++] = c2; 2140Sstevel@tonic-gate } 215