diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-06-19 11:53:16 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-06-19 11:53:16 +0530 |
commit | 7698d438f594665661edf90964f92591b7a29556 (patch) | |
tree | 7c92c3ff429c15a1b97ec13c125f1f32e8613f76 /src/engine.c | |
parent | bfdbb1e1316225f5bff0309a1b9008dcff567cf5 (diff) |
(misc): modularize program
Diffstat (limited to 'src/engine.c')
-rw-r--r-- | src/engine.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/engine.c b/src/engine.c new file mode 100644 index 0000000..4e4d037 --- /dev/null +++ b/src/engine.c @@ -0,0 +1,52 @@ +#define _GNU_SOURCE + +#include <engine.h> +#include <filehandler.h> +#include <lexer.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> + +#include "../config.h" + +void +ingest(char **buffer) +{ + key_match_t *match; + + while (true) { + match = find_next_key(*buffer); + if (match == NULL) + break; + + directive_t *directive = find_directive(*buffer, match); + if (directive == NULL) + break; + + if (directive->type == INCLUDE) { + char *operand = (char *) directive->operands; + char *partial_path; + asprintf(&partial_path, "%s/%s/%s", DIRECTORY, PARTIALS, operand); + + FILE *f = fopen(partial_path, "r"); + unsigned int size = fsize(f); + char *partial_content = fcontent(f, size); + + char *temp_buffer; + asprintf(&temp_buffer, "%s", *buffer); + + free(*buffer); + asprintf(buffer, + "%.*s%s%s\n", + match->offset, + temp_buffer, + partial_content, + temp_buffer + match->offset + match->length); + + free(temp_buffer); + } + + free(directive); + free(match); + } +} |