summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2007-10-11 14:39:15 +0000
committerderaadt <deraadt@openbsd.org>2007-10-11 14:39:15 +0000
commitd5d66eae4c20d72f986a3f39150c3d21c0517b23 (patch)
treef8aca41758493cd07447885f0f607f31ab80cb3a
parentBye bye global ospf options. OSPF options are per area (at least the one (diff)
downloadwireguard-openbsd-d5d66eae4c20d72f986a3f39150c3d21c0517b23.tar.xz
wireguard-openbsd-d5d66eae4c20d72f986a3f39150c3d21c0517b23.zip
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
-rw-r--r--bin/chio/parse.y40
-rw-r--r--sbin/ipsecctl/parse.y44
-rw-r--r--sbin/pfctl/parse.y49
-rw-r--r--usr.sbin/bgpd/parse.y65
-rw-r--r--usr.sbin/dvmrpd/parse.y48
-rw-r--r--usr.sbin/hostapd/parse.y33
-rw-r--r--usr.sbin/hoststated/parse.y42
-rw-r--r--usr.sbin/ifstated/parse.y44
-rw-r--r--usr.sbin/ntpd/parse.y40
-rw-r--r--usr.sbin/ospf6d/parse.y52
-rw-r--r--usr.sbin/ospfd/parse.y52
-rw-r--r--usr.sbin/relayd/parse.y42
-rw-r--r--usr.sbin/ripd/parse.y48
13 files changed, 362 insertions, 237 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)
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)
diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y
index 135a132a50f..88a7280bbe4 100644
--- a/usr.sbin/bgpd/parse.y
+++ b/usr.sbin/bgpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.208 2007/09/13 20:39:58 claudio Exp $ */
+/* $OpenBSD: parse.y,v 1.209 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -65,7 +65,7 @@ int yyerror(const char *, ...);
int yyparse(void);
int kw_cmp(const void *, const void *);
int lookup(char *);
-int lgetc(void);
+int lgetc(int);
int lungetc(int);
int findeol(void);
int yylex(void);
@@ -1861,10 +1861,11 @@ char pushback_buffer[MAXPUSHBACK];
int pushback_index = 0;
int
-lgetc(void)
+lgetc(int inquot)
{
- int c, next;
+ FILE *f = file->stream;
struct file *prevfile;
+ int c, next;
if (parsebuf) {
/* Read character from the parsebuffer instead of input. */
@@ -1880,8 +1881,13 @@ lgetc(void)
if (pushback_index)
return (pushback_buffer[--pushback_index]);
- while ((c = getc(file->stream)) == '\\') {
- next = getc(file->stream);
+ if (inquot) {
+ c = getc(f);
+ return (c);
+ }
+
+ while ((c = getc(f)) == '\\') {
+ next = getc(f);
if (next != '\n') {
c = next;
break;
@@ -1892,9 +1898,9 @@ lgetc(void)
if (c == '\t' || c == ' ') {
/* Compress blanks to a single space. */
do {
- c = getc(file->stream);
+ c = getc(f);
} while (c == '\t' || c == ' ');
- ungetc(c, file->stream);
+ ungetc(c, f);
c = ' ';
}
@@ -1902,11 +1908,12 @@ lgetc(void)
(prevfile = TAILQ_PREV(file, files, entry)) != NULL) {
prevfile->errors += file->errors;
TAILQ_REMOVE(&files, file, entry);
- fclose(file->stream);
+ fclose(f);
free(file->name);
free(file);
file = prevfile;
- c = getc(file->stream);
+ f = file->stream;
+ c = getc(f);
}
return (c);
@@ -1938,7 +1945,7 @@ findeol(void)
/* skip to either EOF or the first real EOL */
while (1) {
- c = lgetc();
+ c = lgetc(0);
if (c == '\n') {
file->lineno++;
break;
@@ -1954,21 +1961,21 @@ yylex(void)
{
char buf[8096];
char *p, *val;
- int endc, c;
+ int endc, next, c;
int token;
top:
p = buf;
- while ((c = lgetc()) == ' ')
+ while ((c = lgetc(0)) == ' ')
; /* nothing */
yylval.lineno = file->lineno;
if (c == '#')
- while ((c = lgetc()) != '\n' && c != EOF)
+ while ((c = lgetc(0)) != '\n' && c != EOF)
; /* nothing */
if (c == '$' && parsebuf == NULL) {
while (1) {
- if ((c = lgetc()) == EOF)
+ if ((c = lgetc(0)) == EOF)
return (0);
if (p + 1 >= buf + sizeof(buf) - 1) {
@@ -1985,7 +1992,7 @@ top:
}
val = symget(buf);
if (val == NULL) {
- yyerror("macro \"%s\" not defined", buf);
+ yyerror("macro '%s' not defined", buf);
return (findeol());
}
parsebuf = val;
@@ -1998,15 +2005,21 @@ top:
case '"':
endc = c;
while (1) {
- if ((c = lgetc()) == EOF)
+ if ((c = lgetc(1)) == EOF)
return (0);
- if (c == endc) {
- *p = '\0';
- break;
- }
if (c == '\n') {
file->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");
@@ -2030,7 +2043,7 @@ top:
yyerror("string too long");
return (findeol());
}
- } while ((c = lgetc()) != EOF && isdigit(c));
+ } while ((c = lgetc(0)) != EOF && isdigit(c));
lungetc(c);
if (p == buf + 1 && buf[0] == '-')
goto nodigits;
@@ -2038,9 +2051,11 @@ top:
const char *errstr = NULL;
*p = '\0';
- yylval.v.number = strtonum(buf, LLONG_MIN, LLONG_MAX, &errstr);
+ yylval.v.number = strtonum(buf, LLONG_MIN,
+ LLONG_MAX, &errstr);
if (errstr) {
- yyerror("\"%s\" invalid number: %s", buf, errstr);
+ yyerror("\"%s\" invalid number: %s",
+ buf, errstr);
return (findeol());
}
return (NUMBER);
@@ -2067,7 +2082,7 @@ nodigits:
yyerror("string too long");
return (findeol());
}
- } while ((c = lgetc()) != 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/usr.sbin/dvmrpd/parse.y b/usr.sbin/dvmrpd/parse.y
index e6f21dff75b..fddbd797a29 100644
--- a/usr.sbin/dvmrpd/parse.y
+++ b/usr.sbin/dvmrpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.7 2007/09/12 02:07:07 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.8 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org>
@@ -55,7 +55,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);
@@ -403,9 +403,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. */
@@ -421,12 +422,15 @@ 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') {
- if (isspace(next))
- yyerror("whitespace after \\");
- ungetc(next, f);
+ c = next;
break;
}
yylval.lineno = lineno;
@@ -470,7 +474,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;
@@ -486,21 +490,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) {
@@ -530,15 +534,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");
@@ -548,7 +558,7 @@ top:
}
yylval.v.string = strdup(buf);
if (yylval.v.string == NULL)
- errx(1, "yylex: strdup");
+ err(1, "yylex: strdup");
return (STRING);
}
@@ -562,7 +572,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;
@@ -601,7 +611,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/usr.sbin/hostapd/parse.y b/usr.sbin/hostapd/parse.y
index 1d4310494b5..fdbc297616e 100644
--- a/usr.sbin/hostapd/parse.y
+++ b/usr.sbin/hostapd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.30 2007/09/12 09:07:38 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.31 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2004, 2005, 2006 Reyk Floeter <reyk@openbsd.org>
@@ -82,7 +82,7 @@ int yyerror(const char *, ...);
int yyparse(void);
int kw_cmp(const void *, const void *);
int lookup(char *);
-int lgetc(void);
+int lgetc(int);
int lungetc(int);
int findeol(void);
int yylex(void);
@@ -1331,7 +1331,7 @@ char pushback_buffer[MAXPUSHBACK];
int pushback_index = 0;
int
-lgetc(void)
+lgetc(int inquot)
{
int c, next;
struct file *pfile;
@@ -1350,6 +1350,11 @@ lgetc(void)
if (pushback_index)
return (pushback_buffer[--pushback_index]);
+ if (inquot) {
+ c = getc(file->stream);
+ return (c);
+ }
+
while ((c = getc(file->stream)) == '\\') {
next = getc(file->stream);
if (next != '\n') {
@@ -1409,7 +1414,7 @@ findeol(void)
/* skip to either EOF or the first real EOL */
while (1) {
- c = lgetc();
+ c = lgetc(0);
if (c == '\n') {
file->lineno++;
break;
@@ -1430,16 +1435,16 @@ yylex(void)
top:
p = buf;
- while ((c = lgetc()) == ' ')
+ while ((c = lgetc(0)) == ' ')
; /* nothing */
yylval.lineno = file->lineno;
if (c == '#')
- while ((c = lgetc()) != '\n' && c != EOF)
+ while ((c = lgetc(0)) != '\n' && c != EOF)
; /* nothing */
if (c == '$' && parsebuf == NULL) {
while (1) {
- if ((c = lgetc()) == EOF)
+ if ((c = lgetc(0)) == EOF)
return (0);
if (p + 1 >= buf + sizeof(buf) - 1) {
@@ -1469,7 +1474,7 @@ top:
case '"':
endc = c;
while (1) {
- if ((c = lgetc()) == EOF)
+ if ((c = lgetc(1)) == EOF)
return (0);
if (c == endc) {
*p = '\0';
@@ -1501,7 +1506,7 @@ top:
yyerror("string too long");
return (findeol());
}
- } while ((c = lgetc()) != EOF && isdigit(c));
+ } while ((c = lgetc(0)) != EOF && isdigit(c));
lungetc(c);
if (p == buf + 1 && buf[0] == '-')
goto nodigits;
@@ -1509,9 +1514,11 @@ top:
const char *errstr = NULL;
*p = '\0';
- yylval.v.number = strtonum(buf, LLONG_MIN, LLONG_MAX, &errstr);
+ yylval.v.number = strtonum(buf, LLONG_MIN,
+ LLONG_MAX, &errstr);
if (errstr) {
- yyerror("\"%s\" invalid number: %s", buf, errstr);
+ yyerror("\"%s\" invalid number: %s",
+ buf, errstr);
return (findeol());
}
return (NUMBER);
@@ -1538,7 +1545,7 @@ nodigits:
yyerror("string too long");
return (findeol());
}
- } while ((c = lgetc()) != EOF && (allowed_in_string(c)));
+ } while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
lungetc(c);
*p = '\0';
if ((token = lookup(buf)) == STRING)
@@ -1707,7 +1714,7 @@ hostapd_parse_file(struct hostapd_config *cfg)
next = TAILQ_NEXT(sym, entry);
if (!sym->used)
hostapd_log(HOSTAPD_LOG_VERBOSE,
- "warning: macro \"%s\" not used", sym->nam);
+ "warning: macro '%s' not used", sym->nam);
if (!sym->persist) {
free(sym->nam);
free(sym->val);
diff --git a/usr.sbin/hoststated/parse.y b/usr.sbin/hoststated/parse.y
index fa1103b827a..1b995e11516 100644
--- a/usr.sbin/hoststated/parse.y
+++ b/usr.sbin/hoststated/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.61 2007/10/09 22:32:52 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.62 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -67,7 +67,7 @@ int yyerror(const char *, ...);
int yyparse(void);
int kw_cmp(const void *, const void *);
int lookup(char *);
-int lgetc(FILE *, int);
+int lgetc(int);
int lungetc(int);
int findeol(void);
int yylex(void);
@@ -95,7 +95,7 @@ struct table *table_inherit(const char *, in_port_t);
typedef struct {
union {
- int32_t number;
+ int64_t number;
char *string;
struct host *host;
struct timeval tv;
@@ -1258,9 +1258,10 @@ char pushback_buffer[MAXPUSHBACK];
int pushback_index = 0;
int
-lgetc(FILE *f, int inquot)
+lgetc(int inquot)
{
int c, next;
+ FILE *f = fin;
if (parsebuf) {
/* Read character from the parsebuffer instead of input. */
@@ -1328,7 +1329,7 @@ findeol(void)
/* skip to either EOF or the first real EOL */
while (1) {
- c = lgetc(fin, 0);
+ c = lgetc(0);
if (c == '\n') {
lineno++;
break;
@@ -1349,16 +1350,16 @@ yylex(void)
top:
p = buf;
- while ((c = lgetc(fin, 0)) == ' ')
+ while ((c = lgetc(0)) == ' ')
; /* nothing */
yylval.lineno = lineno;
if (c == '#')
- while ((c = lgetc(fin, 0)) != '\n' && c != EOF)
+ while ((c = lgetc(0)) != '\n' && c != EOF)
; /* nothing */
if (c == '$' && parsebuf == NULL) {
while (1) {
- if ((c = lgetc(fin, 0)) == EOF)
+ if ((c = lgetc(0)) == EOF)
return (0);
if (p + 1 >= buf + sizeof(buf) - 1) {
@@ -1388,10 +1389,14 @@ top:
case '"':
endc = c;
while (1) {
- if ((c = lgetc(fin, 1)) == EOF)
+ if ((c = lgetc(1)) == EOF)
return (0);
- if (c == '\\') {
- next = lgetc(fin, 1);
+ if (c == '\n') {
+ lineno++;
+ continue;
+ } else if (c == '\\') {
+ if ((next = lgetc(1)) == EOF)
+ return (0);
if (next == endc)
c = next;
else
@@ -1400,10 +1405,6 @@ top:
*p = '\0';
break;
}
- if (c == '\n') {
- lineno++;
- continue;
- }
if (p + 1 >= buf + sizeof(buf) - 1) {
yyerror("string too long");
return (findeol());
@@ -1412,7 +1413,7 @@ top:
}
yylval.v.string = strdup(buf);
if (yylval.v.string == NULL)
- errx(1, "yylex: strdup");
+ err(1, "yylex: strdup");
return (STRING);
}
@@ -1426,7 +1427,7 @@ top:
yyerror("string too long");
return (findeol());
}
- } while ((c = lgetc(fin, 0)) != EOF && isdigit(c));
+ } while ((c = lgetc(0)) != EOF && isdigit(c));
lungetc(c);
if (p == buf + 1 && buf[0] == '-')
goto nodigits;
@@ -1434,8 +1435,8 @@ top:
const char *errstr = NULL;
*p = '\0';
- yylval.v.number = (int)strtonum(buf, -INT_MAX,
- INT_MAX, &errstr);
+ yylval.v.number = strtonum(buf, LLONG_MIN,
+ LLONG_MAX, &errstr);
if (errstr) {
yyerror("\"%s\" invalid number: %s",
buf, errstr);
@@ -1465,8 +1466,7 @@ nodigits:
yyerror("string too long");
return (findeol());
}
- } while ((c = lgetc(fin, 0)) != 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/usr.sbin/ifstated/parse.y b/usr.sbin/ifstated/parse.y
index bb6a209d560..6b80338df66 100644
--- a/usr.sbin/ifstated/parse.y
+++ b/usr.sbin/ifstated/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.18 2007/09/12 02:09:03 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.19 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2004 Ryan McBride <mcbride@openbsd.org>
@@ -54,7 +54,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);
@@ -417,9 +417,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. */
@@ -435,6 +436,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') {
@@ -482,7 +488,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;
@@ -498,21 +504,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) {
@@ -542,15 +548,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");
@@ -560,7 +572,7 @@ top:
}
yylval.v.string = strdup(buf);
if (yylval.v.string == NULL)
- errx(1, "yylex: strdup");
+ err(1, "yylex: strdup");
return (STRING);
}
@@ -574,7 +586,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;
@@ -613,7 +625,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/usr.sbin/ntpd/parse.y b/usr.sbin/ntpd/parse.y
index 02be8030b9d..cbaaa3cd334 100644
--- a/usr.sbin/ntpd/parse.y
+++ b/usr.sbin/ntpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.35 2007/09/14 06:29:54 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.36 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -46,7 +46,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);
@@ -327,9 +327,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. */
@@ -345,6 +346,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') {
@@ -392,7 +398,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;
@@ -408,16 +414,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) {
@@ -425,15 +431,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");
@@ -457,7 +469,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;
@@ -496,7 +508,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/usr.sbin/ospf6d/parse.y b/usr.sbin/ospf6d/parse.y
index 2bd307695f6..fee8e559749 100644
--- a/usr.sbin/ospf6d/parse.y
+++ b/usr.sbin/ospf6d/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.2 2007/10/09 06:12:04 claudio Exp $ */
+/* $OpenBSD: parse.y,v 1.3 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -53,7 +53,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);
@@ -602,9 +602,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. */
@@ -620,6 +621,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') {
@@ -667,7 +673,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;
@@ -683,21 +689,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) {
@@ -727,15 +733,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");
@@ -745,7 +757,7 @@ top:
}
yylval.v.string = strdup(buf);
if (yylval.v.string == NULL)
- errx(1, "yylex: strdup");
+ err(1, "yylex: strdup");
return (STRING);
}
@@ -759,7 +771,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;
@@ -767,11 +779,11 @@ top:
const char *errstr = NULL;
*p = '\0';
- yylval.v.number = strtonum(buf, LLONG_MIN, LLONG_MAX,
- &errstr);
+ yylval.v.number = strtonum(buf, LLONG_MIN,
+ LLONG_MAX, &errstr);
if (errstr) {
- yyerror("\"%s\" invalid number: %s", buf,
- errstr);
+ yyerror("\"%s\" invalid number: %s",
+ buf, errstr);
return (findeol());
}
return (NUMBER);
@@ -798,7 +810,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/usr.sbin/ospfd/parse.y b/usr.sbin/ospfd/parse.y
index a942ac6fc62..2a8df3e22f9 100644
--- a/usr.sbin/ospfd/parse.y
+++ b/usr.sbin/ospfd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.53 2007/10/11 12:19:31 claudio Exp $ */
+/* $OpenBSD: parse.y,v 1.54 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -53,7 +53,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);
@@ -687,9 +687,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. */
@@ -705,6 +706,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') {
@@ -752,7 +758,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;
@@ -768,21 +774,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) {
@@ -812,15 +818,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");
@@ -830,7 +842,7 @@ top:
}
yylval.v.string = strdup(buf);
if (yylval.v.string == NULL)
- errx(1, "yylex: strdup");
+ err(1, "yylex: strdup");
return (STRING);
}
@@ -844,7 +856,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;
@@ -852,11 +864,11 @@ top:
const char *errstr = NULL;
*p = '\0';
- yylval.v.number = strtonum(buf, LLONG_MIN, LLONG_MAX,
- &errstr);
+ yylval.v.number = strtonum(buf, LLONG_MIN,
+ LLONG_MAX, &errstr);
if (errstr) {
- yyerror("\"%s\" invalid number: %s", buf,
- errstr);
+ yyerror("\"%s\" invalid number: %s",
+ buf, errstr);
return (findeol());
}
return (NUMBER);
@@ -883,7 +895,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/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y
index fa1103b827a..1b995e11516 100644
--- a/usr.sbin/relayd/parse.y
+++ b/usr.sbin/relayd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.61 2007/10/09 22:32:52 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.62 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -67,7 +67,7 @@ int yyerror(const char *, ...);
int yyparse(void);
int kw_cmp(const void *, const void *);
int lookup(char *);
-int lgetc(FILE *, int);
+int lgetc(int);
int lungetc(int);
int findeol(void);
int yylex(void);
@@ -95,7 +95,7 @@ struct table *table_inherit(const char *, in_port_t);
typedef struct {
union {
- int32_t number;
+ int64_t number;
char *string;
struct host *host;
struct timeval tv;
@@ -1258,9 +1258,10 @@ char pushback_buffer[MAXPUSHBACK];
int pushback_index = 0;
int
-lgetc(FILE *f, int inquot)
+lgetc(int inquot)
{
int c, next;
+ FILE *f = fin;
if (parsebuf) {
/* Read character from the parsebuffer instead of input. */
@@ -1328,7 +1329,7 @@ findeol(void)
/* skip to either EOF or the first real EOL */
while (1) {
- c = lgetc(fin, 0);
+ c = lgetc(0);
if (c == '\n') {
lineno++;
break;
@@ -1349,16 +1350,16 @@ yylex(void)
top:
p = buf;
- while ((c = lgetc(fin, 0)) == ' ')
+ while ((c = lgetc(0)) == ' ')
; /* nothing */
yylval.lineno = lineno;
if (c == '#')
- while ((c = lgetc(fin, 0)) != '\n' && c != EOF)
+ while ((c = lgetc(0)) != '\n' && c != EOF)
; /* nothing */
if (c == '$' && parsebuf == NULL) {
while (1) {
- if ((c = lgetc(fin, 0)) == EOF)
+ if ((c = lgetc(0)) == EOF)
return (0);
if (p + 1 >= buf + sizeof(buf) - 1) {
@@ -1388,10 +1389,14 @@ top:
case '"':
endc = c;
while (1) {
- if ((c = lgetc(fin, 1)) == EOF)
+ if ((c = lgetc(1)) == EOF)
return (0);
- if (c == '\\') {
- next = lgetc(fin, 1);
+ if (c == '\n') {
+ lineno++;
+ continue;
+ } else if (c == '\\') {
+ if ((next = lgetc(1)) == EOF)
+ return (0);
if (next == endc)
c = next;
else
@@ -1400,10 +1405,6 @@ top:
*p = '\0';
break;
}
- if (c == '\n') {
- lineno++;
- continue;
- }
if (p + 1 >= buf + sizeof(buf) - 1) {
yyerror("string too long");
return (findeol());
@@ -1412,7 +1413,7 @@ top:
}
yylval.v.string = strdup(buf);
if (yylval.v.string == NULL)
- errx(1, "yylex: strdup");
+ err(1, "yylex: strdup");
return (STRING);
}
@@ -1426,7 +1427,7 @@ top:
yyerror("string too long");
return (findeol());
}
- } while ((c = lgetc(fin, 0)) != EOF && isdigit(c));
+ } while ((c = lgetc(0)) != EOF && isdigit(c));
lungetc(c);
if (p == buf + 1 && buf[0] == '-')
goto nodigits;
@@ -1434,8 +1435,8 @@ top:
const char *errstr = NULL;
*p = '\0';
- yylval.v.number = (int)strtonum(buf, -INT_MAX,
- INT_MAX, &errstr);
+ yylval.v.number = strtonum(buf, LLONG_MIN,
+ LLONG_MAX, &errstr);
if (errstr) {
yyerror("\"%s\" invalid number: %s",
buf, errstr);
@@ -1465,8 +1466,7 @@ nodigits:
yyerror("string too long");
return (findeol());
}
- } while ((c = lgetc(fin, 0)) != 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/usr.sbin/ripd/parse.y b/usr.sbin/ripd/parse.y
index 7c5d3ae70a1..8ccac2102ad 100644
--- a/usr.sbin/ripd/parse.y
+++ b/usr.sbin/ripd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.8 2007/09/11 23:06:37 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.9 2007/10/11 14:39:17 deraadt Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -54,7 +54,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);
@@ -410,9 +410,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. */
@@ -428,12 +429,15 @@ 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') {
- if (isspace(next))
- yyerror("whitespace after \\");
- ungetc(next, f);
+ c = next;
break;
}
yylval.lineno = lineno;
@@ -477,7 +481,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;
@@ -493,21 +497,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) {
@@ -537,15 +541,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");
@@ -555,7 +565,7 @@ top:
}
yylval.v.string = strdup(buf);
if (yylval.v.string == NULL)
- errx(1, "yylex: strdup");
+ err(1, "yylex: strdup");
return (STRING);
}
@@ -569,7 +579,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;
@@ -608,7 +618,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)