From: Roy Marples Date: Fri, 5 Feb 2016 14:28:08 +0000 (+0000) Subject: Allow embedded comments. X-Git-Tag: v6.10.2~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67f84564b74557cfde2a06af69643c1c38015d80;p=thirdparty%2Fdhcpcd.git Allow embedded comments. --- diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index 024a2a82..9a7ad827 100644 --- a/dhcpcd.conf.5.in +++ b/dhcpcd.conf.5.in @@ -1,4 +1,4 @@ -.\" Copyright (c) 2006-2015 Roy Marples +.\" Copyright (c) 2006-2016 Roy Marples .\" All rights reserved .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 29, 2016 +.Dd February 5, 2016 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -39,8 +39,8 @@ can be used here. The first word on the line is the option and the rest of the line is the value. Leading and trailing whitespace for the option and value are trimmed. You can escape characters in the value using the \\ character. -.Pp -Blank lines and lines starting with # are ignored. +Comments can be prefixed with the # character. +String values should be quoted with the " character. .Pp Here's a list of available options: .Bl -tag -width indent diff --git a/if-options.c b/if-options.c index ff28aa39..294f8c8c 100644 --- a/if-options.c +++ b/if-options.c @@ -2125,8 +2125,9 @@ static char * get_line(char ** __restrict buf, size_t * __restrict buflen, FILE * __restrict fp) { - char *p; + char *p, *c; ssize_t bytes; + int quoted; do { bytes = getline(buf, buflen, fp); @@ -2137,6 +2138,22 @@ get_line(char ** __restrict buf, size_t * __restrict buflen, } while (*p == '\0' || *p == '\n' || *p == '#' || *p == ';'); if ((*buf)[--bytes] == '\n') (*buf)[bytes] = '\0'; + + /* Strip embedded comments unless in a quoted string or escaped */ + quoted = 0; + for (c = p; *c != '\0'; c++) { + if (*c == '\\') { + c++; /* escaped */ + continue; + } + if (*c == '"') + quoted = !quoted; + else if (*c == '#' && !quoted) { + *c = '\0'; + break; + } + } + printf ("*%s*\n", p); return p; }