]> Pileus Git - ~andy/ct/commitdiff
Initial import
authorAndy Spencer <andy753421@gmail.com>
Sat, 21 Nov 2009 10:09:57 +0000 (10:09 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 21 Nov 2009 10:09:57 +0000 (10:09 +0000)
.gitignore [new file with mode: 0644]
lib.ct [new file with mode: 0644]
lib.h [new file with mode: 0644]
mkfile [new file with mode: 0644]
test.c [new file with mode: 0644]
tmpl.awk [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b3f23b6
--- /dev/null
@@ -0,0 +1,4 @@
+*.o
+*~
+lib.c
+test
diff --git a/lib.ct b/lib.ct
new file mode 100644 (file)
index 0000000..e38344f
--- /dev/null
+++ b/lib.ct
@@ -0,0 +1,16 @@
+[void header() {]
+Content-Type: application/xhtml+xml; charset=UTF-8
+[}]
+
+[void body() {]
+       [for (int i = 0; i < 3; i++)]
+               <p>hello, world</p>
+[}]
+
+[void html() {]
+<html>
+       <body>
+               [body();]
+       </body>
+</html>
+[}]
diff --git a/lib.h b/lib.h
new file mode 100644 (file)
index 0000000..677dc0e
--- /dev/null
+++ b/lib.h
@@ -0,0 +1,2 @@
+void header();
+int html();
diff --git a/mkfile b/mkfile
new file mode 100644 (file)
index 0000000..0d3a704
--- /dev/null
+++ b/mkfile
@@ -0,0 +1,10 @@
+PKGS=glib-2.0
+PROGS=test
+default:V: test
+       #cat test.c
+       ./test
+test: test.o lib.o
+lib.c: lib.ct tmpl.awk
+       ./tmpl.awk <lib.ct >lib.c
+       ex +'norm gg=G' +'wq' lib.c
+<$HOME/lib/mkcommon
diff --git a/test.c b/test.c
new file mode 100644 (file)
index 0000000..dec3b4a
--- /dev/null
+++ b/test.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include "lib.h"
+
+int main(int argc, char **argv)
+{
+       header();
+       puts("");
+       html();
+       return 0;
+}
diff --git a/tmpl.awk b/tmpl.awk
new file mode 100755 (executable)
index 0000000..19dc06e
--- /dev/null
+++ b/tmpl.awk
@@ -0,0 +1,20 @@
+#!/bin/awk -f
+/\[/ {
+       gsub(/[\[\]]/, "")
+       code[length(code)] = $0
+       next
+}
+/./{
+       data[length(data)] = "\""$0"\\n\""
+       i=length(data)-1
+       code[length(code)] = "fwrite(data"i", sizeof(data"i")-1, 1, stdout);"
+}
+END {
+        print "#include <stdio.h>"
+       print ""
+       for (i=0; i < length(data); i++)
+               print "static char data"i"[] = "data[i]";"
+        print ""
+       for (i=0; i < length(code); i++)
+               print code[i]
+}