-.\" 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
.\" 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
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
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);
} 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;
}