aboutsummaryrefslogtreecommitdiff
path: root/src/engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine.c')
-rw-r--r--src/engine.c52
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);
+ }
+}