From: Roy Marples Date: Thu, 24 Apr 2008 12:35:03 +0000 (+0000) Subject: Allow values to be escaped using \ X-Git-Tag: v4.0.2~457 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=967194ef5414a00284bba2bd03ff9a3c7363c078;p=thirdparty%2Fdhcpcd.git Allow values to be escaped using \ --- diff --git a/dhcpcd.c b/dhcpcd.c index 761eeaa5..9d607930 100644 --- 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; diff --git a/dhcpcd.conf.5 b/dhcpcd.conf.5 index 9befff3a..e0b37a77 100644 --- a/dhcpcd.conf.5 +++ b/dhcpcd.conf.5 @@ -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