config PARSE
bool "Uniform config file parser debugging applet: parse"
-config FEATURE_PARSE_COPY
- bool "Keep a copy of current line"
- depends on PARSE
-
endmenu
menu 'Installation Options'
/*
* Config file parser
*/
-#define PARSE_DONT_REDUCE 0x00010000 // do not treat consecutive delimiters as one
-#define PARSE_DONT_TRIM 0x00020000 // do not trim line of leading and trailing delimiters
-#define PARSE_LAST_IS_GREEDY 0x00040000 // last token takes whole remainder of the line
-//#define PARSE_DONT_NULL 0x00080000 // do not set tokens[] to NULL
+enum {
+ PARSE_DONT_REDUCE = 0x00010000, // do not treat consecutive delimiters as one
+ PARSE_DONT_TRIM = 0x00020000, // do not trim line of leading and trailing delimiters
+ PARSE_LAST_IS_GREEDY = 0x00040000, // last token takes whole remainder of the line
+// PARSE_DONT_NULL = 0x00080000, // do not set tokens[] to NULL
+ // keep a copy of current line
+ PARSE_KEEP_COPY = 0x00200000 * ENABLE_DEBUG_CROND_OPTION,
+};
typedef struct parser_t {
FILE *fp;
char *line;
- USE_FEATURE_PARSE_COPY(char *data;)
+ char *data;
int lineno;
} parser_t;
parser_t* config_open(const char *filename) FAST_FUNC;
{
free(parser->line);
parser->line = NULL;
- USE_FEATURE_PARSE_COPY(
+ if (PARSE_KEEP_COPY) { /* compile-time constant */
free(parser->data);
parser->data = NULL;
- )
+ }
}
void FAST_FUNC config_close(parser_t *parser)
// store line
parser->line = line = xrealloc(line, ii + 1);
- USE_FEATURE_PARSE_COPY(
+ if (flags & PARSE_KEEP_COPY) {
parser->data = xstrdup(line);
- )
+ }
/* now split line to tokens */
ntokens--; // now it's max allowed token no
pline = &file->cf_LineBase;
while (--maxLines
- && (n = config_read(parser, tokens, 6, 1, "# \t", PARSE_LAST_IS_GREEDY))
+ && (n = config_read(parser, tokens, 6, 1, "# \t", PARSE_LAST_IS_GREEDY|PARSE_KEEP_COPY))
) {
CronLine *line;
- USE_FEATURE_PARSE_COPY(
- if (DebugOpt)
- crondlog(LVL5 "user:%s entry:%s", fileName, parser->data);
- )
+ if (DebugOpt)
+ crondlog(LVL5 "user:%s entry:%s", fileName, parser->data);
/* check if line is setting MAILTO= */
if (0 == strncmp(tokens[0], "MAILTO=", 7)) {