version 1.12, 2022/03/29 21:15:15 |
version 1.16, 2022/04/10 20:03:38 |
|
|
#include "log.h" |
#include "log.h" |
|
|
static struct file { |
static struct file { |
FILE *stream; |
FILE *stream; |
char *name; |
char *name; |
size_t ungetpos; |
size_t ungetpos; |
size_t ungetsize; |
size_t ungetsize; |
u_char *ungetbuf; |
u_char *ungetbuf; |
int eof_reached; |
int eof_reached; |
int lineno; |
int lineno; |
} *f; |
} *f; |
|
|
int lookup(char *); |
int lookup(char *); |
Line 49 int yyerror(const char *, ...) |
|
Line 49 int yyerror(const char *, ...) |
|
|
|
int config_load(struct blind *); |
int config_load(struct blind *); |
struct file *config_push(const char *); |
struct file *config_push(const char *); |
int config_pop(void); |
int config_close(void); |
|
#define START_EXPAND 1 |
|
#define DONE_EXPAND 2 |
|
static int expanding; |
|
|
TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); |
TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); |
struct sym { |
struct sym { |
|
|
return (STRING); |
return (STRING); |
} |
} |
|
|
#define START_EXPAND 1 |
|
#define DONE_EXPAND 2 |
|
|
|
static int expanding; |
|
|
|
char * |
char * |
symget(const char *nam) |
symget(const char *nam) |
{ |
{ |
Line 197 lgetc(int quotec) |
|
Line 195 lgetc(int quotec) |
|
if ((c = igetc()) == EOF) { |
if ((c = igetc()) == EOF) { |
yyerror("reached end of file while parsing " |
yyerror("reached end of file while parsing " |
"quoted string"); |
"quoted string"); |
if (config_pop() == EOF) |
if (config_close() == EOF) |
return (EOF); |
return (EOF); |
return (quotec); |
return (quotec); |
} |
} |
Line 225 lgetc(int quotec) |
|
Line 223 lgetc(int quotec) |
|
return ('\n'); |
return ('\n'); |
} |
} |
while (c == EOF) { |
while (c == EOF) { |
if (config_pop() == EOF) |
if (config_close() == EOF) |
return (EOF); |
return (EOF); |
c = igetc(); |
c = igetc(); |
} |
} |
|
|
if (c == '-' || isdigit(c)) { |
if (c == '-' || isdigit(c)) { |
do { |
do { |
*p++ = c; |
*p++ = c; |
if ((size_t)(p-buf) >= sizeof(buf)) { |
if ((size_t)(p-buf) >= sizeof(buf)) { |
yyerror("string too long"); |
yyerror("string too long"); |
return (findeol()); |
return (findeol()); |
} |
} |
|
|
int |
int |
config_load(struct blind *temp) |
config_load(struct blind *temp) |
{ |
{ |
env = temp; |
env = temp; |
errors = 0; |
errors = 0; |
|
|
if ((f = config_push(env->bl_conf)) == NULL) { |
if ((f = calloc(1, sizeof(struct file))) == NULL) { |
// config_purge(PURGE_ALL); |
log_debug("cannot allocate memory"); |
return (-1); |
return (-1); |
|
} |
|
if ((f->name = strdup(env->bl_conf)) == NULL) { |
|
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); |
|
free(f); |
|
return (-1); |
|
} |
|
if (config_perm(fileno(f->stream), f->name)) { |
|
fclose(f->stream); |
|
free(f->name); |
|
free(f); |
|
return (-1); |
|
} |
|
f->lineno = 1; |
|
f->ungetsize = 16; |
|
f->ungetbuf = malloc(f->ungetsize); |
|
if (f->ungetbuf == NULL) { |
|
log_debug("cannot allocate buffer"); |
|
fclose(f->stream); |
|
free(f->name); |
|
free(f); |
|
return (-1); |
|
} |
|
|
yyparse(); |
yyparse(); |
|
// setup |
|
|
// setup |
if (errors) |
|
return (-1); |
|
|
if (errors) { |
return (0); |
// config_purge(PURGE_ALL); |
|
return (-1); |
|
} |
|
|
|
return (0); |
|
} |
} |
|
|
struct file * |
|
config_push(const char *name) |
|
{ |
|
struct file *nf; |
|
|
|
if ((nf = calloc(1, sizeof(struct file))) == NULL) { |
|
log_debug("cannot allocate memory"); |
|
return (NULL); |
|
} |
|
if ((nf->name = strdup(name)) == NULL) { |
|
log_debug("cannot duplicate name"); |
|
free(nf); |
|
return (NULL); |
|
} |
|
if ((nf->stream = fopen(nf->name, "r")) == NULL) { |
|
log_debug("cannot open config file"); |
|
free(nf->name); |
|
free(nf); |
|
return (NULL); |
|
} |
|
if (config_perm(fileno(nf->stream), nf->name)) { |
|
fclose(nf->stream); |
|
free(nf->name); |
|
free(nf); |
|
return (NULL); |
|
} |
|
nf->lineno = 1; |
|
nf->ungetsize = 16; |
|
nf->ungetbuf = malloc(nf->ungetsize); |
|
if (nf->ungetbuf == NULL) { |
|
log_debug("cannot allocate buffer"); |
|
fclose(nf->stream); |
|
free(nf->name); |
|
free(nf); |
|
return (NULL); |
|
} |
|
|
|
return (nf); |
|
} |
|
|
|
int |
int |
config_pop(void) |
config_close(void) |
{ |
{ |
fclose(f->stream); |
fclose(f->stream); |
free(f->name); |
free(f->name); |
free(f->ungetbuf); |
free(f->ungetbuf); |
free(f); |
free(f); |
|
|
return (EOF); |
return (EOF); |
} |
} |