- 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
This commit is contained in:
Bernhard Reutner-Fischer
2008-07-17 14:00:42 +00:00
parent 679212836a
commit 54d50a0b47
2 changed files with 76 additions and 16 deletions

View File

@ -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