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