aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/template.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/template.c b/src/template.c
index e8f8fd5..7a0b64b 100644
--- a/src/template.c
+++ b/src/template.c
@@ -1,7 +1,9 @@
#define _GNU_SOURCE
+#include <engine.h>
#include <filehandler.h>
#include <lexer.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <template.h>
@@ -12,22 +14,46 @@ template_t *
template_create(void)
{
template_t *template = malloc(sizeof(template_t));
+ template->components = list_create(sizeof(directive_t));
FILE *base = fopen(DIRECTORY "/" BASE_TEMPLATE, "r");
unsigned int size = fsize(base);
- char *contents = fcontent(base, size);
+ char *buffer = fcontent(base, size);
fclose(base);
- key_match_t *match = find_next_key(contents);
+ key_match_t *match;
+ while (true) {
+ match = find_next_key(buffer);
+ if (match == NULL)
+ break;
- asprintf(&template->pre, "%.*s", match->offset, contents);
- asprintf(&template->post,
- "%.*s",
- size - match->offset - match->length,
- contents + match->offset + match->length);
+ directive_t *directive = find_directive(buffer, match);
+ if (directive == NULL) {
+ printf(
+ "Unknown directive: %.*s\n", match->length, buffer + match->offset);
+
+ break;
+ }
+
+ switch (directive->type) {
+ case CONTENT:
+ case BODY:
+ break;
+
+ /* TODO: Handle this gracefully */
+ case INCLUDE:
+ case CONTENTFOR:
+ case ENDCONTENT:
+ break;
+ }
+
+ if (directive != NULL)
+ free(directive);
+
+ if (match != NULL)
+ free(match);
+ }
- free(contents);
- free(match);
return template;
}