=================================================================== RCS file: /cvs/cvs/blind/parse.y,v retrieving revision 1.19 retrieving revision 1.20 diff -u -p -r1.19 -r1.20 --- blind/parse.y 2022/04/17 21:23:34 1.19 +++ blind/parse.y 2022/04/19 02:16:17 1.20 @@ -28,32 +28,27 @@ #define EXPAND_ON 1 #define EXPAND_OFF 2 -int lookup(char *); -int igetc(void); -int lgetc(int); -int findeol(void); -void lungetc(int); -int kw_cmp(const void *, const void *); -int yyparse(void); -int yylex(void); -int yyerror(const char *, ...) - __attribute__((__format__ (printf, 1, 2))) - __attribute__((__nonnull__ (1))); +int lookup(char *); +int igetc(void); +int lgetc(int); +int findeol(void); +void lungetc(int); +int kw_cmp(const void *, const void *); +int yyparse(void); +int yylex(void); +int yyerror(const char *, ...) + __attribute__((__format__ (printf, 1, 2))) + __attribute__((__nonnull__ (1))); -int symset(const char *, const char *, int); -char *symget(const char *); +int symset(const char *, const char *, int); +char *symget(const char *); -int config_load(struct blind *); -int config_close(void); +int config_load(struct blind *); +int config_close(void); -static int expanding; -static int errors = 0; -struct blind *env = NULL; -static struct file *f = NULL; - TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); struct sym { - TAILQ_ENTRY(sym) entry; + TAILQ_ENTRY(sym) entry; int used; int persist; char *nam; @@ -68,6 +63,11 @@ typedef struct { int lineno; } YYSTYPE; +static int expanding; +static int errors = 0; +struct blind *env = NULL; +static struct file *f = NULL; + %} %token ACTION ARROW DISABLE ENABLE EXPIRE ERROR SET @@ -86,19 +86,19 @@ grammar : varset : STRING '=' STRING { char *s = $1; while (*s++) { - if (isspace((unsigned char)*s)) { - yyerror("macro contain whitespace"); - free($1); - free($3); - YYERROR; - } - } - if (symset($1, $3, 0) == -1) - log_fatal("cannot store variable"); - free($1); - free($3); + if (isspace((unsigned char)*s)) { + yyerror("macro contain whitespace"); + free($1); + free($3); + YYERROR; + } + } + if (symset($1, $3, 0) == -1) + log_fatal("cannot store variable"); + free($1); + free($3); } -; +; set : SET EXPIRE NUMBER { env->bl_ttl = $3; @@ -114,15 +114,15 @@ set : SET EXPIRE NUMBER { %% struct keywords { - const char *k_name; - int k_val; + const char *k_name; + int k_val; }; int yyerror(const char *fmt, ...) { - va_list ap; - char *msg; + va_list ap; + char *msg; errors++; va_start(ap, fmt); @@ -143,15 +143,14 @@ kw_cmp(const void *k, const void *e) int lookup(char *s) { - /* this has to be sorted always */ static const struct keywords keywords[] = { - { "action", ACTION }, - { "disable", DISABLE }, - { "enable", ENABLE }, - { "expire", EXPIRE }, - { "set", SET }, + { "action", ACTION }, + { "disable", DISABLE }, + { "enable", ENABLE }, + { "expire", EXPIRE }, + { "set", SET }, }; - const struct keywords *p; + const struct keywords *p; p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]), sizeof(keywords[0]), kw_cmp); @@ -240,13 +239,13 @@ igetc(void) int lgetc(int quotec) { - int c, next; + int c, next; if (quotec) { if ((c = igetc()) == EOF) { yyerror("reached end of file while parsing " "quoted string"); - if (config_close() == EOF) + if (config_close() == EOF) return (EOF); return (quotec); } @@ -264,20 +263,9 @@ lgetc(int quotec) } if (c == EOF) { - /* - * Fake EOL when hit EOF for the first time. This gets line - * count right if last line in included file is syntactically - * invalid and has no newline. - */ - if (f->eof == 0) { - f->eof = 1; - return ('\n'); - } - while (c == EOF) { - if (config_close() == EOF) - return (EOF); - c = igetc(); - } + if (config_close() == EOF) + return (EOF); + c = igetc(); } return (c); } @@ -303,7 +291,6 @@ findeol(void) { int c; - /* skip to either EOF or the first real EOL */ while (1) { c = lgetc(0); if (c == '\n') { @@ -319,20 +306,21 @@ findeol(void) int yylex(void) { - char buf[8096]; - char *p, *val; - int quotec, next, c; - int token; + char buf[8096]; + char *p, *val; + int quotec, next, c; + int token; top: p = buf; while ((c = lgetc(0)) == ' ' || c == '\t') - ; /* nothing */ + ; yylval.lineno = f->lineno; if (c == '#') while ((c = lgetc(0)) != '\n' && c != EOF) - ; /* nothing */ + ; + if (c == '$' && !expanding) { while (1) { if ((c = lgetc(0)) == EOF) @@ -411,7 +399,7 @@ top: if (c == '-' || isdigit(c)) { do { *p++ = c; - if ((size_t)(p-buf) >= sizeof(buf)) { + if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } @@ -492,7 +480,7 @@ config_load(struct blind *temp) log_debug("cannot duplicate name"); free(f); return (-1); - } + } if ((f->stream = fopen(f->name, "r")) == NULL) { log_debug("cannot open config file"); free(f->name);