diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/engine.c | 18 | ||||
| -rw-r--r-- | src/lexer.c | 16 |
2 files changed, 30 insertions, 4 deletions
diff --git a/src/engine.c b/src/engine.c index 4e4d037..e4d362e 100644 --- a/src/engine.c +++ b/src/engine.c @@ -23,12 +23,18 @@ ingest(char **buffer) if (directive == NULL) break; - if (directive->type == INCLUDE) { + switch (directive->type) { + case INCLUDE: { char *operand = (char *) directive->operands; char *partial_path; asprintf(&partial_path, "%s/%s/%s", DIRECTORY, PARTIALS, operand); FILE *f = fopen(partial_path, "r"); + if (f == NULL) { + printf("Could not open: %s\n", partial_path); + return; + } + unsigned int size = fsize(f); char *partial_content = fcontent(f, size); @@ -44,6 +50,16 @@ ingest(char **buffer) temp_buffer + match->offset + match->length); free(temp_buffer); + break; + } + case CONTENTFOR: { + contentfor_operands_t *operand + = (contentfor_operands_t *) directive->operands; + printf("CONTENTFOR: %s\n", operand->key); + + return; + break; + } } free(directive); diff --git a/src/lexer.c b/src/lexer.c index 34db154..dc972e9 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -64,9 +64,7 @@ found_start: directive->type = INCLUDE; char *operand = NULL; - for (size_t i = n + strlen("include"); - i < match->length - strlen("include"); - i++) + for (size_t i = n + strlen("include"); i < match->length; i++) if (isalnum(buffer[i])) { sscanf(buffer + i, "%ms\"", &operand); operand[strlen(operand) - 1] = '\0'; @@ -75,6 +73,18 @@ found_start: asprintf((char **) &directive->operands, "%s", operand); free(operand); + } else if (strncmp(buffer + n, "contentfor", strlen("contentfor")) == 0) { + directive->type = CONTENTFOR; + contentfor_operands_t *operands = malloc(sizeof(contentfor_operands_t)); + + for (size_t i = n + strlen("contentfor"); i < match->length; i++) + if (isalnum(buffer[i])) { + sscanf(buffer + i, "%ms\"", &operands->key); + operands->key[strlen(operands->key) - 1] = '\0'; + break; + } + + directive->operands = operands; } return directive; |
