commit - 51b930a3410ed65be5d6e7cc41752945fb37132a
commit + 6d7260fd5af3b577d020bdbcb038b6c245216d5e
blob - fca94244695ea3006c57d02c7d6b23bf7cb6fc31
blob + 2f21cabf60a5f58a82e88cc68ac7102a6ee66f11
--- got/parse.y
+++ got/parse.y
#include "got_error.h"
#include "got.h"
-TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
static struct file {
- TAILQ_ENTRY(file) entry;
FILE *stream;
char *name;
size_t ungetpos;
u_char *ungetbuf;
int eof_reached;
int lineno;
-} *file, *topfile;
-static const struct got_error* pushfile(struct file**, const char *);
-int popfile(void);
+} *file;
+static const struct got_error* newfile(struct file**, const char *);
+static void closefile(struct file *);
int yyparse(void);
int yylex(void);
int yyerror(const char *, ...)
if (c == EOF) {
yyerror("reached end of file while parsing "
"quoted string");
- if (file == topfile || popfile() == EOF)
- return (EOF);
- return (quotec);
}
return (c);
}
file->lineno++;
}
- if (c == EOF) {
- /*
- * Fake EOL when hit EOF for the first time. This gets line
- * count right if last line in included file is syntactically
- * invalid and has no newline.
- */
- if (file->eof_reached == 0) {
- file->eof_reached = 1;
- return ('\n');
- }
- while (c == EOF) {
- if (file == topfile || popfile() == EOF)
- return (EOF);
- c = igetc();
- }
- }
return (c);
}
}
static const struct got_error*
-pushfile(struct file **nfile, const char *name)
+newfile(struct file **nfile, const char *name)
{
const struct got_error* error = NULL;
free(msg);
return error;
}
- (*nfile)->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
+ (*nfile)->lineno = 1;
(*nfile)->ungetsize = 16;
(*nfile)->ungetbuf = malloc((*nfile)->ungetsize);
if ((*nfile)->ungetbuf == NULL) {
free((*nfile));
return got_error_from_errno2(__func__, "malloc");
}
- TAILQ_INSERT_TAIL(&files, (*nfile), entry);
return error;
}
return error;
}
-int
-popfile(void)
+static void
+closefile(struct file *file)
{
- struct file *prev = NULL;
-
- TAILQ_REMOVE(&files, file, entry);
fclose(file->stream);
free(file->name);
free(file->ungetbuf);
free(file);
- file = prev;
- return (file ? 0 : EOF);
}
const struct got_error*
* We don't require that gotconfig exists
* So, null gerror and goto done
*/
- gerror = pushfile(&file, filename);
+ gerror = newfile(&file, filename);
if (gerror && gerror->code == GOT_ERR_NO_CONFIG_FILE) {
gerror = NULL;
goto done;
return gerror;
TAILQ_INIT(&gotconfig.remotes);
- topfile = file;
yyparse();
- popfile();
+ closefile(file);
/* Free macros and check which have not been used. */
TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {