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

Comparing trunk/Zoe.cpp (file contents):
Revision 30 by douglas, 2004-07-19T21:24:52-07:00 vs.
Revision 46 by douglas, 2004-08-16T18:52:59-07:00

# Line 19 | Line 19 | extern "C"
19   #include <unistd.h>
20   }
21  
22 < int main(int argc, char* argv[])
22 > int zoe(const std::vector<const char*> args)
23   {
24 <        Zoe::program = argv[0];
24 >        Zoe::program = args[0];
25  
26 <        for (int index(1); index < argc; ++index)
26 >        for (int index(1); index < args.size(); ++index)
27          {
28 <                ext::String arg(argv[index]);
28 >                ext::String arg(args[index]);
29                  Matcher matcher;
30  
31                  if (arg == matcher("^-config=(.*)$"))
# Line 40 | Line 40 | int main(int argc, char* argv[])
40                  {
41                          if (!Zoe::publisher) Zoe::publisher = true;
42                  }
43 <                else if (arg == "-D")
43 >                else if (arg == "-color")
44                  {
45 <                        if (!Zoe::debug) Zoe::debug = true;
45 >                        if (!Zoe::color) Zoe::color = true;
46                  }
47 <                else
47 >                else if (arg == "-D")
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;
49 >                        if (!Zoe::debug) Zoe::debug = true;
50                  }
51 +                else Zoe::usage();
52          }
53  
54          Zoe zoe;
# Line 61 | Line 56 | int main(int argc, char* argv[])
56          return 0;
57   }
58  
59 + int main(int argc, char* argv[])
60 + {
61 +        std::vector<const char*> args(argv, argv + argc);
62 +
63 +        return app::be::ThreadMain_(etl::BindAll(&zoe, args));
64 + }
65 +
66   Zoe::Zoe()
67   {
68 +        if (!(collector || publisher)) usage();
69 +        
70          configure();
71          initialize();
72  
# Line 70 | Line 74 | Zoe::Zoe()
74          Publisher publisher(buddies, database, Zoe::publisher);
75   }
76  
77 < bool Zoe::debug(false), Zoe::collector(false), Zoe::publisher(false);
77 > bool Zoe::debug(false), Zoe::collector(false), Zoe::publisher(false),
78 >         Zoe::color(false);
79   ext::String Zoe::program, Zoe::config("zoe.xml");
80  
81 < ext::String Zoe::generator()
81 > void Zoe::usage()
82   {
83 <        utsname system;
83 >        cerr << "Usage: " << Zoe::program << " [-config=config] [-collector] "
84 >                "[-publisher] [-color] [-D]\n";
85 >
86 >        exit(1);
87 > }
88 >
89 > ext::String Zoe::generator(Generator generator)
90 > {
91 >        ext::String generator_(generator == all || generator == agent ? "Zoe" : "");
92 >
93 >        switch (generator)
94 >        {
95 >        case all:
96 >                generator_.InsertAllLast("/0.9");
97 >        case agent:
98 >                {
99 >                        utsname system;
100  
101 <        uname(&system);
101 >                        uname(&system);
102  
103 <        return ext::String("Zoe/0.9 (") + system.sysname + "; http://computers.doug"
104 <                + "lasthrift.net/zoe.xml)";
103 >                        generator_.InsertAllLast(_S(" (") + system.sysname);
104 >                }
105 >
106 >                if (generator == agent)
107 >                {
108 >                        generator_.InsertAllLast(")");
109 >
110 >                        break;
111 >                }
112 >                else generator_.InsertAllLast("; ");
113 >        case url:
114 >                generator_.InsertAllLast("http://computers.douglasthrift.net/zoe.xml");
115 >
116 >                if (generator == all) generator_.InsertAllLast(")");
117 >
118 >                break;
119 >        case version:
120 >                generator_ = "0.9";
121 >        }
122 >
123 >        return generator_;
124   }
125  
126   void Zoe::configure()
# Line 99 | Line 139 | void Zoe::configure()
139          if ((*zoe/"database"/"password").IsEmpty())
140          {
141                  ext::String prompt(database.user + (!database.host.IsEmpty() ? "@" : "")
142 <                        + database.host + (!database.user.IsEmpty() ? "'s " : "") + "Databa"
143 <                        + "se Password: ");
142 >                        + database.host + (!database.user.IsEmpty() ? "'s " : "")
143 >                        + "Database Password: ");
144                  char* password(getpass(prompt.NullTerminate()));
145  
146                  database.password = password;
# Line 112 | Line 152 | void Zoe::configure()
152  
153          database.db = std::string(*zoe/"database"/"db");
154  
155 <        if (debug) cerr << "login = " << login << "\npassword = "
156 <                << std::string(password.GetSize(), '*') << "\ndatabase = {\n   driver ="
157 <                << ' ' << database.driver << "\n   host=" << database.host << "\n   use"
158 <                << "r = " << database.user << "\n   password = "
159 <                << std::string(database.password.GetSize(), '*') << "\n   db = "
160 <                << database.db << "\n}\n";
155 >        if (debug) cerr << "login = " << login << "\npassword = "
156 >                << std::string(password.GetSize(), '*') << "\ndatabase = {\n"
157 >                << "   driver = " << database.driver << "\n   host=" << database.host
158 >                << "\n   user = " << database.user << '\n'
159 >                << "   password = " << std::string(database.password.GetSize(), '*')
160 >                << "\n   db = " << database.db << "\n}\n";
161  
162 +        std::string link(*zoe/"link");
163          xml::NodeSet buddies(*zoe/"buddy");
164  
165          for (xml::NodeSet::Iterator buddy(buddies.Begin()); buddy != buddies.End();
166 <                ++buddy) this->buddies.insert(Buddy(**buddy/"login", **buddy/"rss"));
166 >                ++buddy)
167 >        {
168 >                Buddy buddy_(**buddy/"login", **buddy/"rss", **buddy/"atom",
169 >                        !(**buddy/"link").IsEmpty() ? **buddy/"link" : (link
170 >                        + std::string(**buddy/"login") + ".html"));
171 >
172 >                this->buddies.insert(buddy_);
173 >        }
174  
175          if (debug)
176          {
177                  cerr << "buddies = {\n";
178  
179 <                for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy
180 <                        != this->buddies.end(); ++buddy) cerr << "   " << *buddy << '\n';
179 >                for (std::set<Buddy>::const_iterator buddy(this->buddies.begin());
180 >                        buddy != this->buddies.end(); ++buddy)
181 >                {
182 >                        cerr << "   " << *buddy << " = {\n      rss = " << buddy->getRss()
183 >                                << "\n      atom = " << buddy->getAtom() << "\n      link = "
184 >                                << buddy->getLink() << "\n   }\n";
185 >                }
186  
187                  cerr << "}\n";
188          }
189  
137        if (!collector && !publisher)
138        {
139                collector = true;
140                publisher = true;
141        }
142
190          if (debug) cerr << "collector = " << lexical_cast<ext::String>(collector)
191 <                << "\npublisher = " << lexical_cast<ext::String>(publisher) << '\n';
191 >                << "\npublisher = " << lexical_cast<ext::String>(publisher)
192 >                << "\ncolor = " << lexical_cast<ext::String>(color) << '\n';
193   }
194  
195   void Zoe::initialize()
# Line 165 | Line 213 | void Zoe::initialize()
213                  buddies_.end(), std::insert_iterator<std::vector<Buddy> >(difference,
214                  difference.begin()));
215  
216 <        for (std::vector<Buddy>::iterator buddy(difference.begin()); buddy !=
217 <                difference.end(); ++buddy)
216 >        for (std::vector<Buddy>::iterator buddy(difference.begin());
217 >                buddy != difference.end(); ++buddy)
218          {
219                  ext::Uuid id;
220  
221                  api::Uuid::CreateSequential(id);
222  
223                  buddy->setId(id);
224 <                db->Execute("INSERT INTO buddies (id, buddy) VALUES ('" + id + "', '" +
225 <                        *buddy + "')");
224 >                db->Execute("INSERT INTO buddies (id, buddy) VALUES ('"
225 >                        + lexical_cast<ext::String>(id) + "', '" + ext::String(*buddy)
226 >                        + "')");
227                  
228                  buddies_.insert(*buddy);
229          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines