diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-06-01 00:18:02 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-06-01 00:18:02 +0200 |
commit | 666ff89a231b8753f790e833b37537d9d09d5778 (patch) | |
tree | 4764493dd116dd20381a7dece7948014cf543860 | |
parent | 5b1217409fdaec05eb08f94a8db8da78e5f9d46a (diff) |
POTD skeleton #88.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | src/options.c | 26 | ||||
-rw-r--r-- | src/options.h | 5 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/options.c b/src/options.c index 6a122b5..28c9a58 100644 --- a/src/options.c +++ b/src/options.c @@ -98,11 +98,15 @@ static int setopt_list(struct opt *o, const char *optarg) assert(o && o->type != OT_INVALID); - if (o->type == OT_NOARG || !o->is_list) + if (!optarg || o->type == OT_NOARG || !o->is_list) return 1; l = &o->value.list; while (*l) l = &(*l)->next; + *l = (opt_list *) calloc(1, sizeof **l); + + if (opt_convert(o->type, &(*l)->value)) + return 1; o->used = 1; @@ -191,3 +195,23 @@ getopt_str(opt_name on) return str; } + +char * +getopt_strlist(opt_name on, opt_list **ol) +{ + opt_list *o; + + assert(options[on].is_list && ol); + assert(options[on].type == OT_STR || + options[on].type == OT_PATH); + assert(getopt_used(on) && !options[on].def_value.str); + + if (*ol) { + o = (*ol)->next; + } else { + o = options[on].value.list; + } + *ol = o; + + return (o ? o->value.str_dup : NULL); +} diff --git a/src/options.h b/src/options.h index 8ba6016..1b3fe5b 100644 --- a/src/options.h +++ b/src/options.h @@ -1,6 +1,8 @@ #ifndef POTD_OPTIONS_H #define POTD_OPTIONS_H 1 +struct opt_list; + typedef enum opt_name { OPT_LOGTOFILE = 0, OPT_LOGFILE, OPT_LOGLEVEL, OPT_DAEMON, @@ -17,4 +19,7 @@ int getopt_used(opt_name on); char * getopt_str(opt_name on); +char * +getopt_strlist(opt_name on, struct opt_list **ol); + #endif |