aboutsummaryrefslogtreecommitdiff
path: root/libbb/parse_config.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-20 13:01:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-20 13:01:56 +0000
commit4a717e0c19098111d7fc41f260e01258556ddfbb (patch)
treed65386c0c0a0c2d80d712847221551ebecee33e3 /libbb/parse_config.c
parentdcb3fcb042612bfbb311a488379c65024bafd52b (diff)
downloadbusybox-w32-4a717e0c19098111d7fc41f260e01258556ddfbb.tar.gz
busybox-w32-4a717e0c19098111d7fc41f260e01258556ddfbb.tar.bz2
busybox-w32-4a717e0c19098111d7fc41f260e01258556ddfbb.zip
libbb: fixes to config_read() by maintainer
sysctl: use config_read() function old new delta sysctl_main 121 232 +111 config_read 478 502 +24 parse_main 239 241 +2 sysctl_preload_file_and_exit 234 - -234 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 3/0 up/down: 137/-234) Total: -97 bytes
Diffstat (limited to 'libbb/parse_config.c')
-rw-r--r--libbb/parse_config.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/libbb/parse_config.c b/libbb/parse_config.c
index 8d7c97eb1..68caa2c37 100644
--- a/libbb/parse_config.c
+++ b/libbb/parse_config.c
@@ -25,7 +25,7 @@ int parse_main(int argc UNUSED_PARAM, char **argv)
25 if (p) { 25 if (p) {
26 int n; 26 int n;
27 char **t = xmalloc(sizeof(char *) * ntokens); 27 char **t = xmalloc(sizeof(char *) * ntokens);
28 while ((n = config_read(p, t, ntokens, mintokens, delims, flags)) > 0) { 28 while ((n = config_read(p, t, ntokens, mintokens, delims, flags)) != 0) {
29 for (int i = 0; i < n; ++i) 29 for (int i = 0; i < n; ++i)
30 printf("[%s]", t[i]); 30 printf("[%s]", t[i]);
31 puts(""); 31 puts("");
@@ -114,10 +114,8 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
114 int ntokens = flags & 0xFF; 114 int ntokens = flags & 0xFF;
115 int mintokens = (flags & 0xFF00) >> 8; 115 int mintokens = (flags & 0xFF00) >> 8;
116 116
117 /*
118 // N.B. this could only be used in read-in-one-go version, or when tokens use xstrdup(). TODO 117 // N.B. this could only be used in read-in-one-go version, or when tokens use xstrdup(). TODO
119 if (!parser->lineno || !(flags & PARSE_DONT_NULL)) 118 //if (!parser->lineno || !(flags & PARSE_DONT_NULL))
120 */
121 memset(tokens, 0, sizeof(tokens[0]) * ntokens); 119 memset(tokens, 0, sizeof(tokens[0]) * ntokens);
122 config_free_data(parser); 120 config_free_data(parser);
123 121
@@ -171,7 +169,7 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
171 break; 169 break;
172 170
173 next_line: 171 next_line:
174 /* skip empty line */ 172 // skip empty line
175 free(line); 173 free(line);
176 } 174 }
177 175
@@ -183,9 +181,9 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
183 parser->data = xstrdup(line); 181 parser->data = xstrdup(line);
184 } 182 }
185 183
186 /* now split line to tokens */ 184 // split line to tokens
187 ntokens--; // now it's max allowed token no 185 ntokens--; // now it's max allowed token no
188 // N.B, non-empty remainder is also a token, 186 // N.B. non-empty remainder is also a token,
189 // so if ntokens <= 1, we just return the whole line 187 // so if ntokens <= 1, we just return the whole line
190 // N.B. if PARSE_LAST_IS_GREEDY is set the remainder of the line is stuck to the last token 188 // N.B. if PARSE_LAST_IS_GREEDY is set the remainder of the line is stuck to the last token
191 for (ii = 0; *line && ii <= ntokens; ) { 189 for (ii = 0; *line && ii <= ntokens; ) {
@@ -193,7 +191,10 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
193 // get next token 191 // get next token
194 // at the last token and need greedy token -> 192 // at the last token and need greedy token ->
195 if ((flags & PARSE_LAST_IS_GREEDY) && (ii == ntokens)) { 193 if ((flags & PARSE_LAST_IS_GREEDY) && (ii == ntokens)) {
196 // ... don't cut the line 194 // skip possible delimiters
195 if (!(flags & PARSE_DONT_REDUCE))
196 line += strspn(line, delims);
197 // don't cut the line
197 q = line + strlen(line); 198 q = line + strlen(line);
198 } else { 199 } else {
199 // vanilla token. cut the line at the first delim 200 // vanilla token. cut the line at the first delim