mirror of
https://git.busybox.net/busybox.git
synced 2024-12-18 18:03:29 +08:00
libbb: config_read() update
This commit is contained in:
parent
c29684afd6
commit
dcb3fcb042
@ -482,10 +482,6 @@ config INCLUDE_SUSv2
|
||||
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'
|
||||
|
@ -990,14 +990,18 @@ int bb_parse_mode(const char* s, mode_t* theMode) FAST_FUNC;
|
||||
/*
|
||||
* 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;
|
||||
|
@ -75,10 +75,10 @@ static void config_free_data(parser_t *const parser)
|
||||
{
|
||||
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)
|
||||
@ -179,9 +179,9 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
|
||||
|
||||
// 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
|
||||
|
@ -470,14 +470,12 @@ static void SynchronizeFile(const char *fileName)
|
||||
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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user