ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FeepingCreaturism/FeepingCreaturism.cpp
(Generate patch)

Comparing FeepingCreaturism/FeepingCreaturism.cpp (file contents):
Revision 243 by Douglas Thrift, 2004-09-11T21:27:10-07:00 vs.
Revision 352 by douglas, 2004-12-17T17:50:49-08:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "Environment.hpp"
8 < #include "Matcher.hpp"
8 > #include "Matcher/Matcher.hpp"
9   #include "Jargon.hpp"
10  
11 extern "C"
12 {
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fts.h>
16 }
17
11   #include <menes-api/exename.hpp>
12 < #include <menes-app/application.hpp>
12 > #include <menes-app/simple.hpp>
13  
14 < struct FeepingCreaturismCommand : public app::Application
14 > int Main(const app::Options& options)
15   {
16 <        virtual int Run(const app::ArgumentList& args)
24 <        {
25 <                FeepingCreaturism::program = api::GetExecutableName();
16 >        FeepingCreaturism::program = api::GetExecutablePath().GetName();
17  
18 <                FeepingCreaturism creaturism;
18 >        FeepingCreaturism creaturism;
19  
20 <                return 0;
21 <        }
31 < } creaturism;
20 >        return 0;
21 > }
22  
23   FeepingCreaturism::FeepingCreaturism()
24   {
# Line 52 | Line 42 | FeepingCreaturism::FeepingCreaturism()
42          }
43          else
44          {
45 <                api::Cout << "Location: http://" << env.get("HTTP_HOST")
56 <                        << env.get("SCRIPT_NAME") << "/daily/\r\n\r\n";
45 >                api::Cout << "Location: http://" << env.get("HTTP_HOST") << env.get("SCRIPT_NAME") << "/daily/\r\n\r\n";
46          }
47   }
48  
# Line 68 | Line 57 | bool FeepingCreaturism::CaseLess::operat
57          std::transform(one.begin(), one.end(), one_.begin(), ::tolower);
58          std::transform(two.begin(), two.end(), two_.begin(), ::tolower);
59  
60 +        if (one_ == two_) return one < two;
61 +
62          return one_ < two_;
63   }
64  
65   void FeepingCreaturism::initialize()
66   {
67 <        ext::Handle<xml::Document> document(xml::Parse("jargon.xml"));
68 <        ext::Handle<xml::Node> node(*document/"feepingcreaturism");
67 >        _H<xml::Document> document(xml::Parse("jargon.xml"));
68 >        _H<xml::Node> node(*document/"feepingcreaturism");
69  
70          this->path = *node/"jargon";
71          this->matcher = *node/"matcher";
72  
73 <        char* path[] = { new char[this->path.GetData().GetSize()] };
73 >        _L<ext::String> args(1, this->path);
74  
75 <        std::strcpy(path[0], this->path.NullTerminate());
75 >        args.InsertLast("-type");
76 >        args.InsertLast("f");
77  
78 <        ::FTS* traversal(::fts_open(path, FTS_LOGICAL, NULL));
78 >        _S<api::Process> find("/usr/bin/find", args);
79          Matcher matcher("^" + this->path + "/(" + this->matcher + ")$");
80 +        ext::String path;
81  
82 <        if (traversal == NULL)
82 >        while (ios::ReadLine(*find.GetReader(), path)) if (matcher == path)
83          {
84 <                api::Cerr << program << ": Horrible Failure!\n";
92 <
93 <                std::exit(1);
94 <        }
95 <
96 <        for (::FTSENT* entity(::fts_read(traversal)); entity != NULL;
97 <                entity = ::fts_read(traversal))
98 <        {
99 <                if (entity->fts_info == FTS_F && entity->fts_path == matcher)
100 <                {
101 <                        jargon.insert(matcher[1]);
102 <                }
84 >                jargon.insert(matcher[1]);
85          }
104
105        ::fts_close(traversal);
106
107        delete [] path[0];
86   }
87  
88   void FeepingCreaturism::parse()
# Line 113 | Line 91 | void FeepingCreaturism::parse()
91  
92          if (env.get("REQUEST_METHOD") == "POST")
93          {
94 <                std::streamsize length(lexical_cast<std::streamsize>(env.get("CONTENT_"
117 <                        "TYPE")));
94 >                std::streamsize length(lexical_cast<std::streamsize>(env.get("CONTENT_TYPE")));
95                  char* content(new char[length]);
96  
97                  api::Cin.Read(content, length);
# Line 149 | Line 126 | void FeepingCreaturism::daily(const ext:
126          if (!date.IsEmpty()) ::strptime(date.NullTerminate(), "%Y-%m-%d", day);
127  
128          std::time_t difference(mktime(day) / 86400);
129 <        std::vector<ext::String> jargon(this->jargon.begin(), this->jargon.end());
130 <        ext::String entry(jargon.size() ? jargon[difference % jargon.size()] : "");
129 >        ext::Vector<ext::String> jargon(this->jargon.begin(), this->jargon.end());
130 >        ext::String entry(jargon.GetSize() ? jargon[difference % jargon.GetSize()] : "");
131  
132          select(entry);
133   }
# Line 159 | Line 136 | void FeepingCreaturism::random(const ext
136   {
137          ::srandomdev();
138  
139 <        std::vector<ext::String> jargon(this->jargon.begin(), this->jargon.end());
140 <        std::vector<ext::String>::size_type random(number.IsEmpty() ? ::random() :
164 <                lexical_cast<std::vector<ext::String>::size_type>(number));
139 >        ext::Vector<ext::String> jargon(this->jargon.begin(), this->jargon.end());
140 >        size_t random(number.IsEmpty() ? ::random() : lexical_cast<size_t>(number));
141  
142          assert(random >= 0);
143 <        assert(random % jargon.size() < jargon.size());
143 >        assert(random % jargon.GetSize() < jargon.GetSize());
144  
145 <        ext::String entry(jargon.size() ? jargon[random % jargon.size()] : "");
145 >        ext::String entry(jargon.GetSize() ? jargon[random % jargon.GetSize()] : "");
146  
147          select(entry);
148   }
# Line 177 | Line 153 | void FeepingCreaturism::select(const ext
153          {
154                  api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n";
155  
156 <                Jargon jargon(path, selection, cgi.find("include") != cgi.end()
181 <                        && lexical_cast<bool>(ext::String(cgi.find("include")->second)),
182 <                        cgi.find("relative") != cgi.end()
183 <                        ? ext::String(cgi.find("relative")->second) : ext::String());
156 >                Jargon jargon(path, selection, cgi.find("include") != cgi.end() && lexical_cast<bool>(ext::String(cgi.find("include")->second)), cgi.find("relative") != cgi.end() ? ext::String(cgi.find("relative")->second) : ext::String());
157  
158                  api::Cout << jargon;
159          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines