summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko2008-07-20 17:58:12 +0000
committerDenis Vlasenko2008-07-20 17:58:12 +0000
commiteb7512984a26baab2db1913c38a7107f745a70ab (patch)
tree6640c564d8d7865a5218f8224bf69b88c1c6958f /networking
parent9b366f41367f717d8ddd9909fdc710b92f92a16c (diff)
downloadbusybox-eb7512984a26baab2db1913c38a7107f745a70ab.zip
busybox-eb7512984a26baab2db1913c38a7107f745a70ab.tar.gz
udhcp: use libbb for config file parsing (by Vladimir)
function old new delta read_config 313 230 -83
Diffstat (limited to 'networking')
-rw-r--r--networking/udhcp/files.c49
1 files changed, 16 insertions, 33 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index eaa50b8..fe6bff4 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -307,53 +307,36 @@ static const struct config_keyword keywords[] = {
};
enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
-
-/*
- * Domain names may have 254 chars, and string options can be 254
- * chars long. However, 80 bytes will be enough for most, and won't
- * hog up memory. If you have a special application, change it
- */
-#define READ_CONFIG_BUF_SIZE 80
-
void read_config(const char *file)
{
- FILE *in;
- char buffer[READ_CONFIG_BUF_SIZE], *token, *line;
- unsigned i, lineno;
+ parser_t *parser;
+ const struct config_keyword *k;
+ unsigned i;
+ char *token[2];
for (i = 0; i < KWS_WITH_DEFAULTS; i++)
keywords[i].handler(keywords[i].def, keywords[i].var);
- in = fopen_or_warn(file, "r");
- if (!in)
+ parser = config_open(file);
+ if (!parser)
return;
- lineno = 0;
- while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) {
- lineno++;
- /* *strchrnul(buffer, '\n') = '\0'; - trim() will do it */
- *strchrnul(buffer, '#') = '\0';
-
- token = strtok(buffer, " \t");
- if (!token) continue;
- line = strtok(NULL, "");
- if (!line) continue;
-
- trim(line); /* remove leading/trailing whitespace */
-
- for (i = 0; i < ARRAY_SIZE(keywords); i++) {
- if (!strcasecmp(token, keywords[i].keyword)) {
- if (!keywords[i].handler(line, keywords[i].var)) {
- bb_error_msg("can't parse line %u in %s at '%s'",
- lineno, file, line);
+ while (config_read(parser, token, 2, 0, "# \t", PARSE_LAST_IS_GREEDY)) {
+ if (!token[1])
+ continue;
+ for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
+ if (!strcasecmp(token[0], k->keyword)) {
+ if (!k->handler(token[1], k->var)) {
+ bb_error_msg("can't parse line %u in %s",
+ parser->lineno, file);
/* reset back to the default value */
- keywords[i].handler(keywords[i].def, keywords[i].var);
+ k->handler(k->def, k->var);
}
break;
}
}
}
- fclose(in);
+ config_close(parser);
server_config.start_ip = ntohl(server_config.start_ip);
server_config.end_ip = ntohl(server_config.end_ip);