aboutsummaryrefslogtreecommitdiff
path: root/libbb/parse_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/parse_config.c')
-rw-r--r--libbb/parse_config.c18
1 files changed, 7 insertions, 11 deletions
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)
59int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mintokens, const char*delims,char comment) 59int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mintokens, const char*delims,char comment)
60{ 60{
61 char *line, *q; 61 char *line, *q;
62 int ii; 62 int ii, seen;
63 /* do not treat subsequent delimiters as one delimiter */ 63 /* do not treat subsequent delimiters as one delimiter */
64 bool noreduce = (ntokens < 0); 64 bool noreduce = (ntokens < 0);
65 if (noreduce) 65 if (noreduce)
@@ -69,9 +69,6 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mint
69 config_free_data(parser); 69 config_free_data(parser);
70 70
71 while (1) { 71 while (1) {
72 int n;
73
74 // get fresh line
75//TODO: speed up xmalloc_fgetline by internally using fgets, not fgetc 72//TODO: speed up xmalloc_fgetline by internally using fgets, not fgetc
76 line = xmalloc_fgetline(parser->fp); 73 line = xmalloc_fgetline(parser->fp);
77 if (!line) 74 if (!line)
@@ -102,10 +99,10 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mint
102 ii = q - line; 99 ii = q - line;
103 } 100 }
104 // skip leading delimiters 101 // skip leading delimiters
105 n = strspn(line, delims); 102 seen = strspn(line, delims);
106 if (n) { 103 if (seen) {
107 ii -= n; 104 ii -= seen;
108 strcpy(line, line + n); 105 strcpy(line, line + seen);
109 } 106 }
110 if (ii) 107 if (ii)
111 break; 108 break;
@@ -121,9 +118,8 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mint
121 parser->line = line = xrealloc(line, ii + 1); 118 parser->line = line = xrealloc(line, ii + 1);
122 parser->data = xstrdup(line); 119 parser->data = xstrdup(line);
123 120
124 // now split line to tokens 121 /* now split line to tokens */
125//TODO: discard consecutive delimiters? 122 ii = noreduce ? seen : 0;
126 ii = 0;
127 ntokens--; // now it's max allowed token no 123 ntokens--; // now it's max allowed token no
128 while (1) { 124 while (1) {
129 // get next token 125 // get next token