diff --git a/gossipd/gossipd.h b/gossipd/gossipd.h index 650d87a5c..0b3b26455 100644 --- a/gossipd/gossipd.h +++ b/gossipd/gossipd.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include #include /* We talk to `hsmd` to sign our gossip messages with the node key */ diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 83fb2745f..2a34f572e 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -69,7 +69,6 @@ #include #include #include -#include #include #include #include diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 22e47010e..b41b86c8b 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include #include #include #include diff --git a/lightningd/options.c b/lightningd/options.c index 968f0ae82..d5311314c 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -102,6 +102,41 @@ static char *opt_set_s32(const char *arg, s32 *u) return NULL; } +char *opt_set_autobool_arg(const char *arg, enum opt_autobool *b) +{ + if (!strcasecmp(arg, "yes") || + !strcasecmp(arg, "true")) { + *b = OPT_AUTOBOOL_TRUE; + return NULL; + } + if (!strcasecmp(arg, "no") || + !strcasecmp(arg, "false")) { + *b = OPT_AUTOBOOL_FALSE; + return NULL; + } + if (!strcasecmp(arg, "auto") || + !strcasecmp(arg, "default")) { + *b = OPT_AUTOBOOL_AUTO; + return NULL; + } + return opt_invalid_argument(arg); +} + +void opt_show_autobool(char buf[OPT_SHOW_LEN], const enum opt_autobool *b) +{ + switch (*b) { + case OPT_AUTOBOOL_TRUE: + strncpy(buf, "true", OPT_SHOW_LEN); + break; + case OPT_AUTOBOOL_FALSE: + strncpy(buf, "false", OPT_SHOW_LEN); + break; + case OPT_AUTOBOOL_AUTO: + default: + strncpy(buf, "auto", OPT_SHOW_LEN); + } +} + static char *opt_set_mode(const char *arg, mode_t *m) { char *endp; diff --git a/lightningd/options.h b/lightningd/options.h index f46a86bda..55054f994 100644 --- a/lightningd/options.h +++ b/lightningd/options.h @@ -1,6 +1,7 @@ #ifndef LIGHTNING_LIGHTNINGD_OPTIONS_H #define LIGHTNING_LIGHTNINGD_OPTIONS_H #include "config.h" +#include struct lightningd; @@ -13,4 +14,12 @@ void handle_opts(struct lightningd *ld, int argc, char *argv[]); /* Derive default color and alias from the pubkey. */ void setup_color_and_alias(struct lightningd *ld); +enum opt_autobool { + OPT_AUTOBOOL_FALSE = 0, + OPT_AUTOBOOL_TRUE = 1, + OPT_AUTOBOOL_AUTO = 2, +}; +char *opt_set_autobool_arg(const char *arg, enum opt_autobool *b); +void opt_show_autobool(char buf[OPT_SHOW_LEN], const enum opt_autobool *b); + #endif /* LIGHTNING_LIGHTNINGD_OPTIONS_H */