1: # include "e.h"
   2: #define MAXLINE 1200    /* maximum input line */
   3: 
   4: char    in[MAXLINE];    /* input buffer */
   5: int eqnexit();
   6: int noeqn;
   7: 
   8: main(argc,argv) int argc; char *argv[];{
   9: 
  10:     eqnexit(eqn(argc, argv));
  11: }
  12: 
  13: eqnexit(n) {
  14: #ifdef gcos
  15:     if (n)
  16:         fprintf(stderr, "run terminated due to eqn error\n");
  17:     exit(0);
  18: #endif
  19:     exit(n);
  20: }
  21: 
  22: eqn(argc,argv) int argc; char *argv[];{
  23:     int i, type;
  24: 
  25:     setfile(argc,argv);
  26:     init_tbl(); /* install keywords in tables */
  27:     while ((type=getline(in)) != EOF) {
  28:         eqline = linect;
  29:         if (in[0]=='.' && in[1]=='E' && in[2]=='Q') {
  30:             for (i=11; i<100; used[i++]=0);
  31:             printf("%s",in);
  32:             printf(".nr 99 \\n(.s\n.nr 98 \\n(.f\n");
  33:             markline = 0;
  34:             init();
  35:             yyparse();
  36:             if (eqnreg>0) {
  37:                 printf(".nr %d \\w'\\*(%d'\n", eqnreg, eqnreg);
  38:                 /* printf(".if \\n(%d>\\n(.l .tm too-long eqn, file %s, between lines %d-%d\n",	*/
  39:                 /*	eqnreg, svargv[ifile], eqline, linect);	*/
  40:                 printf(".nr MK %d\n", markline);    /* for -ms macros */
  41:                 printf(".if %d>\\n(.v .ne %du\n", eqnht, eqnht);
  42:                 printf(".rn %d 10\n", eqnreg);
  43:                 if(!noeqn)printf("\\*(10\n");
  44:             }
  45:             printf(".ps \\n(99\n.ft \\n(98\n");
  46:             printf(".EN");
  47:             if (lastchar == EOF) {
  48:                 putchar('\n');
  49:                 break;
  50:             }
  51:             if (putchar(lastchar) != '\n')
  52:                 while (putchar(gtc()) != '\n');
  53:         }
  54:         else if (type == lefteq)
  55:             inline();
  56:         else
  57:             printf("%s",in);
  58:     }
  59:     return(0);
  60: }
  61: 
  62: getline(s) register char *s; {
  63:     register c;
  64:     while((*s++=c=gtc())!='\n' && c!=EOF && c!=lefteq)
  65:         if (s >= in+MAXLINE) {
  66:             error( !FATAL, "input line too long: %.20s\n", in);
  67:             in[MAXLINE] = '\0';
  68:             break;
  69:         }
  70:     if (c==lefteq)
  71:         s--;
  72:     *s++ = '\0';
  73:     return(c);
  74: }
  75: 
  76: inline() {
  77:     int ds;
  78: 
  79:     printf(".nr 99 \\n(.s\n.nr 98 \\n(.f\n");
  80:     ds = oalloc();
  81:     printf(".rm %d \n", ds);
  82:     do{
  83:         if (*in)
  84:             printf(".as %d \"%s\n", ds, in);
  85:         init();
  86:         yyparse();
  87:         if (eqnreg > 0) {
  88:             printf(".as %d \\*(%d\n", ds, eqnreg);
  89:             ofree(eqnreg);
  90:         }
  91:         printf(".ps \\n(99\n.ft \\n(98\n");
  92:     } while (getline(in) == lefteq);
  93:     if (*in)
  94:         printf(".as %d \"%s", ds, in);
  95:     printf(".ps \\n(99\n.ft \\n(98\n");
  96:     printf("\\*(%d\n", ds);
  97:     ofree(ds);
  98: }
  99: 
 100: putout(p1) int p1; {
 101:     extern int gsize, gfont;
 102:     int before, after;
 103:     if(dbg)printf(".\tanswer <- S%d, h=%d,b=%d\n",p1, eht[p1], ebase[p1]);
 104:     eqnht = eht[p1];
 105:     printf(".ds %d \\x'0'", p1);
 106:     /* suppposed to leave room for a subscript or superscript */
 107:     before = eht[p1] - ebase[p1] - VERT((ps*6*12)/10);
 108:     if (before > 0)
 109:         printf("\\x'0-%du'", before);
 110:     printf("\\f%c\\s%d\\*(%d%s\\s\\n(99\\f\\n(98",
 111:         gfont, gsize, p1, rfont[p1] == ITAL ? "\\|" : "");
 112:     after = ebase[p1] - VERT((ps*6*2)/10);
 113:     if (after > 0)
 114:         printf("\\x'%du'", after);
 115:     putchar('\n');
 116:     eqnreg = p1;
 117: }
 118: 
 119: max(i,j) int i,j; {
 120:     return (i>j ? i : j);
 121: }
 122: 
 123: oalloc() {
 124:     int i;
 125:     for (i=11; i<100; i++)
 126:         if (used[i]++ == 0) return(i);
 127:     error( FATAL, "no eqn strings left", i);
 128:     return(0);
 129: }
 130: 
 131: ofree(n) int n; {
 132:     used[n] = 0;
 133: }
 134: 
 135: setps(p) int p; {
 136:     printf(".ps %d\n", EFFPS(p));
 137: }
 138: 
 139: nrwid(n1, p, n2) int n1, p, n2; {
 140:     printf(".nr %d \\w'\\s%d\\*(%d'\n", n1, EFFPS(p), n2);
 141: }
 142: 
 143: setfile(argc, argv) int argc; char *argv[]; {
 144:     static char *nullstr = "-";
 145: 
 146:     svargc = --argc;
 147:     svargv = argv;
 148:     while (svargc > 0 && svargv[1][0] == '-') {
 149:         switch (svargv[1][1]) {
 150: 
 151:         case 'd': lefteq=svargv[1][2]; righteq=svargv[1][3]; break;
 152:         case 's': gsize = atoi(&svargv[1][2]); break;
 153:         case 'p': deltaps = atoi(&svargv[1][2]); break;
 154:         case 'f': gfont = svargv[1][2]; break;
 155:         case 'e': noeqn++; break;
 156:         default: dbg = 1;
 157:         }
 158:         svargc--;
 159:         svargv++;
 160:     }
 161:     ifile = 1;
 162:     linect = 1;
 163:     if (svargc <= 0) {
 164:         curfile = stdin;
 165:         svargv[1] = nullstr;
 166:     }
 167:     else if ((curfile = fopen(svargv[1], "r")) == NULL)
 168:         error( FATAL,"can't open file %s", svargv[1]);
 169: }
 170: 
 171: yyerror() {;}
 172: 
 173: init() {
 174:     ct = 0;
 175:     ps = gsize;
 176:     ft = gfont;
 177:     setps(ps);
 178:     printf(".ft %c\n", ft);
 179: }
 180: 
 181: error(fatal, s1, s2) int fatal; char *s1, *s2; {
 182:     if (fatal>0)
 183:         printf("eqn fatal error: ");
 184:     printf(s1,s2);
 185:     printf("\nfile %s, between lines %d and %d\n",
 186:          svargv[ifile], eqline, linect);
 187:     fprintf(stderr, "eqn: ");
 188:     if (fatal>0)
 189:         fprintf(stderr, "fatal error: ");
 190:     fprintf(stderr, s1, s2);
 191:     fprintf(stderr, "\nfile %s, between lines %d and %d\n",
 192:          svargv[ifile], eqline, linect);
 193:     if (fatal > 0)
 194:         eqnexit(1);
 195: }

Defined functions

eqn defined in line 22; used 1 times
  • in line 10
eqnexit defined in line 13; used 3 times
error defined in line 181; used 17 times
getline defined in line 62; used 2 times
init defined in line 173; used 2 times
inline defined in line 76; used 1 times
  • in line 55
main defined in line 8; never used
max defined in line 119; used 13 times
putout defined in line 100; used 1 times
setfile defined in line 143; used 1 times
  • in line 25
setps defined in line 135; used 2 times
yyerror defined in line 171; never used

Defined variables

in defined in line 4; used 14 times
noeqn defined in line 6; used 2 times

Defined macros

MAXLINE defined in line 2; used 3 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1072
Valid CSS Valid XHTML 1.0 Strict