// keep a copy of current line
PARSE_KEEP_COPY = 0x00200000 * ENABLE_FEATURE_CROND_D,
PARSE_EOL_COMMENTS = 0x00400000, // comments are recognized even if they aren't the first char
+ PARSE_ALT_COMMENTS = 0x00800000, // delim[0] and delim[1] are two different allowed comment chars
+ // (so far, delim[0] will only work as comment char for full-line comment)
+ // (IOW: it works as if PARSE_EOL_COMMENTS is not set. sysctl applet is okay with this)
+ PARSE_WS_COMMENTS = 0x01000000, // comments are recognized even if there is whitespace before
+ // ("line start><space><tab><space>#comment" is also comment, not only "line start>#comment")
// NORMAL is:
// * remove leading and trailing delimiters and collapse
// multiple delimiters into one
#undef config_read
int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const char *delims)
{
- char *line;
+ char *line, *p;
int ntokens, mintokens;
int t;
+ char alt_comment_ch;
if (!parser)
return 0;
+ alt_comment_ch = '\0';
+ if (flags & PARSE_ALT_COMMENTS)
+ alt_comment_ch = *delims++;
+
ntokens = (uint8_t)flags;
mintokens = (uint8_t)(flags >> 8);
if (flags & PARSE_TRIM)
line += strspn(line, delims + 1);
- if (line[0] == '\0' || line[0] == delims[0])
+ p = line;
+ if (flags & PARSE_WS_COMMENTS)
+ p = skip_whitespace(p);
+ if (p[0] == '\0' || p[0] == delims[0] || p[0] == alt_comment_ch)
goto again;
if (flags & PARSE_KEEP_COPY) {
/* Must do it _after_ config_open(): */
xchdir("/proc/sys");
-//TODO: ';' is comment char too
-//TODO: <space><tab><space>#comment is also comment, not strictly 1st char only
parse_flags = 0;
parse_flags &= ~PARSE_COLLAPSE; // NO (var==val is not var=val) - treat consecutive delimiters as one
parse_flags &= ~PARSE_TRIM; // NO - trim leading and trailing delimiters
parse_flags |= PARSE_GREEDY; // YES - last token takes entire remainder of the line
parse_flags &= ~PARSE_MIN_DIE; // NO - die if < min tokens found
parse_flags &= ~PARSE_EOL_COMMENTS; // NO (only first char) - comments are recognized even if not first char
- while (config_read(parser, token, 2, 2, "#=", parse_flags)) {
+ parse_flags |= PARSE_ALT_COMMENTS;// YES - two comment chars: ';' and '#'
+ /* <space><tab><space>#comment is also comment, not strictly 1st char only */
+ parse_flags |= PARSE_WS_COMMENTS; // YES - comments are recognized even if there is whitespace before
+ while (config_read(parser, token, 2, 2, ";#=", parse_flags)) {
char *tp;
trim(token[1]);