1: #include "e.h"
   2: #include "e.def"
   3: 
   4: #define SSIZE   400
   5: char    token[SSIZE];
   6: int sp;
   7: #define putbak(c)   *ip++ = c;
   8: #define PUSHBACK    300 /* maximum pushback characters */
   9: char    ibuf[PUSHBACK+SSIZE];   /* pushback buffer for definitions, etc. */
  10: char    *ip = ibuf;
  11: 
  12: gtc() {
  13:   loop:
  14:     if (ip > ibuf)
  15:         return(*--ip);  /* already present */
  16:     lastchar = getc(curfile);
  17:     if (lastchar=='\n')
  18:         linect++;
  19:     if (lastchar != EOF)
  20:         return(lastchar);
  21:     if (++ifile > svargc) {
  22:         return(EOF);
  23:     }
  24:     fclose(curfile);
  25:     linect = 1;
  26:     if ((curfile=fopen(svargv[ifile], "r")) != NULL)
  27:         goto loop;
  28:     error(FATAL, "can't open file %s", svargv[ifile]);
  29:     return(EOF);
  30: }
  31: 
  32: pbstr(str)
  33: register char *str;
  34: {
  35:     register char *p;
  36: 
  37:     p = str;
  38:     while (*p++);
  39:     --p;
  40:     if (ip >= &ibuf[PUSHBACK])
  41:         error( FATAL, "pushback overflow");
  42:     while (p > str)
  43:         putbak(*--p);
  44: }
  45: 
  46: yylex() {
  47:     register int c;
  48:     tbl *tp, *lookup();
  49:     extern tbl **keytbl, **deftbl;
  50: 
  51:   beg:
  52:     while ((c=gtc())==' ' || c=='\n')
  53:         ;
  54:     yylval=c;
  55:     switch(c) {
  56: 
  57:     case EOF:
  58:         return(EOF);
  59:     case '~':
  60:         return(SPACE);
  61:     case '^':
  62:         return(THIN);
  63:     case '\t':
  64:         return(TAB);
  65:     case '{':
  66:         return('{');
  67:     case '}':
  68:         return('}');
  69:     case '"':
  70:         for (sp=0; (c=gtc())!='"' && c != '\n'; ) {
  71:             if (c == '\\')
  72:                 if ((c = gtc()) != '"')
  73:                     token[sp++] = '\\';
  74:             token[sp++] = c;
  75:             if (sp>=SSIZE)
  76:                 error(FATAL, "quoted string %.20s... too long", token);
  77:         }
  78:         token[sp]='\0';
  79:         yylval = (int) &token[0];
  80:         if (c == '\n')
  81:             error(!FATAL, "missing \" in %.20s", token);
  82:         return(QTEXT);
  83:     }
  84:     if (c==righteq)
  85:         return(EOF);
  86: 
  87:     putbak(c);
  88:     getstr(token, SSIZE);
  89:     if (dbg)printf(".\tlex token = |%s|\n", token);
  90:     if ((tp = lookup(&deftbl, token, NULL)) != NULL) {
  91:         putbak(' ');
  92:         pbstr(tp->defn);
  93:         putbak(' ');
  94:         if (dbg)
  95:             printf(".\tfound %s|=%s|\n", token, tp->defn);
  96:     }
  97:     else if ((tp = lookup(&keytbl, token, NULL)) == NULL) {
  98:         if(dbg)printf(".\t%s is not a keyword\n", token);
  99:         return(CONTIG);
 100:     }
 101:     else if (tp->defn == (char *) DEFINE || tp->defn == (char *) NDEFINE || tp->defn == (char *) TDEFINE)
 102:         define(tp->defn);
 103:     else if (tp->defn == (char *) DELIM)
 104:         delim();
 105:     else if (tp->defn == (char *) GSIZE)
 106:         globsize();
 107:     else if (tp->defn == (char *) GFONT)
 108:         globfont();
 109:     else if (tp->defn == (char *) INCLUDE)
 110:         include();
 111:     else {
 112:         return((int) tp->defn);
 113:     }
 114:     goto beg;
 115: }
 116: 
 117: getstr(s, n) char *s; register int n; {
 118:     register int c;
 119:     register char *p;
 120: 
 121:     p = s;
 122:     while ((c = gtc()) == ' ' || c == '\n')
 123:         ;
 124:     if (c == EOF) {
 125:         *s = 0;
 126:         return;
 127:     }
 128:     while (c != ' ' && c != '\t' && c != '\n' && c != '{' && c != '}'
 129:       && c != '"' && c != '~' && c != '^' && c != righteq) {
 130:         if (c == '\\')
 131:             if ((c = gtc()) != '"')
 132:                 *p++ = '\\';
 133:         *p++ = c;
 134:         if (--n <= 0)
 135:             error(FATAL, "token %.20s... too long", s);
 136:         c = gtc();
 137:     }
 138:     if (c=='{' || c=='}' || c=='"' || c=='~' || c=='^' || c=='\t' || c==righteq)
 139:         putbak(c);
 140:     *p = '\0';
 141:     yylval = (int) s;
 142: }
 143: 
 144: cstr(s, quote, maxs) char *s; int quote; {
 145:     int del, c, i;
 146: 
 147:     while((del=gtc()) == ' ' || del == '\t' || del == '\n');
 148:     if (quote)
 149:         for (i=0; (c=gtc()) != del && c != EOF;) {
 150:             s[i++] = c;
 151:             if (i >= maxs)
 152:                 return(1);  /* disaster */
 153:         }
 154:     else {
 155:         s[0] = del;
 156:         for (i=1; (c=gtc())!=' ' && c!= '\t' && c!='\n' && c!=EOF;) {
 157:             s[i++]=c;
 158:             if (i >= maxs)
 159:                 return(1);  /* disaster */
 160:         }
 161:     }
 162:     s[i] = '\0';
 163:     if (c == EOF)
 164:         error(FATAL, "Unexpected end of input at %.20s", s);
 165:     return(0);
 166: }
 167: 
 168: define(type) int type; {
 169:     char *strsave(), *p1, *p2;
 170:     tbl *lookup();
 171:     extern tbl **deftbl;
 172: 
 173:     getstr(token, SSIZE);   /* get name */
 174:     if (type != DEFINE) {
 175:         cstr(token, 1, SSIZE);  /* skip the definition too */
 176:         return;
 177:     }
 178:     p1 = strsave(token);
 179:     if (cstr(token, 1, SSIZE))
 180:         error(FATAL, "Unterminated definition at %.20s", token);
 181:     p2 = strsave(token);
 182:     lookup(&deftbl, p1, p2);
 183:     if (dbg)printf(".\tname %s defined as %s\n", p1, p2);
 184: }
 185: 
 186: char *strsave(s)
 187: char *s;
 188: {
 189:     char *malloc();
 190:     register char *q;
 191: 
 192:     q = malloc(strlen(s)+1);
 193:     if (q == NULL)
 194:         error(FATAL, "out of space in strsave on %s", s);
 195:     strcpy(q, s);
 196:     return(q);
 197: }
 198: 
 199: include() {
 200:     error(!FATAL, "Include not yet implemented");
 201: }
 202: 
 203: delim() {
 204:     yyval = eqnreg = 0;
 205:     if (cstr(token, 0, SSIZE))
 206:         error(FATAL, "Bizarre delimiters at %.20s", token);
 207:     lefteq = token[0];
 208:     righteq = token[1];
 209:     if (lefteq == 'o' && righteq == 'f')
 210:         lefteq = righteq = '\0';
 211: }

Defined functions

cstr defined in line 144; used 3 times
define defined in line 168; used 1 times
delim defined in line 203; used 1 times
getstr defined in line 117; used 4 times
gtc defined in line 12; used 11 times
include defined in line 199; used 1 times
pbstr defined in line 32; used 1 times
  • in line 92
strsave defined in line 186; used 3 times
yylex defined in line 46; used 2 times

Defined variables

ibuf defined in line 9; used 3 times
ip defined in line 10; used 4 times
sp defined in line 6; used 5 times
token defined in line 5; used 22 times

Defined macros

PUSHBACK defined in line 8; used 2 times
  • in line 9, 40
SSIZE defined in line 4; used 8 times
putbak defined in line 7; used 5 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1059
Valid CSS Valid XHTML 1.0 Strict