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 206 by Douglas Thrift, 2004-09-01T03:36:00-07:00 vs.
Revision 255 by Douglas Thrift, 2004-09-15T21:38:10-07:00

# Line 32 | Line 32 | FeepingCreaturism::FeepingCreaturism()
32          ext::String path(env.get("PATH_INFO"));
33          Matcher matcher;
34  
35 <        if (path == "/daily/") daily(); else if (path == "/random/")
35 >        if (path == matcher("^/daily/(\\d{4}-\\d{2}-\\d{2})?$"))
36          {
37 <                random();
37 >                daily(matcher.size() > 1 ? matcher[1] : "");
38 >        }
39 >        else if (path == matcher("^/random/(\\d+)?$"))
40 >        {
41 >                random(matcher.size() > 1 ? matcher[1] : "");
42          }
43          else if (path == matcher("^/(" + this->matcher + ")$"))
44          {
# Line 58 | Line 62 | bool FeepingCreaturism::CaseLess::operat
62          std::transform(one.begin(), one.end(), one_.begin(), ::tolower);
63          std::transform(two.begin(), two.end(), two_.begin(), ::tolower);
64  
65 +        if (one_ == two_) return one < two;
66 +
67          return one_ < two_;
68   }
69  
# Line 69 | Line 75 | void FeepingCreaturism::initialize()
75          this->path = *node/"jargon";
76          this->matcher = *node/"matcher";
77  
78 <        char* path[] = { new char[this->path.size()] };
78 >        char* path[] = { new char[this->path.GetData().GetSize()] };
79  
80 <        std::strcpy(path[0], this->path.c_str());
80 >        std::strcpy(path[0], this->path.NullTerminate());
81  
82          ::FTS* traversal(::fts_open(path, FTS_LOGICAL, NULL));
83          Matcher matcher("^" + this->path + "/(" + this->matcher + ")$");
# Line 127 | Line 133 | void FeepingCreaturism::parse()
133          while (query.good());
134   }
135  
136 < void FeepingCreaturism::daily()
136 > void FeepingCreaturism::daily(const ext::String& date)
137   {
138          std::time_t when(std::time(NULL));
139 <        std::tm* now(std::localtime(&when));
139 >        std::tm* day(std::localtime(&when));
140  
141 <        now->tm_sec = 0;
142 <        now->tm_min = 0;
143 <        now->tm_hour = 0;
141 >        day->tm_sec = 0;
142 >        day->tm_min = 0;
143 >        day->tm_hour = 0;
144  
145 <        std::time_t difference(mktime(now) / 86400);
145 >        if (!date.IsEmpty()) ::strptime(date.NullTerminate(), "%Y-%m-%d", day);
146 >
147 >        std::time_t difference(mktime(day) / 86400);
148          std::vector<ext::String> jargon(this->jargon.begin(), this->jargon.end());
149          ext::String entry(jargon.size() ? jargon[difference % jargon.size()] : "");
150  
151          select(entry);
152   }
153  
154 < void FeepingCreaturism::random()
154 > void FeepingCreaturism::random(const ext::String& number)
155   {
156          ::srandomdev();
157  
158          std::vector<ext::String> jargon(this->jargon.begin(), this->jargon.end());
159 <        ext::String entry(jargon.size() ? jargon[::random() % jargon.size()] : "");
159 >        std::vector<ext::String>::size_type random(number.IsEmpty() ? ::random() :
160 >                lexical_cast<std::vector<ext::String>::size_type>(number));
161 >
162 >        assert(random >= 0);
163 >        assert(random % jargon.size() < jargon.size());
164 >
165 >        ext::String entry(jargon.size() ? jargon[random % jargon.size()] : "");
166  
167          select(entry);
168   }
# Line 159 | Line 173 | void FeepingCreaturism::select(const ext
173          {
174                  api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n";
175  
176 <                _M::iterator include(cgi.find("include"));
176 >                Jargon jargon(path, selection, cgi.find("include") != cgi.end()
177 >                        && lexical_cast<bool>(ext::String(cgi.find("include")->second)),
178 >                        cgi.find("relative") != cgi.end()
179 >                        ? ext::String(cgi.find("relative")->second) : ext::String());
180  
181 <                if (include != cgi.end())
165 <                {
166 <                        Jargon jargon(path + "/" + selection,
167 <                                lexical_cast<bool>(include->second));
168 <
169 <                        api::Cout << jargon;
170 <                }
171 <                else
172 <                {
173 <                        Jargon jargon(path + "/" + selection);
174 <
175 <                        api::Cout << jargon;
176 <                }
181 >                api::Cout << jargon;
182          }
183          else
184          {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines