From 77b9052ac307ffcd15e5785668d704b5e46371d4 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Mon, 7 Jun 2021 19:12:29 -0400 Subject: Replace `func` in config_opt with `offset`. `offset` is the offset of the member of the config option in the `config` struct. This was done in order to allow for setting any member of the config struct with just a single function. --- config.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/config.h b/config.h index 9835033..036d7ca 100644 --- a/config.h +++ b/config.h @@ -1,10 +1,11 @@ #ifndef CONFIG_H #define CONFIG_H +#include + typedef struct config_opt config_opt; typedef union config_val config_val; typedef enum config_type config_type; -typedef void (*config_func)(config_opt *, config_val); enum config_type { TYPE_NONE, @@ -19,7 +20,7 @@ struct config_opt { const char *name; /* Name of the config option. */ const char *desc; /* Description of the config option. */ config_type type; /* Datatype of the config option. */ - config_func func; /* Function of the config option. */ + size_t offset; /* Offset of the member of the config option in the config struct. */ }; union config_val { @@ -31,13 +32,13 @@ union config_val { 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}, - {"socket-type", "Socket type to use (options: unix, network. default: network).", TYPE_STRING, &get_sock_type}, - {"socket", "Path, IP address, or domain name of socket.", TYPE_STRING, &get_sock}, - {"port", "Port to listen on (network socket only).", TYPE_INT, &get_sock_port}, - {"merge-type", "Type of merge (options: 0 = Merge individually, 1 = Merge into one).", TYPE_INT, &get_merge_type}, - {"pr-root", "Directory to store pull requests in.", TYPE_STRING, &pr_root}, - {"key-file", "Path to file containing gpg/pgp public keys of each maintainer.", TYPE_STRING, &get_key_path}, + {"git-root", "Root of git server (can also be a url).", TYPE_STRING, offsetof(config, git_root)}, + {"socket-type", "Socket type to use (options: unix, network. default: network).", TYPE_STRING, offsetof(config, sock_type)}, + {"socket", "Path, IP address, or domain name of socket.", TYPE_STRING, offsetof(config, sock)}, + {"port", "Port to listen on (network socket only).", TYPE_INT, offsetof(config, sock_port)}, + {"merge-type", "Type of merge (options: 0 = Merge individually, 1 = Merge into one).", TYPE_INT, offsetof(config, merge_type)}, + {"pr-root", "Directory to store pull requests in.", TYPE_STRING, offsetof(config, pr_root)}, + {"key-file", "Path to file containing gpg/pgp public keys of each maintainer.", TYPE_STRING, offsetof(config, key_path)}, {NULL, NULL, TYPE_NONE, NULL}, }; -- cgit v1.2.3-13-gbd6f