diff options
Diffstat (limited to 'lib/libcfg/rdcfg.c')
-rw-r--r-- | lib/libcfg/rdcfg.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/libcfg/rdcfg.c b/lib/libcfg/rdcfg.c index 71a994f..ccbcf7b 100644 --- a/lib/libcfg/rdcfg.c +++ b/lib/libcfg/rdcfg.c @@ -19,6 +19,7 @@ #include <string.h> #include <stdio.h> +#include <ctype.h> static const cfg_param_t *find_param(rdline_t *rd, const char *name, const cfg_param_t *params, size_t count) @@ -35,6 +36,33 @@ static const cfg_param_t *find_param(rdline_t *rd, const char *name, return NULL; } +static int splitkv(rdline_t *rd, char **k, char **v) +{ + char *key = rd->line, *value = rd->line; + + while (*value != ' ' && *value != '\0') { + if (!isalpha(*value)) { + fprintf(stderr, + "%s: %zu: unexpected '%c' in keyword\n", + rd->filename, rd->lineno, *value); + return -1; + } + ++value; + } + + if (*value != ' ') { + fprintf(stderr, "%s: %zu: expected argument after '%s'\n", + rd->filename, rd->lineno, key); + return -1; + } + + *(value++) = '\0'; + + *k = key; + *v = value; + return 0; +} + int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count, int flags) { @@ -61,9 +89,9 @@ int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count, } while ((ret = rdline(rd)) == 0) { - if (strcmp(rd->buffer, "}") == 0) + if (strcmp(rd->line, "}") == 0) break; - if (p->handle(cfgobj, rd->buffer, rd, flags)) + if (p->handle(cfgobj, rd->line, rd, flags)) return -1; } |