libbb: config_read() update

This commit is contained in:
Denis Vlasenko 2008-07-19 22:57:00 +00:00
parent c29684afd6
commit dcb3fcb042
4 changed files with 16 additions and 18 deletions

View File

@ -482,10 +482,6 @@ config INCLUDE_SUSv2
config PARSE config PARSE
bool "Uniform config file parser debugging applet: parse" bool "Uniform config file parser debugging applet: parse"
config FEATURE_PARSE_COPY
bool "Keep a copy of current line"
depends on PARSE
endmenu endmenu
menu 'Installation Options' menu 'Installation Options'

View File

@ -990,14 +990,18 @@ int bb_parse_mode(const char* s, mode_t* theMode) FAST_FUNC;
/* /*
* Config file parser * Config file parser
*/ */
#define PARSE_DONT_REDUCE 0x00010000 // do not treat consecutive delimiters as one enum {
#define PARSE_DONT_TRIM 0x00020000 // do not trim line of leading and trailing delimiters PARSE_DONT_REDUCE = 0x00010000, // do not treat consecutive delimiters as one
#define PARSE_LAST_IS_GREEDY 0x00040000 // last token takes whole remainder of the line PARSE_DONT_TRIM = 0x00020000, // do not trim line of leading and trailing delimiters
//#define PARSE_DONT_NULL 0x00080000 // do not set tokens[] to NULL 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 { typedef struct parser_t {
FILE *fp; FILE *fp;
char *line; char *line;
USE_FEATURE_PARSE_COPY(char *data;) char *data;
int lineno; int lineno;
} parser_t; } parser_t;
parser_t* config_open(const char *filename) FAST_FUNC; parser_t* config_open(const char *filename) FAST_FUNC;

View File

@ -75,10 +75,10 @@ static void config_free_data(parser_t *const parser)
{ {
free(parser->line); free(parser->line);
parser->line = NULL; parser->line = NULL;
USE_FEATURE_PARSE_COPY( if (PARSE_KEEP_COPY) { /* compile-time constant */
free(parser->data); free(parser->data);
parser->data = NULL; parser->data = NULL;
) }
} }
void FAST_FUNC config_close(parser_t *parser) void FAST_FUNC config_close(parser_t *parser)
@ -179,9 +179,9 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
// store line // store line
parser->line = line = xrealloc(line, ii + 1); parser->line = line = xrealloc(line, ii + 1);
USE_FEATURE_PARSE_COPY( if (flags & PARSE_KEEP_COPY) {
parser->data = xstrdup(line); parser->data = xstrdup(line);
) }
/* now split line to tokens */ /* now split line to tokens */
ntokens--; // now it's max allowed token no ntokens--; // now it's max allowed token no

View File

@ -470,14 +470,12 @@ static void SynchronizeFile(const char *fileName)
pline = &file->cf_LineBase; pline = &file->cf_LineBase;
while (--maxLines 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; CronLine *line;
USE_FEATURE_PARSE_COPY( if (DebugOpt)
if (DebugOpt) crondlog(LVL5 "user:%s entry:%s", fileName, parser->data);
crondlog(LVL5 "user:%s entry:%s", fileName, parser->data);
)
/* check if line is setting MAILTO= */ /* check if line is setting MAILTO= */
if (0 == strncmp(tokens[0], "MAILTO=", 7)) { if (0 == strncmp(tokens[0], "MAILTO=", 7)) {