diff options
| author | Raghuram Subramani <raghus2247@gmail.com> | 2025-06-17 12:43:31 +0530 |
|---|---|---|
| committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-06-17 12:43:31 +0530 |
| commit | 8f09884fa5af21358fd34f9fd98b130a0318a696 (patch) | |
| tree | 0de27ee4df62c04b7eacb4a6dcd7b94d65ddf4bc /msg.c | |
| parent | 052d81f790ca89308908fd0e1dfa6b68ce0e7b68 (diff) | |
(config): manually define resources instead of automatically finding them
Diffstat (limited to 'msg.c')
| -rw-r--r-- | msg.c | 70 |
1 files changed, 38 insertions, 32 deletions
@@ -2,6 +2,7 @@ #include <ctype.h> #include <ftw.h> +#include <libgen.h> #include <mkdio.h> #include <regex.h> #include <stdbool.h> @@ -182,9 +183,34 @@ handle_file(const char *path) asprintf(&outpath, "%s/%s", OUTPUT, path); } + char *directory = dirname(strdup(outpath)); + char *next = calloc(strlen(directory) + 1, sizeof(char)); + strcpy(next, ""); + + char *token; + for (token = strtok(directory, "/"); token != NULL; + token = strtok(NULL, "/")) { + if (strcmp(next, "") != 0) { + strcat(next, "/"); + } + + strcat(next, token); + mkdir(next, 0700); + } + FILE *in = fopen(inpath, "r"); FILE *out = fopen(outpath, "w"); + if (in == NULL) { + printf("Failed to open %s\n", inpath); + return; + } + + if (out == NULL) { + printf("Failed to open %s\n", outpath); + return; + } + unsigned int size = fsize(in); char *buffer = fcontent(in, size); @@ -201,38 +227,10 @@ handle_file(const char *path) fclose(in); fclose(out); - free(buffer); -} - -int -fn(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) -{ - (void) sb; - - const char *basename = fpath + ftwbuf->base; - const char *path = fpath + strlen(DIRECTORY) + 1; - char *output_path = NULL; - asprintf(&output_path, "%s/%s", OUTPUT, path); - - if (typeflag == FTW_D) { - if (strcmp(basename, PARTIALS) == 0 || strcmp(basename, ASSETS) == 0) - return FTW_SKIP_SUBTREE; - - mkdir(output_path, 0700); - - return FTW_CONTINUE; - } - - if (typeflag != FTW_F) - return FTW_CONTINUE; + free(inpath); + free(outpath); - if (ftwbuf->level == 1 && strcmp(basename, BASE_TEMPLATE) == 0) - return FTW_CONTINUE; - - printf("handling: %s\n", path); - handle_file(path); - - return FTW_CONTINUE; + free(buffer); } int @@ -257,7 +255,15 @@ main(int argc, char **argv) fclose(base); mkdir(OUTPUT, 0700); - nftw(DIRECTORY, fn, 64, FTW_PHYS | FTW_ACTIONRETVAL); + + char **x; + char *filepath; + + for (x = (char **) html_resources; *x != NULL; x++) { + asprintf(&filepath, "%s.html", *x); + handle_file(filepath); + free(filepath); + } free(base_pre); free(base_post); |
