From e51b5bf8b2b74bdc759d7b035bac7cbe2fa4b1f4 Mon Sep 17 00:00:00 2001 From: krw Date: Mon, 13 Jan 2014 23:42:18 +0000 Subject: [PATCH] peek_token() a bit more to replace a bunch of manual checks with the perfectly adequate parse_semi(). And some blocks didn't even need to peek. --- sbin/dhclient/clparse.c | 39 +++++++++++++++++---------------------- sbin/dhclient/parse.c | 8 ++------ 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 29949c19110..9fc075369da 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.70 2014/01/13 21:36:46 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.71 2014/01/13 23:42:18 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -347,13 +347,13 @@ parse_option_list(FILE *cfile, u_int8_t *list, size_t sz) ; if (j == ix) list[ix++] = i; - token = next_token(&val, cfile); + token = peek_token(NULL, cfile); + if (token == ',') + token = next_token(NULL, cfile); } while (token == ','); - if (token != ';') { - parse_warn("expecting semicolon."); - goto syntaxerror; - } - return (ix); + + if (parse_semi(cfile)) + return (ix); syntaxerror: skip_to_semi(cfile); @@ -578,11 +578,8 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease) skip_to_semi(cfile); return; } - token = next_token(&val, cfile); - if (token != ';') { - parse_warn("expecting semicolon."); - skip_to_semi(cfile); - } + + parse_semi(cfile); } int @@ -724,14 +721,13 @@ bad_flag: return (-1); } } - token = next_token(&val, cfile); + token = peek_token(NULL, cfile); + if (*fmt == 'A' && token == ',') + token = next_token(NULL, cfile); } while (*fmt == 'A' && token == ','); - if (token != ';') { - parse_warn("semicolon expected."); - skip_to_semi(cfile); + if (!parse_semi(cfile)) return (-1); - } options[code].data = malloc(hunkix + nul_term); if (!options[code].data) @@ -762,11 +758,10 @@ parse_reject_statement(FILE *cfile) elem->addr = addr; TAILQ_INSERT_TAIL(&config->reject_list, elem, next); - token = next_token(NULL, cfile); + token = peek_token(NULL, cfile); + if (token == ',') + token = next_token(NULL, cfile); } while (token == ','); - if (token != ';') { - parse_warn("expecting semicolon."); - skip_to_semi(cfile); - } + parse_semi(cfile); } diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c index 31f49f8f160..d77661f31db 100644 --- a/sbin/dhclient/parse.c +++ b/sbin/dhclient/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.30 2014/01/13 20:56:24 krw Exp $ */ +/* $OpenBSD: parse.c,v 1.31 2014/01/13 23:42:18 krw Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -161,11 +161,7 @@ parse_hardware_param(FILE *cfile, struct ether_addr *hardware) ETHER_ADDR_LEN, ':', 16) == 0) return; - token = next_token(NULL, cfile); - if (token != ';') { - parse_warn("expecting semicolon."); - skip_to_semi(cfile); - } + parse_semi(cfile); } /* -- 2.20.1