summaryrefslogtreecommitdiff
path: root/config.h
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-07 19:12:29 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-07 19:12:29 -0400
commit77b9052ac307ffcd15e5785668d704b5e46371d4 (patch)
tree0d66a8441cb65a20e12d25a15f02600804669a80 /config.h
parenta4a50055dc52c86cab350561d2cb62a284b5ece5 (diff)
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.
Diffstat (limited to 'config.h')
-rw-r--r--config.h19
1 files 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 <stddef.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 *, 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},
};