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-1988, 2001 by Sun Microsystems, Inc. 13 * All rights reserved. 14 */ 15 16 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */ 17 18 # include "e.h" 19 #include <locale.h> 20 #define MAXLINE 8192 /* maximum input line */ 21 22 char in[MAXLINE+1]; /* input buffer */ 23 int eqnexit(); 24 int noeqn; 25 26 main(argc,argv) int argc; char *argv[];{ 27 28 (void) setlocale(LC_ALL, ""); 29 #if !defined(TEXT_DOMAIN) 30 #define TEXT_DOMAIN "SYS_TEST" 31 #endif 32 (void) textdomain(TEXT_DOMAIN); 33 eqnexit(eqn(argc, argv)); 34 } 35 36 eqnexit(n) { 37 #ifdef gcos 38 if (n) 39 fprintf(stderr, gettext("run terminated due to eqn error\n")); 40 exit(0); 41 #endif 42 exit(n); 43 } 44 45 eqn(argc,argv) int argc; char *argv[];{ 46 int i, type; 47 48 setfile(argc,argv); 49 init_tbl(); /* install keywords in tables */ 50 while ((type=getline(in)) != EOF) { 51 eqline = linect; 52 if (in[0]=='.' && in[1]=='E' && in[2]=='Q') { 53 for (i=11; i<100; used[i++]=0); 54 printf("%s",in); 55 printf(".nr 99 \\n(.s\n.nr 98 \\n(.f\n"); 56 markline = 0; 57 init(); 58 yyparse(); 59 if (eqnreg>0) { 60 printf(".nr %d \\w'\\*(%d'\n", eqnreg, eqnreg); 61 /* printf(".if \\n(%d>\\n(.l .tm too-long eqn, file %s, between lines %d-%d\n", */ 62 /* eqnreg, svargv[ifile], eqline, linect); */ 63 printf(".nr MK %d\n", markline); /* for -ms macros */ 64 printf(".if %d>\\n(.v .ne %du\n", eqnht, eqnht); 65 printf(".rn %d 10\n", eqnreg); 66 if(!noeqn)printf("\\*(10\n"); 67 } 68 printf(".ps \\n(99\n.ft \\n(98\n"); 69 printf(".EN"); 70 if (lastchar == EOF) { 71 putchar('\n'); 72 break; 73 } 74 if (putchar(lastchar) != '\n') 75 while (putchar(gtc()) != '\n'); 76 } 77 else if (type == lefteq) 78 do_inline(); 79 else 80 printf("%s",in); 81 } 82 return(0); 83 } 84 85 getline(s) register char *s; { 86 register c; 87 while((*s++=c=gtc())!='\n' && c!=EOF && c!=lefteq) 88 if (s >= in+MAXLINE) { 89 error( !FATAL, gettext("input line too long: %.20s\n"), in); 90 in[MAXLINE] = '\0'; 91 break; 92 } 93 if (c==lefteq) 94 s--; 95 *s++ = '\0'; 96 return(c); 97 } 98 99 do_inline() { 100 int ds; 101 102 printf(".nr 99 \\n(.s\n.nr 98 \\n(.f\n"); 103 ds = oalloc(); 104 printf(".rm %d \n", ds); 105 do{ 106 if (*in) 107 printf(".as %d \"%s\n", ds, in); 108 init(); 109 yyparse(); 110 if (eqnreg > 0) { 111 printf(".as %d \\*(%d\n", ds, eqnreg); 112 ofree(eqnreg); 113 } 114 printf(".ps \\n(99\n.ft \\n(98\n"); 115 } while (getline(in) == lefteq); 116 if (*in) 117 printf(".as %d \"%s", ds, in); 118 printf(".ps \\n(99\n.ft \\n(98\n"); 119 printf("\\*(%d\n", ds); 120 ofree(ds); 121 } 122 123 putout(p1) int p1; { 124 extern int gsize, gfont; 125 int before, after; 126 if(dbg)printf(".\tanswer <- S%d, h=%d,b=%d\n",p1, eht[p1], ebase[p1]); 127 eqnht = eht[p1]; 128 printf(".ds %d \\x'0'", p1); 129 /* suppposed to leave room for a subscript or superscript */ 130 #ifndef NEQN 131 before = eht[p1] - ebase[p1] - VERT(EM(1.2, ps)); 132 #else NEQN 133 before = eht[p1] - ebase[p1] - VERT(3); /* 3 = 1.5 lines */ 134 #endif NEQN 135 if (spaceval != NULL) 136 printf("\\x'0-%s'", spaceval); 137 else if (before > 0) 138 printf("\\x'0-%du'", before); 139 printf("\\f%c\\s%d\\*(%d%s\\s\\n(99\\f\\n(98", 140 gfont, gsize, p1, rfont[p1] == ITAL ? "\\|" : ""); 141 #ifndef NEQN 142 after = ebase[p1] - VERT(EM(0.2, ps)); 143 #else NEQN 144 after = ebase[p1] - VERT(1); 145 #endif NEQN 146 if (spaceval == NULL && after > 0) 147 printf("\\x'%du'", after); 148 putchar('\n'); 149 eqnreg = p1; 150 if (spaceval != NULL) { 151 free(spaceval); 152 spaceval = NULL; 153 } 154 155 } 156 157 max(i,j) int i,j; { 158 return (i>j ? i : j); 159 } 160 161 oalloc() { 162 int i; 163 for (i=11; i<100; i++) 164 if (used[i]++ == 0) return(i); 165 error( FATAL, gettext("no eqn strings left"), i); 166 return(0); 167 } 168 169 ofree(n) int n; { 170 used[n] = 0; 171 } 172 173 setps(p) int p; { 174 printf(".ps %d\n", EFFPS(p)); 175 } 176 177 nrwid(n1, p, n2) int n1, p, n2; { 178 printf(".nr %d \\w'\\s%d\\*(%d'\n", n1, EFFPS(p), n2); 179 } 180 181 setfile(argc, argv) int argc; char *argv[]; { 182 static char *nullstr = "-"; 183 184 svargc = --argc; 185 svargv = argv; 186 while (svargc > 0 && svargv[1][0] == '-') { 187 switch (svargv[1][1]) { 188 189 case 'd': lefteq=svargv[1][2]; righteq=svargv[1][3]; break; 190 case 's': gsize = atoi(&svargv[1][2]); break; 191 case 'p': deltaps = atoi(&svargv[1][2]); break; 192 case 'f': gfont = svargv[1][2]; break; 193 case 'e': noeqn++; break; 194 case 0: goto endargs; 195 default: dbg = 1; 196 } 197 svargc--; 198 svargv++; 199 } 200 endargs: 201 ifile = 1; 202 linect = 1; 203 if (svargc <= 0) { 204 curfile = stdin; 205 svargv[1] = nullstr; 206 } 207 else 208 openinfile(); /* opens up the first input file */ 209 } 210 211 yyerror() {;} 212 213 init() { 214 ct = 0; 215 ps = gsize; 216 ft = gfont; 217 setps(ps); 218 printf(".ft %c\n", ft); 219 } 220 221 error(fatal, s1, s2) int fatal; char *s1, *s2; { 222 if (fatal>0) 223 printf(gettext("eqn fatal error: ")); 224 printf(s1, s2); 225 printf(gettext("\nfile %s, between lines %d and %d\n"), 226 svargv[ifile], eqline, linect); 227 fprintf(stderr, gettext("eqn: ")); 228 if (fatal>0) 229 fprintf(stderr, gettext("fatal error: ")); 230 fprintf(stderr, s1, s2); 231 fprintf(stderr, gettext("\nfile %s, between lines %d and %d\n"), 232 svargv[ifile], eqline, linect); 233 if (fatal > 0) 234 eqnexit(1); 235 } 236