ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/GoogleTron/GoogleTron.cpp
Revision: 679
Committed: 2006-03-05T19:57:15-08:00 (19 years, 4 months ago) by douglas
File size: 2123 byte(s)
Log Message:
Schema something something and arguments.

File Contents

# User Rev Content
1 douglas 672 // Google Tron
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include <cxx/standard.hh>
8    
9 douglas 679 #include <api/exename.hpp>
10     #include <api/pcre/regex.hpp>
11 douglas 673 #include <api/process.hpp>
12 douglas 672 #include <app/simple.hpp>
13 douglas 673 #include <xml/textwriter.hpp>
14 douglas 672
15 douglas 676 #include "GoogleTron.hpp"
16 douglas 674 #include "GzipWriter.hpp"
17 douglas 677 #include "Sleep.hpp"
18 douglas 674
19 douglas 672 int Main(const app::Options &options)
20     {
21 douglas 679 cse::String sitemap(_B("sitemap.gz"));
22 douglas 676
23 douglas 679 api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$"));
24    
25     _foreach (const app::ArgumentList, arg, app::GetArguments())
26     {
27     api::Pcre::RegEx::Match match;
28    
29     if (match = sitemap_(*arg))
30     sitemap = match[1];
31     else
32     {
33     api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=sitemap]") << ios::NewLine;
34    
35     return 1;
36     }
37     }
38    
39     GoogleTron tron(sitemap);
40    
41 douglas 676 return 0;
42     }
43    
44 douglas 677 GoogleTron::GoogleTron(const cse::String &sitemap) : working(true), sitemap(sitemap)
45 douglas 676 {
46 douglas 677 // XXX: start some threads
47 douglas 676 }
48    
49     GoogleTron::~GoogleTron()
50     {
51 douglas 677 // XXX: wait on threads
52    
53     working = false;
54    
55     // XXX: wait on output thread
56 douglas 676 }
57    
58     int GoogleTron::Output()
59     {
60 douglas 677 _S<GzipWriter> gzip(sitemap);
61 douglas 674 _S<xml::TextWriter> writer(gzip);
62 douglas 673 xml::ScopeElement urlset(writer, _B("urlset"));
63    
64     writer.SetAttribute(_B("xmlns"), _B("http://www.google.com/schemas/sitemap/0.84"));
65 douglas 679 writer.SetAttribute(_B("xmlns:xsi"), _B("http://www.w3.org/2001/XMLSchema-instance"));
66     writer.SetAttribute(_B("xsi:schemaLocation"), _B("http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"));
67 douglas 673
68 douglas 677 do
69     {
70     Sleep();
71    
72     _synchronized (queueLock)
73     if (queue.size())
74     {
75     xml::ScopeElement url_(writer, _B("url"));
76     const Url &url(queue.front());
77    
78     {
79     xml::ScopeElement loc(writer, _B("loc"));
80    
81     writer.OutputText(url.GetLocation());
82     }
83    
84     {
85     xml::ScopeElement lastmod(writer, _B("lastmod"));
86    
87     writer.OutputText(url.GetModified());
88     }
89    
90     {
91     xml::ScopeElement changefreq(writer, _B("changefreq"));
92    
93     writer.OutputText(url.GetFrequency());
94     }
95    
96     {
97     xml::ScopeElement priority(writer, _B("priority"));
98    
99     writer.OutputText(url.GetPriority());
100     }
101    
102     queue.pop();
103     }
104     }
105     while (working);
106    
107 douglas 672 return 0;
108     }

Properties

Name Value
svn:eol-style native
svn:keywords Id