8 |
|
#include "Matcher.hpp" |
9 |
|
#include "Page.hpp" |
10 |
|
|
11 |
+ |
#include <menes-api/exename.hpp> |
12 |
+ |
#include <menes-app/application.hpp> |
13 |
+ |
|
14 |
+ |
#include <cassert> |
15 |
+ |
|
16 |
|
string program; |
17 |
|
bool debug(false); |
18 |
|
|
19 |
< |
int main(int argc, char* argv[]) |
19 |
> |
struct SiteMapperCommand : public app::Application |
20 |
|
{ |
21 |
< |
program = argv[0]; |
17 |
< |
|
18 |
< |
string siteIndex, siteMap; |
19 |
< |
|
20 |
< |
for (int index(1); index < argc; index++) |
21 |
> |
virtual int Run(const app::ArgumentList& args) |
22 |
|
{ |
23 |
< |
string arg(argv[index]); |
24 |
< |
Matcher matcher; |
23 |
> |
program = api::GetExecutableName(); |
24 |
> |
|
25 |
> |
string siteIndex, siteMap; |
26 |
|
|
27 |
< |
if (arg == matcher("^-index=(.*)$")) |
27 |
> |
for (size_t index(0); index < args.GetSize(); index++) |
28 |
|
{ |
29 |
< |
siteIndex = matcher[1]; |
29 |
> |
string arg(args[index]); |
30 |
> |
Matcher matcher; |
31 |
> |
|
32 |
> |
if (arg == matcher("^-index=(.*)$")) |
33 |
> |
{ |
34 |
> |
siteIndex = matcher[1]; |
35 |
> |
} |
36 |
> |
else if (arg == matcher("^-map=(.*)$")) |
37 |
> |
{ |
38 |
> |
siteMap = matcher[1]; |
39 |
> |
} |
40 |
> |
else if (arg == "-D") |
41 |
> |
{ |
42 |
> |
if (!debug) debug = true; |
43 |
> |
} |
44 |
|
} |
45 |
< |
else if (arg == matcher("^-map=(.*)$")) |
45 |
> |
|
46 |
> |
if (!siteIndex.empty() && !siteMap.empty()) |
47 |
|
{ |
48 |
< |
siteMap = matcher[1]; |
48 |
> |
SiteMapper mapper(siteIndex, siteMap); |
49 |
|
} |
50 |
< |
else if (arg == "-D") |
50 |
> |
else |
51 |
|
{ |
52 |
< |
if (!debug) debug = true; |
52 |
> |
cout << "Usage: " << program << " -index=index -map=map [-D]\n"; |
53 |
|
} |
37 |
– |
} |
54 |
|
|
55 |
< |
if (!siteIndex.empty() && !siteMap.empty()) |
40 |
< |
{ |
41 |
< |
SiteMapper mapper(siteIndex, siteMap); |
42 |
< |
} |
43 |
< |
else |
44 |
< |
{ |
45 |
< |
cout << "Usage: " << program << " -index=index -map=map [-D]\n"; |
55 |
> |
return 0; |
56 |
|
} |
57 |
< |
|
48 |
< |
return 0; |
49 |
< |
} |
57 |
> |
} mapper; |
58 |
|
|
59 |
|
SiteMapper::SiteMapper(const string& siteIndex, const string& siteMap) |
60 |
|
{ |
68 |
|
ext::Handle<xml::Document> document(xml::Parse(siteMap)); |
69 |
|
ext::Handle<xml::Node> list(*document/"page"/"section"/"list"); |
70 |
|
|
71 |
< |
comment = *document/"comment()"; |
71 |
> |
comment = ext::String(*document/"comment()"); |
72 |
> |
|
73 |
> |
if (debug) cerr << "comment = " << comment << '\n'; |
74 |
> |
|
75 |
> |
assert(comment == " Cheese! "); |
76 |
|
|
77 |
|
oldMap(pages, list); |
78 |
|
} |
84 |
|
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
85 |
|
++node) |
86 |
|
{ |
87 |
< |
string url(**node/"link"/"@address"), title(**node/"link"); |
87 |
> |
string url(ext::String(**node/"link"/"@address")), |
88 |
> |
title(ext::String(**node/"link")); |
89 |
|
Page page(url, title); |
90 |
|
ext::Handle<xml::Node> list(**node/"list"); |
91 |
|
|
103 |
|
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
104 |
|
++node) |
105 |
|
{ |
106 |
< |
string address(**node/"address"); |
107 |
< |
string port(**node/"port"); |
106 |
> |
string address(ext::String(**node/"address")), |
107 |
> |
port(ext::String(**node/"port")); |
108 |
|
|
109 |
|
if (!port.empty()) |
110 |
|
{ |
111 |
|
address += ':' + port; |
112 |
|
} |
113 |
|
|
114 |
< |
string path(**node/"path"), title(**node/"title"); |
114 |
> |
string path(ext::String(**node/"path")), |
115 |
> |
title(ext::String(**node/"title")); |
116 |
|
Page page(address, path, title); |
117 |
|
Matcher matcher; |
118 |
|
|