lander/ltm/example/test.c

35 lines
755 B
C
Raw Normal View History

2023-12-16 22:15:21 +01:00
#include <stdio.h>
#include <sys/stat.h>
#include "ltm/template.h"
const char *s = "<body><pre><code>\n"
"{{ paste }}\n"
"</code></pre></body>";
int main() {
ltm_template *template;
ltm_template_compile(&template, s);
ltm_instance *instance;
ltm_template_instantiate(&instance, template);
struct stat sb;
stat("Makefile", &sb);
FILE *f = fopen("Makefile", "rb");
ltm_instance_block_add_var(instance, "paste", ltm_instance_block_type_file_owned, f, sb.st_size);
char buf[1024];
size_t written = 0;
while (ltm_instance_write(&written, buf, 1024, instance) != ltm_err_done) {
printf("%.*s", (int)written, buf);
}
printf("%.*s", (int)written, buf);
ltm_instance_free(instance);
ltm_template_free(template);
}