]> Pileus Git - ~andy/ct/commitdiff
Adding gallery and reorganizing
authorAndy Spencer <andy753421@gmail.com>
Sat, 21 Nov 2009 23:41:22 +0000 (23:41 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 21 Nov 2009 23:41:22 +0000 (23:41 +0000)
13 files changed:
example/.gitignore [new file with mode: 0644]
example/html.ct [moved from lib.ct with 100% similarity]
example/html.h [moved from lib.h with 100% similarity]
example/main.c [moved from test.c with 84% similarity]
example/mkfile [new file with mode: 0644]
gallery/.gitignore [new file with mode: 0644]
gallery/gallery.c [new file with mode: 0644]
gallery/html.ct [new file with mode: 0644]
gallery/html.h [new file with mode: 0644]
gallery/mkfile [new file with mode: 0644]
mkcommon [new file with mode: 0644]
mkfile [deleted file]
tmpl.awk

diff --git a/example/.gitignore b/example/.gitignore
new file mode 100644 (file)
index 0000000..b0ec2b2
--- /dev/null
@@ -0,0 +1,2 @@
+html.c
+main
similarity index 100%
rename from lib.ct
rename to example/html.ct
similarity index 100%
rename from lib.h
rename to example/html.h
similarity index 84%
rename from test.c
rename to example/main.c
index dec3b4a51c8b425b5d4f30704c5047dc05eff1cb..7111e42703cb8b5f6de2d6a0454e0b9ea8ba9ae7 100644 (file)
--- a/test.c
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include "lib.h"
+#include "html.h"
 
 int main(int argc, char **argv)
 {
diff --git a/example/mkfile b/example/mkfile
new file mode 100644 (file)
index 0000000..bd43d89
--- /dev/null
@@ -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 (file)
index 0000000..2c7f8fc
--- /dev/null
@@ -0,0 +1,2 @@
+gallery
+html.c
diff --git a/gallery/gallery.c b/gallery/gallery.c
new file mode 100644 (file)
index 0000000..537be3e
--- /dev/null
@@ -0,0 +1,41 @@
+#include <glib.h>
+#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 (file)
index 0000000..2b04615
--- /dev/null
@@ -0,0 +1,94 @@
+[#include <glib.h>]
+
+[void header() {]
+Content-Type: text/html; charset=UTF-8
+[}]
+
+
+[void frame_index(){]
+<html>
+       <frameset rows="20, *">
+               <frame name="head" src="?head">
+               <frameset cols="240,*">
+                       <frame name="nav" src="?nav">
+                       <frame name="content" src="?content">
+               </frameset>
+       </frameset>
+</html>
+[}]
+
+
+[void frame_head(){]
+<html>
+       <head>
+               <style>
+                       body {
+                               padding:0px;
+                               margin:0px;
+                       }
+               </style>
+       </head>
+       <body>
+               <center>
+                       <a href="?noframe" target="parent">No Frames</a>
+               </center>
+       </body>
+</html>
+[}]
+
+
+[void frame_nav(int square, GList *thumbs) {]
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+       <head>
+               <title>Image viewer</title>
+               <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
+               <style type="text/css">
+                       * {padding:0; margin:0;}
+                       .align {
+                               display:block;
+                               float:left;
+                               margin:10px;
+                               text-align:center;
+                               text-decoration:none;
+                               width:214px;
+                               [if (square)]
+                               height:214px;
+                       }
+                       .box {
+                               background-color:#f8fbFF;
+                               border:solid 2px #B4C7F8;
+                               display:block;
+                               text-align:center;
+                               text-decoration:none;
+                               padding:5px;
+                               overflow:hidden;
+                       }
+                       .box img {
+                               border:none;
+                       }
+                       .box:hover {
+                               color:transparent;
+                       }
+               </style>
+       </head>
+       <body>
+               [for (GList *cur =thumbs; cur; cur = cur->next) {]
+                       <div class="align">
+                               <a class="box" target="content"
+                                       [g_print("href=\"images/%s\"", (gchar*)cur->data);]
+                               ><img
+                                       [g_print("src=\"thumbs/%s\"", (gchar*)cur->data);]
+                               ></a>
+                       </div>
+               [}]
+       </body>
+</html>
+[}]
+
+
+[void frame_content(){]
+<html>
+</html>
+[}]
diff --git a/gallery/html.h b/gallery/html.h
new file mode 100644 (file)
index 0000000..85f95d4
--- /dev/null
@@ -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 (file)
index 0000000..b141b31
--- /dev/null
@@ -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 (file)
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 (file)
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.ct >lib.c
-       ex +'norm gg=G' +'wq' lib.c
-<$HOME/lib/mkcommon
index 19dc06ec30a01a9469beb26d395b031dbe7ee9cc..09bef2e3c6243de93c3a71380da1358bf42f906b 100755 (executable)
--- 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);"