]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Allow values to be escaped using \
authorRoy Marples <roy@marples.name>
Thu, 24 Apr 2008 12:35:03 +0000 (12:35 +0000)
committerRoy Marples <roy@marples.name>
Thu, 24 Apr 2008 12:35:03 +0000 (12:35 +0000)
dhcpcd.c
dhcpcd.conf.5

index 761eeaa5fb16a003e8d5b4e535ccee8b888b89ea..9d6079306d9deec8ab5bbb2f458fe1aae093ed44 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -330,7 +330,8 @@ parse_config_line(const char *opt, char *line, struct options *options)
        unsigned int i;
 
        for (i = 0; i < sizeof(longopts) / sizeof(longopts[0]); i++) {
-               if (strcmp(longopts[i].name, opt) != 0)
+               if (!longopts[i].name ||
+                   strcmp(longopts[i].name, opt) != 0)
                        continue;
 
                if (longopts[i].has_arg == required_argument && !line) {
@@ -360,7 +361,8 @@ main(int argc, char **argv)
        int pidfd = -1;
        int sig = 0;
        int retval = EXIT_FAILURE;
-       char *line, *option, *p, *buffer = NULL;
+       char *line, *option, *p, *lp, *buffer = NULL;
+       char lt = '\\';
        size_t len = 0;
        FILE *f;
 
@@ -390,7 +392,9 @@ main(int argc, char **argv)
                r = 1;
                while ((get_line(&buffer, &len, f))) {
                        line = buffer;
-                       option = strsep(&line, " ");
+                       while ((option = strsep(&line, " \t")))
+                               if (*option != '\0')
+                                       break;
                        if (!option || *option == '\0' || *option == '#')
                                continue;
                        /* Trim leading whitespace */
@@ -401,9 +405,27 @@ main(int argc, char **argv)
                        /* Trim trailing whitespace */
                        if (line && *line) {
                                p = line + strlen(line) - 1;
-                               while (p != line && (*p == ' ' || *p == '\t'))
+                               while (p != line && (*p == ' ' || *p == '\t')) {
+                                       /* Remember the last char trimmed */
+                                       lt = *p;
                                        *p-- = '\0';
+                               }
+                       }
+                       /* Process escapes */
+                       lp = p = line;
+                       while (p && *p) {
+                               if (*p == '\\')
+                                       p++;
+                               /* EOL? */
+                               if (*p == '\0') {
+                                       /* Restore the last char trimmed */
+                                       *lp++ = lt;
+                                       break;
+                               }
+                               *lp++ = *p++;
                        }
+                       if (lp)
+                               *lp = '\0';
                        r = parse_config_line(option, line, options);
                        if (r != 1)
                                break;
index 9befff3ae505237dad94dac21a04b3cb6b024cce..e0b37a77330eb6f73fd7d566a610752e44bdc502 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd Apr 18, 2008
+.Dd Apr 24, 2008
 .Dt DHCPCD.CONF 5 SMM
 .Sh NAME
 .Nm dhcpcd.conf
@@ -34,7 +34,10 @@ can do everything from the command line, there are cases where it's just easier
 to do it once in a configuration file. Most of the options found in
 .Xr dhcpcd 8
 can be used here. The first word on the line is the option and the rest of the
-line is the value. Blank lines and lines starting with # are ignored.
+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.
 .Pp
 Here's a list of available options:
 .Bl -tag -width indent