Browse Source

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
OPENBSD_4_3
deraadt 17 years ago
parent
commit
708686ed78
1 changed files with 26 additions and 14 deletions
  1. +26
    -14
      src/usr.sbin/ntpd/parse.y

+ 26
- 14
src/usr.sbin/ntpd/parse.y View File

@ -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> * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -46,7 +46,7 @@ int yyerror(const char *, ...);
int yyparse(void); int yyparse(void);
int kw_cmp(const void *, const void *); int kw_cmp(const void *, const void *);
int lookup(char *); int lookup(char *);
int lgetc(FILE *);
int lgetc(int);
int lungetc(int); int lungetc(int);
int findeol(void); int findeol(void);
int yylex(void); int yylex(void);
@ -327,9 +327,10 @@ char pushback_buffer[MAXPUSHBACK];
int pushback_index = 0; int pushback_index = 0;
int int
lgetc(FILE *f)
lgetc(int inquot)
{ {
int c, next; int c, next;
FILE *f = fin;
if (parsebuf) { if (parsebuf) {
/* Read character from the parsebuffer instead of input. */ /* Read character from the parsebuffer instead of input. */
@ -345,6 +346,11 @@ lgetc(FILE *f)
if (pushback_index) if (pushback_index)
return (pushback_buffer[--pushback_index]); return (pushback_buffer[--pushback_index]);
if (inquot) {
c = getc(f);
return (c);
}
while ((c = getc(f)) == '\\') { while ((c = getc(f)) == '\\') {
next = getc(f); next = getc(f);
if (next != '\n') { if (next != '\n') {
@ -392,7 +398,7 @@ findeol(void)
/* skip to either EOF or the first real EOL */ /* skip to either EOF or the first real EOL */
while (1) { while (1) {
c = lgetc(fin);
c = lgetc(0);
if (c == '\n') { if (c == '\n') {
lineno++; lineno++;
break; break;
@ -408,16 +414,16 @@ yylex(void)
{ {
char buf[8096]; char buf[8096];
char *p; char *p;
int endc, c;
int endc, next, c;
int token; int token;
p = buf; p = buf;
while ((c = lgetc(fin)) == ' ')
while ((c = lgetc(0)) == ' ')
; /* nothing */ ; /* nothing */
yylval.lineno = lineno; yylval.lineno = lineno;
if (c == '#') if (c == '#')
while ((c = lgetc(fin)) != '\n' && c != EOF)
while ((c = lgetc(0)) != '\n' && c != EOF)
; /* nothing */ ; /* nothing */
switch (c) { switch (c) {
@ -425,15 +431,21 @@ yylex(void)
case '"': case '"':
endc = c; endc = c;
while (1) { while (1) {
if ((c = lgetc(fin)) == EOF)
if ((c = lgetc(1)) == EOF)
return (0); return (0);
if (c == endc) {
*p = '\0';
break;
}
if (c == '\n') { if (c == '\n') {
lineno++; lineno++;
continue; 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) { if (p + 1 >= buf + sizeof(buf) - 1) {
yyerror("string too long"); yyerror("string too long");
@ -457,7 +469,7 @@ yylex(void)
yyerror("string too long"); yyerror("string too long");
return (findeol()); return (findeol());
} }
} while ((c = lgetc(fin)) != EOF && isdigit(c));
} while ((c = lgetc(0)) != EOF && isdigit(c));
lungetc(c); lungetc(c);
if (p == buf + 1 && buf[0] == '-') if (p == buf + 1 && buf[0] == '-')
goto nodigits; goto nodigits;
@ -496,7 +508,7 @@ nodigits:
yyerror("string too long"); yyerror("string too long");
return (findeol()); return (findeol());
} }
} while ((c = lgetc(fin)) != EOF && (allowed_in_string(c)));
} while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
lungetc(c); lungetc(c);
*p = '\0'; *p = '\0';
if ((token = lookup(buf)) == STRING) if ((token = lookup(buf)) == STRING)


Loading…
Cancel
Save