diff options
| author | verdant <i@glowisle.me> | 2026-05-20 23:45:48 +0800 |
|---|---|---|
| committer | verdant <i@glowisle.me> | 2026-05-20 23:45:48 +0800 |
| commit | a622d01c581b18335670c7a473ed9a729d63a556 (patch) | |
| tree | 2438dbb6099e31143e9c5fea1c8735bd8796460b /config.h | |
| parent | 9c7a531c6a60a4263de044d0fa80880a518f4a4b (diff) | |
| download | kl-a622d01c581b18335670c7a473ed9a729d63a556.tar.gz kl-a622d01c581b18335670c7a473ed9a729d63a556.zip | |
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
Diffstat (limited to 'config.h')
| -rw-r--r-- | config.h | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -3,6 +3,7 @@ #include <stdbool.h> #include <stdlib.h> +#include <stddef.h> #include <string.h> #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 |
