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