1*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2*0Sstevel@tonic-gate /* All Rights Reserved */ 3*0Sstevel@tonic-gate 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gate /* 6*0Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 7*0Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 8*0Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 9*0Sstevel@tonic-gate */ 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gate /* 12*0Sstevel@tonic-gate * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. 13*0Sstevel@tonic-gate * All Rights Reserved. 14*0Sstevel@tonic-gate */ 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */ 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate # include "e.h" 19*0Sstevel@tonic-gate # include "e.def" 20*0Sstevel@tonic-gate #include <locale.h> 21*0Sstevel@tonic-gate 22*0Sstevel@tonic-gate int csp; 23*0Sstevel@tonic-gate int psp; 24*0Sstevel@tonic-gate #define CSSIZE 400 25*0Sstevel@tonic-gate char cs[420]; 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate int lf, rf; /* temporary spots for left and right fonts */ 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate text(t,p1) int t; char *p1; { 30*0Sstevel@tonic-gate int c; 31*0Sstevel@tonic-gate char *p; 32*0Sstevel@tonic-gate tbl *tp, *lookup(); 33*0Sstevel@tonic-gate extern tbl *restbl; 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate yyval = oalloc(); 36*0Sstevel@tonic-gate ebase[yyval] = 0; 37*0Sstevel@tonic-gate #ifndef NEQN 38*0Sstevel@tonic-gate eht[yyval] = VERT(EM(1.0, EFFPS(ps))); /* ht in machine units */ 39*0Sstevel@tonic-gate #else NEQN 40*0Sstevel@tonic-gate eht[yyval] = VERT(2); /* 2 half-spaces */ 41*0Sstevel@tonic-gate #endif NEQN 42*0Sstevel@tonic-gate lfont[yyval] = rfont[yyval] = ROM; 43*0Sstevel@tonic-gate if (t == QTEXT) 44*0Sstevel@tonic-gate p = p1; 45*0Sstevel@tonic-gate else if ( t == SPACE ) 46*0Sstevel@tonic-gate p = "\\ "; 47*0Sstevel@tonic-gate else if ( t == THIN ) 48*0Sstevel@tonic-gate p = "\\|"; 49*0Sstevel@tonic-gate else if ( t == TAB ) 50*0Sstevel@tonic-gate p = "\\t"; 51*0Sstevel@tonic-gate else if ((tp = lookup(&restbl, p1, NULL)) != NULL) 52*0Sstevel@tonic-gate p = tp->defn; 53*0Sstevel@tonic-gate else { 54*0Sstevel@tonic-gate lf = rf = 0; 55*0Sstevel@tonic-gate for (csp=psp=0; (c=p1[psp++])!='\0';) { 56*0Sstevel@tonic-gate rf = trans(c, p1); 57*0Sstevel@tonic-gate if (lf == 0) 58*0Sstevel@tonic-gate lf = rf; /* save first */ 59*0Sstevel@tonic-gate if (csp>CSSIZE) 60*0Sstevel@tonic-gate error(FATAL, gettext("converted token %.25s... too long") ,p1); 61*0Sstevel@tonic-gate } 62*0Sstevel@tonic-gate cs[csp] = '\0'; 63*0Sstevel@tonic-gate p = cs; 64*0Sstevel@tonic-gate lfont[yyval] = lf; 65*0Sstevel@tonic-gate rfont[yyval] = rf; 66*0Sstevel@tonic-gate } 67*0Sstevel@tonic-gate if(dbg)printf(".\t%dtext: S%d <- %s; b=%d,h=%d,lf=%c,rf=%c\n", 68*0Sstevel@tonic-gate t, yyval, p, ebase[yyval], eht[yyval], lfont[yyval], rfont[yyval]); 69*0Sstevel@tonic-gate printf(".ds %d \"%s\n", yyval, p); 70*0Sstevel@tonic-gate } 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate trans(c,p1) int c; char *p1; { 73*0Sstevel@tonic-gate int f; 74*0Sstevel@tonic-gate f = ROM; 75*0Sstevel@tonic-gate switch( c) { 76*0Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4': 77*0Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9': 78*0Sstevel@tonic-gate case ':': case ';': case '!': case '%': 79*0Sstevel@tonic-gate case '(': case '[': case ')': case ']': 80*0Sstevel@tonic-gate case ',': 81*0Sstevel@tonic-gate if (rf == ITAL) 82*0Sstevel@tonic-gate shim(); 83*0Sstevel@tonic-gate roman(c); break; 84*0Sstevel@tonic-gate case '.': 85*0Sstevel@tonic-gate if (rf == ROM) 86*0Sstevel@tonic-gate roman(c); 87*0Sstevel@tonic-gate else 88*0Sstevel@tonic-gate cs[csp++] = c; 89*0Sstevel@tonic-gate f = rf; 90*0Sstevel@tonic-gate break; 91*0Sstevel@tonic-gate case '|': 92*0Sstevel@tonic-gate if (rf == ITAL) 93*0Sstevel@tonic-gate shim(); 94*0Sstevel@tonic-gate shim(); roman(c); shim(); break; 95*0Sstevel@tonic-gate case '=': 96*0Sstevel@tonic-gate if (rf == ITAL) 97*0Sstevel@tonic-gate shim(); 98*0Sstevel@tonic-gate name4('e','q'); 99*0Sstevel@tonic-gate break; 100*0Sstevel@tonic-gate case '+': 101*0Sstevel@tonic-gate if (rf == ITAL) 102*0Sstevel@tonic-gate shim(); 103*0Sstevel@tonic-gate name4('p', 'l'); 104*0Sstevel@tonic-gate break; 105*0Sstevel@tonic-gate case '>': case '<': 106*0Sstevel@tonic-gate if (rf == ITAL) 107*0Sstevel@tonic-gate shim(); 108*0Sstevel@tonic-gate if (p1[psp]=='=') { /* look ahead for == <= >= */ 109*0Sstevel@tonic-gate name4(c,'='); 110*0Sstevel@tonic-gate psp++; 111*0Sstevel@tonic-gate } else { 112*0Sstevel@tonic-gate cs[csp++] = c; 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate break; 115*0Sstevel@tonic-gate case '-': 116*0Sstevel@tonic-gate if (rf == ITAL) 117*0Sstevel@tonic-gate shim(); 118*0Sstevel@tonic-gate if (p1[psp]=='>') { 119*0Sstevel@tonic-gate name4('-','>'); psp++; 120*0Sstevel@tonic-gate } else { 121*0Sstevel@tonic-gate name4('m','i'); 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate break; 124*0Sstevel@tonic-gate case '/': 125*0Sstevel@tonic-gate if (rf == ITAL) 126*0Sstevel@tonic-gate shim(); 127*0Sstevel@tonic-gate name4('s','l'); 128*0Sstevel@tonic-gate break; 129*0Sstevel@tonic-gate case '~': case ' ': 130*0Sstevel@tonic-gate shim(); shim(); break; 131*0Sstevel@tonic-gate case '^': 132*0Sstevel@tonic-gate shim(); break; 133*0Sstevel@tonic-gate case '\\': /* troff - pass 2 or 3 more chars */ 134*0Sstevel@tonic-gate if (rf == ITAL) 135*0Sstevel@tonic-gate shim(); 136*0Sstevel@tonic-gate cs[csp++] = c; cs[csp++] = c = p1[psp++]; cs[csp++] = p1[psp++]; 137*0Sstevel@tonic-gate if (c=='(') cs[csp++] = p1[psp++]; 138*0Sstevel@tonic-gate if (c=='*' && cs[csp-1] == '(') { 139*0Sstevel@tonic-gate cs[csp++] = p1[psp++]; 140*0Sstevel@tonic-gate cs[csp++] = p1[psp++]; 141*0Sstevel@tonic-gate } 142*0Sstevel@tonic-gate break; 143*0Sstevel@tonic-gate case '\'': 144*0Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = rf==ITAL ? ITAL : ROM; 145*0Sstevel@tonic-gate name4('f','m'); 146*0Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = 'P'; 147*0Sstevel@tonic-gate f = rf==ITAL ? ITAL : ROM; 148*0Sstevel@tonic-gate break; 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate case 'f': 151*0Sstevel@tonic-gate if (ft == ITAL) { 152*0Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '^'; 153*0Sstevel@tonic-gate cs[csp++] = 'f'; 154*0Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '|'; /* trying | instead of ^ */ 155*0Sstevel@tonic-gate f = ITAL; 156*0Sstevel@tonic-gate } 157*0Sstevel@tonic-gate else 158*0Sstevel@tonic-gate cs[csp++] = 'f'; 159*0Sstevel@tonic-gate break; 160*0Sstevel@tonic-gate case 'j': 161*0Sstevel@tonic-gate if (ft == ITAL) { 162*0Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '^'; 163*0Sstevel@tonic-gate cs[csp++] = 'j'; 164*0Sstevel@tonic-gate f = ITAL; 165*0Sstevel@tonic-gate } 166*0Sstevel@tonic-gate else 167*0Sstevel@tonic-gate cs[csp++] = 'j'; 168*0Sstevel@tonic-gate break; 169*0Sstevel@tonic-gate default: 170*0Sstevel@tonic-gate cs[csp++] = c; 171*0Sstevel@tonic-gate f = ft==ITAL ? ITAL : ROM; 172*0Sstevel@tonic-gate break; 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate return(f); 175*0Sstevel@tonic-gate } 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate shim() { 178*0Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = '|'; 179*0Sstevel@tonic-gate } 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate roman(c) int c; { 182*0Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = ROM; 183*0Sstevel@tonic-gate cs[csp++] = c; 184*0Sstevel@tonic-gate cs[csp++] = '\\'; cs[csp++] = 'f'; cs[csp++] = 'P'; 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate name4(c1,c2) int c1,c2; { 188*0Sstevel@tonic-gate cs[csp++] = '\\'; 189*0Sstevel@tonic-gate cs[csp++] = '('; 190*0Sstevel@tonic-gate cs[csp++] = c1; 191*0Sstevel@tonic-gate cs[csp++] = c2; 192*0Sstevel@tonic-gate } 193