--- Represent/Represent.cpp 2004/12/22 07:19:54 371 +++ Represent/Represent.cpp 2004/12/23 04:42:52 379 @@ -6,8 +6,14 @@ #include "Hexadecimal.hpp" +#include #include +struct Environment +{ + ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } } +} env; + int Main(const app::Options& options) { Represent represent; @@ -17,18 +23,46 @@ int Main(const app::Options& options) Represent::Represent() { - ext::String string("1001"); - Binary sign(string, true), unsign(string, false); + parse(); + + api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush; + + xml::TextWriter xhtml(api::Cout); + xml::ScopeElement table(xhtml, "table"); + + { + xml::ScopeElement tr(xhtml, "tr"); + ext::String headings[] = { "Type", "Data Representation", "Storage" }; + + _foru (index, 0, sizeof (headings) / sizeof (ext::String)) + { + xml::ScopeElement th(xhtml, "th"); + + xhtml.OutputText(headings[index]); + } + } +} + +void Represent::parse() +{ + ext::String query(env.get("QUERY_STRING")); - api::Cerr << string << ios::NewLine << ext::String(sign) << ios::NewLine << ext::String(unsign) << ios::NewLine; + if (env.get("REQUEST_METHOD") == "POST") + { + ext::Buffer content(lexical_cast(env.get("CONTENT_LENGTH"))); - string = "deadbeef"; + api::Cin.ReadFully(content.Begin(), content.GetSize()); - Hexadecimal test(string, false); + query = content; + } - api::Cerr << string << ios::NewLine << ext::String(test) << ios::NewLine; + ext::Vector pairs(query.Split('&')); - Hexadecimal sign_(sign), unsign_(unsign); + _foreach (ext::Vector, pair, pairs) + { + ext::String::ConstIterator equal(pair->FindFirst('=')); + ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End()); - api::Cerr << ext::String(sign_) << ios::NewLine << ext::String(unsign_) << ios::NewLine; + cgi.insert(std::pair(name, value)); + } }