]> Pileus Git - ~andy/aweather-web/blob - index.c
Version 0.5.2
[~andy/aweather-web] / index.c
1 #include <glib.h>
2 #include "html.h"
3
4 const char desc[] =
5         "AWeather is a free real-time weather data viewer that "
6         "supports Level-II NEXRAD files, polarimetric radars, "
7         "and volume rendering.";
8
9 /* Page data */
10 page_t header[] = {
11         {"about",       "About",       print_about,        0.7, NULL},
12         {"news",        "News",        print_news,         0.3, NULL},
13         {"screenshots", "Screenshots", print_screenshots,  0.5, NULL},
14         {"download",    "Download",    print_download,     0.7, NULL},
15         {"development", "Development", print_development,  0.3, NULL},
16         {NULL,          NULL,          NULL,               0.0, NULL},
17 };
18 page_t other[] = {
19         {"grits",       "Grits",       print_grits,        0.8, NULL},
20         {"rsl",         "RSL",         print_rsl,          0.3, NULL},
21         {NULL,          NULL,          NULL,               0.0, NULL},
22 };
23 page_t footer[] = {
24         {"contact",     "Contact",     print_contact,      0.2, NULL},
25         {NULL,          NULL,          NULL,               0.0, NULL},
26 };
27 page_t special[] = {
28         {"",            NULL,          print_index,        1.0, desc},
29         {NULL,          "Not found",   print_notfound,    -1.0, NULL},
30         {NULL,          NULL,          NULL,               0.0, NULL},
31 };
32 const page_t *everything[] = {header, other, footer, special, NULL};
33 const page_t *index        = &special[0];
34 const page_t *notfound     = &special[1];
35
36 /* Main */
37 int main(int argc, char **argv)
38 {
39         print_header();
40
41         const gchar *name = g_getenv("PATH_INFO");
42         if (name == NULL || name[0] == '\0' || name[1] == '\0')
43                 return print_page(index), 0;
44
45         /* Look up a specific page */
46         for (int i = 0; everything[i];         i++)
47         for (int j = 0; everything[i][j].link; j++) {
48                 const page_t *page = &everything[i][j];
49                 if (g_str_equal(name+1, page->link))
50                         return print_page(page), 0;
51         }
52
53         /* Print sitemap by itself */
54         if (g_str_equal(name+1, "sitemap.xml"))
55                 return print_sitemap(everything), 0;
56
57         /* 404 */
58         return print_page(notfound), 0;
59 }