--- SiteMapper/SiteMapper.cpp 2004/06/04 09:40:33 154 +++ SiteMapper/SiteMapper.cpp 2004/10/02 00:19:10 259 @@ -4,53 +4,55 @@ // // $Id$ -#ifdef _WIN32 -#pragma warning(disable:4503) -#endif - #include "SiteMapper.hpp" #include "Matcher.hpp" #include "Page.hpp" +#include +#include + string program; bool debug(false); -int main(int argc, char* argv[]) +struct SiteMapperCommand : public app::Application { - program = argv[0]; - - string siteIndex, siteMap; - - for (int index(1); index < argc; index++) + virtual int Run(const app::ArgumentList& args) { - string arg(argv[index]); - Matcher matcher; + program = api::GetExecutablePath().GetName(); + + string siteIndex, siteMap; - if (arg == matcher("^-index=(.*)$")) + for (size_t index(0); index < args.GetSize(); index++) { - siteIndex = matcher[1]; + string arg(args[index]); + Matcher matcher; + + if (arg == matcher("^-index=(.*)$")) + { + siteIndex = matcher[1]; + } + else if (arg == matcher("^-map=(.*)$")) + { + siteMap = matcher[1]; + } + else if (arg == "-D") + { + if (!debug) debug = true; + } } - else if (arg == matcher("^-map=(.*)$")) + + if (!siteIndex.empty() && !siteMap.empty()) { - siteMap = matcher[1]; + SiteMapper mapper(siteIndex, siteMap); } - else if (arg == "-D") + else { - if (!debug) debug = true; + cout << "Usage: " << program << " -index=index -map=map [-D]\n"; } - } - if (siteIndex != "" && siteMap != "") - { - SiteMapper mapper(siteIndex, siteMap); - } - else - { - cout << "Usage: " << program << " -index=index -map=map [-D]\n"; + return 0; } - - return 0; -} +} mapper; SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap) { @@ -64,7 +66,9 @@ void SiteMapper::oldMap(const string& si ext::Handle document(xml::Parse(siteMap)); ext::Handle list(*document/"page"/"section"/"list"); - comment = *document/"comment()"; + comment = ext::String(*document/"comment()"); + + if (debug) cerr << "comment = " << comment << '\n'; oldMap(pages, list); } @@ -76,7 +80,8 @@ void SiteMapper::oldMap(vector& pa for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); ++node) { - string url(**node/"link"/"@address"), title(**node/"link"); + string url(ext::String(**node/"link"/"@address")), + title(ext::String(**node/"link")); Page page(url, title); ext::Handle list(**node/"list"); @@ -94,22 +99,23 @@ void SiteMapper::newIndex(const string& for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); ++node) { - string address(**node/"address"); - string port(**node/"port"); + string address(ext::String(**node/"address")), + port(ext::String(**node/"port")); if (!port.empty()) { address += ':' + port; } - string path(**node/"path"), title(**node/"title"); + string path(ext::String(**node/"path")), + title(ext::String(**node/"title")); Page page(address, path, title); Matcher matcher; if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou") + "glas\\sThrift's\\sBlog:\\s(.+)$")) { - if (Matcher("^\\w+\\s\\d\\d\\d\\d\\sArchives$") == matcher[1]) + if (Matcher("^\\w+\\s\\d{4}\\sArchives$") == matcher[1]) { page.setTitle(matcher[1]); @@ -147,6 +153,8 @@ bool SiteMapper::newIndex(vector& pages[index] = page; + cout << "Updated: " << page.getUrl() << '\n'; + return true; } else if (matcher('^' + pages[index].getPath()) == page) @@ -210,6 +218,8 @@ void SiteMapper::newMap(vector& pa for (multimap::iterator itor(newPages.lower_bound(childOf)); itor != newPages.upper_bound(childOf); itor++) { + cout << "Added: " << itor->second.getUrl() << '\n'; + pages.push_back(itor->second); }