--- FeepingCreaturism/Jargon.cpp 2004/09/02 10:41:06 209 +++ FeepingCreaturism/Jargon.cpp 2004/09/15 00:42:21 254 @@ -5,222 +5,58 @@ // $Id$ #include "Jargon.hpp" +#include "Matcher.hpp" -Jargon::Jargon(const ext::String& path, bool include) : include(include) +Jargon::Jargon(const ext::String& path, const ext::String& jargon, bool include, + const ext::String& relative) : include(include), + args(1, FeepingCreaturism::program) { - std::vector args(1, FeepingCreaturism::program); + args.push_back("-m"); + args.push_back("-p"); + args.push_back("jargon"); + args.push_back("\"" + jargon + "\""); + args.push_back("-p"); + args.push_back("include"); + args.push_back(lexical_cast(include) + "()"); - args.push_back(path); - args.push_back("jargon.xsl"); - - redi::pstreambuf pin("/usr/local/bin/Xalan", args, std::ios_base::in); - ios::FromStreamBuf adaptor(pin); - - ext::Handle document(xml::Parse(adaptor)); - ext::Handle jargon(*document/"jargon"); - - word = *jargon/"word"; - pronunciation = *jargon/"pronunciation"; - grammar = *jargon/"grammar"; - definition = *jargon/"definition"/"p"; -} - -void Jargon::display(ios::PrintWriter& pout, xml::TextWriter& xhtml) const -{ + if (!relative.IsEmpty()) { - xml::ScopeElement p(xhtml, "p"); - - xhtml.OpenElement("strong"); - xhtml.OutputText(word + ":"); - xhtml.CloseElement(); - xhtml.OutputText(" " + pronunciation); - - if (!grammar.IsEmpty()) xhtml.OutputText(", " + grammar); + args.push_back("-p"); + args.push_back("relative"); + args.push_back("\"" + relative + "\""); } - for (xml::NodeSet::ConstIterator node(definition.Begin()); - node != definition.End(); ++node) - { - xml::ScopeElement p(xhtml, "p"); - - xhtml.OutputText(**node); - } + args.push_back(path + "/" + jargon); + args.push_back("jargon.xsl"); } -struct Section -{ - Section(const ext::String& name, const ext::String& path, - const ext::String& subdomain = "www") : name(name), url("http://" - + subdomain + ".douglasthrift.net" + path) {} - ext::String name, url; -}; - ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Jargon& jargon) { - if (jargon.include) - { - xml::TextWriter xhtml(pout); - - jargon.display(pout, xhtml); - - return pout; - } - - pout << "\n"; - - xml::TextWriter xhtml(pout); - xml::ScopeElement html(xhtml, "html"); - - xhtml.SetAttribute("xmlns", "http://www.w3.org/1999/xhtml"); + redi::ipstream pin("/usr/local/bin/Xalan", jargon.args); + if (jargon.include) { - xml::ScopeElement head(xhtml, "head"); - - xhtml.OpenElement("title"); - xhtml.OutputText("Douglas Thrift"); - - pout << "'"; + std::string ignore; - xhtml.OutputText("s Computers Website | Jargon: " + jargon.word); - xhtml.CloseElement(); - xhtml.OpenElement("link"); - xhtml.SetAttribute("rel", "stylesheet"); - xhtml.SetAttribute("href", "../../stylesheets/regular.css"); - xhtml.SetAttribute("type", "text/css"); - xhtml.CloseElement(); - xhtml.OpenElement("link"); - xhtml.SetAttribute("rel", "Icon"); - xhtml.SetAttribute("href", "../../favicon.ico"); - xhtml.SetAttribute("type", "image/ico"); - xhtml.CloseElement(); - xhtml.OpenElement("script"); - xhtml.SetAttribute("src", "../../nav/functions.js"); - xhtml.SetAttribute("type", "text/javascript"); - xhtml.OutputText(""); - xhtml.CloseElement(); + std::getline(pin, ignore); } + do { - xml::ScopeElement body(xhtml, "body"); - - { - xml::ScopeElement div(xhtml, "div"); - - xhtml.OpenElement("p"); - xhtml.SetAttribute("class", "center"); - xhtml.OpenElement("a"); - xhtml.SetAttribute("href", Section("", "/", "computers").url); - xhtml.OpenElement("img"); - xhtml.SetAttribute("src", "../../masthead.png"); - xhtml.SetAttribute("alt", "Douglas Thrift's Computers Website"); - xhtml.SetAttribute("title", "Douglas Thrift's Computers Website"); - xhtml.CloseElement(); - xhtml.CloseElement(); - xhtml.CloseElement(); - xhtml.OpenElement("p"); - xhtml.SetAttribute("class", "center nav"); - - std::vector
sections; - - sections.push_back(Section("Home", "/")); - sections.push_back(Section("Blog", "/blog/")); - sections.push_back(Section("Computers", "/", "computers")); - sections.push_back(Section("Movies", "/", "movies")); - sections.push_back(Section("Music", "/", "music")); - sections.push_back(Section("TV Shows", "/", "tvshows")); - sections.push_back(Section("Sitemap", "/sitemap.xml")); - sections.push_back(Section("Contact", "/contact.php")); - sections.push_back(Section("Linking", "/linking.xml")); - sections.push_back(Section("Search", "/search.cgi")); - - for (std::vector
::size_type index(0); - index < sections.size(); ++index) - { - if (index > 0) xhtml.OutputText(" | "); - - xhtml.OpenElement("a"); - xhtml.SetAttribute("href", sections[index].url); - - if (index != 2) - { - xhtml.SetAttribute("onmouseout", "deselect(" - + lexical_cast(index + 1) + ")"); - xhtml.SetAttribute("onmouseover", "select(" - + lexical_cast(index + 1) + ")"); - xhtml.SetAttribute("class", "nav"); - } - else xhtml.SetAttribute("class", "nav select"); - - xhtml.OutputText(sections[index].name); - xhtml.CloseElement(); - } + std::string line; - xhtml.CloseElement(); - } + std::getline(pin, line); + while (jargon.include && line.find(" xmlns=") != std::string::npos) { - xml::ScopeElement div(xhtml, "div"); + std::string::size_type position(line.find(" xmlns=")); - xhtml.SetAttribute("class", "hr"); - xhtml.OpenElement("h1"); - xhtml.SetAttribute("id", "title"); - xhtml.SetAttribute("class", "center"); - xhtml.OutputText("Jargon: " + jargon.word); - xhtml.CloseElement(); + line.replace(position, 37, ""); } - { - xml::ScopeElement div(xhtml, "div"); - - xhtml.SetAttribute("class", "hr"); - jargon.display(pout, xhtml); - } - - { - xml::ScopeElement div(xhtml, "div"); - - xhtml.SetAttribute("class", "hr"); - xhtml.OpenElement("p"); - xhtml.SetAttribute("class", "center"); - xhtml.OutputText("Copyright "); pout << "©"; // XXX hmm? - xhtml.OutputText(" 2002-2004, "); - xhtml.OpenElement("a"); - xhtml.SetAttribute("href", Section("", "/contact.php").url); - xhtml.OutputText("Douglas Thrift"); - xhtml.CloseElement(); - xhtml.OutputText(". All Rights Reserved."); - xhtml.CloseElement(); - xhtml.OpenElement("p"); - xhtml.SetAttribute("class", "center"); - xhtml.OutputText(""); - - pout << ""; - - { - xml::ScopeElement img(xhtml, "img"); - - xhtml.SetAttribute("src", "../../w3c_images/vxh10.png"); - xhtml.SetAttribute("alt", "Valid XHTML 1.0!"); - xhtml.SetAttribute("title", "Valid XHTML 1.0!"); - } - - pout << " "; - - { - xml::ScopeElement img(xhtml, "img"); - - xhtml.SetAttribute("src", "../../w3c_images/vcss.png"); - xhtml.SetAttribute("alt", "Valid CSS!"); - xhtml.SetAttribute("title", "Valid CSS!"); - } - - pout << ""; - - xhtml.CloseElement(); - } + pout << line << "\n"; } + while (pin.good()); return pout; }