aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-11 11:20:27 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-11 11:20:27 +0530
commit7eb270eabb42bb896f41f8ad36fdd79cc6371d26 (patch)
tree06be10bc770484c83d4aa2c58ee2721a3176416e
parentcde16169e0dec04ecef4bd228f770c254314f148 (diff)
template: template_ingest() must write to a FILE
-rw-r--r--include/template.h4
-rw-r--r--src/template.c16
2 files changed, 12 insertions, 8 deletions
diff --git a/include/template.h b/include/template.h
index c14936e..30b2882 100644
--- a/include/template.h
+++ b/include/template.h
@@ -2,6 +2,7 @@
#define __TEMPLATE_H
#include <list.h>
+#include <stdio.h>
typedef struct {
list_t *components;
@@ -10,7 +11,6 @@ typedef struct {
template_t *template_create(void);
void template_delete(template_t *template);
-char *
-template_ingest(template_t *template, list_t *content_headers, char *body);
+void template_ingest(template_t *template, list_t *content_headers, FILE *f);
#endif
diff --git a/src/template.c b/src/template.c
index d4aa9ed..8ad11a2 100644
--- a/src/template.c
+++ b/src/template.c
@@ -3,6 +3,7 @@
#include <filehandler.h>
#include <lexer.h>
+#include <stdio.h>
#include <stdlib.h>
#include <template.h>
#include <util.h>
@@ -33,10 +34,9 @@ template_delete(template_t *template)
free(template);
}
-char *
-template_ingest(template_t *template, list_t *content_headers, char *body)
+void
+template_ingest(template_t *template, list_t *content_headers, FILE *f)
{
- (void) body;
char *output = malloc(1);
strcpy(output, "");
@@ -45,14 +45,18 @@ template_ingest(template_t *template, list_t *content_headers, char *body)
switch (match->type) {
case _RAW:
- xstrcat(output, match->operands);
+ fprintf(f, "%s", (char *) match->operands);
break;
+ case CONTENT: {
+ char *content = find_contentfor_value(content_headers, match->operands);
+ fprintf(f, "%s", content);
+ break;
+ }
+
/* TODO: Handle this gracefully */
default:
break;
}
}
-
- return output;
}