diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-19 22:57:00 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-19 22:57:00 +0000 |
commit | dcb3fcb042612bfbb311a488379c65024bafd52b (patch) | |
tree | ce29b24ad433b8d8a4e0b450ca458bcde69a9a88 | |
parent | c29684afd61b841c93517f378aaa1fd7750b038d (diff) | |
download | busybox-w32-dcb3fcb042612bfbb311a488379c65024bafd52b.tar.gz busybox-w32-dcb3fcb042612bfbb311a488379c65024bafd52b.tar.bz2 busybox-w32-dcb3fcb042612bfbb311a488379c65024bafd52b.zip |
libbb: config_read() update
-rw-r--r-- | Config.in | 4 | ||||
-rw-r--r-- | include/libbb.h | 14 | ||||
-rw-r--r-- | libbb/parse_config.c | 8 | ||||
-rw-r--r-- | miscutils/crond.c | 8 |
4 files changed, 16 insertions, 18 deletions
@@ -482,10 +482,6 @@ config INCLUDE_SUSv2 | |||
482 | config PARSE | 482 | config PARSE |
483 | bool "Uniform config file parser debugging applet: parse" | 483 | bool "Uniform config file parser debugging applet: parse" |
484 | 484 | ||
485 | config FEATURE_PARSE_COPY | ||
486 | bool "Keep a copy of current line" | ||
487 | depends on PARSE | ||
488 | |||
489 | endmenu | 485 | endmenu |
490 | 486 | ||
491 | menu 'Installation Options' | 487 | menu 'Installation Options' |
diff --git a/include/libbb.h b/include/libbb.h index af6c1385d..4e4e37911 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -990,14 +990,18 @@ int bb_parse_mode(const char* s, mode_t* theMode) FAST_FUNC; | |||
990 | /* | 990 | /* |
991 | * Config file parser | 991 | * Config file parser |
992 | */ | 992 | */ |
993 | #define PARSE_DONT_REDUCE 0x00010000 // do not treat consecutive delimiters as one | 993 | enum { |
994 | #define PARSE_DONT_TRIM 0x00020000 // do not trim line of leading and trailing delimiters | 994 | PARSE_DONT_REDUCE = 0x00010000, // do not treat consecutive delimiters as one |
995 | #define PARSE_LAST_IS_GREEDY 0x00040000 // last token takes whole remainder of the line | 995 | PARSE_DONT_TRIM = 0x00020000, // do not trim line of leading and trailing delimiters |
996 | //#define PARSE_DONT_NULL 0x00080000 // do not set tokens[] to NULL | 996 | PARSE_LAST_IS_GREEDY = 0x00040000, // last token takes whole remainder of the line |
997 | // PARSE_DONT_NULL = 0x00080000, // do not set tokens[] to NULL | ||
998 | // keep a copy of current line | ||
999 | PARSE_KEEP_COPY = 0x00200000 * ENABLE_DEBUG_CROND_OPTION, | ||
1000 | }; | ||
997 | typedef struct parser_t { | 1001 | typedef struct parser_t { |
998 | FILE *fp; | 1002 | FILE *fp; |
999 | char *line; | 1003 | char *line; |
1000 | USE_FEATURE_PARSE_COPY(char *data;) | 1004 | char *data; |
1001 | int lineno; | 1005 | int lineno; |
1002 | } parser_t; | 1006 | } parser_t; |
1003 | parser_t* config_open(const char *filename) FAST_FUNC; | 1007 | parser_t* config_open(const char *filename) FAST_FUNC; |
diff --git a/libbb/parse_config.c b/libbb/parse_config.c index 3945501ad..8d7c97eb1 100644 --- a/libbb/parse_config.c +++ b/libbb/parse_config.c | |||
@@ -75,10 +75,10 @@ static void config_free_data(parser_t *const parser) | |||
75 | { | 75 | { |
76 | free(parser->line); | 76 | free(parser->line); |
77 | parser->line = NULL; | 77 | parser->line = NULL; |
78 | USE_FEATURE_PARSE_COPY( | 78 | if (PARSE_KEEP_COPY) { /* compile-time constant */ |
79 | free(parser->data); | 79 | free(parser->data); |
80 | parser->data = NULL; | 80 | parser->data = NULL; |
81 | ) | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | void FAST_FUNC config_close(parser_t *parser) | 84 | 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 | |||
179 | 179 | ||
180 | // store line | 180 | // store line |
181 | parser->line = line = xrealloc(line, ii + 1); | 181 | parser->line = line = xrealloc(line, ii + 1); |
182 | USE_FEATURE_PARSE_COPY( | 182 | if (flags & PARSE_KEEP_COPY) { |
183 | parser->data = xstrdup(line); | 183 | parser->data = xstrdup(line); |
184 | ) | 184 | } |
185 | 185 | ||
186 | /* now split line to tokens */ | 186 | /* now split line to tokens */ |
187 | ntokens--; // now it's max allowed token no | 187 | ntokens--; // now it's max allowed token no |
diff --git a/miscutils/crond.c b/miscutils/crond.c index 154243c78..c7ee793a5 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -470,14 +470,12 @@ static void SynchronizeFile(const char *fileName) | |||
470 | pline = &file->cf_LineBase; | 470 | pline = &file->cf_LineBase; |
471 | 471 | ||
472 | while (--maxLines | 472 | while (--maxLines |
473 | && (n = config_read(parser, tokens, 6, 1, "# \t", PARSE_LAST_IS_GREEDY)) | 473 | && (n = config_read(parser, tokens, 6, 1, "# \t", PARSE_LAST_IS_GREEDY|PARSE_KEEP_COPY)) |
474 | ) { | 474 | ) { |
475 | CronLine *line; | 475 | CronLine *line; |
476 | 476 | ||
477 | USE_FEATURE_PARSE_COPY( | 477 | if (DebugOpt) |
478 | if (DebugOpt) | 478 | crondlog(LVL5 "user:%s entry:%s", fileName, parser->data); |
479 | crondlog(LVL5 "user:%s entry:%s", fileName, parser->data); | ||
480 | ) | ||
481 | 479 | ||
482 | /* check if line is setting MAILTO= */ | 480 | /* check if line is setting MAILTO= */ |
483 | if (0 == strncmp(tokens[0], "MAILTO=", 7)) { | 481 | if (0 == strncmp(tokens[0], "MAILTO=", 7)) { |