1 |
// Zoe AIM Away Message RSS Feed Generator |
2 |
// |
3 |
// Seth King and Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
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 |
{ |
24 |
Zoe::program = argv[0]; |
25 |
|
26 |
for (int index(1); index < argc; ++index) |
27 |
{ |
28 |
ext::String arg(argv[index]); |
29 |
Matcher matcher; |
30 |
|
31 |
if (arg == matcher("^-config=(.*)$")) |
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 << 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 |
} |
57 |
} |
58 |
|
59 |
Zoe zoe; |
60 |
|
61 |
return 0; |
62 |
} |
63 |
|
64 |
Zoe::Zoe() |
65 |
{ |
66 |
configure(); |
67 |
|
68 |
Collector collector(login, password, buddies, Zoe::collector); |
69 |
Publisher publisher(buddies, Zoe::publisher); |
70 |
} |
71 |
|
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() |
76 |
{ |
77 |
ext::Handle<xml::Document> document(xml::Parse(config)); |
78 |
ext::Handle<xml::Node> zoe(*document/"zoe"); |
79 |
|
80 |
login = std::string(*zoe/"login"); |
81 |
password = std::string(*zoe/"password"); |
82 |
|
83 |
xml::NodeSet buddies(*zoe/"buddy"); |
84 |
|
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 |
} |