#include #include #include struct values { char *fragment; float value; } prefixes[] = { { "http://weblog.pell.portland.or.us/", 2356889.25 }, { "http://tsfr.org/", 2356889.25 }, { "http://pell.portland.or.us/", 2356889.25 }, { "http://pell.chi.il.us/", 2356889.25 }, { "http://pell.volcano.org/", 2356889.25 }, { "http://instapundit.com", 0.75 }, { "http://www.instapundit.com", 0.25 }, { 0 }, } ; ok(char *url) { if (url == 0) return 0; do { if (*url == '<' || *url == '&' || *url == '$') return 0; } while (*url++); return 1; } display(char *url, double value) { int i; int j; int sz, res; char valstr[200], number[200]; char *p, *q; char *urlarg; char *valarg; puts("Status: 200 Ok\n" "Date: Thu. 24 May 2007 23:26:47 GMT\n" "Server: This one\n" "Connection: close\n" "Content-Type: text/html\n"); if (ok(url)) { sprintf(number, "%.2f", value); sz = strlen(number); for (p=valstr, q=number; *q && *q != '.'; ++q, ++p, --sz) { *p = *q; if ( ((sz%3) == 1) && (q[1] != '.') ) *++p = ','; } while (*q) *p++ = *q++; *p = 0; valarg = alloca(strlen(valstr) + 10); sprintf(valarg, "-DVALUE=%s", valstr); urlarg = alloca(strlen(url) + 10); sprintf(urlarg, "-DWEBLOG=%s", url); execlp("m4", "m4", valarg, urlarg, "results-template", 0L); } execlp("m4", "m4", "index.html", 0L); } main() { char *url, *copyofurl; double value = 0; int i, len; int slashes=0; uncgi(); if ( (copyofurl = url = getenv("WWW_url")) ) { for (i=0; prefixes[i].fragment; i++) { len = strlen(prefixes[i].fragment); if (strncasecmp(url, prefixes[i].fragment, len) == 0) { value = prefixes[i].value; url += len; slashes=3; break; } } while (url[0]) { if (url[0] == '/') if ( ++slashes > 3 ) break; value = value + (url[1] * url[0]); url++; } } display(copyofurl, value); exit(0); }