diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-10-11 14:39:18 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-10-11 14:39:18 +0000 |
commit | 1f1de6e9c4176c83df8002a4cd3223d5996a6c13 (patch) | |
tree | 8eecf0adcebd265a34813982a1bcb022a1b87c9f /bin/chio | |
parent | 883c6340d4913899a5a68266d31ecd995948b29b (diff) |
next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others
Diffstat (limited to 'bin/chio')
-rw-r--r-- | bin/chio/parse.y | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/bin/chio/parse.y b/bin/chio/parse.y index c72489b1c2c..a3000e8e39d 100644 --- a/bin/chio/parse.y +++ b/bin/chio/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.6 2007/09/11 23:06:37 deraadt Exp $ */ +/* $OpenBSD: parse.y,v 1.7 2007/10/11 14:39:15 deraadt Exp $ */ /* * Copyright (c) 2006 Bob Beck <beck@openbsd.org> @@ -51,7 +51,7 @@ int yyerror(const char *, ...); int yyparse(void); int kw_cmp(const void *, const void *); int lookup(char *); -int lgetc(FILE *); +int lgetc(int); int lungetc(int); int findeol(void); int yylex(void); @@ -175,9 +175,10 @@ char pushback_buffer[MAXPUSHBACK]; int pushback_index = 0; int -lgetc(FILE *f) +lgetc(int inquot) { int c, next; + FILE *f = fin; if (parsebuf) { /* Read character from the parsebuffer instead of input. */ @@ -193,6 +194,11 @@ lgetc(FILE *f) if (pushback_index) return (pushback_buffer[--pushback_index]); + if (inquot) { + c = getc(f); + return (c); + } + while ((c = getc(f)) == '\\') { next = getc(f); if (next != '\n') { @@ -240,7 +246,7 @@ findeol(void) /* skip to either EOF or the first real EOL */ while (1) { - c = lgetc(fin); + c = lgetc(0); if (c == '\n') { lineno++; break; @@ -256,16 +262,16 @@ yylex(void) { char buf[8096]; char *p; - int endc, c; + int endc, next, c; int token; p = buf; - while ((c = lgetc(fin)) == ' ') + while ((c = lgetc(0)) == ' ') ; /* nothing */ yylval.lineno = lineno; if (c == '#') - while ((c = lgetc(fin)) != '\n' && c != EOF) + while ((c = lgetc(0)) != '\n' && c != EOF) ; /* nothing */ switch (c) { @@ -273,15 +279,21 @@ yylex(void) case '"': endc = c; while (1) { - if ((c = lgetc(fin)) == EOF) + if ((c = lgetc(1)) == EOF) return (0); - if (c == endc) { - *p = '\0'; - break; - } if (c == '\n') { lineno++; continue; + } else if (c == '\\') { + if ((next = lgetc(1)) == EOF) + return (0); + if (next == endc) + c = next; + else + lungetc(next); + } else if (c == endc) { + *p = '\0'; + break; } if (p + 1 >= buf + sizeof(buf) - 1) { yyerror("string too long"); @@ -305,7 +317,7 @@ yylex(void) yyerror("string too long"); return (findeol()); } - } while ((c = lgetc(fin)) != EOF && isdigit(c)); + } while ((c = lgetc(0)) != EOF && isdigit(c)); lungetc(c); if (p == buf + 1 && buf[0] == '-') goto nodigits; @@ -344,7 +356,7 @@ nodigits: yyerror("string too long"); return (findeol()); } - } while ((c = lgetc(fin)) != EOF && (allowed_in_string(c))); + } while ((c = lgetc(0)) != EOF && (allowed_in_string(c))); lungetc(c); *p = '\0'; if ((token = lookup(buf)) == STRING) |