From 9376c06ded47c4b77b94cb4d1e628537d9d69fce Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Sat, 26 Jul 2025 18:25:04 +0530 Subject: config,main,list: get resources from config.cfg instead of a compiled config.h --- src/main.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index b14a9b7..3ed84a1 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ #define _GNU_SOURCE +#include #include #include #include @@ -17,6 +18,8 @@ #include "../config.h" +#define ASSETS "assets" + template_t *base_template; void @@ -93,6 +96,14 @@ main(int argc, char **argv) (void) argc; (void) argv; + FILE *f = fopen("config.cfg", "r"); + size_t s = fsize(f); + char *content = fcontent(f, s); + fclose(f); + + config_t *config = config_parse(content); + free(content); + struct stat sb; if (stat(DIRECTORY, &sb) != 0 || !S_ISDIR(sb.st_mode)) { printf("%s does not exist.\n", DIRECTORY); @@ -110,22 +121,22 @@ main(int argc, char **argv) nftw( DIRECTORY "/" ASSETS, copy_recursively, 64, FTW_PHYS | FTW_ACTIONRETVAL); - char **x; - char *filepath; + list_t *resources = list_find_corresponding_value_from_ptr_wrapper( + config->keys, config->array_values, "resources"); - for (x = (char **) html_resources; *x != NULL; x++) { - asprintf(&filepath, "%s.html", *x); - printf("HANDLING: %s\n", filepath); - handle_file(filepath); - free(filepath); + if (resources == NULL) { + printf("Could not find resources in config.cfg\n"); + return EXIT_FAILURE; } - for (x = (char **) md_resources; *x != NULL; x++) { - asprintf(&filepath, "%s.md", *x); - printf("HANDLING: %s\n", filepath); - handle_file(filepath); - free(filepath); + for (size_t i = 0; i < resources->size; i++) { + ptr_wrapper_t *value = list_get(resources, i); + char *path = value->ptr; + printf("HANDLING: %s\n", path); + handle_file(path); } + free(config); + return EXIT_SUCCESS; } -- cgit v1.2.3