diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-30 20:41:40 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-30 20:41:40 +0530 |
commit | fabba1b2fbcb0d8dcbf77f5336ec880f561d627c (patch) | |
tree | 7c7fa4045731aac09e4c4cd10f98471cc75701ba /src/engine.c | |
parent | 0cd55a7b37edf098c6b6ffdb551cfb80629e3c79 (diff) |
engine,template: engine_ingest() must return engine_t and template_write() must get the template from config
Diffstat (limited to 'src/engine.c')
-rw-r--r-- | src/engine.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/engine.c b/src/engine.c index b9825bf..d62b44f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -96,8 +96,8 @@ handle_eachdo(char **buffer, key_match_t *match, directive_t *directive) { eachdo_operands_t *operands = directive->operands; - list_t *content_headers = engine_ingest(&operands->content); - list_delete(content_headers); + engine_t *engine = engine_ingest(&operands->content); + engine_delete(engine); list_t *directives = lex(operands->content); #ifdef DEBUG @@ -206,18 +206,21 @@ handle_eachdo(char **buffer, key_match_t *match, directive_t *directive) free(temp_buffer); } -list_t * +engine_t * engine_ingest(char **buffer) { - /* don't ingest the config if it is present */ + engine_t *engine = malloc(sizeof(engine_t)); + engine->config = NULL; + char *p = strstr(*buffer, "---"); if (p != NULL) { + engine->config = config_parse(p); strcpy(*buffer, p + strlen("---")); } key_match_t *match; - list_t *content_headers = list_create(sizeof(contentfor_operand_t)); - if (content_headers == NULL) { + engine->content_headers = list_create(sizeof(contentfor_operand_t)); + if (engine->content_headers == NULL) { printf("Could not create content_headers\n"); return NULL; } @@ -249,7 +252,7 @@ engine_ingest(char **buffer) handle_include(buffer, match, directive); break; case CONTENTFOR: - handle_contentfor(buffer, match, directive, content_headers); + handle_contentfor(buffer, match, directive, engine->content_headers); break; case EACHDO: handle_eachdo(buffer, match, directive); @@ -271,5 +274,15 @@ engine_ingest(char **buffer) free(match); } - return content_headers; + return engine; +} + +void +engine_delete(engine_t *engine) +{ + if (engine->config != NULL) + config_delete(engine->config); + + list_delete(engine->content_headers); + free(engine); } |