diff options
Diffstat (limited to 'src/engine.c')
-rw-r--r-- | src/engine.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/engine.c b/src/engine.c index 1cb3ae7..3d46373 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3,6 +3,7 @@ #include <engine.h> #include <filehandler.h> #include <lexer.h> +#include <list.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -13,6 +14,11 @@ void ingest(char **buffer) { key_match_t *match; + list_t *content_headers = list_create(sizeof(contentfor_operand_t)); + if (content_headers == NULL) { + printf("Could not create content_headers\n"); + return; + } while (true) { match = find_next_key(*buffer); @@ -29,7 +35,7 @@ ingest(char **buffer) switch (directive->type) { case INCLUDE: { - char *operand = (char *) directive->operands; + char *operand = directive->operands; char *partial_path; asprintf(&partial_path, "%s/%s/%s", DIRECTORY, PARTIALS, operand); @@ -57,12 +63,27 @@ ingest(char **buffer) break; } case CONTENTFOR: { - contentfor_operands_t *operand - = (contentfor_operands_t *) directive->operands; - printf("CONTENTFOR: %s\n", operand->key); - printf("CONTENT: %s\n", operand->content); + contentfor_operand_t *operand = directive->operands; + list_add(content_headers, operand); + + /* printf("CONTENTFOR: %s\n", operand->key); */ + /* printf("CONTENT: %s\n", operand->content); */ + + /* printf("CONTENT: %.*s\n", operand->length, *buffer + match->offset); + */ + + char *temp_buffer; + asprintf(&temp_buffer, "%s", *buffer); - return; + free(*buffer); + asprintf(buffer, + "%.*s%s", + match->offset, + temp_buffer, + temp_buffer + operand->length); + + free(temp_buffer); + /* free(operand); */ break; } @@ -77,4 +98,12 @@ ingest(char **buffer) if (match != NULL) free(match); } + + for (size_t i = 0; i < content_headers->size; i++) { + contentfor_operand_t *op = list_get(content_headers, i); + free(op->content); + free(op->key); + } + + list_delete(content_headers); } |