Add user manual
authorAndy Spencer <andy753421@gmail.com>
Wed, 28 Dec 2011 05:41:49 +0000 (05:41 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 28 Dec 2011 05:59:04 +0000 (05:59 +0000)
.gitignore
data/global.css
html.ct
html.h
index.c
mkfile
toc.awk [new file with mode: 0644]

index e419fa2..e28005f 100644 (file)
@@ -3,4 +3,5 @@
 *.cgi
 *.swp
 html.c
+manual.inc
 tags
index aa85aad..970effd 100644 (file)
@@ -339,3 +339,15 @@ dl.inline dt:after {
 dl.small dt {
        width: 4em;
 }
+
+/* Asciidoc */
+.asciidoc p {
+       margin-top: 0.7em;
+}
+.asciidoc li p,
+.asciidoc td p {
+       margin-top: 0em;
+}
+.asciidoc .hdlist table {
+       padding-left: 1em;
+}
diff --git a/html.ct b/html.ct
index f9194a3..68be683 100644 (file)
--- a/html.ct
+++ b/html.ct
@@ -127,6 +127,12 @@ Content-Type: text/html; charset=UTF-8
           without any license fees or royalties.</p>
 <% } %>
 
+<% void print_manual(void) { %>
+       <div class="asciidoc">
+               <% print_file("manual.inc"); %>
+       </div>
+<% } %>
+
 <% void print_news(void) { %>
        <!-- It's not really spring anymore :/ -->
        <!-- <p class="quote">Now that it's spring again, progress on AWeather is continuing.</p> -->
diff --git a/html.h b/html.h
index 4c84a58..4ad29e0 100644 (file)
--- a/html.h
+++ b/html.h
@@ -49,11 +49,13 @@ extern page_t footer[];
 extern page_t special[];
 
 /* Global functions */
+void print_file(char *file);
 void print_header(void);
 void print_page(const page_t *which);
 
 /* Pages */
 void print_about(void);
+void print_manual(void);
 void print_news(void);
 void print_oldnews(void);
 void print_screenshots(void);
diff --git a/index.c b/index.c
index 7877fb0..304293d 100644 (file)
--- a/index.c
+++ b/index.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "html.h"
@@ -10,6 +11,7 @@ const char desc[] =
 /* Page data */
 page_t header[] = {
        {"about",       "About",       print_about,        0.7, NULL},
+       {"manual",      "Manual",      print_manual,       0.5, NULL},
        {"news",        "News",        print_news,         0.3, NULL},
        {"screenshots", "Screenshots", print_screenshots,  0.5, NULL},
        {"download",    "Download",    print_download,     0.7, NULL},
@@ -35,6 +37,17 @@ const page_t *everything[] = {header, other, footer, special, NULL};
 const page_t *index        = &special[0];
 const page_t *notfound     = &special[2];
 
+/* Helper functions */
+void print_file(char *file)
+{
+       char data[512];
+       FILE *fd = fopen(file, "r");
+       while (!feof(fd)) {
+               size_t size = fread(data, 1, sizeof(data), fd);
+               fwrite(data, 1, size, stdout);
+       }
+}
+
 /* Main */
 int main(int argc, char **argv)
 {
diff --git a/mkfile b/mkfile
index dc18067..83df932 100644 (file)
--- a/mkfile
+++ b/mkfile
@@ -1,6 +1,8 @@
 CT=/scratch/ct/ct
 CFLAGS='--std=c99 -Wall'
 
+all:V: index.cgi manual.inc
+
 index.cgi: index.o html.o
        gcc $CFLAGS -o $target $prereq $PKG_LIBS
 
@@ -10,16 +12,21 @@ index.cgi: index.o html.o
 %.c: %.ct
        $CT -o $target $prereq 
 
+manual.inc: ../docs/manual.ad
+       asciidoc -s -a toc -a numbered -b xhtml11 -o- $prereq \
+       | awk -f toc.awk > $target
+
 clean:V:
        rm -f *.o *.cgi html.c
 
 push:V:
        user=spenceal
        dest=/home/lug/htdocs/proj/aweather/
+       serv=lug.rose-hulman.edu
        rsync -uavz .htaccess \
-               $user@lug.rose-hulman.edu:$dest
+               $user@$serv:$dest
        rsync -uavz --delete \
                --exclude '*~' \
                --exclude '.*' \
-               index.cgi images screens data \
-               $user@lug.rose-hulman.edu:$dest
+               index.cgi manual.inc images screens data  \
+               $user@$serv:$dest
diff --git a/toc.awk b/toc.awk
new file mode 100644 (file)
index 0000000..c973f66
--- /dev/null
+++ b/toc.awk
@@ -0,0 +1,16 @@
+// {
+       if (match($0, /<h[0-9] id="([^"]*)">([0-9.]* *)([^<]*)<\/h[0-9]>/, arr)) {
+               id   = arr[1];
+               num  = arr[2];
+               txt  = arr[3];
+               toc  = toc  "\n" "<li>" num "<a href=\"#" id "\">" txt "</a></li>"
+               body = body "\n" "<a id=\"" id "\"></a>"
+       }
+       body = body "\n" $0
+}
+
+END {
+       print "<h2>Table of Contents</h2>";
+       print "<ul style=\"list-style:none;\">" toc "</ul>";
+       print body;
+}