=================================================================== RCS file: /cvs/cvs/blind/parse.y,v retrieving revision 1.16 retrieving revision 1.17 diff -u -p -r1.16 -r1.17 --- blind/parse.y 2022/04/10 20:03:38 1.16 +++ blind/parse.y 2022/04/10 21:04:06 1.17 @@ -25,16 +25,11 @@ #include "config.h" #include "log.h" -static struct file { - FILE *stream; - char *name; - size_t ungetpos; - size_t ungetsize; - u_char *ungetbuf; - int eof_reached; - int lineno; -} *f; +#define START_EXPAND 1 +#define DONE_EXPAND 2 +static struct file *f; + int lookup(char *); int igetc(void); int lgetc(int); @@ -50,9 +45,10 @@ int yyerror(const char *, ...) int config_load(struct blind *); struct file *config_push(const char *); int config_close(void); -#define START_EXPAND 1 -#define DONE_EXPAND 2 + static int expanding; +static int errors = 0; +struct blind *env = NULL; TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); struct sym { @@ -62,11 +58,9 @@ struct sym { char *nam; char *val; }; + char *symget(const char *); -struct blind *env = NULL; -static int errors = 0; - typedef struct { union { int64_t number; @@ -171,8 +165,8 @@ igetc(void) int c; while (1) { - if (f->ungetpos > 0) - c = f->ungetbuf[--f->ungetpos]; + if (f->unpos > 0) + c = f->unbuf[--f->unpos]; else c = getc(f->stream); @@ -218,8 +212,8 @@ lgetc(int quotec) * count right if last line in included file is syntactically * invalid and has no newline. */ - if (f->eof_reached == 0) { - f->eof_reached = 1; + if (f->eof == 0) { + f->eof = 1; return ('\n'); } while (c == EOF) { @@ -237,14 +231,14 @@ lungetc(int c) if (c == EOF) return; - if (f->ungetpos >= f->ungetsize) { - void *p = reallocarray(f->ungetbuf, f->ungetsize, 2); + if (f->unpos >= f->unsize) { + void *p = reallocarray(f->unbuf, f->unsize, 2); if (p == NULL) log_fatal("cannot reallocate memory"); - f->ungetbuf = p; - f->ungetsize *= 2; + f->unbuf = p; + f->unsize *= 2; } - f->ungetbuf[f->ungetpos++] = c; + f->unbuf[f->unpos++] = c; } int @@ -455,9 +449,8 @@ config_load(struct blind *temp) return (-1); } f->lineno = 1; - f->ungetsize = 16; - f->ungetbuf = malloc(f->ungetsize); - if (f->ungetbuf == NULL) { + f->unsize = 16; + if ((f->unbuf = malloc(f->unsize)) == NULL) { log_debug("cannot allocate buffer"); fclose(f->stream); free(f->name); @@ -479,7 +472,7 @@ config_close(void) { fclose(f->stream); free(f->name); - free(f->ungetbuf); + free(f->unbuf); free(f); return (EOF);