From b5eebeef24c64020d84211f26e51cce70e402576 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sun, 6 Jun 2021 13:21:17 -0400 Subject: Added a new union called `config_val`. This is so that I don't have to cast the variable as a `void *`, and make it easier to read. I also added `TYPE_NONE` to the `config_type` enum for denoting that the config option doesn't take a value. --- config.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index 9993680..5dbc531 100644 --- a/config.h +++ b/config.h @@ -2,17 +2,18 @@ #define CONFIG_H typedef struct config_opt config_opt; +typedef union config_val config_val; typedef enum config_type config_type; -typedef void (*config_func)(config_opt *, void *); +typedef void (*config_func)(config_opt *, config_val); enum config_type { TYPE_INT, TYPE_STRING, TYPE_FLOAT, TYPE_BOOL, + TYPE_NONE, }; - struct config_opt { const char *name; /* Name of the config option. */ const char *desc; /* Description of the config option. */ @@ -20,6 +21,13 @@ struct config_opt { config_func func; /* Function of the config option. */ }; +union config_val { + int i; /* Integer. */ + char *str; /* String. */ + float f; /* Float. */ + int b : 1; /* Bool. */ +}; + static const config_opt config_opts[] = { /* {"name", "desc", type, &func} */ {"git-root", "Root of git server (can also be a url).", TYPE_STRING, &get_git_root}, -- cgit v1.2.3-13-gbd6f