ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/Host.cpp
Revision: 38
Committed: 2003-11-15T20:23:23-08:00 (21 years, 7 months ago) by Douglas Thrift
File size: 2030 byte(s)
Log Message:
Works right in Cygwin now.

File Contents

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

Properties

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