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