From 70dc340b3ed7f599dbd4f1576d8270e8fe2e8f9a Mon Sep 17 00:00:00 2001 From: swym <0xfd000000@gmail.com> Date: Tue, 27 Aug 2019 20:56:57 +0200 Subject: [PATCH] card10.cfg: use X-macro idion for declaring settings --- epicardium/modules/config.c | 18 +++++++++++++++--- epicardium/modules/config.def | 11 +++++++++++ epicardium/modules/config.h | 3 ++- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 epicardium/modules/config.def diff --git a/epicardium/modules/config.c b/epicardium/modules/config.c index 5be76cd9..2c41f814 100644 --- a/epicardium/modules/config.c +++ b/epicardium/modules/config.c @@ -30,9 +30,21 @@ struct config_option { }; static struct config_option s_options[_EpicOptionCount] = { - [OptionExecuteElf] = { .name = "execute_elf", - .type = OptionType_Boolean, - .value = { .boolean = false } }, +/* clang-format off */ + #define INIT_Boolean(v) { .boolean = (v) } + #define INIT_Int(v) { .integer = (v) } + #define INIT_Float(v) { .floating_point = (v) } + #define INIT_String(v) { .string = (v) } + #define INIT_(tp, v) INIT_ ## tp (v) + #define INIT(tp, v) INIT_ (tp, v) + + #define CARD10_SETTING(identifier, spelling, tp, default_value) \ + [Option ## identifier] = { .name = (spelling), \ + .type = OptionType_ ## tp, \ + .value = INIT(tp, (default_value)) }, + + #include "modules/config.def" + /* clang-format on */ }; static struct config_option *findOption(const char *key) diff --git a/epicardium/modules/config.def b/epicardium/modules/config.def new file mode 100644 index 00000000..455aaedd --- /dev/null +++ b/epicardium/modules/config.def @@ -0,0 +1,11 @@ +#ifndef CARD10_SETTING +# define CARD10_SETTING(identifier, spelling, type, default_value) +#endif + +CARD10_SETTING(ExecuteElf, "execute_elf", Boolean, false) +//CARD10_SETTING(Nick, "nick", String, "an0n") +//CARD10_SETTING(Timeout, "timeout", Integer, 123) +//CARD10_SETTING(Dampening, "dampening", Float, 420) + + +#undef CARD10_SETTING diff --git a/epicardium/modules/config.h b/epicardium/modules/config.h index cfde8b16..b72b08a5 100644 --- a/epicardium/modules/config.h +++ b/epicardium/modules/config.h @@ -4,7 +4,8 @@ #include <stdbool.h> enum EpicConfigOption { - OptionExecuteElf, + #define CARD10_SETTING(identifier, spelling, type, default_value) Option ## identifier, + #include "modules/config.def" _EpicOptionCount }; -- GitLab