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 '~':   /* stan */
  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:     /* Next line: modified by stan ~ to ` */
 129:     while (c != ' ' && c != '\t' && c != '\n' && c != '{' && c != '}'
 130:       && c != '"' && c != '~' && c != '^' && c != righteq) {
 131:         if (c == '\\')
 132:             if ((c = gtc()) != '"')
 133:                 *p++ = '\\';
 134:         *p++ = c;
 135:         if (--n <= 0)
 136:             error(FATAL, "token %.20s... too long", s);
 137:         c = gtc();
 138:     }
 139:     /* Next line: modified by stan ~ to ` */
 140:     if (c=='{' || c=='}' || c=='"' || c=='~' || c=='^' || c=='\t' || c==righteq)
 141:         putbak(c);
 142:     *p = '\0';
 143:     yylval = (int) s;
 144: }
 145: 
 146: cstr(s, quote, maxs) char *s; int quote; {
 147:     int del, c, i;
 148: 
 149:     while((del=gtc()) == ' ' || del == '\t' || del == '\n');
 150:     if (quote)
 151:         for (i=0; (c=gtc()) != del && c != EOF;) {
 152:             s[i++] = c;
 153:             if (i >= maxs)
 154:                 return(1);  /* disaster */
 155:         }
 156:     else {
 157:         s[0] = del;
 158:         for (i=1; (c=gtc())!=' ' && c!= '\t' && c!='\n' && c!=EOF;) {
 159:             s[i++]=c;
 160:             if (i >= maxs)
 161:                 return(1);  /* disaster */
 162:         }
 163:     }
 164:     s[i] = '\0';
 165:     if (c == EOF)
 166:         error(FATAL, "Unexpected end of input at %.20s", s);
 167:     return(0);
 168: }
 169: 
 170: define(type) int type; {
 171:     char *strsave(), *p1, *p2;
 172:     tbl *lookup();
 173:     extern tbl **deftbl;
 174: 
 175:     getstr(token, SSIZE);   /* get name */
 176:     if (type != DEFINE) {
 177:         cstr(token, 1, SSIZE);  /* skip the definition too */
 178:         return;
 179:     }
 180:     p1 = strsave(token);
 181:     if (cstr(token, 1, SSIZE))
 182:         error(FATAL, "Unterminated definition at %.20s", token);
 183:     p2 = strsave(token);
 184:     lookup(&deftbl, p1, p2);
 185:     if (dbg)printf(".\tname %s defined as %s\n", p1, p2);
 186: }
 187: 
 188: char *strsave(s)
 189: char *s;
 190: {
 191:     char *malloc();
 192:     register char *q;
 193: 
 194:     q = malloc(strlen(s)+1);
 195:     if (q == NULL)
 196:         error(FATAL, "out of space in strsave on %s", s);
 197:     strcpy(q, s);
 198:     return(q);
 199: }
 200: 
 201: include() {
 202:     error(!FATAL, "Include not yet implemented");
 203: }
 204: 
 205: delim() {
 206:     yyval = eqnreg = 0;
 207:     if (cstr(token, 0, SSIZE))
 208:         error(FATAL, "Bizarre delimiters at %.20s", token);
 209:     lefteq = token[0];
 210:     righteq = token[1];
 211:     if (lefteq == 'o' && righteq == 'f')
 212:         lefteq = righteq = '\0';
 213: }

Defined functions

cstr defined in line 146; used 3 times
define defined in line 170; used 1 times
delim defined in line 205; used 1 times
getstr defined in line 117; used 4 times
gtc defined in line 12; used 11 times
include defined in line 201; used 1 times
pbstr defined in line 32; used 1 times
  • in line 92
strsave defined in line 188; 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: 1982-03-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 926
Valid CSS Valid XHTML 1.0 Strict