added demo

This commit is contained in:
overflowerror 2021-05-21 21:53:34 +02:00
parent 2804ca7c0a
commit 24712fdc3a
4 changed files with 39 additions and 0 deletions

View file

@ -40,9 +40,16 @@ gen/lex.yy.c: src/scanner.l gen/y.tab.h gen
$(LEX) $< $(LEX) $<
mv lex.yy.c gen/ mv lex.yy.c gen/
demo: demofiles/demo.c gen/demo.tab.c $(A_LIB)
$(CC) $(CFLAGS) -o $@ $^
gen/demo.tab.c: demofiles/demo.html.templ $(BIN) gen
# change dir to set template name
cd demofiles && ../$(BIN) demo.html.templ > ../$@
clean: clean:
rm -f gen/* rm -f gen/*
rm -f obj/* rm -f obj/*
rm -f $(BIN) rm -f $(BIN)
rm -f $(A_LIB) rm -f $(A_LIB)
rm -f demo

15
demofiles/demo.c Normal file
View file

@ -0,0 +1,15 @@
#include <stdio.h>
#include <templates.h>
int main() {
char *names[] = {
"foo",
"bar",
"foobar"
};
findTemplate("demo.html.templ")(stdout, "User-List", names, 3);
return 0;
}

16
demofiles/demo.html.templ Normal file
View file

@ -0,0 +1,16 @@
{$ char* title, char** names, size_t no $}
%%
<!DOCTYPE html>
<html>
<head>
<title>
{{ "%s", title }}
</title>
</head>
<body>
{% for(size_t i = 0; i < no; i++) %}
{{ "%s", names[i] }}<br />
{% end %}
</body>
</html>

View file

@ -20,6 +20,7 @@ const char* filename;
void generateHeader() { void generateHeader() {
fprintf(output, "#include <stdio.h>\n"); fprintf(output, "#include <stdio.h>\n");
fprintf(output, "#include <stdlib.h>\n");
fprintf(output, "#include <stdarg.h>\n"); fprintf(output, "#include <stdarg.h>\n");
fprintf(output, "\n"); fprintf(output, "\n");
fprintf(output, "#include <templates.h>\n"); fprintf(output, "#include <templates.h>\n");