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;
149 cstr(char *s, int quote, int maxs)
154 while ((del=input()) == ' ' || del == '\t')
157 for (i=0; (c=input()) != del && c != EOF;) {
160 return(1); /* disaster */
166 for (i=1; (c=input())!=' ' && c!= '\t' && c!='\n' && c!=EOF;) {
169 return(1); /* disaster */
174 ERROR "Unexpected end of input at %.20s", s FATAL;
178 void define(int type)
181 extern int ftune(char *, char *);
183 getstr(token, SSIZE); /* get name */
184 if (type != DEFINE) {
185 cstr(token, 1, SSIZE); /* skip the definition too */
189 if (cstr(token, 1, SSIZE))
190 ERROR "Unterminated definition at %.20s", token FATAL;
191 if (lookup(ftunetbl, p1) != NULL) { /* double tuning param */
192 dprintf(".\ttune %s %s\n", p1, token);
196 install(deftbl, p1, p2, 0);
197 dprintf(".\tname %s defined as %s\n", p1, p2);
201 void ifdef(void) /* do body if name is defined */
205 getstr(name, sizeof(name)); /* get name */
206 cstr(token, 1, SSIZE); /* and body */
207 if (lookup(deftbl, name) != NULL) { /* found it */
214 char *spaceval = NULL;
216 void space(void) /* collect line of form "space amt" to replace \x in output */
218 getstr(token, SSIZE);
219 spaceval = strsave(token);
220 dprintf(".\tsetting spaceval to %s\n", token);
223 char *strsave(char *s)
227 q = malloc(strlen(s)+1);
229 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';