site

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

commit a5704f3f9e91a7c19088e305ca874ca4dad58663
parent 59268ded03b095b5bd16d1e323932f100ce56053
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sat, 11 Apr 2026 23:33:40 +0000

feat: init strings

Diffstat:
MREADME.md | 6+++---
Msrc/generate_pages.c | 2+-
Msrc/generate_pages.h | 8+-------
Msrc/get_content_files.c | 5++---
Msrc/get_content_files.h | 8+-------
Dsrc/string_list.c | 37-------------------------------------
Dsrc/string_list.h | 15---------------
Asrc/strings.c | 37+++++++++++++++++++++++++++++++++++++
Asrc/strings.h | 15+++++++++++++++
9 files changed, 60 insertions(+), 73 deletions(-)

diff --git a/README.md b/README.md @@ -23,15 +23,15 @@ Modules ``` main +string_list -> strings +string_replace -> strings +trim_whitespace -> strings get_content_files -> content generate_pages -> generate create_subdirectories -> generate (private) path_root -> generate (private) run_pandoc -> generate (private) to_write_path -> genrate (private) -string_list -> strings -string_replace -> strings -trim_whitespace -> strings ``` TODO: main constants -> env vars diff --git a/src/generate_pages.c b/src/generate_pages.c @@ -1,8 +1,8 @@ #include "create_subdirectories.h" #include "run_pandoc.h" -#include "string_list.h" #include "to_write_path.h" #include "trim_whitespace.h" +#include "strings.h" #include <stdio.h> #include <string.h> diff --git a/src/generate_pages.h b/src/generate_pages.h @@ -1,11 +1,6 @@ -#ifndef GENERATE_PAGES_H -#define GENERATE_PAGES_H - #include "create_subdirectories.h" #include "run_pandoc.h" -#include "string_list.h" +#include "strings.h" #include "to_write_path.h" void generate_pages(StringList *list); - -#endif -\ No newline at end of file diff --git a/src/get_content_files.c b/src/get_content_files.c @@ -1,4 +1,4 @@ -#include "string_list.h" +#include "strings.h" #include <dirent.h> #include <stdio.h> #include <string.h> @@ -35,4 +35,4 @@ void get_content_files(StringList *list, char *content_path) { } closedir(dr); -} -\ No newline at end of file +} diff --git a/src/get_content_files.h b/src/get_content_files.h @@ -1,8 +1,3 @@ -#ifndef GET_CONTENT_FILES_H -#define GET_CONTENT_FILES_H - -#include "string_list.h" +#include "strings.h" void get_content_files(StringList *list, char *content_path); - -#endif -\ No newline at end of file diff --git a/src/string_list.c b/src/string_list.c @@ -1,37 +0,0 @@ -#include "string_list.h" -#include <stddef.h> -#include <stdlib.h> -#include <string.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; - - if (size > 0) { - string_list->strings[0] = NULL; - } - - 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) * sizeof(char *)); - string_list->size = string_list->size * 2; - } - - size_t len = strlen(string) + 1; - char *str = malloc(len); - - strcpy(str, string); - - string_list->strings[string_list->count] = str; - string_list->count++; - string_list->strings[string_list->count] = NULL; -} diff --git a/src/string_list.h b/src/string_list.h @@ -1,15 +0,0 @@ -#ifndef STRING_LIST_H -#define STRING_LIST_H - -#include <stddef.h> - -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); - -#endif diff --git a/src/strings.c b/src/strings.c @@ -0,0 +1,37 @@ +#include "strings.h" +#include <stddef.h> +#include <stdlib.h> +#include <string.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; + + if (size > 0) { + string_list->strings[0] = NULL; + } + + 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) * sizeof(char *)); + string_list->size = string_list->size * 2; + } + + size_t len = strlen(string) + 1; + char *str = malloc(len); + + strcpy(str, string); + + string_list->strings[string_list->count] = str; + string_list->count++; + string_list->strings[string_list->count] = NULL; +} diff --git a/src/strings.h b/src/strings.h @@ -0,0 +1,15 @@ +#ifndef STRINGS_H +#define STRINGS_H + +#include <stddef.h> + +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); + +#endif