]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Allow embedded comments.
authorRoy Marples <roy@marples.name>
Fri, 5 Feb 2016 14:28:08 +0000 (14:28 +0000)
committerRoy Marples <roy@marples.name>
Fri, 5 Feb 2016 14:28:08 +0000 (14:28 +0000)
dhcpcd.conf.5.in
if-options.c

index 024a2a82cf6b92d3543d2c5142474653dea9f92b..9a7ad827b4bd9f1a239edc820cf9767cb6f8fd45 100644 (file)
@@ -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
index ff28aa39a40f65f9fa54b5d82be448adf4013352..294f8c8c781296e6f31e4c532d4189049ef2f542 100644 (file)
@@ -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;
 }