From 99726f9b8716daf3973712d53dfc0ffaf2cfa37f Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sat, 21 Nov 2009 23:41:22 +0000 Subject: [PATCH] Adding gallery and reorganizing --- example/.gitignore | 2 + lib.ct => example/html.ct | 0 lib.h => example/html.h | 0 test.c => example/main.c | 2 +- example/mkfile | 7 +++ gallery/.gitignore | 2 + gallery/gallery.c | 41 +++++++++++++++++ gallery/html.ct | 94 +++++++++++++++++++++++++++++++++++++++ gallery/html.h | 9 ++++ gallery/mkfile | 8 ++++ mkcommon | 5 +++ mkfile | 10 ----- tmpl.awk | 1 + 13 files changed, 170 insertions(+), 11 deletions(-) create mode 100644 example/.gitignore rename lib.ct => example/html.ct (100%) rename lib.h => example/html.h (100%) rename test.c => example/main.c (84%) create mode 100644 example/mkfile create mode 100644 gallery/.gitignore create mode 100644 gallery/gallery.c create mode 100644 gallery/html.ct create mode 100644 gallery/html.h create mode 100644 gallery/mkfile create mode 100644 mkcommon delete mode 100644 mkfile diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..b0ec2b2 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,2 @@ +html.c +main diff --git a/lib.ct b/example/html.ct similarity index 100% rename from lib.ct rename to example/html.ct diff --git a/lib.h b/example/html.h similarity index 100% rename from lib.h rename to example/html.h diff --git a/test.c b/example/main.c similarity index 84% rename from test.c rename to example/main.c index dec3b4a..7111e42 100644 --- a/test.c +++ b/example/main.c @@ -1,5 +1,5 @@ #include -#include "lib.h" +#include "html.h" int main(int argc, char **argv) { diff --git a/example/mkfile b/example/mkfile new file mode 100644 index 0000000..bd43d89 --- /dev/null +++ b/example/mkfile @@ -0,0 +1,7 @@ +PROGS=main +CLEAN=html.c + +default:V: run +main: main.o html.o + +<../mkcommon diff --git a/gallery/.gitignore b/gallery/.gitignore new file mode 100644 index 0000000..2c7f8fc --- /dev/null +++ b/gallery/.gitignore @@ -0,0 +1,2 @@ +gallery +html.c diff --git a/gallery/gallery.c b/gallery/gallery.c new file mode 100644 index 0000000..537be3e --- /dev/null +++ b/gallery/gallery.c @@ -0,0 +1,41 @@ +#include +#include "html.h" + +const gchar *query_string; + +void ct_init() +{ + query_string = g_getenv("QUERY_STRING"); +} + +GList *read_dir(gchar *dirname) +{ + GDir *dir = g_dir_open(dirname, 0, NULL); + const gchar *name = NULL; + GList *images = NULL; + while ((name = g_dir_read_name(dir))) + images = g_list_prepend(images, (gchar*)name); + g_dir_close(dir); + return images; +} + +int main() +{ + ct_init(); + + header(); + g_print("\n"); + + if (query_string == NULL) + frame_index(); + else if (g_str_equal(query_string, "noframe")) + frame_nav(TRUE, read_dir("images")); + else if (g_str_equal(query_string, "nav")) + frame_nav(FALSE, read_dir("images")); + else if (g_str_equal(query_string, "head")) + frame_head(); + else if (g_str_equal(query_string, "content")) + frame_content(); + else + frame_index(); +} diff --git a/gallery/html.ct b/gallery/html.ct new file mode 100644 index 0000000..2b04615 --- /dev/null +++ b/gallery/html.ct @@ -0,0 +1,94 @@ +[#include ] + +[void header() {] +Content-Type: text/html; charset=UTF-8 +[}] + + +[void frame_index(){] + + + + + + + + + +[}] + + +[void frame_head(){] + + + + + +
+ No Frames +
+ + +[}] + + +[void frame_nav(int square, GList *thumbs) {] + + + + Image viewer + + + + + [for (GList *cur =thumbs; cur; cur = cur->next) {] + + [}] + + +[}] + + +[void frame_content(){] + + +[}] diff --git a/gallery/html.h b/gallery/html.h new file mode 100644 index 0000000..85f95d4 --- /dev/null +++ b/gallery/html.h @@ -0,0 +1,9 @@ +void header(); + +void frame_index(); + +void frame_head(); + +void frame_nav(int square, GList *thumbs); + +void frame_content(); diff --git a/gallery/mkfile b/gallery/mkfile new file mode 100644 index 0000000..b141b31 --- /dev/null +++ b/gallery/mkfile @@ -0,0 +1,8 @@ +PROGS=gallery +PKGS=glib-2.0 +CLEAN=html.c + +default:V: run +gallery: gallery.o html.o + +<../mkcommon diff --git a/mkcommon b/mkcommon new file mode 100644 index 0000000..4e2afaf --- /dev/null +++ b/mkcommon @@ -0,0 +1,5 @@ +%.c: %.ct + ../tmpl.awk <$prereq >$target + ex +'norm gg=G' +'wq' $target + +<$HOME/lib/mkcommon diff --git a/mkfile b/mkfile deleted file mode 100644 index 0d3a704..0000000 --- a/mkfile +++ /dev/null @@ -1,10 +0,0 @@ -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.c - ex +'norm gg=G' +'wq' lib.c -<$HOME/lib/mkcommon diff --git a/tmpl.awk b/tmpl.awk index 19dc06e..09bef2e 100755 --- a/tmpl.awk +++ b/tmpl.awk @@ -5,6 +5,7 @@ next } /./{ + gsub(/"/, "\\\"") data[length(data)] = "\""$0"\\n\"" i=length(data)-1 code[length(code)] = "fwrite(data"i", sizeof(data"i")-1, 1, stdout);" -- 2.43.2