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