diff options
Diffstat (limited to 'core/defconf.c')
| -rw-r--r-- | core/defconf.c | 70 |
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; +} |
