diff options
-rw-r--r-- | compromyse.xyz/index.html | 6 | ||||
-rw-r--r-- | include/lexer.h | 2 | ||||
-rw-r--r-- | src/engine.c | 5 | ||||
-rw-r--r-- | src/lexer.c | 42 |
4 files changed, 54 insertions, 1 deletions
diff --git a/compromyse.xyz/index.html b/compromyse.xyz/index.html index 5cab5fd..1388859 100644 --- a/compromyse.xyz/index.html +++ b/compromyse.xyz/index.html @@ -1,5 +1,11 @@ {{ contentfor "head" }} +<style> + .body {} +</style> + +{{ endcontent }} + {{ include "navbar.html" }} <div class="p-16"> diff --git a/include/lexer.h b/include/lexer.h index 48deb0c..88ed4df 100644 --- a/include/lexer.h +++ b/include/lexer.h @@ -1,7 +1,7 @@ #ifndef __LEXER_H #define __LEXER_H -typedef enum { INCLUDE, CONTENTFOR } directive_e; +typedef enum { INCLUDE, CONTENTFOR, ENDCONTENT } directive_e; typedef struct { unsigned int offset; diff --git a/src/engine.c b/src/engine.c index c78f6b3..1cb3ae7 100644 --- a/src/engine.c +++ b/src/engine.c @@ -60,10 +60,15 @@ ingest(char **buffer) contentfor_operands_t *operand = (contentfor_operands_t *) directive->operands; printf("CONTENTFOR: %s\n", operand->key); + printf("CONTENT: %s\n", operand->content); return; break; } + + /* NOTE: This will never occur */ + case ENDCONTENT: + break; } if (directive != NULL) diff --git a/src/lexer.c b/src/lexer.c index 44462bb..8a04df1 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -2,6 +2,7 @@ #include <ctype.h> #include <lexer.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -76,6 +77,9 @@ found_start: } directive->operands = operand; + } else if (strncmp(buffer + n, "endcontent", strlen("endcontent")) == 0) { + directive->type = ENDCONTENT; + directive->operands = NULL; } else if (strncmp(buffer + n, "contentfor", strlen("contentfor")) == 0) { directive->type = CONTENTFOR; contentfor_operands_t *operands = malloc(sizeof(contentfor_operands_t)); @@ -87,6 +91,44 @@ found_start: break; } + buffer = content + match->length + match->offset; + + size_t content_length = 0; + + key_match_t *new_match; + directive_t *new_directive; + + while (true) { + new_match = find_next_key(buffer); + if (new_match == NULL) { + printf("Cannot find endcontent\n"); + free(new_directive); + free(new_match); + free(directive); + return NULL; + } + + new_directive = find_directive(buffer, new_match); + if (new_directive == NULL) { + printf("Cannot find directive: %.*s\n", + new_match->length, + buffer + new_match->offset); + free(new_directive); + free(new_match); + free(directive); + return NULL; + } + + if (new_directive->type == ENDCONTENT) { + break; + } + } + + asprintf(&operands->content, "%.*s", new_match->offset, buffer); + + free(new_directive); + free(new_match); + directive->operands = operands; } else { free(directive); |