]> Pileus Git - ~andy/aweather-web/blob - index.c
Update for 0.5
[~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         {NULL,      NULL,      NULL},
20 };
21 page_t special[] = {
22         {"index.cgi", NULL,        print_index},
23         {"notfound",  "Not found", print_notfound},
24         {NULL,        NULL,        NULL},
25 };
26 page_t *everything[] = {header, grits, footer, special, NULL};
27 const page_t *index    = &special[0];
28 const page_t *notfound = &special[1];
29
30 /* Main */
31 int main(int argc, char **argv)
32 {
33         print_header();
34
35         const gchar *name = g_getenv("PATH_INFO");
36         if (name == NULL || name[0] == '\0' || name[1] == '\0')
37                 return print_page(index), 0;
38
39         /* Look up a specific page */
40         for (int i = 0; everything[i];         i++)
41         for (int j = 0; everything[i][j].link; j++) {
42                 page_t *page = &everything[i][j];
43                 if (g_str_equal(page->link, name+1))
44                         return print_page(page), 0;
45         }
46
47         /* 404 */
48         return print_page(notfound), 0;
49 }