summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-10-11 14:39:18 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-10-11 14:39:18 +0000
commit1f1de6e9c4176c83df8002a4cd3223d5996a6c13 (patch)
tree8eecf0adcebd265a34813982a1bcb022a1b87c9f /sbin
parent883c6340d4913899a5a68266d31ecd995948b29b (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 'sbin')
-rw-r--r--sbin/ipsecctl/parse.y44
-rw-r--r--sbin/pfctl/parse.y49
2 files changed, 58 insertions, 35 deletions
diff --git a/sbin/ipsecctl/parse.y b/sbin/ipsecctl/parse.y
index 7960c1b6c9e..ccfe17cb2b2 100644
--- a/sbin/ipsecctl/parse.y
+++ b/sbin/ipsecctl/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.126 2007/09/12 20:22:59 hshoexer Exp $ */
+/* $OpenBSD: parse.y,v 1.127 2007/10/11 14:39:16 deraadt Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -114,7 +114,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);
@@ -915,9 +915,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. */
@@ -933,6 +934,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') {
@@ -980,7 +986,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;
@@ -996,21 +1002,21 @@ yylex(void)
{
char buf[8096];
char *p, *val;
- int endc, c;
+ int endc, next, c;
int token;
top:
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 */
if (c == '$' && parsebuf == NULL) {
while (1) {
- if ((c = lgetc(fin)) == EOF)
+ if ((c = lgetc(0)) == EOF)
return (0);
if (p + 1 >= buf + sizeof(buf) - 1) {
@@ -1027,7 +1033,7 @@ top:
}
val = symget(buf);
if (val == NULL) {
- yyerror("macro \"%s\" not defined", buf);
+ yyerror("macro '%s' not defined", buf);
return (findeol());
}
parsebuf = val;
@@ -1040,15 +1046,21 @@ top:
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");
@@ -1072,7 +1084,7 @@ top:
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;
@@ -1111,7 +1123,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)
diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
index 7a8fff9ac88..d00a59f38a2 100644
--- a/sbin/pfctl/parse.y
+++ b/sbin/pfctl/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.525 2007/10/01 12:37:40 mpf Exp $ */
+/* $OpenBSD: parse.y,v 1.526 2007/10/11 14:39:16 deraadt Exp $ */
/*
* Copyright (c) 2001 Markus Friedl. All rights reserved.
@@ -289,7 +289,7 @@ int expand_skip_interface(struct node_if *);
int check_rulestate(int);
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);
@@ -5149,9 +5149,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. */
@@ -5167,6 +5168,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') {
@@ -5214,7 +5220,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;
@@ -5230,21 +5236,21 @@ yylex(void)
{
char buf[8096];
char *p, *val;
- int endc, c, next;
+ int endc, next, c;
int token;
top:
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 */
if (c == '$' && parsebuf == NULL) {
while (1) {
- if ((c = lgetc(fin)) == EOF)
+ if ((c = lgetc(0)) == EOF)
return (0);
if (p + 1 >= buf + sizeof(buf) - 1) {
@@ -5274,15 +5280,21 @@ top:
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");
@@ -5295,7 +5307,7 @@ top:
err(1, "yylex: strdup");
return (STRING);
case '<':
- next = lgetc(fin);
+ next = lgetc(0);
if (next == '>') {
yylval.v.i = PF_OP_XRG;
return (PORTBINARY);
@@ -5303,7 +5315,7 @@ top:
lungetc(next);
break;
case '>':
- next = lgetc(fin);
+ next = lgetc(0);
if (next == '<') {
yylval.v.i = PF_OP_IRG;
return (PORTBINARY);
@@ -5311,7 +5323,7 @@ top:
lungetc(next);
break;
case '-':
- next = lgetc(fin);
+ next = lgetc(0);
if (next == '>')
return (ARROW);
lungetc(next);
@@ -5328,9 +5340,8 @@ top:
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;
if (c == EOF || allowed_to_end_number(c)) {
@@ -5368,7 +5379,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)