24 while ((c = input()) == ' ' || c == '\n' || c == '\t')
29 ERROR "unexpected end of input inside equation" WARNING;
43 for (sp = 0; (c=input())!='"' && c != '\n'; ) {
45 if ((c = input()) != '"')
49 ERROR "quoted string %.20s... too long", token FATAL;
52 yylval = (intptr_t)&token[0];
54 ERROR "missing \" in %.20s", token WARNING;
57 if (!display && c == righteq)
62 dprintf(".\tlex token = |%s|\n", token);
63 if ((tp = lookup(deftbl, token)) != NULL) { /* defined term */
66 if (c == '(') /* macro with args */
71 dprintf(".\tfound %s|=%s|\n", token, tp->cval);
76 if ((tp = lookup(keytbl, token)) == NULL) /* not a keyword */
79 switch (tp->ival) { /* some kind of keyword */
80 case DEFINE: case TDEFINE: case NDEFINE:
102 /* .EQ inside equation -- should warn if at bottom level */
105 if (curfile == infile)
107 /* else ignore nested .EN */
115 void getstr(char *s, int n)
121 while ((c = input()) == ' ' || c == '\n')
127 while (c != ' ' && c != '\t' && c != '\n' && c != '{' && c != '}'
128 && c != '"' && c != '~' && c != '^') {
129 if (!display && c == righteq)
131 if (c == '(' && p > s) { /* might be defined(...) */
133 if (lookup(deftbl, s) != NULL)
137 if ((c = input()) != '"')
141 ERROR "token %.20s... too long", s FATAL;
146 yylval = (uintptr_t)s;
150 cstr(char *s, int quote, int maxs)
155 while ((del=input()) == ' ' || del == '\t')
158 for (i=0; (c=input()) != del && c != EOF;) {
161 return(1); /* disaster */
167 for (i=1; (c=input())!=' ' && c!= '\t' && c!='\n' && c!=EOF;) {
170 return(1); /* disaster */
175 ERROR "Unexpected end of input at %.20s", s FATAL;
179 void define(int type)
182 extern int ftune(char *, char *);
184 getstr(token, SSIZE); /* get name */
185 if (type != DEFINE) {
186 cstr(token, 1, SSIZE); /* skip the definition too */
190 if (cstr(token, 1, SSIZE))
191 ERROR "Unterminated definition at %.20s", token FATAL;
192 if (lookup(ftunetbl, p1) != NULL) { /* double tuning param */
193 dprintf(".\ttune %s %s\n", p1, token);
197 install(deftbl, p1, p2, 0);
198 dprintf(".\tname %s defined as %s\n", p1, p2);
202 void ifdef(void) /* do body if name is defined */
206 getstr(name, sizeof(name)); /* get name */
207 cstr(token, 1, SSIZE); /* and body */
208 if (lookup(deftbl, name) != NULL) { /* found it */
215 char *spaceval = NULL;
217 void space(void) /* collect line of form "space amt" to replace \x in output */
219 getstr(token, SSIZE);
220 spaceval = strsave(token);
221 dprintf(".\tsetting spaceval to %s\n", token);
224 char *strsave(char *s)
228 q = malloc(strlen(s)+1);
230 ERROR "out of space in strsave on %s", s FATAL;
241 while ((c = input()) == ' ')
244 cstr(name, c == '"', sizeof(name)); /* gets it quoted or not */
245 if ((fin = fopen(name, "r")) == NULL)
246 ERROR "can't open file %s", name FATAL;
250 curfile->fname = strsave(name);
252 printf(".lf 1 %s\n", curfile->fname);
253 pushsrc(File, curfile->fname);
259 if (cstr(token, 0, SSIZE))
260 ERROR "Bizarre delimiters" FATAL;
263 if (!isprint(lefteq) || !isprint(righteq))
264 ERROR "Bizarre delimiters" FATAL;
265 if (lefteq == 'o' && righteq == 'f')
266 lefteq = righteq = '\0';