site

A custom static site generator written in C.
git clone https://unitehenry.com/git/site.git
Log | Files | Refs | README

commit 8550bf26cc0c2866d1b675dc1c80bfd9a53320d2
parent db2f2daa84a5e0af413f6f6822570f9fc60c6490
Author: Henry Unite <unitehenry@gmail.com>
Date:   Wed,  8 Apr 2026 06:25:00 +0000

feat: string lists

Diffstat:
Mscripts/generate | 2+-
Msrc/main.c | 46+++++++++++-----------------------------------
Asrc/string_list.c | 25+++++++++++++++++++++++++
Asrc/string_list.h | 8++++++++
4 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/scripts/generate b/scripts/generate @@ -1,6 +1,6 @@ #!/usr/bin/env bash -gcc src/main.c -o site +gcc src/*.c -o site if [ $? -eq 0 ]; then chmod +x site diff --git a/src/main.c b/src/main.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <stdlib.h> #include <string.h> +#include "string_list.h" /* * - For each markdown file in `content` (command line arg) @@ -11,49 +12,32 @@ * - Generate output html file equivalent */ char** get_content_files(char* content_path) { - printf("content path: %s\n", content_path); + StringList* list = init_string_list(sizeof(size_t)); struct dirent *de; - DIR *dr = opendir("content"); - - int file_count = 0; + DIR *dr = opendir(content_path); while((de = readdir(dr)) != NULL) { if (strcmp(de->d_name, ".") == 0) { continue; } + if (strcmp(de->d_name, "..") == 0) { continue; } - printf("filename %s; filetype: %i\n", de->d_name, de->d_type); - file_count++; - } - - printf("file count: %i\n", file_count); - - closedir(dr); - char** files = malloc(file_count + 1); - - dr = opendir("content"); - - int file_idx = 0; - - while((de = readdir(dr)) != NULL) { - if (strcmp(de->d_name, ".") == 0) { - continue; + // TODO: recurse directories + if (de->d_type == DT_DIR) { + printf("filename %s; filetype: %i (DT_DIR)\n", de->d_name, de->d_type); } - if (strcmp(de->d_name, "..") == 0) { - continue; - } - files[file_idx] = de->d_name; - file_idx++; + + string_list_append(list, de->d_name); } - files[file_count] = NULL; + closedir(dr); - return files; + return list->strings; } int main(int argc, char **args) { @@ -65,13 +49,5 @@ int main(int argc, char **args) { char** files = get_content_files(args[1]); - int i = 0; - - while(files[i] != NULL) { - printf("filename: %s\n", files[i]); - - i++; - } - return 0; } diff --git a/src/string_list.c b/src/string_list.c @@ -0,0 +1,25 @@ +#include <stddef.h> +#include <stdlib.h> +#include "string_list.h" + +StringList* init_string_list(size_t size) { + StringList* string_list = malloc(sizeof(StringList)); + + string_list->strings = malloc(size * sizeof(char*)); + + string_list->count = 0; + + string_list->size = size; + + return string_list; +} + +void string_list_append(StringList* string_list, char* string) { + if (string_list->count + 1 > string_list->size) { + string_list->strings = realloc(string_list->strings, string_list->size * 2); + string_list->size = string_list->size * 2; + } + + string_list->strings[string_list->count] = string; + string_list->count++; +} diff --git a/src/string_list.h b/src/string_list.h @@ -0,0 +1,8 @@ +typedef struct { + size_t size; + size_t count; + char** strings; +} StringList; + +StringList* init_string_list(size_t size); +void string_list_append(StringList* string_list, char* string);