ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/GoogleTron/GoogleTron.cpp
(Generate patch)

Comparing GoogleTron/GoogleTron.cpp (file contents):
Revision 677 by douglas, 2006-03-04T07:11:04-08:00 vs.
Revision 687 by douglas, 2006-03-06T18:05:20-08:00

# Line 6 | Line 6
6  
7   #include <cxx/standard.hh>
8  
9 + #include <api/exename.hpp>
10 + #include <api/pcre/regex.hpp>
11   #include <api/process.hpp>
12   #include <app/simple.hpp>
13 + #include <hop/bind.hpp>
14   #include <xml/textwriter.hpp>
15  
16   #include "GoogleTron.hpp"
14 #include "GzipWriter.hpp"
17   #include "Sleep.hpp"
18 + #include "Zlib/GzipWriter.hpp"
19  
20   int Main(const app::Options &options)
21   {
22 <        GoogleTron tron(_B("sitemap.gz"));
22 >        cse::String sitemap(_B("sitemap.gz"));
23 >        _L<_R<Command> > commands;
24 >
25 >        api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$")), fs_(_B("^-fs=(.*)$")), exclude(_B("^-exclude=(.+)$"));
26 >
27 >        _foreach (const app::ArgumentList, arg, app::GetArguments())
28 >        {
29 >                api::Pcre::RegEx::Match match;
30 >                _R<FileSystemCommand> fs;
31 >
32 >                if (match = sitemap_(*arg))
33 >                        sitemap = match[1];
34 >                else if (match = fs_(*arg))
35 >                        commands.InsertLast(new _H<FileSystemCommand>(match[1]));
36 >                else if (commands.GetSize() && (fs = dynamic_cast<FileSystemCommand *>(commands.Last().GetValue())) && (match = exclude(*arg)))
37 >                        fs->excludes.InsertLast(match[1]);
38 >                else
39 >                {
40 >                        api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=.+] [-fs=.* [-exclude=.+] ...] ...") << ios::NewLine;
41 >
42 >                        return 1;
43 >                }
44 >        }
45 >
46 >        GoogleTron tron(sitemap, commands);
47  
48          return 0;
49   }
50  
51 < GoogleTron::GoogleTron(const cse::String &sitemap) : working(true), sitemap(sitemap)
51 > GoogleTron::GoogleTron(const cse::String &sitemap, const _L<_R<Command> > &commands) : working(true), sitemap(sitemap), output(hop::BindAll(&GoogleTron::Output, this))
52   {
53 <        // XXX: start some threads
53 >        _foreach (const _L<_R<Command> >, command_, commands)
54 >                if (_R<FileSystemCommand> command = dynamic_cast<FileSystemCommand *>(command_->GetValue()))
55 >                        threads.Add(hop::BindAll(&GoogleTron::FileSystem_, this, command));
56   }
57  
58   GoogleTron::~GoogleTron()
59   {
60 <        // XXX: wait on threads
61 <        
60 >        threads.Join();
61 >
62          working = false;
63  
64 <        // XXX: wait on output thread
64 >        output.Join();
65   }
66  
67   int GoogleTron::Output()
68   {
69 <        _S<GzipWriter> gzip(sitemap);
69 >        _S<Zlib::GzipWriter> gzip(sitemap);
70          _S<xml::TextWriter> writer(gzip);
71          xml::ScopeElement urlset(writer, _B("urlset"));
72  
73          writer.SetAttribute(_B("xmlns"), _B("http://www.google.com/schemas/sitemap/0.84"));
74 +        writer.SetAttribute(_B("xmlns:xsi"), _B("http://www.w3.org/2001/XMLSchema-instance"));
75 +        writer.SetAttribute(_B("xsi:schemaLocation"), _B("http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"));
76  
77          do
78          {
# Line 84 | Line 115 | int GoogleTron::Output()
115  
116          return 0;
117   }
118 +
119 + int GoogleTron::FileSystem_(const _R<FileSystemCommand> &command)
120 + {
121 +        FileSystem fs(sitemap, queue, queueLock, command);
122 +
123 +        return 0;
124 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines