4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
– |
#include "Zoe.hpp" |
7 |
|
#include "Matcher.hpp" |
8 |
+ |
#include "Collector.hpp" |
9 |
+ |
#include "Publisher.hpp" |
10 |
+ |
|
11 |
+ |
enum Color { reset, bright, dim, underscore = 4, blink, reverse = 7, hidden, |
12 |
+ |
black = 30, red, green, yellow, blue, magenta, cyan, white, _black = 40, |
13 |
+ |
_red, _green, _yellow, _blue, _magenta, _cyan, _white }; |
14 |
+ |
|
15 |
+ |
inline std::ostream& operator<<(std::ostream& sout, Color color) |
16 |
+ |
{ |
17 |
+ |
sout << "\033[" << unsigned(color) << 'm'; |
18 |
+ |
|
19 |
+ |
return sout; |
20 |
+ |
} |
21 |
|
|
22 |
|
int main(int argc, char* argv[]) |
23 |
|
{ |
32 |
|
{ |
33 |
|
Zoe::config = matcher[1]; |
34 |
|
} |
35 |
+ |
else if (arg == "-collector") |
36 |
+ |
{ |
37 |
+ |
if (!Zoe::collector) Zoe::collector = true; |
38 |
+ |
} |
39 |
+ |
else if (arg == "-publisher") |
40 |
+ |
{ |
41 |
+ |
if (!Zoe::publisher) Zoe::publisher = true; |
42 |
+ |
} |
43 |
|
else if (arg == "-D") |
44 |
|
{ |
45 |
|
if (!Zoe::debug) Zoe::debug = true; |
46 |
|
} |
47 |
|
else |
48 |
|
{ |
49 |
< |
cerr << "Usage: " << Zoe::program << " [-config=config] [-D]\n"; |
49 |
> |
cerr << bright << "Usage: " << cyan << Zoe::program << reset << " [" |
50 |
> |
<< bright << blue << "-config=" << yellow << "config" << reset |
51 |
> |
<< "] [" << bright << blue << "-collector" << reset << "] [" |
52 |
> |
<< bright << blue << "-publisher" << reset << "] [" << bright |
53 |
> |
<< blue << "-D" << reset << "]\n"; |
54 |
|
|
55 |
|
return 1; |
56 |
|
} |
61 |
|
return 0; |
62 |
|
} |
63 |
|
|
64 |
< |
Zoe::Zoe() : rss("zoe.rss") |
64 |
> |
Zoe::Zoe() |
65 |
|
{ |
66 |
|
configure(); |
67 |
|
|
68 |
< |
// This is just to figure out Jay's XML output, seems to have worked! |
69 |
< |
// It should really go in Rss.cpp later |
46 |
< |
api::FileOutputStream fout(this->rss != "-" ? this->rss : "/dev/null"); |
47 |
< |
xml::TextWriter rss(this->rss != "-" ? fout : api::Cout.GetStream()); |
48 |
< |
xml::ScopeElement root(rss, "rss"); |
49 |
< |
|
50 |
< |
rss.SetAttribute("version", "2.0"); |
51 |
< |
|
52 |
< |
xml::ScopeElement channel(rss, "channel"); |
53 |
< |
|
54 |
< |
rss.OpenElement("title"); |
55 |
< |
rss.OutputText("Zoe's Away Messages"); |
56 |
< |
rss.CloseElement(); |
57 |
< |
rss.OpenElement("link"); |
58 |
< |
rss.OutputText("http://computers.douglasthrift.net/zoe.xml"); |
59 |
< |
rss.CloseElement(); |
68 |
> |
Collector collector(login, password, buddies, Zoe::collector); |
69 |
> |
Publisher publisher(buddies, Zoe::publisher); |
70 |
|
} |
71 |
|
|
72 |
< |
bool Zoe::debug(false); |
72 |
> |
bool Zoe::debug(false), Zoe::collector(false), Zoe::publisher(false); |
73 |
|
ext::String Zoe::program, Zoe::config("zoe.xml"); |
74 |
|
|
75 |
|
void Zoe::configure() |
77 |
|
ext::Handle<xml::Document> document(xml::Parse(config)); |
78 |
|
ext::Handle<xml::Node> zoe(*document/"zoe"); |
79 |
|
|
80 |
< |
login = *zoe/"login"; |
81 |
< |
password = *zoe/"password"; |
80 |
> |
login = std::string(*zoe/"login"); |
81 |
> |
password = std::string(*zoe/"password"); |
82 |
> |
|
83 |
> |
xml::NodeSet buddies(*zoe/"buddy"); |
84 |
|
|
85 |
< |
if (!(*zoe/"rss").IsEmpty()) rss = *zoe/"rss"; |
85 |
> |
for (xml::NodeSet::Iterator buddy(buddies.Begin()); buddy != buddies.End(); |
86 |
> |
++buddy) |
87 |
> |
{ |
88 |
> |
this->buddies.insert(Buddy(**buddy/"login", **buddy/"rss")); |
89 |
> |
} |
90 |
> |
|
91 |
> |
if (!collector && !publisher) |
92 |
> |
{ |
93 |
> |
collector = true; |
94 |
> |
publisher = true; |
95 |
> |
} |
96 |
|
} |