2023-12-16 22:15:21 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "ltm/template.h"
|
|
|
|
|
2023-12-16 23:00:00 +01:00
|
|
|
const char *s = "<head><link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css\">\n"
|
|
|
|
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js\"></script>\n"
|
|
|
|
"<script>hljs.highlightAll();</script></head>\n"
|
|
|
|
"<body><pre><code>{{ paste }}</code></pre></body>";
|
|
|
|
|
|
|
|
ltm_err reader(size_t *written, char *buf, size_t len, void *data) {
|
|
|
|
FILE *f = data;
|
|
|
|
|
|
|
|
*written = fread(buf, 1, len, f);
|
|
|
|
|
|
|
|
return ltm_err_ok;
|
|
|
|
}
|
2023-12-16 22:15:21 +01:00
|
|
|
|
|
|
|
int main() {
|
|
|
|
ltm_template *template;
|
|
|
|
ltm_template_compile(&template, s);
|
|
|
|
ltm_instance *instance;
|
|
|
|
ltm_template_instantiate(&instance, template);
|
|
|
|
|
2023-12-16 23:00:00 +01:00
|
|
|
const char *filename = "src/ltm_instance.c";
|
|
|
|
|
2023-12-16 22:15:21 +01:00
|
|
|
struct stat sb;
|
2023-12-16 23:00:00 +01:00
|
|
|
stat(filename, &sb);
|
2023-12-16 22:15:21 +01:00
|
|
|
|
2023-12-16 23:00:00 +01:00
|
|
|
FILE *f = fopen(filename, "rb");
|
2023-12-16 22:15:21 +01:00
|
|
|
|
2023-12-16 23:00:00 +01:00
|
|
|
ltm_instance_block_add_var_fn(instance, "paste", reader, f, sb.st_size);
|
|
|
|
/* ltm_instance_block_add_var(instance, "paste", ltm_instance_block_type_file_owned, f, sb.st_size); */
|
|
|
|
/* ltm_instance_block_add_var(instance, "paste", ltm_instance_block_type_buf, "hello\n", 6); */
|
|
|
|
/* ltm_instance_block_add_var(instance, "paste", ltm_instance_block_type_buf, "world\n", 6); */
|
2023-12-16 22:15:21 +01:00
|
|
|
|
2023-12-16 23:00:00 +01:00
|
|
|
char buf[128];
|
2023-12-16 22:15:21 +01:00
|
|
|
size_t written = 0;
|
|
|
|
|
2023-12-16 23:00:00 +01:00
|
|
|
while (ltm_instance_write(&written, buf, 128, instance) != ltm_err_done) {
|
2023-12-16 22:15:21 +01:00
|
|
|
printf("%.*s", (int)written, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%.*s", (int)written, buf);
|
|
|
|
|
|
|
|
ltm_instance_free(instance);
|
|
|
|
ltm_template_free(template);
|
|
|
|
}
|