// Host Update // // Douglas Thrift // // $Id$ #include "Host.hpp" void Host::setSince(const string& since) { struct tm when; memset(&when, 0, sizeof(struct tm)); #ifndef __CYGWIN__ strptime(since.c_str(), "%m/%d/%Y %H:%M:%S %Z", &when); #else strptime(since.c_str(), "%m/%d/%Y %H:%M:%S", &when); #endif mktime(&when); char then[61]; strftime(then, 61, "%A, %B %e, %Y %l:%M:%S %p %Z", &when); this->since = then; } ostream& operator<<(ostream& output, Host& host) { output << "\n"; if (host.host != "") output << "" << host.host << "\n"; if (host.name != "") output << "" << host.name << "\n"; if (host.address != "") output << "" << host.address << "\n"; if (host.platform != "") output << "" << host.platform << "\n"; if (host.since != "") output << "" << host.since << "\n"; output << "\n"; return output; } istream& operator>>(istream& input, Host& host) { bool done = false; do { switch (input.peek()) { case 'h': if (host.host != "") { done = true; continue; } break; case 'n': if (host.name != "") { done = true; continue; } break; case 'a': if (host.address != "") { done = true; continue; } break; case 'p': if (host.platform != "") { done = true; continue; } break; case 's': if (host.since != "") { done = true; continue; } break; default: done = true; continue; } string name, value; getline(input, name, '='); getline(input, value); if (name == "host") { host.host = value; } else if (name == "name") { host.name = value != "" ? value : " "; } else if (name == "address") { host.address = value; } else if (name == "platform") { host.platform = value; } else if (name == "since") { host.setSince(value); } } while (!done && input.good()); return input; }