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.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/libbb/parse_config.c b/libbb/parse_config.c
index 307ae2cd2..8701b010c 100644
--- a/libbb/parse_config.c
+++ b/libbb/parse_config.c
@@ -42,8 +42,9 @@ int parse_main(int argc UNUSED_PARAM, char **argv)
42 int mintokens = 0, ntokens = 128; 42 int mintokens = 0, ntokens = 128;
43 unsigned noout; 43 unsigned noout;
44 44
45 opt_complementary = "-1"; 45 noout = 1 & getopt32(argv, "^" "xn:+m:+d:f:+" "\0" "-1",
46 noout = 1 & getopt32(argv, "xn:+m:+d:f:+", &ntokens, &mintokens, &delims, &flags); 46 &ntokens, &mintokens, &delims, &flags
47 );
47 //argc -= optind; 48 //argc -= optind;
48 argv += optind; 49 argv += optind;
49 50
@@ -161,13 +162,18 @@ mintokens > 0 make config_read() print error message if less than mintokens
161#undef config_read 162#undef config_read
162int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const char *delims) 163int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const char *delims)
163{ 164{
164 char *line; 165 char *line, *p;
165 int ntokens, mintokens; 166 int ntokens, mintokens;
166 int t; 167 int t;
168 char alt_comment_ch;
167 169
168 if (!parser) 170 if (!parser)
169 return 0; 171 return 0;
170 172
173 alt_comment_ch = '\0';
174 if (flags & PARSE_ALT_COMMENTS)
175 alt_comment_ch = *delims++;
176
171 ntokens = (uint8_t)flags; 177 ntokens = (uint8_t)flags;
172 mintokens = (uint8_t)(flags >> 8); 178 mintokens = (uint8_t)(flags >> 8);
173 179
@@ -184,7 +190,10 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
184 if (flags & PARSE_TRIM) 190 if (flags & PARSE_TRIM)
185 line += strspn(line, delims + 1); 191 line += strspn(line, delims + 1);
186 192
187 if (line[0] == '\0' || line[0] == delims[0]) 193 p = line;
194 if (flags & PARSE_WS_COMMENTS)
195 p = skip_whitespace(p);
196 if (p[0] == '\0' || p[0] == delims[0] || p[0] == alt_comment_ch)
188 goto again; 197 goto again;
189 198
190 if (flags & PARSE_KEEP_COPY) { 199 if (flags & PARSE_KEEP_COPY) {
@@ -201,10 +210,10 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
201 /* Combine remaining arguments? */ 210 /* Combine remaining arguments? */
202 if ((t != (ntokens-1)) || !(flags & PARSE_GREEDY)) { 211 if ((t != (ntokens-1)) || !(flags & PARSE_GREEDY)) {
203 /* Vanilla token, find next delimiter */ 212 /* Vanilla token, find next delimiter */
204 line += strcspn(line, delims[0] ? delims : delims + 1); 213 line += strcspn(line, (delims[0] && (flags & PARSE_EOL_COMMENTS)) ? delims : delims + 1);
205 } else { 214 } else {
206 /* Combining, find comment char if any */ 215 /* Combining, find comment char if any */
207 line = strchrnul(line, PARSE_EOL_COMMENTS ? delims[0] : '\0'); 216 line = strchrnul(line, (flags & PARSE_EOL_COMMENTS) ? delims[0] : '\0');
208 217
209 /* Trim any extra delimiters from the end */ 218 /* Trim any extra delimiters from the end */
210 if (flags & PARSE_TRIM) { 219 if (flags & PARSE_TRIM) {
@@ -214,10 +223,10 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
214 } 223 }
215 224
216 /* Token not terminated? */ 225 /* Token not terminated? */
217 if (*line == delims[0]) 226 if ((flags & PARSE_EOL_COMMENTS) && *line == delims[0])
218 *line = '\0'; 227 *line = '\0'; /* ends with comment char: this line is done */
219 else if (*line != '\0') 228 else if (*line != '\0')
220 *line++ = '\0'; 229 *line++ = '\0'; /* token is done, continue parsing line */
221 230
222#if 0 /* unused so far */ 231#if 0 /* unused so far */
223 if (flags & PARSE_ESCAPE) { 232 if (flags & PARSE_ESCAPE) {