ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/Host.cpp
(Generate patch)

Comparing HostStatus/Host.cpp (file contents):
Revision 31 by Douglas Thrift, 2003-11-14T20:11:01-08:00 vs.
Revision 38 by Douglas Thrift, 2003-11-15T20:23:23-08:00

# Line 8 | Line 8
8  
9   void Host::setSince(const string& since)
10   {
11 <        //
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 >
21 >        time_t time = timegm(&when);
22 >
23 >        memcpy(&when, localtime(&time), sizeof(struct tm));
24 >
25 >        char then[61];
26 >
27 >        strftime(then, 61, "%A, %B %e,&nbsp;%Y %l:%M:%S&nbsp;%p&nbsp;%Z", &when);
28 >
29 >        this->since = then;
30   }
31  
32   ostream& operator<<(ostream& output, Host& host)
33   {
34 <        //
34 >        output << "<tr>\n";
35 >
36 >        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          return output;
45   }
46  
47   istream& operator>>(istream& input, Host& host)
48   {
49 <        //
49 >        bool done = false;
50 >
51 >        do
52 >        {
53 >                switch (input.peek())
54 >                {
55 >                case 'h':
56 >                        if (host.host != "")
57 >                        {
58 >                                done = true;
59 >
60 >                                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          return input;
129   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines