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 37 by douglas, 2004-07-22T01:19:40-07:00 vs.
Revision 38 by douglas, 2004-07-22T22:42:40-07:00

# Line 40 | Line 40 | int main(int argc, char* argv[])
40                  {
41                          if (!Zoe::publisher) Zoe::publisher = true;
42                  }
43 +                else if (arg == "-color")
44 +                {
45 +                        if (!Zoe::color) Zoe::color = true;
46 +                }
47                  else if (arg == "-D")
48                  {
49                          if (!Zoe::debug) Zoe::debug = true;
50                  }
51                  else
52                  {
53 <                        cerr << bright << "Usage: " << cyan << Zoe::program << reset << " ["
54 <                                << bright << blue <<  "-config=" << yellow << "config" << reset
51 <                                << "] [" << bright << blue << "-collector" << reset << "] ["
52 <                                << bright << blue << "-publisher" << reset << "] [" << bright
53 <                                << blue << "-D" << reset << "]\n";
53 >                        cerr << "Usage: " << Zoe::program << " [-config=config] "
54 >                                "[-collector] [-publisher] [-color] [-D]\n";
55  
56                          return 1;
57                  }
# Line 70 | Line 71 | Zoe::Zoe()
71          Publisher publisher(buddies, database, Zoe::publisher);
72   }
73  
74 < bool Zoe::debug(false), Zoe::collector(false), Zoe::publisher(false);
74 > bool Zoe::debug(false), Zoe::collector(false), Zoe::publisher(false),
75 >         Zoe::color(false);
76   ext::String Zoe::program, Zoe::config("zoe.xml");
77  
78   ext::String Zoe::generator(Generator generator)
# Line 125 | Line 127 | void Zoe::configure()
127  
128          if ((*zoe/"database"/"password").IsEmpty())
129          {
130 <                ext::String prompt(database.user + (!database.host.IsEmpty() ? "@" : "") + database.host
131 <                        + (!database.user.IsEmpty() ? "'s " : "") + "Database Password: ");
130 >                ext::String prompt(database.user + (!database.host.IsEmpty() ? "@" : "")
131 >                        + database.host + (!database.user.IsEmpty() ? "'s " : "")
132 >                        + "Database Password: ");
133                  char* password(getpass(prompt.NullTerminate()));
134  
135                  database.password = password;
136  
137 <                for (size_t index(std::strlen(password)); index > 0; --index) password[index - 1] = '\0';
137 >                for (size_t index(std::strlen(password)); index > 0; --index)
138 >                        password[index - 1] = '\0';
139          }
140          else database.password = std::string(*zoe/"database"/"password");
141  
142          database.db = std::string(*zoe/"database"/"db");
143  
144 <        if (debug) cerr << "login = " << login << "\npassword = " << std::string(password.GetSize(), '*') << "\ndatabase = {\n"
145 <                << "   driver = " << database.driver << "\n   host=" << database.host << "\n   user = " << database.user << '\n'
146 <                << "   password = " << std::string(database.password.GetSize(), '*') << "\n   db = " << database.db << "\n}\n";
144 >        if (debug) cerr << "login = " << login << "\npassword = "
145 >                << std::string(password.GetSize(), '*') << "\ndatabase = {\n"
146 >                << "   driver = " << database.driver << "\n   host=" << database.host
147 >                << "\n   user = " << database.user << '\n'
148 >                << "   password = " << std::string(database.password.GetSize(), '*')
149 >                << "\n   db = " << database.db << "\n}\n";
150  
151          xml::NodeSet buddies(*zoe/"buddy");
152  
153 <        for (xml::NodeSet::Iterator buddy(buddies.Begin()); buddy != buddies.End(); ++buddy)
154 <                this->buddies.insert(Buddy(**buddy/"login", **buddy/"rss"));
153 >        for (xml::NodeSet::Iterator buddy(buddies.Begin()); buddy != buddies.End();
154 >                ++buddy)
155 >        {
156 >                this->buddies.insert(Buddy(**buddy/"login", **buddy/"rss",
157 >                        **buddy/"atom"));
158 >        }
159  
160          if (debug)
161          {
162                  cerr << "buddies = {\n";
163  
164 <                for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy != this->buddies.end(); ++buddy)
165 <                        cerr << "   " << *buddy << " = " << buddy->getRss() << '\n';
164 >                for (std::set<Buddy>::const_iterator buddy(this->buddies.begin());
165 >                        buddy != this->buddies.end(); ++buddy)
166 >                {
167 >                        cerr << "   " << *buddy << " = {\n      rss = " << buddy->getRss()
168 >                                << "\n      atom = " << buddy->getAtom() << "\n   }\n";
169 >                }
170  
171                  cerr << "}\n";
172          }
# Line 163 | Line 178 | void Zoe::configure()
178          }
179  
180          if (debug) cerr << "collector = " << lexical_cast<ext::String>(collector)
181 <                << "\npublisher = " << lexical_cast<ext::String>(publisher) << '\n';
181 >                << "\npublisher = " << lexical_cast<ext::String>(publisher)
182 >                << "\ncolor = " << lexical_cast<ext::String>(color) << '\n';
183   }
184  
185   void Zoe::initialize()
186   {
187 <        ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, database.user, database.password,
188 <                database.db));
187 >        ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host,
188 >                database.user, database.password, database.db));
189          ext::Handle<dbi::ResultSet> buddies(db->Execute("SELECT * FROM buddies"));
190          std::set<Buddy> buddies_;
191  
# Line 183 | Line 199 | void Zoe::initialize()
199  
200          std::vector<Buddy> difference;
201  
202 <        set_difference(this->buddies.begin(), this->buddies.end(), buddies_.begin(), buddies_.end(),
203 <                std::insert_iterator<std::vector<Buddy> >(difference, difference.begin()));
202 >        set_difference(this->buddies.begin(), this->buddies.end(), buddies_.begin(),
203 >                buddies_.end(), std::insert_iterator<std::vector<Buddy> >(difference,
204 >                difference.begin()));
205  
206 <        for (std::vector<Buddy>::iterator buddy(difference.begin()); buddy != difference.end(); ++buddy)
206 >        for (std::vector<Buddy>::iterator buddy(difference.begin());
207 >                buddy != difference.end(); ++buddy)
208          {
209                  ext::Uuid id;
210  
211                  api::Uuid::CreateSequential(id);
212  
213                  buddy->setId(id);
214 <                db->Execute("INSERT INTO buddies (id, buddy) VALUES ('" + lexical_cast<ext::String>(id) + "', '"
215 <                        + ext::String(*buddy) + "')");
214 >                db->Execute("INSERT INTO buddies (id, buddy) VALUES ('"
215 >                        + lexical_cast<ext::String>(id) + "', '" + ext::String(*buddy)
216 >                        + "')");
217                  
218                  buddies_.insert(*buddy);
219          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines