23 while ((c = input()) == ' ' || c == '\n' || c == '\t')
28 ERROR "unexpected end of input inside equation" WARNING;
42 for (sp = 0; (c=input())!='"' && c != '\n'; ) {
44 if ((c = input()) != '"')
48 ERROR "quoted string %.20s... too long", token FATAL;
51 yylval = (int) &token[0];
53 ERROR "missing \" in %.20s", token WARNING;
56 if (!display && c == righteq)
61 dprintf(".\tlex token = |%s|\n", token);
62 if ((tp = lookup(deftbl, token)) != NULL) { /* defined term */
65 if (c == '(') /* macro with args */
70 dprintf(".\tfound %s|=%s|\n", token, tp->cval);
75 if ((tp = lookup(keytbl, token)) == NULL) /* not a keyword */
78 switch (tp->ival) { /* some kind of keyword */
79 case DEFINE: case TDEFINE: case NDEFINE:
101 /* .EQ inside equation -- should warn if at bottom level */
104 if (curfile == infile)
106 /* else ignore nested .EN */
114 void getstr(char *s, int n)
120 while ((c = input()) == ' ' || c == '\n')
126 while (c != ' ' && c != '\t' && c != '\n' && c != '{' && c != '}'
127 && c != '"' && c != '~' && c != '^') {
128 if (!display && c == righteq)
130 if (c == '(' && p > s) { /* might be defined(...) */
132 if (lookup(deftbl, s) != NULL)
136 if ((c = input()) != '"')
140 ERROR "token %.20s... too long", s FATAL;
148 cstr(char *s, int quote, int maxs)
153 while ((del=input()) == ' ' || del == '\t')
156 for (i=0; (c=input()) != del && c != EOF;) {
159 return(1); /* disaster */
165 for (i=1; (c=input())!=' ' && c!= '\t' && c!='\n' && c!=EOF;) {
168 return(1); /* disaster */
173 ERROR "Unexpected end of input at %.20s", s FATAL;
177 void define(int type)
180 extern int ftune(char *, char *);
182 getstr(token, SSIZE); /* get name */
183 if (type != DEFINE) {
184 cstr(token, 1, SSIZE); /* skip the definition too */
188 if (cstr(token, 1, SSIZE))
189 ERROR "Unterminated definition at %.20s", token FATAL;
190 if (lookup(ftunetbl, p1) != NULL) { /* double tuning param */
191 dprintf(".\ttune %s %s\n", p1, token);
195 install(deftbl, p1, p2, 0);
196 dprintf(".\tname %s defined as %s\n", p1, p2);
200 void ifdef(void) /* do body if name is defined */
204 getstr(name, sizeof(name)); /* get name */
205 cstr(token, 1, SSIZE); /* and body */
206 if (lookup(deftbl, name) != NULL) { /* found it */
213 char *spaceval = NULL;
215 void space(void) /* collect line of form "space amt" to replace \x in output */
217 getstr(token, SSIZE);
218 spaceval = strsave(token);
219 dprintf(".\tsetting spaceval to %s\n", token);
222 char *strsave(char *s)
226 q = malloc(strlen(s)+1);
228 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';