summaryrefslogtreecommitdiff
path: root/core/defconf.c
diff options
context:
space:
mode:
authorChloe M. <chloe@aptel.org>2026-08-23 04:49:51 +0000
committerChloe M. <chloe@aptel.org>2026-08-23 04:49:51 +0000
commit78b925a4d86b57e58e6322b7cad7bc47098618fd (patch)
treee66da7a598bb4be1ca869f72600112dda34a4067 /core/defconf.c
initial commit
There is some work to be done on top of this such as creating a way to manage memory to be freed later without needing to manually manage every pointer. Signed-off-by: Chloe M. <chloe@aptel.org>
Diffstat (limited to 'core/defconf.c')
-rw-r--r--core/defconf.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/core/defconf.c b/core/defconf.c
new file mode 100644
index 0000000..4444179
--- /dev/null
+++ b/core/defconf.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "defconf/state.h"
+
+/* Globals */
+static char *config_path = NULL;
+
+static void
+help(void)
+{
+ printf("usage: ./defconf [flags]\n");
+ printf("[-h] Display this help menu\n");
+ printf("[-c] Target config file\n");
+}
+
+static int
+defconf_run(void)
+{
+ struct defconf_state state;
+
+ if (defconf_state_init(config_path, &state) < 0) {
+ return -1;
+ }
+
+ defconf_state_destroy(&state);
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ int opt, retval;
+
+ if (argc < 2) {
+ printf("fatal: too few arguments\n");
+ help();
+ return -1;
+ }
+
+ while ((opt = getopt(argc, argv, "hc:")) != -1) {
+ switch (opt) {
+ case 'h':
+ help();
+ return -1;
+ case 'c':
+ if ((config_path = strdup(optarg)) == NULL) {
+ printf("fatal: out of memory\n");
+ return -1;
+ }
+
+ break;
+ }
+ }
+
+ if (config_path == NULL) {
+ printf("fatal: expected config path\n");
+ return -1;
+ }
+
+ retval = defconf_run();
+ free(config_path);
+ return retval;
+}