diff options
author | Okan Demirmen <okan@cvs.openbsd.org> | 2013-05-22 13:02:15 +0000 |
---|---|---|
committer | Okan Demirmen <okan@cvs.openbsd.org> | 2013-05-22 13:02:15 +0000 |
commit | 9cd950121163619dea53d336a0cf827912acb042 (patch) | |
tree | 89ee0152f117e8904acee7aa1b815c713e185260 /app | |
parent | 9e635b3f4067cb2f7c6bd1378dcbb6f326050220 (diff) |
sync with src changes
Diffstat (limited to 'app')
-rw-r--r-- | app/cwm/parse.y | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/app/cwm/parse.y b/app/cwm/parse.y index d088b69b9..4a41710f4 100644 --- a/app/cwm/parse.y +++ b/app/cwm/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.42 2013/05/19 23:09:59 okan Exp $ */ +/* $OpenBSD: parse.y,v 1.43 2013/05/22 13:02:14 okan Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -42,18 +42,17 @@ static struct file { char *name; int lineno; int errors; -} *file; - -struct file *pushfile(const char *); -int popfile(void); -int yyparse(void); -int yylex(void); -int yyerror(const char *, ...); -int kw_cmp(const void *, const void *); -int lookup(char *); -int lgetc(int); -int lungetc(int); -int findeol(void); +} *file, *topfile; +struct file *pushfile(const char *); +int popfile(void); +int yyparse(void); +int yylex(void); +int yyerror(const char *, ...); +int kw_cmp(const void *, const void *); +int lookup(char *); +int lgetc(int); +int lungetc(int); +int findeol(void); static struct conf *conf; @@ -224,7 +223,7 @@ struct keywords { int yyerror(const char *fmt, ...) { - va_list ap; + va_list ap; file->errors++; va_start(ap, fmt); @@ -308,8 +307,9 @@ lgetc(int quotec) if (quotec) { if ((c = getc(file->stream)) == EOF) { - yyerror("reached end of file while parsing quoted string"); - if (popfile() == EOF) + yyerror("reached end of file while parsing " + "quoted string"); + if (file == topfile || popfile() == EOF) return (EOF); return (quotec); } @@ -327,7 +327,7 @@ lgetc(int quotec) } while (c == EOF) { - if (popfile() == EOF) + if (file == topfile || popfile() == EOF) return (EOF); c = getc(file->stream); } @@ -356,11 +356,13 @@ findeol(void) int c; parsebuf = NULL; - pushback_index = 0; /* skip to either EOF or the first real EOL */ while (1) { - c = lgetc(0); + if (pushback_index) + c = pushback_buffer[--pushback_index]; + else + c = lgetc(0); if (c == '\n') { file->lineno++; break; @@ -461,9 +463,10 @@ nodigits: #define allowed_in_string(x) \ (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ x != '{' && x != '}' && x != '<' && x != '>' && \ - x != '!' && x != '=' && x != '#' && x != ',')) + x != '!' && x != '=' && x != '/' && x != '#' && \ + x != ',')) - if (isalnum(c) || c == ':' || c == '_' || c == '*' || c == '/') { + if (isalnum(c) || c == ':' || c == '_' || c == '*') { do { *p++ = c; if ((unsigned)(p-buf) >= sizeof(buf)) { @@ -495,6 +498,7 @@ pushfile(const char *name) nfile->name = xstrdup(name); if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { + warn("%s", nfile->name); free(nfile->name); free(nfile); return (NULL); @@ -509,16 +513,15 @@ popfile(void) { struct file *prev; - if ((prev = TAILQ_PREV(file, files, entry)) != NULL) { + if ((prev = TAILQ_PREV(file, files, entry)) != NULL) prev->errors += file->errors; - TAILQ_REMOVE(&files, file, entry); - fclose(file->stream); - free(file->name); - free(file); - file = prev; - return (0); - } - return (EOF); + + TAILQ_REMOVE(&files, file, entry); + fclose(file->stream); + free(file->name); + free(file); + file = prev; + return (file ? 0 : EOF); } int @@ -532,12 +535,12 @@ parse_config(const char *filename, struct conf *xconf) free(conf); return (-1); } + topfile = file; conf_init(conf); yyparse(); errors = file->errors; - file->errors = 0; popfile(); if (errors) { |