4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
– |
#ifdef _WIN32 |
8 |
– |
#pragma warning(disable:4503) |
9 |
– |
#endif |
10 |
– |
|
7 |
|
#include "SiteMapper.hpp" |
8 |
|
#include "Matcher.hpp" |
9 |
|
#include "Page.hpp" |
10 |
|
|
11 |
+ |
#include <menes-api/exename.hpp> |
12 |
+ |
#include <menes-app/application.hpp> |
13 |
+ |
|
14 |
|
string program; |
15 |
|
bool debug(false); |
16 |
|
|
17 |
< |
int main(int argc, char* argv[]) |
17 |
> |
struct SiteMapperCommand : public app::Application |
18 |
|
{ |
19 |
< |
program = argv[0]; |
21 |
< |
|
22 |
< |
string siteIndex, siteMap; |
23 |
< |
|
24 |
< |
for (int index(1); index < argc; index++) |
19 |
> |
virtual int Run(const app::ArgumentList& args) |
20 |
|
{ |
21 |
< |
string arg(argv[index]); |
22 |
< |
Matcher matcher; |
21 |
> |
program = api::GetExecutablePath().GetName(); |
22 |
> |
|
23 |
> |
string siteIndex, siteMap; |
24 |
|
|
25 |
< |
if (arg == matcher("^-index=(.*)$")) |
25 |
> |
for (size_t index(0); index < args.GetSize(); index++) |
26 |
|
{ |
27 |
< |
siteIndex = matcher[1]; |
27 |
> |
string arg(args[index]); |
28 |
> |
Matcher matcher; |
29 |
> |
|
30 |
> |
if (arg == matcher("^-index=(.*)$")) |
31 |
> |
{ |
32 |
> |
siteIndex = matcher[1]; |
33 |
> |
} |
34 |
> |
else if (arg == matcher("^-map=(.*)$")) |
35 |
> |
{ |
36 |
> |
siteMap = matcher[1]; |
37 |
> |
} |
38 |
> |
else if (arg == "-D") |
39 |
> |
{ |
40 |
> |
if (!debug) debug = true; |
41 |
> |
} |
42 |
|
} |
43 |
< |
else if (arg == matcher("^-map=(.*)$")) |
43 |
> |
|
44 |
> |
if (!siteIndex.empty() && !siteMap.empty()) |
45 |
|
{ |
46 |
< |
siteMap = matcher[1]; |
46 |
> |
SiteMapper mapper(siteIndex, siteMap); |
47 |
|
} |
48 |
< |
else if (arg == "-D") |
48 |
> |
else |
49 |
|
{ |
50 |
< |
if (!debug) debug = true; |
50 |
> |
cout << "Usage: " << program << " -index=index -map=map [-D]\n"; |
51 |
|
} |
41 |
– |
} |
52 |
|
|
53 |
< |
if (siteIndex != "" && siteMap != "") |
44 |
< |
{ |
45 |
< |
SiteMapper mapper(siteIndex, siteMap); |
46 |
< |
} |
47 |
< |
else |
48 |
< |
{ |
49 |
< |
cout << "Usage: " << program << " -index=index -map=map [-D]\n"; |
53 |
> |
return 0; |
54 |
|
} |
55 |
< |
|
52 |
< |
return 0; |
53 |
< |
} |
55 |
> |
} mapper; |
56 |
|
|
57 |
|
SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap) |
58 |
|
{ |
66 |
|
ext::Handle<xml::Document> document(xml::Parse(siteMap)); |
67 |
|
ext::Handle<xml::Node> list(*document/"page"/"section"/"list"); |
68 |
|
|
69 |
< |
comment = *document/"comment()"; |
69 |
> |
comment = ext::String(*document/"comment()"); |
70 |
> |
|
71 |
> |
if (debug) cerr << "comment = " << comment << '\n'; |
72 |
|
|
73 |
|
oldMap(pages, list); |
74 |
|
} |
80 |
|
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
81 |
|
++node) |
82 |
|
{ |
83 |
< |
string url(**node/"link"/"@address"), title(**node/"link"); |
83 |
> |
string url(ext::String(**node/"link"/"@address")), |
84 |
> |
title(ext::String(**node/"link")); |
85 |
|
Page page(url, title); |
86 |
|
ext::Handle<xml::Node> list(**node/"list"); |
87 |
|
|
99 |
|
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
100 |
|
++node) |
101 |
|
{ |
102 |
< |
string address(**node/"address"); |
103 |
< |
string port(**node/"port"); |
102 |
> |
string address(ext::String(**node/"address")), |
103 |
> |
port(ext::String(**node/"port")); |
104 |
|
|
105 |
|
if (!port.empty()) |
106 |
|
{ |
107 |
|
address += ':' + port; |
108 |
|
} |
109 |
|
|
110 |
< |
string path(**node/"path"), title(**node/"title"); |
110 |
> |
string path(ext::String(**node/"path")), |
111 |
> |
title(ext::String(**node/"title")); |
112 |
|
Page page(address, path, title); |
113 |
|
Matcher matcher; |
114 |
|
|
115 |
|
if (page == matcher(string("^Douglas\\sThrift's\\sWebsite\\s\\|\\sDou") |
116 |
|
+ "glas\\sThrift's\\sBlog:\\s(.+)$")) |
117 |
|
{ |
118 |
< |
if (Matcher("^\\w+\\s\\d\\d\\d\\d\\sArchives$") == matcher[1]) |
118 |
> |
if (Matcher("^\\w+\\s\\d{4}\\sArchives$") == matcher[1]) |
119 |
|
{ |
120 |
|
page.setTitle(matcher[1]); |
121 |
|
|
153 |
|
|
154 |
|
pages[index] = page; |
155 |
|
|
156 |
+ |
cout << "Updated: " << page.getUrl() << '\n'; |
157 |
+ |
|
158 |
|
return true; |
159 |
|
} |
160 |
|
else if (matcher('^' + pages[index].getPath()) == page) |
218 |
|
for (multimap<string, Page>::iterator itor(newPages.lower_bound(childOf)); |
219 |
|
itor != newPages.upper_bound(childOf); itor++) |
220 |
|
{ |
221 |
+ |
cout << "Added: " << itor->second.getUrl() << '\n'; |
222 |
+ |
|
223 |
|
pages.push_back(itor->second); |
224 |
|
} |
225 |
|
|