=================================================================== RCS file: /cvs/cvs/blind/parse.y,v retrieving revision 1.2 retrieving revision 1.3 diff -u -p -r1.2 -r1.3 --- blind/parse.y 2022/03/20 17:33:18 1.2 +++ blind/parse.y 2022/03/20 18:47:16 1.3 @@ -15,13 +15,31 @@ */ %{ +#include + +#include #include #include "blind.h" +#include "log.h" +TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files); +static struct file { + TAILQ_ENTRY(file) entry; + FILE *stream; + char *name; + size_t ungetpos; + size_t ungetsize; + u_char *ungetbuf; + int eof_reached; + int lineno; + int errors; +} *file, *top; + int yylex(void); int yyerror(const char *, ...); -int config_load(struct blind *, const char *); +int config_load(struct blind *); +struct file *config_push(const char *); struct blind *env = NULL; static int errors = 0; @@ -66,12 +84,48 @@ yylex(void) } int -config_load(struct blind *temp, const char *filename) +config_load(struct blind *temp) { env = temp; errors = 0; - // + if ((file = config_push(env->bl_conf)) == NULL) { + // config_purge(PURGE_ALL); + return (-1); + } + top = file; + // parse config + return (0); +} + +struct file * +config_push(const char *name) +{ + struct file *nfile; + + if ((nfile = calloc(1, sizeof(struct file))) == NULL) { + log_debug("%s", __func__); + return (NULL); + } + + if ((nfile->name = strdup(name)) == NULL) { + log_debug("%s", __func__); + free(nfile); + return (NULL); + } + + if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { + log_debug("%s: %s", __func__, nfile->name); + free(nfile->name); + free(nfile); + return (NULL); + } + + // check file permission + + // load file + + return (nfile); }