6 |
|
|
7 |
|
#include "Environment.hpp" |
8 |
|
#include "Matcher.hpp" |
9 |
+ |
#include "Jargon.hpp" |
10 |
|
|
11 |
|
extern "C" |
12 |
|
{ |
17 |
|
|
18 |
|
int main(int argc, char* argv[]) |
19 |
|
{ |
20 |
+ |
FeepingCreaturism::program = argv[0]; |
21 |
+ |
|
22 |
|
FeepingCreaturism creaturism; |
23 |
|
|
24 |
|
return 0; |
31 |
|
std::string path(env.get("PATH_INFO")); |
32 |
|
Matcher matcher; |
33 |
|
|
34 |
< |
if (path.empty()) daily(); else if (path == "/random") |
34 |
> |
if (path == "/daily/") daily(); else if (path == "/random/") |
35 |
|
{ |
36 |
|
random(); |
37 |
|
} |
39 |
|
{ |
40 |
|
select(matcher[1], true); |
41 |
|
} |
42 |
< |
else daily(); |
42 |
> |
else |
43 |
> |
{ |
44 |
> |
cout << "Status: 301\r\nLocation: http://" << env.get("HTTP_HOST") |
45 |
> |
<< env.get("SCRIPT_NAME") << "/daily/\r\n\r\n"; |
46 |
> |
} |
47 |
|
} |
48 |
|
|
49 |
+ |
std::string FeepingCreaturism::program; |
50 |
+ |
|
51 |
|
void FeepingCreaturism::initialize() |
52 |
|
{ |
53 |
< |
ext::Handle<xml::Document> document(xml::Parse("FeepingCreaturism.xml")); |
54 |
< |
ext::Handle<xml::Node> node(*document/"FeepingCreaturism"); |
53 |
> |
ext::Handle<xml::Document> document(xml::Parse("jargon.xml")); |
54 |
> |
ext::Handle<xml::Node> node(*document/"feepingcreaturism"); |
55 |
|
|
56 |
< |
this->path = *node/"Jargon"; |
57 |
< |
this->matcher = *node/"Matcher"; |
56 |
> |
this->path = *node/"jargon"; |
57 |
> |
this->matcher = *node/"matcher"; |
58 |
|
|
59 |
|
char* path[] = { new char[this->path.size()] }; |
60 |
|
|
63 |
|
::FTS* traversal(::fts_open(path, FTS_LOGICAL, NULL)); |
64 |
|
Matcher matcher('^' + this->path + "/(" + this->matcher + ")$"); |
65 |
|
|
66 |
+ |
if (traversal == NULL) |
67 |
+ |
{ |
68 |
+ |
cerr << program << ": Horrible Failure!\n"; |
69 |
+ |
|
70 |
+ |
std::exit(1); |
71 |
+ |
} |
72 |
+ |
|
73 |
|
for (::FTSENT* entity(::fts_read(traversal)); entity != NULL; |
74 |
|
entity = ::fts_read(traversal)) |
75 |
|
{ |
114 |
|
{ |
115 |
|
if (!validate || jargon.find(selection) != jargon.end()) |
116 |
|
{ |
117 |
< |
cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << selection |
118 |
< |
<< "\r\n"; |
117 |
> |
cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n"; |
118 |
> |
|
119 |
> |
Jargon jargon(path + '/' + selection); |
120 |
> |
|
121 |
> |
cout << jargon; |
122 |
|
} |
123 |
|
else |
124 |
|
{ |