=================================================================== RCS file: /cvs/cvs/blind/parse.y,v retrieving revision 1.1 retrieving revision 1.3 diff -u -p -r1.1 -r1.3 --- blind/parse.y 2022/03/19 10:04:59 1.1 +++ blind/parse.y 2022/03/20 18:47:16 1.3 @@ -15,14 +15,34 @@ */ %{ +#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 *); +struct file *config_push(const char *); struct blind *env = NULL; +static int errors = 0; typedef struct { union { @@ -36,8 +56,8 @@ typedef struct { %token EXPIRE -%token STRING %token NUMBER +%token STRING %% grammar : @@ -61,4 +81,51 @@ int yylex(void) { return (0); +} + +int +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); }