commit - 08150ec2be39e7a8747c5db057b41a68ee9cc587
commit + f1e7891fb4f9c4e2c4bcbc2345ecfdd33d850475
blob - 0f7784f5e9374d911a44d26414999c6ba3dc4042
blob + 5859b788c996a02896f8d82d446ceb13634f9bab
--- thingsd/parse.y
+++ thingsd/parse.y
char *name;
int lineno;
int errors;
-} *file, *topfile;
-struct file *pushfile(const char *, int);
-struct file *pushbuff(u_char *);
-int popfile(void);
-int popbuff(void);
+} *file;
+struct file *newfile(const char *, int);
+struct file *newbuff(u_char *);
+static void closefile(struct file *);
+static void closebuff(struct file *);
int check_file_secrecy(int, const char *);
int yyparse(void);
int yylex(void);
include : INCLUDE STRING {
struct file *nfile;
- nfile = pushfile($2, 1);
+ nfile = newfile($2, 1);
if (nfile == NULL) {
yyerror("failed to include file %s", $2);
free($2);
if (c == EOF) {
yyerror("reached end of file while parsing "
"quoted string");
- if (file == topfile || popfile() == EOF)
- return (EOF);
return (quotec);
}
return (c);
}
}
- while (c == EOF) {
- if (file == topfile || popfile() == EOF)
- return (EOF);
- c = getc(file->stream);
- }
-
parseindex = 0;
return (c);
}
}
struct file *
-pushfile(const char *name, int secret)
+newfile(const char *name, int secret)
{
struct file *nfile;
return (NULL);
}
nfile->lineno = 1;
- TAILQ_INSERT_TAIL(&files, nfile, entry);
return (nfile);
}
struct file *
-pushbuff(u_char *pkt)
+newbuff(u_char *pkt)
{
struct file *bfile;
return (NULL);
}
bfile->lineno = 1;
- TAILQ_INSERT_TAIL(&files, bfile, entry);
return (bfile);
}
-int
-popfile(void)
+static void
+closefile(struct file *xfile)
{
- struct file *prev;
-
- prev = TAILQ_PREV(file, files, entry);
- if (prev != NULL)
- prev->errors += file->errors;
-
- TAILQ_REMOVE(&files, file, entry);
- fclose(file->stream);
- free(file->name);
- free(file);
- file = prev;
- return (file ? 0 : EOF);
+ fclose(xfile->stream);
+ free(xfile->name);
+ free(xfile);
}
-int
-popbuff(void)
+static void
+closebuff(struct file *xfile)
{
- struct file *prev;
-
- prev = TAILQ_PREV(file, files, entry);
- if (prev != NULL)
- prev->errors += file->errors;
- TAILQ_REMOVE(&files, file, entry);
- free(file->name);
- free(file);
- file = prev;
- return (file ? 0 : EOF);
+ free(xfile->name);
+ free(xfile);
}
int
{
struct sym *sym, *next;
- file = pushfile(filename, 0);
+ file = newfile(filename, 0);
if (file == NULL) {
log_warn("failed to open %s", filename);
return (0);
}
- topfile = file;
TAILQ_INIT(thingsd_env->things);
thingsd_env->client_fptr = client_do_chk;
yyparse();
errors = file->errors;
- popfile();
-
+ closefile(file);
/* Free macros and check which have not been used. */
TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
if ((thingsd_env->thingsd_verbose > 1) && !sym->used)
tclient = pclient;
my_fd = tclient->fd;
- file = pushbuff(pkt);
+ file = newbuff(pkt);
if (file == NULL)
return (-1);
- topfile = file;
yyparse();
errors = file->errors;
- popbuff();
- free(file);
+ closebuff(file);
return (errors ? -1 : 0);
}