aboutsummaryrefslogtreecommitdiff
path: root/src/lexer.c
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-30 08:33:53 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-30 08:33:53 +0530
commit6b618e71f577ecc3e2665717515828d1ae12927b (patch)
tree3a13d301c48b93dc3f090506be273e5bc537ffd2 /src/lexer.c
parent22b62228d0b8fe081ec6df95cf331b3d290127ab (diff)
lexer: add directive_delete()
Diffstat (limited to 'src/lexer.c')
-rw-r--r--src/lexer.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 829942a..47f76f0 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -128,6 +128,7 @@ lexer_handle_contentfor(directive_t *directive,
size_t n)
{
directive->type = CONTENTFOR;
+ directive->operands = NULL;
contentfor_operand_t *operands = malloc(sizeof(contentfor_operand_t));
for (size_t i = n + strlen("contentfor"); i < match->length; i++)
@@ -163,8 +164,8 @@ lexer_handle_contentfor(directive_t *directive,
}
if (new_directive->type == ENDCONTENT) {
- break;
free(new_directive);
+ break;
}
free(new_directive);
@@ -334,3 +335,30 @@ find_contentfor_value(list_t *content_headers, char *key)
return NULL;
}
+
+void
+directive_delete(directive_t *directive)
+{
+ switch (directive->type) {
+ case EACHDO: {
+ eachdo_operands_t *operands = directive->operands;
+ free(operands->content);
+ free(operands->key);
+ free(operands);
+ }
+ case CONTENTFOR: {
+ contentfor_operand_t *operands = directive->operands;
+ free(operands->content);
+ free(operands->key);
+ free(operands);
+ }
+ case PUT:
+ case CONTENT:
+ case INCLUDE:
+ if (directive->operands != NULL)
+ free(directive->operands);
+ break;
+ default:
+ break;
+ }
+}