ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/Host.cpp
Revision: 193
Committed: 2004-08-22T22:05:31-07:00 (20 years, 10 months ago) by Douglas Thrift
File size: 1961 byte(s)
Log Message:
Meep!

File Contents

# Content
1 // Host Update
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include "Host.hpp"
8
9 void Host::setSince(const string& since)
10 {
11 struct tm when;
12
13 memset(&when, 0, sizeof(struct tm));
14
15 #ifndef __CYGWIN__
16 strptime(since.c_str(), "%m/%d/%Y %H:%M:%S %Z", &when);
17 #else
18 strptime(since.c_str(), "%m/%d/%Y %H:%M:%S", &when);
19 #endif
20 mktime(&when);
21
22 char then[61];
23
24 strftime(then, 61, "%A, %B %e, %Y %l:%M:%S %p %Z", &when);
25
26 this->since = then;
27 }
28
29 ostream& operator<<(ostream& output, Host& host)
30 {
31 output << "<tr>\n";
32
33 if (host.host != "") output << "<td>" << host.host << "</td>\n";
34 if (host.name != "") output << "<td>" << host.name << "</td>\n";
35 if (host.address != "") output << "<td>" << host.address << "</td>\n";
36 if (host.platform != "") output << "<td>" << host.platform << "</td>\n";
37 if (host.since != "") output << "<td>" << host.since << "</td>\n";
38
39 output << "</tr>\n";
40
41 return output;
42 }
43
44 istream& operator>>(istream& input, Host& host)
45 {
46 bool done = false;
47
48 do
49 {
50 switch (input.peek())
51 {
52 case 'h':
53 if (host.host != "")
54 {
55 done = true;
56
57 continue;
58 }
59 break;
60 case 'n':
61 if (host.name != "")
62 {
63 done = true;
64
65 continue;
66 }
67 break;
68 case 'a':
69 if (host.address != "")
70 {
71 done = true;
72
73 continue;
74 }
75 break;
76 case 'p':
77 if (host.platform != "")
78 {
79 done = true;
80
81 continue;
82 }
83 break;
84 case 's':
85 if (host.since != "")
86 {
87 done = true;
88
89 continue;
90 }
91 break;
92 default:
93 done = true;
94 continue;
95 }
96
97 string name, value;
98
99 getline(input, name, '=');
100 getline(input, value);
101
102 if (name == "host")
103 {
104 host.host = value;
105 }
106 else if (name == "name")
107 {
108 host.name = value != "" ? value : "&nbsp;";
109 }
110 else if (name == "address")
111 {
112 host.address = value;
113 }
114 else if (name == "platform")
115 {
116 host.platform = value;
117 }
118 else if (name == "since")
119 {
120 host.setSince(value);
121 }
122 }
123 while (!done && input.good());
124
125 return input;
126 }

Properties

Name Value
svn:eol-style native
svn:keywords Id