commit fab07ffbc1c4da23bafef4a43a4086b3c206c9c7
parent 420e41dc8875ddb880fcf5c0e09788c5f18682d8
Author: Henry Unite <unitehenry@gmail.com>
Date: Sat, 11 Apr 2026 23:46:48 +0000
refactor: create subdirectories
Diffstat:
6 files changed, 37 insertions(+), 41 deletions(-)
diff --git a/src/create_subdirectories.c b/src/create_subdirectories.c
@@ -1,37 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-void create_subdirectories(char *filepath) {
- char *path_copy = strdup(filepath);
-
- if (!path_copy)
- return;
-
- char *last_slash = strrchr(path_copy, '/');
-
- if (last_slash) {
- *last_slash = '\0';
- } else {
- free(path_copy);
-
- return;
- }
-
- char *p;
-
- for (p = path_copy + 1; *p; p++) {
- if (*p == '/') {
- *p = '\0';
-
- mkdir(path_copy, 0755);
-
- *p = '/';
- }
- }
-
- mkdir(path_copy, 0755);
-
- free(path_copy);
-}
diff --git a/src/create_subdirectories.h b/src/create_subdirectories.h
@@ -1 +0,0 @@
-void create_subdirectories(char *filepath);
-\ No newline at end of file
diff --git a/src/generate.c b/src/generate.c
@@ -2,6 +2,8 @@
#include <dirent.h>
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
void get_content_files(StringList *list, char *content_path) {
struct dirent *de;
@@ -36,3 +38,36 @@ void get_content_files(StringList *list, char *content_path) {
closedir(dr);
}
+
+void create_subdirectories(char *filepath) {
+ char *path_copy = strdup(filepath);
+
+ if (!path_copy)
+ return;
+
+ char *last_slash = strrchr(path_copy, '/');
+
+ if (last_slash) {
+ *last_slash = '\0';
+ } else {
+ free(path_copy);
+
+ return;
+ }
+
+ char *p;
+
+ for (p = path_copy + 1; *p; p++) {
+ if (*p == '/') {
+ *p = '\0';
+
+ mkdir(path_copy, 0755);
+
+ *p = '/';
+ }
+ }
+
+ mkdir(path_copy, 0755);
+
+ free(path_copy);
+}
diff --git a/src/generate.h b/src/generate.h
@@ -2,5 +2,6 @@
#define GENERATE_H
void get_content_files(StringList *list, char *content_path);
+void create_subdirectories(char *filepath);
#endif
diff --git a/src/generate_pages.c b/src/generate_pages.c
@@ -1,7 +1,7 @@
-#include "create_subdirectories.h"
#include "run_pandoc.h"
#include "strings.h"
#include "to_write_path.h"
+#include "generate.h"
#include <stdio.h>
#include <string.h>
diff --git a/src/generate_pages.h b/src/generate_pages.h
@@ -1,4 +1,3 @@
-#include "create_subdirectories.h"
#include "run_pandoc.h"
#include "strings.h"
#include "to_write_path.h"