22 while ((c = input()) == ' ' || c == '\n' || c == '\t')
27 ERROR "unexpected end of input inside equation" WARNING;
41 for (sp = 0; (c=input())!='"' && c != '\n'; ) {
43 if ((c = input()) != '"')
47 ERROR "quoted string %.20s... too long", token FATAL;
50 yylval = (int) &token[0];
52 ERROR "missing \" in %.20s", token WARNING;
55 if (!display && c == righteq)
60 dprintf(".\tlex token = |%s|\n", token);
61 if ((tp = lookup(deftbl, token)) != NULL) { /* defined term */
64 if (c == '(') /* macro with args */
69 dprintf(".\tfound %s|=%s|\n", token, tp->cval);
74 if ((tp = lookup(keytbl, token)) == NULL) /* not a keyword */
77 switch (tp->ival) { /* some kind of keyword */
78 case DEFINE: case TDEFINE: case NDEFINE:
100 /* .EQ inside equation -- should warn if at bottom level */
103 if (curfile == infile)
105 /* else ignore nested .EN */
113 void getstr(char *s, int n)
119 while ((c = input()) == ' ' || c == '\n')
125 while (c != ' ' && c != '\t' && c != '\n' && c != '{' && c != '}'
126 && c != '"' && c != '~' && c != '^') {
127 if (!display && c == righteq)
129 if (c == '(' && p > s) { /* might be defined(...) */
131 if (lookup(deftbl, s) != NULL)
135 if ((c = input()) != '"')
139 ERROR "token %.20s... too long", s FATAL;
147 cstr(char *s, int quote, int maxs)
152 while ((del=input()) == ' ' || del == '\t')
155 for (i=0; (c=input()) != del && c != EOF;) {
158 return(1); /* disaster */
164 for (i=1; (c=input())!=' ' && c!= '\t' && c!='\n' && c!=EOF;) {
167 return(1); /* disaster */
172 ERROR "Unexpected end of input at %.20s", s FATAL;
176 void define(int type)
179 extern int ftune(char *, char *);
181 getstr(token, SSIZE); /* get name */
182 if (type != DEFINE) {
183 cstr(token, 1, SSIZE); /* skip the definition too */
187 if (cstr(token, 1, SSIZE))
188 ERROR "Unterminated definition at %.20s", token FATAL;
189 if (lookup(ftunetbl, p1) != NULL) { /* double tuning param */
190 dprintf(".\ttune %s %s\n", p1, token);
194 install(deftbl, p1, p2, 0);
195 dprintf(".\tname %s defined as %s\n", p1, p2);
199 void ifdef(void) /* do body if name is defined */
203 getstr(name, sizeof(name)); /* get name */
204 cstr(token, 1, SSIZE); /* and body */
205 if (lookup(deftbl, name) != NULL) { /* found it */
212 char *spaceval = NULL;
214 void space(void) /* collect line of form "space amt" to replace \x in output */
216 getstr(token, SSIZE);
217 spaceval = strsave(token);
218 dprintf(".\tsetting spaceval to %s\n", token);
221 char *strsave(char *s)
225 q = malloc(strlen(s)+1);
227 ERROR "out of space in strsave on %s", s FATAL;
239 while ((c = input()) == ' ')
242 cstr(name, c == '"', sizeof(name)); /* gets it quoted or not */
243 if ((fin = fopen(name, "r")) == NULL)
244 ERROR "can't open file %s", name FATAL;
248 curfile->fname = strsave(name);
250 printf(".lf 1 %s\n", curfile->fname);
251 pushsrc(File, curfile->fname);
257 if (cstr(token, 0, SSIZE))
258 ERROR "Bizarre delimiters" FATAL;
261 if (!isprint(lefteq) || !isprint(righteq))
262 ERROR "Bizarre delimiters" FATAL;
263 if (lefteq == 'o' && righteq == 'f')
264 lefteq = righteq = '\0';