diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-06 13:21:17 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-06 13:21:17 -0400 |
commit | b5eebeef24c64020d84211f26e51cce70e402576 (patch) | |
tree | 4f69369347dd695a30d1302336371812739e3163 /config.h | |
parent | fafa513041fb13f679dfe107749aa2a8223040e3 (diff) |
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.
Diffstat (limited to 'config.h')
-rw-r--r-- | config.h | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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}, |