ctl
Static template generator for C
Usage
<h1>Hello, % STRING(name) %!</h1>
<ul>
% for (int i = 0; i < len; i++) { %
<li>Item % NUMBER(i) %</li>
% } %
</ul>
ctl example.html > ctl_example.h
#define LIB_CTL_IMPL
#include <libctl.h>
#define CTL_OUT(out, x) { \
str_append(out, x); \
}
#define STRING(x) str_append(ctl_out, x);
#define NUMBER(x) { \
str_appendf(ctl_out, "%d", x); \
}
void ctl_fn_example(char **ctl_out, ctl_ctx_t ctx) {
(void) ctx;
char *name = "world";
int len = 10;
#include "ctl_example.h"
}