diff options
author | Thomas Adam <thomas@xteddy.org> | 2021-10-14 16:01:20 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2021-10-14 16:01:20 +0100 |
commit | 264fe7fc2ac87ee1d337506606f45b3ee4028afe (patch) | |
tree | 43a1dc9eb44d6a367404a2a67701c7b47f5680b3 /options.c | |
parent | ee9885a40ced1fd34fe2eed879a40975a0691ac8 (diff) | |
parent | add20637f256c0118d3c687d5d1446612d14389a (diff) | |
download | rtmux-264fe7fc2ac87ee1d337506606f45b3ee4028afe.tar.gz rtmux-264fe7fc2ac87ee1d337506606f45b3ee4028afe.tar.bz2 rtmux-264fe7fc2ac87ee1d337506606f45b3ee4028afe.zip |
Merge branch 'obsd-master' into master
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -989,28 +989,39 @@ options_from_string_flag(struct options *oo, const char *name, return (0); } +int +options_find_choice(const struct options_table_entry *oe, const char *value, + char **cause) +{ + const char **cp; + int n = 0, choice = -1; + + for (cp = oe->choices; *cp != NULL; cp++) { + if (strcmp(*cp, value) == 0) + choice = n; + n++; + } + if (choice == -1) { + xasprintf(cause, "unknown value: %s", value); + return (-1); + } + return (choice); +} + static int options_from_string_choice(const struct options_table_entry *oe, struct options *oo, const char *name, const char *value, char **cause) { - const char **cp; - int n, choice = -1; + int choice = -1; if (value == NULL) { choice = options_get_number(oo, name); if (choice < 2) choice = !choice; } else { - n = 0; - for (cp = oe->choices; *cp != NULL; cp++) { - if (strcmp(*cp, value) == 0) - choice = n; - n++; - } - if (choice == -1) { - xasprintf(cause, "unknown value: %s", value); + choice = options_find_choice(oe, value, cause); + if (choice < 0) return (-1); - } } options_set_number(oo, name, choice); return (0); |