]> Pileus Git - ~andy/aweather-web/blob - index.c
XHTML Strict fixes
[~andy/aweather-web] / index.c
1 #include <glib.h>
2 #include "html.h"
3
4 /* Page data */
5 page_t header[] = {
6         {"about",       "About",       print_about},
7         {"news",        "News",        print_news},
8         {"screenshots", "Screenshots", print_screenshots},
9         {"download",    "Download",    print_download},
10         {"development", "Development", print_development},
11         {NULL,          NULL,          NULL},
12 };
13 page_t grits[] = {
14         {"grits",   "Grits",   print_grits},
15         {NULL,      NULL,      NULL},
16 };
17 page_t footer[] = {
18         {"contact", "Contact", print_contact},
19         {"legal",   "Legal",   print_legal},
20         {NULL,      NULL,      NULL},
21 };
22 page_t special[] = {
23         {"index.cgi", NULL,        print_index},
24         {"notfound",  "Not found", print_notfound},
25         {NULL,        NULL,        NULL},
26 };
27 page_t *everything[] = {header, grits, footer, special, NULL};
28 const page_t *index    = &special[0];
29 const page_t *notfound = &special[1];
30
31 /* Main */
32 int main(int argc, char **argv)
33 {
34         print_header();
35
36         const gchar *name = g_getenv("PATH_INFO");
37         if (name == NULL || name[0] == '\0' || name[1] == '\0')
38                 return print_page(index), 0;
39
40         /* Look up a specific page */
41         for (int i = 0; everything[i];         i++)
42         for (int j = 0; everything[i][j].link; j++) {
43                 page_t *page = &everything[i][j];
44                 if (g_str_equal(page->link, name+1))
45                         return print_page(page), 0;
46         }
47
48         /* 404 */
49         return print_page(notfound), 0;
50 }