17 |
|
#include "Sleep.hpp" |
18 |
|
#include "Zlib/GzipWriter.hpp" |
19 |
|
|
20 |
– |
int Usage() |
21 |
– |
{ |
22 |
– |
api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=.+] -base=.+ [-fs=.*] [-blog=.*] [-wiki=.*] [...]") << ios::NewLine; |
23 |
– |
|
24 |
– |
return 1; |
25 |
– |
} |
26 |
– |
|
20 |
|
int Main(const app::Options &options) |
21 |
|
{ |
22 |
|
cse::String sitemap(_B("sitemap.gz")), base; |
39 |
|
else if (match = wiki(*arg)) |
40 |
|
commands.InsertLast(new _H<WikiCommand>(match[1])); |
41 |
|
else |
42 |
< |
return Usage(); |
42 |
> |
goto usage; |
43 |
|
} |
44 |
|
|
45 |
|
if (base.IsEmpty() || commands.IsEmpty()) |
46 |
< |
return Usage(); |
46 |
> |
{ |
47 |
> |
usage: api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=.+] -base=.+ [-fs=.*] [-blog=.*] [-wiki=.*] [...]") << ios::NewLine; |
48 |
> |
|
49 |
> |
return 1; |
50 |
> |
} |
51 |
|
|
52 |
|
GoogleTron tron(sitemap, base, commands); |
53 |
|
|
56 |
|
|
57 |
|
GoogleTron::GoogleTron(const cse::String &sitemap, const cse::String &base, const _L<_R<Command> > &commands) : working(true), sitemap(sitemap), base(base), output(hop::BindAll(&GoogleTron::Output, this)) |
58 |
|
{ |
59 |
+ |
api::Apr::CheckError(::apr_initialize()); |
60 |
+ |
|
61 |
|
_foreach (const _L<_R<Command> >, command_, commands) |
62 |
|
if (_R<FileSystemCommand> command = dynamic_cast<FileSystemCommand *>(command_->GetValue())) |
63 |
|
threads.Add(hop::BindAll(&GoogleTron::FileSystem_, this, command)); |
74 |
|
working = false; |
75 |
|
|
76 |
|
output.Join(); |
77 |
+ |
|
78 |
+ |
::apr_terminate(); |
79 |
|
} |
80 |
|
|
81 |
|
int GoogleTron::Output() |
88 |
|
writer.SetAttribute(_B("xmlns:xsi"), _B("http://www.w3.org/2001/XMLSchema-instance")); |
89 |
|
writer.SetAttribute(_B("xsi:schemaLocation"), _B("http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd")); |
90 |
|
|
91 |
< |
do |
92 |
< |
{ |
93 |
< |
Sleep(); |
93 |
< |
|
94 |
< |
_synchronized (queueLock) |
95 |
< |
if (queue.GetSize()) |
91 |
> |
_synchronized (queueLock) |
92 |
> |
do |
93 |
> |
_desynchronized (queueLock) |
94 |
|
{ |
95 |
< |
xml::ScopeElement url_(writer, _B("url")); |
98 |
< |
const Url &url(queue.Front()); |
95 |
> |
Sleep(); |
96 |
|
|
97 |
< |
{ |
98 |
< |
xml::ScopeElement loc(writer, _B("loc")); |
97 |
> |
_synchronized (queueLock) |
98 |
> |
if (queue.GetSize()) |
99 |
> |
{ |
100 |
> |
xml::ScopeElement url_(writer, _B("url")); |
101 |
> |
const Url &url(queue.Front()); |
102 |
|
|
103 |
< |
writer.OutputText(url.GetLocation()); |
104 |
< |
} |
103 |
> |
{ |
104 |
> |
xml::ScopeElement loc(writer, _B("loc")); |
105 |
|
|
106 |
< |
{ |
107 |
< |
xml::ScopeElement lastmod(writer, _B("lastmod")); |
106 |
> |
writer.OutputText(url.GetLocation()); |
107 |
> |
} |
108 |
|
|
109 |
< |
writer.OutputText(url.GetModified()); |
110 |
< |
} |
109 |
> |
{ |
110 |
> |
xml::ScopeElement lastmod(writer, _B("lastmod")); |
111 |
|
|
112 |
< |
{ |
113 |
< |
xml::ScopeElement changefreq(writer, _B("changefreq")); |
112 |
> |
writer.OutputText(url.GetModified()); |
113 |
> |
} |
114 |
|
|
115 |
< |
writer.OutputText(url.GetFrequency()); |
116 |
< |
} |
115 |
> |
{ |
116 |
> |
xml::ScopeElement changefreq(writer, _B("changefreq")); |
117 |
|
|
118 |
< |
{ |
119 |
< |
xml::ScopeElement priority(writer, _B("priority")); |
118 |
> |
writer.OutputText(url.GetFrequency()); |
119 |
> |
} |
120 |
|
|
121 |
< |
writer.OutputText(url.GetPriority()); |
122 |
< |
} |
121 |
> |
{ |
122 |
> |
xml::ScopeElement priority(writer, _B("priority")); |
123 |
|
|
124 |
< |
queue.Pop(); |
124 |
> |
writer.OutputText(url.GetPriority()); |
125 |
> |
} |
126 |
> |
|
127 |
> |
api::Cout << _B("Url: ") << url.GetLocation() << ios::NewLine << _B(" ") << url.GetModified() << _B(" ") << url.GetFrequency() << _B(" ") << url.GetPriority() << ios::NewLine; |
128 |
> |
|
129 |
> |
queue.Pop(); |
130 |
> |
} |
131 |
|
} |
132 |
< |
} |
127 |
< |
while (working); |
132 |
> |
while (working || queue.GetSize()); |
133 |
|
|
134 |
|
return 0; |
135 |
|
} |