From a622d01c581b18335670c7a473ed9a729d63a556 Mon Sep 17 00:00:00 2001 From: verdant Date: Wed, 20 May 2026 23:45:48 +0800 Subject: refactor: implement data-driven config parsing using `offsetof` Replace the bloated, hardcoded if-else chains in parse_config with a static lookup table based on offsetof --- config.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'config.h') diff --git a/config.h b/config.h index dfe754e..2b1825b 100644 --- a/config.h +++ b/config.h @@ -3,6 +3,7 @@ #include #include +#include #include #define PROGRAM_NAME "kl" @@ -27,12 +28,28 @@ struct config { bool time; bool keys_counter; bool show_shifted; + bool repeat; }; struct config *parese_config(struct config *cfg); - struct config *prepare_config_file(); - struct config *config_init(); +typedef enum { + CFG_TYPE_BOOL, + CFG_TYPE_STR, +} cfg_type; + +struct config_item { + char *key; + cfg_type type; + size_t offset; +}; + +extern struct config_item ci[]; + +void* get_member(struct config_item*, size_t offset); + +#define CI_SIZE (int)(sizeof(ci) / sizeof(ci[0])) + #endif -- cgit v1.2.3