From 2b57cfcc59035cc06e490c58076d31698db41276 Mon Sep 17 00:00:00 2001 From: darosior Date: Tue, 4 Feb 2020 22:00:22 +0100 Subject: [PATCH] ccan: retrieve last updates to opt/ Co-authored-by: Rusty Russell --- ccan/ccan/opt/opt.c | 17 +++++++++++++++++ ccan/ccan/opt/opt.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/ccan/ccan/opt/opt.c b/ccan/ccan/opt/opt.c index 0514dc870..d4601dfbb 100644 --- a/ccan/ccan/opt/opt.c +++ b/ccan/ccan/opt/opt.c @@ -176,6 +176,23 @@ void _opt_register(const char *names, enum opt_type type, add_opt(&opt); } +bool opt_unregister(const char *names) +{ + int found = -1, i; + + for (i = 0; i < opt_count; i++) { + if (opt_table[i].type == OPT_SUBTABLE) + continue; + if (strcmp(opt_table[i].names, names) == 0) + found = i; + } + if (found == -1) + return false; + opt_count--; + memmove(&opt_table[found], &opt_table[found+1], opt_count - found); + return true; +} + void opt_register_table(const struct opt_table entry[], const char *desc) { unsigned int i, start = opt_count; diff --git a/ccan/ccan/opt/opt.h b/ccan/ccan/opt/opt.h index c642ec6fa..6f4b9dda8 100644 --- a/ccan/ccan/opt/opt.h +++ b/ccan/ccan/opt/opt.h @@ -228,6 +228,15 @@ void opt_register_table(const struct opt_table *table, const char *desc); _opt_register((names), OPT_CB_ARG((cb), OPT_EARLY, (show),(arg)), \ (arg), (desc)) +/** + * opt_unregister - unregister an option. + * @names: the names it was registered with. + * + * This undoes opt_register[_early]_[no]arg. Returns true if the option was + * found, otherwise false. + */ +bool opt_unregister(const char *names); + /** * opt_parse - parse arguments. * @argc: pointer to argc