chiark / gitweb /
01b770e0bab9d15fa51a76642a7f5806ab9a1fe4
[userv.git] / parser.c
1 /*
2  * userv - parser.c
3  * configuration file parser; this file is actually #included from
4  * lexer.c, which is generated using flex from lexer.l, in turn from
5  * lexer.l.m4.  It's in a separate file so that we don't have to worry
6  * about m4 quoting &c., but we have to #include it so that the C
7  * objects from the lexer are available.
8  *
9  * Copyright (C)1996-1999 Ian Jackson
10  *
11  * This is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with userv; if not, write to the Free Software
23  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 static int parse_file(const char *string, int *didexist);
27 static int parser(int allowce);
28 int parse_string(const char *string, const char *descrip, int isinternal);
29
30 /*
31  * Error-handling routines
32  */
33
34 static void closeerrorfile(void) {
35   if (eh.file && !eh.filekeep) {
36     if (fclose(eh.file)) {
37       eh.handling= tokv_word_errorstostderr;
38       parseerrprint("error writing to error log file `%s': %s",
39                     eh.filename,strerror(errno));
40     }
41     free(eh.filename);
42   }
43   eh.handling= 0;
44   eh.file= 0; eh.filename= 0; eh.filekeep= 0;
45 }
46
47 static void senderrmsg(const char *errmsg, int useehandling) {
48   char suberrmsg[MAX_ERRMSG_LEN];
49   int e;
50   time_t now;
51   struct tm *lt;
52
53   switch (useehandling) {
54   case tokv_word_errorstostderr:
55     senderrmsgstderr(errmsg);
56     break;
57   case tokv_word_errorstosyslog:
58     ensurelogopen(eh.logfacility);
59     syslog(eh.loglevel,"%s",errmsg);
60     break;
61   case tokv_word_errorstofile:
62     if (time(&now)==-1) syscallerror("get current time");
63     lt= localtime(&now); if (!lt) syscallerror("convert current time");
64     if (fprintf(eh.file,"%d-%02d-%02d %02d:%02d:%02d: uservd: %s\n",
65                 lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday,
66                 lt->tm_hour, lt->tm_min, lt->tm_sec,
67                 errmsg) == EOF) {
68       e= errno;
69       closeerrorfile(); eh.handling= tokv_word_errorstofile;
70       snyprintf(suberrmsg,sizeof(suberrmsg),
71                 "error writing to error log file `%.*s': %s;"
72                 " reverting to errors-to-stderr",
73                 (int)(sizeof(suberrmsg)>>1),eh.filename,strerror(e));
74       senderrmsg(suberrmsg,eh.handling);
75       senderrmsg(errmsg,eh.handling);
76     }
77     break;
78   default:
79     abort();
80   }
81 }
82
83 static void errwhere(struct parser_state *tstate, char *bufput, int bufputlen) {
84   static const char suffix[]= "references ...";
85   char errmsg[MAX_ERRMSG_LEN];
86   
87   if (!tstate) {
88     strnycpy(bufput,"<initialisation>: ",bufputlen);
89     return;
90   }
91   if (!tstate->notedreferer && tstate->upstate && !tstate->upstate->isinternal) {
92     errwhere(tstate->upstate,errmsg,sizeof(errmsg)-sizeof(suffix));
93     strcat(errmsg,suffix);
94     senderrmsg(errmsg,eh.handling);
95     tstate->notedreferer= 1;
96   }
97   snyprintf(bufput,bufputlen,"%.*s:%d: ",bufputlen-10,
98             tstate->filename,tstate->reportlineno);
99 }
100
101 void parseerrprint(const char *fmt, ...) {
102   va_list al;
103   char errmsg[MAX_ERRMSG_LEN];
104
105   va_start(al,fmt);
106   errwhere(cstate,errmsg,sizeof(errmsg)>>1);
107   vsnytprintfcat(errmsg,sizeof(errmsg),fmt,al);
108   senderrmsg(errmsg,eh.handling);
109   va_end(al);
110 }
111
112 static int unexpected(int found, int wanted, const char *wantedstr) {
113   /* pass wanted==-1 if you know it's not what you wanted;
114    * otherwise this function will check it for you.
115    */
116   if (found == wanted) return 0;
117   if (found == tokv_error) return found;
118   parseerrprint("found %s, expected %s",printtoken(found),wantedstr);
119   return tokv_error;
120 }
121
122 static int stringoverflow(const char *where) {
123   parseerrprint("string buffer became far too large building %s",where);
124   return tokv_error;
125 }
126
127 /*
128  * General assistance functions
129  */
130
131 static void freecharparray(char **array) {
132   char **pp;
133
134   if (!array) return;
135   for (pp=array; *pp; pp++) free(*pp);
136   free(array);
137 }
138
139 static int dequote(char *inplace) {
140   char *p, *q, buf[4], *bep;
141   int v;
142
143   p=q=inplace;
144   assert(*p++ = '"');
145   while (*p && *p != '"') {
146     if (*p != '\\') { *q++= *p++; continue; }
147     switch (*++p) {
148     case 'n': *q++= '\n'; continue;
149     case 'r': *q++= '\r'; continue;
150     case 't': *q++= '\t'; continue;
151     case 'x':
152       p++;
153       if (!((buf[0]= *p++) && (buf[1]= *p++))) {
154         parseerrprint("quoted string ends inside \\x<hex> sequence");
155         return tokv_error;
156       }
157       buf[2]= 0;
158       v= strtoul(buf,&bep,16);
159       if (bep != buf+2) {
160         parseerrprint("invalid \\<hex> sequence \\x%s in quoted string",buf);
161         return tokv_error;
162       }
163       assert(!(v & ~0xff));
164       *q++= v;
165       continue;
166     default:
167       if (isalpha(*p)) {
168         parseerrprint("unknown \\<letter> sequence \\%c in quoted string",*p);
169         return tokv_error;
170       } else if (isdigit(*p)) {
171         if (!((buf[0]= *p++) && (buf[1]= *p++) && (buf[2]= *p++))) abort();
172         buf[3]= 0; v= strtoul(buf,&bep,8);
173         if (bep != buf+3 || (v & ~0xff)) {
174           parseerrprint("invalid \\<octal> sequence \\%s in quoted string",buf);
175           return tokv_error;
176         }
177         *q++= v; continue;
178       } else if (ispunct(*p)) {
179         *q++= *p++; continue;
180       } else {
181         while (*p==' ' || *p=='\t') p++;
182         v= *p++; assert(v=='\n');
183       }
184     }
185   }
186   assert(*p); assert(!*++p);
187   *q++= 0;
188   return tokv_quotedstring;
189 }
190
191 const char *printtoken(int token) {
192   /* Returns pointer to static buffer, overwritten by next call. */
193   static const char keywordfmt[]= "keyword `%s'";
194   static const char operatorfmt[]= "operator `%s'";
195   
196   static char buf[250];
197   
198   char *q;
199   const char *p;
200   int i, c, l;
201   
202   if ((token & tokm_repres) == tokr_word) {
203     assert(strlen(yytext)+sizeof(keywordfmt)<sizeof(buf));
204     snyprintf(buf,sizeof(buf),keywordfmt,yytext);
205     return buf;
206   } else if (token & tokt_number) {
207     snyprintf(buf,sizeof(buf),"number %d",lr_min); return buf;
208   } else if (token & tokt_fdrange && lr_max==-1) {
209     snyprintf(buf,sizeof(buf),"fdrange %d-",lr_min); return buf;
210   } else if (token & tokt_fdrange) {
211     snyprintf(buf,sizeof(buf),"fdrange %d-%d",lr_min,lr_max); return buf;
212   } else if ((token & tokm_repres) == tokr_punct) {
213     assert(strlen(yytext)+sizeof(operatorfmt)<sizeof(buf));
214     snyprintf(buf,sizeof(buf),operatorfmt,yytext);
215     return buf;
216   } else if (token & tokt_string) {
217     switch (token) {
218     case tokv_barestring: strcpy(buf,"unquoted string (bare word)"); break;
219     case tokv_quotedstring: strcpy(buf,"quoted string"); break;
220     default: abort();
221     }
222     strcat(buf," `");
223     l= strlen(buf); i= sizeof(buf)-l-2; p= yytext; q= buf+l;
224     while ((c= *p++)) {
225       if (i-- <= 0) { q--; strcpy(q-3,"..."); break; }
226       if (isspace(c)) c= ' ';
227       else if (!isprint(c) || iscntrl(c)) c= '?';
228       else *q++= c;
229     }
230     strcpy(q,"'");
231     return buf;
232   } else {
233     switch (token) {
234     case tokv_lwsp:    return "linear whitespace";
235     case tokv_newline: return "newline (or comment followed by newline)";
236     case tokv_eof:     return "end of input file";
237     case tokv_error:   return "syntax error token";
238     default:
239       sprintf(buf,"token#0%o",token); return buf;
240     }
241   }
242 }
243
244 static const char *string2path(const char *in) {
245   /* Returned pointers become invalid on next call.
246    * May return 0, having printed an error message.
247    */
248   static char *p;
249   static int pl;
250   
251   if (strncmp(in,"~/",2)) return in;
252   if (makeroom(&p,&pl,strlen(serviceuser_dir)+1+strlen(in+2)+1)) {
253     stringoverflow("pathname");
254     return 0;
255   }
256   snyprintf(p,pl,"%s/%s",serviceuser_dir,in+2);
257   return p;
258 }
259
260 /*
261  * Parser component functions for parsing parameters to directives
262  *
263  * Functions pa_... parse just one parameter,
264  *  and return tokv_error or 0, having scanned exactly what they were expecting
265  * Functions paa_... parse complete parameter lists, including the leading lwsp,
266  *  and return tokv_error or 0, having scanned up to and including the newline
267  *
268  * For any function which takes `const char **rv' the
269  * value returned in *rv is overwritten by repeated calls to
270  * any of those functions (whether the same or another).
271  */
272
273 static int pa_mnl(void) {
274   return unexpected(yylex(),tokv_newline,"newline");
275 }
276 static int pa_mwsp(void) {
277   return unexpected(yylex(),tokv_lwsp,"linear whitespace");
278 }
279
280 static int pa_string(const char **rv) {
281   static char *p= 0;
282   static int pl= 0;
283
284   int r, l;
285
286   r= pa_mwsp(); if (r) return r;
287   r= yylex(); if (r == tokv_error) return r;
288   if ((r & tokm_repres) == tokr_nonstring) return unexpected(r,-1,"string");
289   l= strlen(yytext)+1;
290   if (makeroom(&p,&pl,l)) return stringoverflow("string argument");
291   strcpy(p,yytext); *rv= p;
292
293   return 0;
294 }  
295
296 static int pa_numberdollar(int *value_r) {
297   /* Also parses the whitespace beforehand. */
298   int r;
299
300   r= pa_mwsp(); if (r) return r;
301   r= yylex(); if (r == tokv_error || r == tokv_dollar) return r;
302   if (unexpected(r,tokv_ordinal,"expected number or dollar")) return tokv_error;
303   *value_r= lr_min;
304   return r;
305 }
306
307 static int paa_1string(const char **rv) {
308   int r;
309
310   r= pa_string(rv); if (r) return r;
311   return pa_mnl();
312 }  
313
314 static int paa_1path(const char **rv) {
315   const char *cp;
316   int r;
317   
318   r= paa_1string(&cp); if (r) return r;
319   *rv= string2path(cp); if (!*rv) return tokv_error;
320   return 0;
321 }
322
323 static int paa_pathargs(const char **path_r, char ***newargs_r) {
324   /* Repeated calls do _not_ overwrite newargs_r; caller must free.
325    * Repeated calls _do_ overwrite string returned in path_r.
326    * Any call to this function invalidates previous returns in *rv.
327    */
328   char **newargs;
329   const char *string;
330   int used, size, r;
331
332   r= pa_string(&string); if (r == tokv_error) return r;
333   *path_r= string2path(string); if (!*path_r) return tokv_error;
334   
335   used=0; size=0;
336   newargs= xmalloc(sizeof(char*)*(size+1));
337
338   for (;;) {
339     r= yylex(); if (r == tokv_error) goto error;
340     if (r==tokv_newline) break;
341     if (unexpected(r,tokv_lwsp,"newline after or whitespace between arguments")) {
342       r= tokv_error; goto error;
343     }
344     r= yylex(); if (r==tokv_error) goto error;
345     if ((r & tokm_repres) == tokr_nonstring) {
346       r= unexpected(r,-1,"string for command argument");
347       goto error;
348     }
349     if (used>=size) {
350       if (used >= MAX_ARGSDEFVAR) {
351         parseerrprint("far too many arguments to service program");
352         r= tokv_error; goto error;
353       }
354       size= (used+5)<<1;
355       newargs= xrealloc(newargs,sizeof(char*)*(size+1));
356     }
357     newargs[used++]= xstrsave(yytext);
358   }
359   newargs[used]= 0;
360   *newargs_r= newargs;
361   return 0;
362   
363 error:
364   newargs[used]=0;
365   freecharparray(newargs);
366   return r;
367 }
368
369 static int paa_message(const char **message_r) {
370   /* Returned value is invalidated by repeated calls. */
371   static char *buildbuf;
372   static int buildbuflen;
373
374   int r, tl;
375
376   r= pa_mwsp(); if (r) return r;
377   tl= 1;
378   if (makeroom(&buildbuf,&buildbuflen,50)) return stringoverflow("start of message");
379   buildbuf[0]= 0;
380   for (;;) {
381     r= yylex(); if (r == tokv_error) return r;
382     if (r == tokv_eof) {
383       parseerrprint("unexpected end of file in message text");
384       return tokv_error;
385     }
386     if (r == tokv_newline) break;
387     tl+= strlen(yytext);
388     if (makeroom(&buildbuf,&buildbuflen,tl)) return stringoverflow("message");
389     strcat(buildbuf,yytext);
390   }
391   *message_r= buildbuf;
392   return 0;
393 }
394
395 /*
396  * Skipping routines (used by e.g. the `if' code).
397  */
398
399 static int skiptoeol(void) {
400   /* Returns 0 if OK, having just parsed the newline
401    * or tokv_error if an error occurs, leaving the position at the error
402    * (which may be EOF or a syntax error token).
403    */
404   int token;
405
406   do { token= yylex(); }
407   while (token != tokv_newline && !(token & tokt_exception));
408   if (token == tokv_newline) return 0;
409   if (token == tokv_error) return token;
410   assert(token == tokv_eof);
411   parseerrprint("unexpected end of file while looking for end of line");
412   return tokv_error;
413 }
414
415 static int skip(int allowce) {
416   /* Scans a piece of config without executing it.  Returns
417    * tokv_error (leaving the parsing state at the error),
418    * or the tokt_controlend token with type allowce if one
419    * was found (in which case rest of line, including any whitespace
420    * after tokt_controlend, has not been parsed), or tokv_eof.
421    */
422   int token, r;
423
424   for (;;) { /* loop over lines */
425     cstate->reportlineno= cstate->lineno;
426     do { token= yylex(); } while (token == tokv_lwsp);
427     if (token & tokt_exception) {
428       return token;
429     } else if (token & tokt_controlend) {
430       if (allowce == lr_controlend) return token;
431       else return unexpected(token,-1,"control structure end of a different kind");
432     } else if (token & tokt_controlstart) {
433       r= token;
434       while (r & tokt_controlstart) {
435         r= skiptoeol(); if (r) return r;
436         cstate->reportlineno= cstate->lineno;
437         r= skip(token); if (r & tokt_exception) return r;
438       }
439     } else if (!(token & tokt_directive) && !(token & tokt_condop)) {
440       parseerrprint("not a directive (or conditional operator) "
441                     "while looking for control structure end");
442       return tokv_error;
443     }
444     r= skiptoeol(); if (r) return r;
445   }
446 }
447
448 /*
449  * Routines for parsing and getting the values of parameters
450  */
451
452 static void parm_1string(char ***rvalues, const char *tocopy) {
453   char **a;
454   a= xmalloc(sizeof(char*)*2);
455   a[0]= xstrsave(tocopy);
456   a[1]= 0;
457   *rvalues= a;
458 }
459
460 static char *parm_ulong(unsigned long ul) {
461   char *p;
462   int l;
463
464   l= CHAR_BIT*sizeof(unsigned long)/3+4;
465   p= xmalloc(l);
466   snyprintf(p,l,"%lu",ul);
467   return p;
468 }
469
470 static int parm_usernameuid(char ***rvalues, const char *name, uid_t id) {
471   char **a;
472   
473   a= xmalloc(sizeof(char*)*3);
474   a[0]= xstrsave(name);
475   a[1]= parm_ulong(id);
476   a[2]= 0;
477   *rvalues= a;
478   return 0;
479 }
480
481 static int parm_groups(char ***rvalues, int size,
482                        gid_t *gids, const char *const *groups) {
483   char **a;
484   int i;
485   
486   if (size >= 2 && gids[0] == gids[1]) { size--; gids++; groups++; }
487   a= xmalloc(sizeof(char*)*(size+1)*2);
488   for (i=0; i<size; i++) {
489     a[i]= xstrsave(groups[i]);
490     a[size+i]= parm_ulong(gids[i]);
491   }
492   a[size*2]= 0;
493   *rvalues= a;
494   return 0;
495 }  
496
497 static int pf_service(int ptoken, char ***rvalues) {
498   parm_1string(rvalues,service); return 0;
499 }
500
501 static int pf_callinguser(int ptoken, char ***rvalues) {
502   return parm_usernameuid(rvalues,loginname,request_mbuf.callinguid);
503 }
504
505 static int pf_serviceuser(int ptoken, char ***rvalues) {
506   return parm_usernameuid(rvalues,serviceuser,serviceuser_uid);
507 }
508
509 static int pf_callinggroup(int ptoken, char ***rvalues) {
510   return parm_groups(rvalues,request_mbuf.ngids,calling_gids,calling_groups);
511 }
512
513 static int pf_servicegroup(int ptoken, char ***rvalues) {
514   return parm_groups(rvalues,service_ngids,service_gids,service_groups);
515 }
516
517 static int pf_callingusershell(int ptoken, char ***rvalues) {
518   parm_1string(rvalues,callinguser_shell); return 0;
519 }
520
521 static int pf_serviceusershell(int ptoken, char ***rvalues) {
522   parm_1string(rvalues,serviceuser_shell); return 0;
523 }
524
525 static int pa_parameter(char ***rvalues, char **rname) {
526   /* Scans a single parameter token and calls the appropriate parameter
527    * function, returning tokv_error (leaving the parser state wherever),
528    * or 0 on success (having just parsed the parameter name).
529    * If rname is non-null then the name of the parameter (malloc'd) will
530    * be stored in it.
531    *
532    * Caller must free *rvalues using freecharparray.
533    */
534   int token, r, i;
535   char *name;
536
537   token= yylex(); if (token == tokv_error) return token;
538   name= xstrsave(yytext);
539   if ((token & tokm_repres) != tokr_nonstring &&
540       !memcmp(yytext,"u-",2) && strlen(yytext)>=3) {
541     for (i=0;
542          i<request_mbuf.nvars && strcmp(yytext+2,defvararray[i].key);
543          i++);
544     if (i>=request_mbuf.nvars) {
545       *rvalues= xmalloc(sizeof(char*));
546       **rvalues= 0;
547     } else {
548       parm_1string(rvalues,defvararray[i].value);
549     }
550   } else if (token & tokt_parameter) {
551     r= (lr_parameter)(token,rvalues);
552     if (r) { free(name); return r; }
553   } else {
554     free(name);
555     return unexpected(token,-1,"parameter name");
556   }
557   debug_dumpparameter(name,*rvalues);
558   if (rname) *rname= name;
559   else free(name);
560   return 0;
561 }
562
563 /*
564  * Routines for parsing conditions, including
565  * parameter-based conditional functions (parmcondition's).
566  */
567
568 int pcf_glob(int ctoken, char *const *pv, int *rtrue) {
569   int token, actrue, r;
570   char *const *pp;
571
572   actrue= 0;
573   r= pa_mwsp(); if (r) return r;
574   for (;;) {
575     token= yylex();
576     if ((token & tokm_repres) == tokr_nonstring)
577       return unexpected(token,-1,"glob pattern");
578     for (pp= pv; !actrue && *pp; pp++) if (!fnmatch(yytext,*pp,0)) actrue= 1;
579     token= yylex(); 
580     if (token == tokv_newline) break;
581     if (unexpected(token,tokv_lwsp,"newline after or whitespace between glob patterns"))
582       return tokv_error;
583   }
584   *rtrue= actrue;
585   return 0;
586 }
587
588 int pcf_range(int ctoken, char *const *pv, int *rtrue) {
589   int mintoken, min, maxtoken, max, r;
590   char *const *pp;
591   char *ep;
592   unsigned long v;
593
594   r= pa_mwsp(); if (r) return r;
595   mintoken= pa_numberdollar(&min); if (mintoken == tokv_error) return mintoken;
596   r= pa_mwsp(); if (r) return r;
597   maxtoken= pa_numberdollar(&max); if (maxtoken == tokv_error) return maxtoken;
598   r= pa_mnl(); if (r) return r;
599   for (pp= pv; *pp; pp++) {
600     v= strtoul(*pp,&ep,10); if (*ep) continue;
601     if (mintoken != tokv_dollar && v < min) continue;
602     if (maxtoken != tokv_dollar && v > max) continue;
603     *rtrue= 1; return 0;
604   }
605   *rtrue= 0; return 0;
606 }
607
608 int pcf_grep(int ctoken, char *const *pv, int *rtrue) {
609   FILE *file;
610   const char *cp;
611   char *const *pp;
612   char *buf, *p;
613   int r, maxlen, l, c, actrue, posstrue;
614   
615   r= paa_1path(&cp); if (r) return r;
616   file= fopen(cp,"r");
617   if (!file) {
618     parseerrprint("unable to open file `%s' for grep: %s",cp,strerror(errno));
619     return tokv_error;
620   }
621   maxlen= 0;
622   for (pp= pv; *pp; pp++) { l= strlen(*pp); if (l > maxlen) maxlen= l; }
623   buf= xmalloc(maxlen+2); actrue= 0; c= 0;
624   while (!actrue && c!=EOF) {
625     c= getc(file); if (c==EOF) break;
626     if (isspace(c)) continue;
627     l= maxlen+1; p= buf;
628     while (l>0 && c!='\n' && c!=EOF) { *p++= c; l--; c= getc(file); } 
629     if (c=='\n' || c==EOF || isspace(c)) {
630       while (p>buf && isspace(p[-1])) --p;
631       *p= 0; posstrue= 0;
632       for (pp= pv; !posstrue && *pp; pp++)
633         if (!strcmp(*pp,buf)) posstrue= 1;
634     } else {
635       posstrue= 0;
636     }
637     if (c!='\n' && c!=EOF) {
638       for (;;) {
639         c= getc(file);
640         if (c==EOF || c=='\n') break;
641         if (!isspace(c)) posstrue= 0;
642       }
643     }
644     if (posstrue) actrue= 1;
645   }
646   if (ferror(file)) {
647     parseerrprint("error while reading `%s' for grep: %s",cp,strerror(errno));
648     fclose(file); free(buf); return tokv_error;
649   }
650   assert(actrue || feof(file));
651   fclose(file); free(buf); *rtrue= actrue;
652   return 0;
653
654
655 static int pa_condition(int *rtrue) {
656   /* Scans up to and including the newline following the condition;
657    * may scan more than one line if the condition is a multi-line
658    * one.  Returns 0 (setting *rtrue, and parsing up to and including
659    * the last newline) or tokv_error.
660    * Expects to scan the whitespace before its condition.
661    */
662   int r, token, andor, ctrue, actrue;
663   char **parmvalues;
664
665   r= pa_mwsp(); if (r) return r;
666   token= yylex();
667   if (token == tokv_error) {
668     return token;
669   } else if (token == tokv_not) {
670     r= pa_condition(&ctrue); if (r) return r;
671     *rtrue= !ctrue; return 0;
672   } else if (token == tokv_openparen) {
673     andor= 0; actrue= -1;
674     for (;;) {
675       cstate->reportlineno= cstate->lineno;
676       r= pa_condition(&ctrue); if (r) return r;
677       switch (andor) {
678       case 0:         assert(actrue==-1); actrue= ctrue;           break;
679       case tokv_and:  assert(actrue>=0); actrue= actrue && ctrue;  break;
680       case tokv_or:   assert(actrue>=0); actrue= actrue || ctrue;  break;
681       default:        abort();
682       }
683       do { token= yylex(); } while (token == tokv_lwsp);
684       if (token == tokv_error) return token;
685       if (token == tokv_closeparen) break;
686       if (andor) {
687         r= unexpected(token,andor,"same conjunction as before"); if (r) return r;
688       } else {
689         if (token != tokv_and && token != tokv_or)
690           return unexpected(token,-1,"first conjunction inside connective");
691         andor= token;
692       }
693     }
694     r= pa_mnl(); if (r) return r;
695     *rtrue= actrue; return 0;
696   } else if (token & tokt_parmcondition) {
697     r= pa_mwsp(); if (r) return r;
698     r= pa_parameter(&parmvalues,0); if (r) return r;
699     r= (lr_parmcond)(token,parmvalues,rtrue); freecharparray(parmvalues);
700     return r;
701   } else {
702     return unexpected(token,-1,"condition");
703   }
704 }
705
706 /*
707  * Directive functions and associated `common code' functions
708  */
709
710 /* Directives specifying the service program (execute-... and reset) */
711
712 static void execreset(void) {
713   execute= 0;
714   execbuiltin= 0;
715   free(execpath); execpath= 0;
716   freecharparray(execargs); execargs= 0;
717 }
718
719 int df_reject(int dtoken) {
720   int r;
721   
722   r= pa_mnl(); if (r) return r;
723   execreset();
724   execute= tokv_word_reject;
725   return 0;
726 }
727
728 int df_executefrompath(int dtoken) {
729   int r;
730   
731   r= pa_mnl(); if (r) return r;
732   execreset();
733   execute= tokv_word_executefrompath;
734   return 0;
735 }
736
737 int df_execute(int dtoken) {
738   const char *rv;
739   char **newargs;
740   int r;
741
742   r= paa_pathargs(&rv,&newargs); if (r) return r;
743   execreset();
744   execute= tokv_word_execute;
745   execargs= newargs;
746   execpath= xstrsave(rv);
747   return 0;
748 }
749
750 int df_executefromdirectory(int dtoken) {
751   const char *p, *q, *rv;
752   struct stat stab;
753   char *fn, **newargs;
754   int l, r;
755
756   r= paa_pathargs(&rv,&newargs); if (r) return r;
757   p= strrchr(service,'/'); if (p) p++; else p= service;
758   if (!*p || !isalnum(*p)) {
759     parseerrprint("execute-from-directory requires initial char of service "
760                   "portion to be alphanumeric (service portion was `%s')",
761                   p);
762     freecharparray(newargs);
763     return tokv_error;
764   }
765   for (q=p+1; *q; q++) {
766     if (!isalnum(*q) && *q != '-') {
767       parseerrprint("execute-from-directory requires service portion to "
768                     "contain only alphanumerics and hyphens (was `%s')",
769                     p);
770       freecharparray(newargs);
771       return tokv_error;
772     }
773   }
774   l= strlen(rv)+1+strlen(p)+1;
775   fn= xmalloc(l);
776   snyprintf(fn,l,"%s/%s",rv,p);
777   if (stat(fn,&stab)) {
778     if (errno == ENOENT) { free(fn); freecharparray(newargs); return 0; }
779     parseerrprint("failed to stat `%s' for execute-from-directory: %s",
780                   fn,strerror(errno));
781     free(fn); freecharparray(newargs); return tokv_error;
782   }
783   if (!S_ISREG(stab.st_mode)) {
784     parseerrprint("file `%s' in execute-from-directory is not an ordinary file"
785                   " or link to one (mode=0%lo)",fn,(unsigned long)stab.st_mode);
786     free(fn); freecharparray(newargs); return tokv_error;
787   }
788   execreset();
789   execute= tokv_word_executefromdirectory;
790   execargs= newargs;
791   execpath= fn;
792   return 0;
793 }
794
795 /* Parsing builtin service requests (execute-builtin) */
796
797 static int bispa_none(char ***rnewargs) {
798   return pa_mnl();
799 }
800
801 static int bispa_parameter(char ***rnewargs) {
802   int r, i;
803   char **parmvalues, *name, **newargs;
804   
805   r= pa_mwsp(); if (r) return r;
806   r= pa_parameter(&parmvalues,&name); if (r) return r;
807   for (i=0; parmvalues[i]; i++);
808   newargs= xmalloc(sizeof(char*)*(i+2));
809   newargs[0]= name;
810   memcpy(newargs+1,parmvalues,sizeof(char*)*(i+1));
811   free(parmvalues);
812   r= pa_mnl(); if (r) { free(newargs); return r; }
813   *rnewargs= newargs;
814   return 0;
815 }
816
817 int df_executebuiltin(int dtoken) {
818   int r;
819   builtinserviceexec_fnt *bisexec;
820   char *newpath, **newargs;
821
822   r= pa_mwsp(); if (r) return r;
823   r= yylex(); if (r == tokv_error) return r;
824   if (!(r & tokt_builtinservice)) return unexpected(r,-1,"builtin service name");
825   bisexec= lr_bisexec;
826   newpath= xstrsave(yytext);
827   newargs= 0;
828   r= lr_bispa(&newargs); if (r) { free(newpath); return r; }
829
830   execreset();
831   execute= tokv_word_executebuiltin;
832   execbuiltin= bisexec;
833   execpath= newpath;
834   execargs= newargs;
835   return 0;
836 }
837
838 /* Directives for changing other execution parameters */
839
840 int dfg_setflag(int dtoken) {
841   int r;
842
843   r= pa_mnl(); if (r) return r;
844   *lr_flag= lr_flagval;
845   return 0;
846 }
847
848 int df_reset(int dtoken) {
849   int r;
850
851   r= pa_mnl(); if (r) return r;
852   r= parse_string(RESET_CONFIGURATION,"<builtin reset configuration>",1);
853   return r;
854 }
855
856 int dfg_fdwant(int dtoken) {
857   int fdmin, fdmax, r, needreadwrite, havereadwrite, fd;
858
859   needreadwrite= lr_fdwant_readwrite;
860   r= pa_mwsp(); if (r) return r;
861   r= yylex(); if (r == tokv_error) return r;
862   if (!(r & tokt_fdrange)) return unexpected(r,-1,"file descriptor range");
863   fdmin= lr_min; fdmax= lr_max;
864   if (fdmin<0 || fdmin>MAX_ALLOW_FD ||
865       (fdmax != -1 && fdmax<0) || fdmax>MAX_ALLOW_FD) {
866     parseerrprint("file descriptor in range is negative or far too large");
867     return tokv_error;
868   }
869   r= yylex(); if (r == tokv_error) return r;
870   if (r == tokv_newline) {
871     if (needreadwrite > 0) {
872       parseerrprint("read or write is required");
873       return tokv_error;
874     }
875     havereadwrite= 0;
876   } else if (r == tokv_lwsp) {
877     if (needreadwrite < 0) {
878       parseerrprint("read or write not allowed"); return tokv_error;
879     }
880     r= yylex(); if (r == tokv_error) return r;
881     if (!(r & tokt_readwrite))
882       return unexpected(r,-1,"read or write (or perhaps newline)");
883     havereadwrite= r;
884     r= pa_mnl(); if (r) return r;
885   } else {
886     return unexpected(r,-1,"whitespace before read or write or newline");
887   }
888   ensurefdarray(fdmin);
889   if (fdmax == -1) {
890     if (!(dtoken == tokv_word_rejectfd || dtoken == tokv_word_ignorefd))
891       parseerrprint("unspecified maximum only allowed with reject-fd and ignore-fd");
892     fdmax= fdarrayused-1;
893     restfdwantstate= dtoken;
894     restfdwantrw= havereadwrite;
895   }
896   ensurefdarray(fdmax);
897   for (fd=fdmin; fd<=fdmax; fd++) {
898     fdarray[fd].wantstate= dtoken;
899     fdarray[fd].wantrw= havereadwrite;
900   }
901   return 0;
902 }
903
904 /* Directives for changing error handling */
905
906 int df_errorstostderr(int dtoken) {
907   int r;
908   
909   r= pa_mnl(); if (r) return r;
910   closeerrorfile(); eh.handling= dtoken;
911   return 0;
912 }
913
914 int df_errorstosyslog(int dtoken) {
915   int token, level, facility;
916
917   facility= DEFUSERLOGFACILITY;
918   level= DEFUSERLOGLEVEL;
919   token= yylex();
920   if (token == tokv_lwsp) {
921     token= yylex(); if (token == tokv_error) return token;
922     if (!(token & tokt_logfacility))
923       return unexpected(token,-1,"syslog facility (or end of line)");
924     facility= lr_logfacility;
925     token= yylex();
926   }    
927   if (token == tokv_lwsp) {
928     token= yylex(); if (token == tokv_error) return token;
929     if (!(token & tokt_loglevel))
930       return unexpected(token,-1,"syslog level (or end of line) after facility");
931     level= lr_loglevel;
932     token= yylex();
933   }
934   if (unexpected(token,tokv_newline,"end of line after errors-to-syslog"))
935     return tokv_error;
936   closeerrorfile(); eh.handling= tokv_word_errorstosyslog;
937   eh.logfacility= facility; eh.loglevel= level;
938   return 0;
939 }
940
941 int df_errorstofile(int dtoken) {
942   const char *cp;
943   FILE *file;
944   int r;
945   
946   r= paa_1path(&cp); if (r) return r;
947   file= fopen(cp,"a");
948   if (!file) {
949     parseerrprint("unable to open error log file `%s': %s",cp,strerror(errno));
950     return tokv_error;
951   }
952   if (setvbuf(file,0,_IOLBF,MAX_ERRMSG_LEN)) {
953     parseerrprint("unable to set line buffering on errors file: %s",strerror(errno));
954     fclose(file); return tokv_error;
955   }
956   closeerrorfile(); eh.handling= tokv_word_errorstofile;
957   eh.file= file; eh.filename= xstrsave(cp);
958   return 0;
959 }
960
961 /* Directives for including other files or configuration data */
962
963 int dfi_includeuserrcfile(int dtoken) {
964   int r;
965
966   r= pa_mnl(); if (r) return r;
967   assert(userrcfile);
968   return parse_file(userrcfile,0);
969 }
970
971 int dfi_includeclientconfig(int dtoken) {
972   int r;
973
974   r= pa_mnl(); if (r) return r;
975   assert(overridedata);
976   return parse_string(overridedata,"<configuration override data>",0);
977 }
978
979 int df_include(int dtoken) {
980   const char *cp;
981   int r, found;
982
983   r= paa_1path(&cp); if (r) return r;
984   r= parse_file(cp,&found); if (r) return r;
985   if (found || dtoken == tokv_word_includeifexist) return 0;
986   parseerrprint(dtoken == tokv_word_includesysconfig ?
987                 "system configuration file `%s' does not exist" :
988                 "included file `%s' does not exist",
989                 cp);
990   return tokv_error;
991 }
992
993 int df_includedirectory(int dtoken) {
994   static char *buildbuf=0;
995   static int buildbuflen=0;
996   
997   int r, cpl, tel, c, found;
998   DIR *d;
999   struct dirent *de;
1000   const char *p, *cpget;
1001   char *cp;
1002   
1003   r= paa_1path(&cpget); if (r) return r;
1004   d= opendir(cpget);
1005   if (!d) {
1006     parseerrprint("unable to open directory `%s': %s",cpget,strerror(errno));
1007     return tokv_error;
1008   }
1009   cp= xstrsave(cpget);
1010   cpl= strlen(cp);
1011   while ((de= readdir(d))) {
1012     tel= strlen(de->d_name);
1013     if (!tel) continue;
1014     p= de->d_name;
1015     if (!*p || !isalnum(*p)) continue;
1016     while ((c= *++p)) if (!(isalnum(c) || c=='-')) break;
1017     if (c) continue;
1018     if (makeroom(&buildbuf,&buildbuflen,cpl+1+tel+1)) {
1019       stringoverflow("pathname in directory");
1020       r= tokv_error; goto x_err;
1021     }
1022     snyprintf(buildbuf,buildbuflen,"%s/%s",cp,de->d_name);
1023     r= parse_file(buildbuf,&found); if (r) goto x_err;
1024     if (!found) {
1025       parseerrprint("unable to open file `%s' in included directory `%s': %s",
1026                     de->d_name,cp,strerror(errno));
1027       r= tokv_error; goto x_err;
1028     }
1029   }
1030   if (closedir(d)) {
1031     parseerrprint("error closing directory `%s': %s",cp,strerror(errno));
1032     free(cp);
1033     return tokv_error;
1034   }
1035   free(cp);
1036   return 0;
1037
1038 x_err:
1039   closedir(d);
1040   free(cp);
1041   return r;
1042 }
1043
1044 int df_includelookup(int dtoken) {
1045   static char *buildbuf=0;
1046   int buildbuflen=0;
1047   
1048   char **parmvalues, **pp, *p, *q, *cp;
1049   const char *cpget;
1050   struct stat stab;
1051   int r, done, thisdone, cpl, c;
1052
1053   r= pa_mwsp(); if (r) return r;
1054   r= pa_parameter(&parmvalues,0); if (r) return r;
1055   r= paa_1path(&cpget); if (r) { freecharparray(parmvalues); return r; }
1056   if (stat(cpget,&stab)) {
1057     parseerrprint("unable to access directory `%s': %s",cpget,strerror(errno));
1058     freecharparray(parmvalues); return tokv_error;
1059   }
1060   if (!S_ISDIR(stab.st_mode)) {
1061     parseerrprint("object `%s' is not a directory or link to one",cpget);
1062     freecharparray(parmvalues); return tokv_error;
1063   }
1064   done= 0;
1065   cp= xstrsave(cpget);
1066   cpl= strlen(cp);
1067   if (!parmvalues[0]) {
1068     if (makeroom(&buildbuf,&buildbuflen,cpl+1+sizeof(NONEINCLUDELOOKUP))) {
1069       stringoverflow("pathname in directory for lookup of undefined parameter");
1070       r= tokv_error; goto x_err;
1071     }
1072     snyprintf(buildbuf,buildbuflen,"%s/" NONEINCLUDELOOKUP,cp);
1073     r= parse_file(buildbuf,&thisdone); if (r) goto x_err;
1074     if (thisdone) done= 1;
1075   } else {
1076     for (pp=parmvalues;
1077          *pp && (!done || dtoken == tokv_word_includelookupall);
1078          pp++) {
1079       if (makeroom(&buildbuf,&buildbuflen,
1080                    cpl+1+strlen(*pp)*2+3+sizeof(EMPTYINCLUDELOOKUP)+1)) {
1081         stringoverflow("pathname in directory for lookup");
1082         r= tokv_error; goto x_err;
1083       }
1084       strcpy(buildbuf,cp);
1085       p= *pp; q= buildbuf+cpl;
1086       *q++= '/';
1087       if (!*p) {
1088         strcpy(q,EMPTYINCLUDELOOKUP);
1089       } else {
1090         if (*p=='.') *q++= ':';
1091         while ((c= *p++)) {
1092           if (c=='/') {
1093             *q++= ':';
1094             c= '-';
1095           } else if (!((c >= '0' && c <= '9') ||
1096                        (c >= 'a' && c <= 'z') ||
1097                        c == '-' || c == '_')) {
1098             *q++= ':';
1099           }
1100           *q++= c;
1101         }
1102         *q++= 0;
1103       }
1104       r= parse_file(buildbuf,&thisdone);
1105       if (r) goto x_err;
1106       if (thisdone) done= 1;
1107     }
1108   }
1109   if (!done) {
1110     if (makeroom(&buildbuf,&buildbuflen,
1111                  cpl+1+sizeof(DEFAULTINCLUDELOOKUP))) {
1112       stringoverflow("pathname in directory for lookup of default");
1113       r= tokv_error; goto x_err;
1114     }
1115     snyprintf(buildbuf,buildbuflen,"%s/" DEFAULTINCLUDELOOKUP,cp);
1116     r= parse_file(buildbuf,0); if (r) goto x_err;
1117   }
1118   r= 0;
1119   
1120 x_err:
1121   freecharparray(parmvalues);
1122   free(cp);
1123   return r;
1124 }
1125
1126 /* Control constructs */
1127
1128 int df_catchquit(int dtoken) {
1129   int r;
1130
1131   r= pa_mnl(); if (r) return r;
1132   r= parser(tokv_word_catchquit);
1133   if (r == tokv_quit || r == tokv_error) {
1134     if (r == tokv_error) {
1135       r= parse_string(RESET_CONFIGURATION,
1136                       "<builtin reset configuration (caught error)>",1);
1137       assert(!r);
1138     }
1139     r= skip(tokv_word_catchquit);
1140   }
1141   if (r & tokt_controlend) {
1142     assert(r == tokv_word_hctac);
1143     r= pa_mnl();
1144   }
1145   return r;
1146 }
1147
1148 int df_if(int dtoken) {
1149   int r, true, done;
1150   
1151   done= 0;
1152   do {
1153     r= pa_condition(&true); if (r) return r;
1154     if (!done && true) { r= parser(tokv_word_if); done= 1; }
1155     else { r= skip(tokv_word_if); }
1156     if (!(r & tokt_controlend)) return r;
1157   } while (r == tokv_word_elif);
1158   if (r == tokv_word_else) {
1159     r= pa_mnl(); if (r) return r;
1160     cstate->reportlineno= cstate->lineno;
1161     if (done) r= skip(tokv_word_if);
1162     else r= parser(tokv_word_if);
1163     if (!(r & tokt_controlend)) return r;
1164   }
1165   if (unexpected(r,tokv_word_fi,"`fi' to end `if'")) return tokv_error;
1166   return pa_mnl();
1167 }
1168
1169 int df_errorspush(int dt) {
1170   struct error_handling save;
1171   int r;
1172
1173   r= pa_mnl(); if (r) return r;
1174
1175   save= eh;
1176   eh.filekeep= 1;
1177
1178   r= parser(tokv_word_errorspush);
1179
1180   closeerrorfile();
1181   eh= save;
1182
1183   if (r & tokt_controlend) {
1184     assert(r == tokv_word_srorre);
1185     r= pa_mnl();
1186   }
1187   return r;
1188 }
1189
1190 /* Miscelleanous directives */
1191
1192 int df_cd(int dtoken) {
1193   const char *cp;
1194   int r;
1195
1196   r= paa_1path(&cp); if (r) return r;
1197   if (!chdir(cp)) return 0;
1198   parseerrprint("unable to change directory to `%s': %s",cp,strerror(errno));
1199   return tokv_error;
1200 }
1201
1202 int df_userrcfile(int dtoken) {
1203   const char *cp;
1204   int r;
1205
1206   r= paa_1path(&cp); if (r) return r;
1207   free(userrcfile); userrcfile= xstrsave(cp);
1208   return 0;
1209 }
1210
1211 int df_message(int dtoken) {
1212   const char *mp;
1213   int r;
1214
1215   r= paa_message(&mp); if (r) return r;
1216   parseerrprint("`message' directive: %s",mp);
1217   return 0;
1218 }
1219
1220 int df_error(int dtoken) {
1221   const char *mp;
1222   int r;
1223
1224   r= paa_message(&mp); if (r) return r;
1225   parseerrprint("`error' directive: %s",mp);
1226   return tokv_error;
1227 }
1228
1229 int df_eof(int dtoken) {
1230   int r;
1231
1232   r= pa_mnl(); if (r) return r;
1233   return tokv_eof;
1234 }
1235
1236 int df_quit(int dtoken) {
1237   int r;
1238
1239   r= pa_mnl(); if (r) return r;
1240   return tokv_quit;
1241 }
1242
1243 /*
1244  * Main parser routines
1245  */
1246       
1247 static void parser_push(struct parser_state *usestate,
1248                         const char *newfile,
1249                         const struct stat *newfilestab,
1250                         YY_BUFFER_STATE ybuf,
1251                         int isinternal) {
1252   usestate->lineno= 1;
1253   usestate->reportlineno= 1;
1254   usestate->filename= newfile;
1255   usestate->filestab= *newfilestab;
1256   usestate->notedreferer= 0;
1257   usestate->isinternal= isinternal;
1258   usestate->ybuf= ybuf;
1259   usestate->upstate= cstate;
1260
1261   cstate= usestate;
1262   yy_switch_to_buffer(ybuf);
1263 }
1264
1265 static void parser_pop(void) {
1266   struct parser_state *oldstate;
1267
1268   oldstate= cstate;
1269   cstate= cstate->upstate;
1270   if (cstate) yy_switch_to_buffer(cstate->ybuf);
1271   yy_delete_buffer(oldstate->ybuf);
1272 }
1273
1274 int parse_string(const char *string, const char *descrip, int isinternal) {
1275   /* Returns the same things as parser, except that tokv_eof is turned
1276    * into 0.  *string must be statically allocated or copied, so that
1277    * it is not overwritten while the parsing takes place (unlike with
1278    * parse_file).
1279    */
1280   static const struct stat blankstab;
1281   
1282   struct parser_state usestate;
1283   YY_BUFFER_STATE ybuf;
1284   int r;
1285
1286   ybuf= yy_scan_string(string);
1287   if (!ybuf) syscallerror("unable to create flex buffer for internal string");
1288   parser_push(&usestate,descrip,&blankstab,ybuf,isinternal);
1289   
1290   r= parser(0);
1291
1292   parser_pop();
1293   if (r == tokv_eof) r= 0;
1294   return r;
1295 }
1296
1297 static int parse_file(const char *string, int *didexist) {
1298   /* Returns the same things as parser, except that tokv_eof is turned
1299    * into 0.  If *didexist is 0 then errno will have been set.
1300    * *string will be copied by parse_file so it may be be overwritten
1301    * during the parsing (so, for example, yytext need not be copied).
1302    */
1303   static int fileparselevel= 0;
1304   
1305   struct parser_state usestate, *checkrecurse;
1306   YY_BUFFER_STATE ybuf;
1307   int r;
1308   FILE *file;
1309   char *filename;
1310   struct stat newstab;
1311
1312   if (fileparselevel >= MAX_INCLUDE_NEST) {
1313     parseerrprint("too many nested levels of included files");
1314     return tokv_error;
1315   }
1316   file= fopen(string,"r");
1317   if (!file) {
1318     if (errno == ENOENT) {
1319       if (didexist) *didexist= 0;
1320       return 0;
1321     }
1322     parseerrprint("unable to open config file `%s': %s",string,strerror(errno));
1323     return tokv_error;
1324   }
1325   r= fstat(fileno(file),&newstab); if (r) syscallerror("unable to fstat new file");
1326   for (checkrecurse= cstate; checkrecurse; checkrecurse= checkrecurse->upstate) {
1327     if (!checkrecurse->filestab.st_mode) continue;
1328     if (newstab.st_dev==checkrecurse->filestab.st_dev &&
1329         newstab.st_ino==checkrecurse->filestab.st_ino) {
1330       parseerrprint("recursion detected - config file `%s' calls itself",string);
1331       fclose(file);
1332       return tokv_error;
1333     }
1334   }
1335   
1336   if (didexist) *didexist= 1;
1337
1338   ybuf= yy_create_buffer(file,YY_BUF_SIZE);
1339   if (!ybuf) syscallerror("unable to create flex buffer for file");
1340   filename= xstrsave(string);
1341   parser_push(&usestate,filename,&newstab,ybuf,0);
1342   fileparselevel++;
1343   
1344   r= parser(0);
1345   if (ferror(file)) {
1346     parseerrprint("error reading configuration file `%s'",string);
1347     r= tokv_error;
1348   }
1349
1350   fileparselevel--;
1351   parser_pop();
1352   free(filename);
1353   fclose(file);
1354   if (r == tokv_eof) r= 0;
1355   return r;
1356 }
1357
1358 static int parser(int allowce) {
1359   /* Returns:
1360    *  an exception (error, eof or quit)
1361    *   then rest of `file' is uninteresting
1362    * or
1363    *  token if allowce was !0 and equal to token's controlend
1364    *   then rest of `file' (including rest of line with the
1365    *   controlend - even the whitespace) not scanned yet
1366    */
1367   int token, r;
1368
1369   for (;;) { /* loop over lines */
1370     cstate->reportlineno= cstate->lineno;
1371     do { token= yylex(); } while (token == tokv_lwsp);
1372     if (token & tokt_exception) {
1373       return token;
1374     } else if (token & tokt_controlend) {
1375       if (lr_controlend == allowce) return token;
1376       else return unexpected(token,-1,"directive (not this kind of"
1377                              " control structure end)");
1378     } else if (token & tokt_directive) {
1379       if ((token & tokt_internal) && !cstate->isinternal)
1380         return unexpected(token,-1,"published directive, not internal-use-only one");
1381       r= (lr_dir)(token); if (r) { assert(r & tokt_exception); return r; }
1382     } else if (token == tokv_newline) {
1383       /* ignore blank lines (and comment-only lines) */
1384     } else {
1385       return unexpected(token,-1,"directive");
1386     }
1387   }
1388 }