From 54d50a0b476ec2e6015dffd9598edc2d7968047b Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 17 Jul 2008 14:00:42 +0000 Subject: - fix "noreduce" flag of config_read (didn't work at all, at least for me). - convert init's inittab parsing to the new config parser: function old new delta config_read 393 386 -7 static.actions 72 64 -8 .rodata 121772 121764 -8 parse_inittab 554 393 -161 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-184) Total: -184 bytes --- libbb/parse_config.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'libbb') diff --git a/libbb/parse_config.c b/libbb/parse_config.c index 70f933fe3..2bd2d4f53 100644 --- a/libbb/parse_config.c +++ b/libbb/parse_config.c @@ -59,7 +59,7 @@ void FAST_FUNC config_close(parser_t *parser) int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mintokens, const char*delims,char comment) { char *line, *q; - int ii; + int ii, seen; /* do not treat subsequent delimiters as one delimiter */ bool noreduce = (ntokens < 0); if (noreduce) @@ -69,9 +69,6 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mint config_free_data(parser); while (1) { - int n; - - // get fresh line //TODO: speed up xmalloc_fgetline by internally using fgets, not fgetc line = xmalloc_fgetline(parser->fp); if (!line) @@ -102,10 +99,10 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mint ii = q - line; } // skip leading delimiters - n = strspn(line, delims); - if (n) { - ii -= n; - strcpy(line, line + n); + seen = strspn(line, delims); + if (seen) { + ii -= seen; + strcpy(line, line + seen); } if (ii) break; @@ -121,9 +118,8 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mint parser->line = line = xrealloc(line, ii + 1); parser->data = xstrdup(line); - // now split line to tokens -//TODO: discard consecutive delimiters? - ii = 0; + /* now split line to tokens */ + ii = noreduce ? seen : 0; ntokens--; // now it's max allowed token no while (1) { // get next token -- cgit v1.2.3