summaryrefslogtreecommitdiff
path: root/src/skonfig.c
diff options
context:
space:
mode:
authorDennis Camera <skonfig@dtnr.ch>2022-08-03 17:42:18 +0200
committerDennis Camera <skonfig@dtnr.ch>2022-08-03 17:58:19 +0200
commitfdccc8b948a4df3b6a2c3dcd6990c05bf8afdb27 (patch)
tree0f42c4d95649ba3e6a181659a0bd053604b499ec /src/skonfig.c
parent26f555c974cf49def75120dada596f421e15f1d4 (diff)
downloadskonfig-c-fdccc8b948a4df3b6a2c3dcd6990c05bf8afdb27.tar.gz
skonfig-c-fdccc8b948a4df3b6a2c3dcd6990c05bf8afdb27.zip
[src/config.c] Add config module (does not parse INI files, yet)
Diffstat (limited to 'src/skonfig.c')
-rw-r--r--src/skonfig.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/skonfig.c b/src/skonfig.c
index 08169fd..1b97adf 100644
--- a/src/skonfig.c
+++ b/src/skonfig.c
@@ -160,6 +160,39 @@ static int sk_get_global_opts(
return true;
}
+/* config */
+
+void sk_init_config(struct sk_config *config, const char *config_file) {
+ FILE *fh;
+
+ if (config_file) {
+ /* Parse config file (as given by option) */
+ printf("processing config file (opt): %s\n", config_file);
+
+ fh = fopen(config_file, "r");
+ if (fh) {
+ sk_config_parse_file(config, fh);
+ fclose(fh);
+ } else {
+ fprintf(stderr, "invalid config file: %s\n", config_file);
+ exit(1);
+ }
+ } else if ((config_file = sk_config_find())) {
+ /* found a config file in default location */
+ printf("processing config file (found): %s\n", config_file);
+
+ fh = fopen(config_file, "r");
+ sk_config_parse_file(config, fh);
+ fclose(fh);
+
+ free((void *)config_file);
+ }
+
+ sk_config_parse_env(config);
+}
+
+
+
int main(int argc, char *argv[]) {
EXECNAME = argv[0];
@@ -193,8 +226,26 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
+ /* Read in skonfig config */
+ struct sk_config *config = sk_config_alloc();
+ sk_init_config(config, NULL);
+
+ /* update config from command line arguments */
+ config->global.init_manifest = strdup(options.init_manifest);
+ config->global.jobs = options.jobs;
+
+ config->global.verbosity_level += options.verbosity;
+ if (config->global.verbosity_level > SK_LOG_MAX)
+ config->global.verbosity_level = SK_LOG_MAX;
+
+#if DEBUG
+ sk_config_print(config, stdout); /* DEBUG */
+#endif
+
printf("conf dir: %s\n", options.conf_root);
printf("target host: %s\n", options.target_host);
+ sk_config_free(config);
+
return EXIT_SUCCESS;
}