comparison sources/engine.cpp @ 2:19227b0b7cc1

.h => .hpp for the headers added year 2008 to copyright notes renamed some functions for better meaning prepared parser module for rewriting added showHelp() function some code clean up
author Vlad Glagolev <enqlave@gmail.com>
date Mon, 21 Jan 2008 01:14:10 +0300
parents bafff9de2a76
children a7051ac7118b
comparison
equal deleted inserted replaced
1:08d8cdf4fe7f 2:19227b0b7cc1
1 /** 1 /**
2 * engine.cpp (2007-03-05) 2 * engine.cpp (2007-03-05)
3 * 3 *
4 * -- CABAL -- engine (useful functions) 4 * -- CABAL -- engine (useful functions)
5 * 5 *
6 * Copyright (c) 2007 Vlad Glagolev <enqlave@gmail.com> 6 * Copyright (c) 2007-2008 Vlad Glagolev <enqlave@gmail.com>
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Permission to use, copy, modify, and distribute this software for any 9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above 10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies. 11 * copyright notice and this permission notice appear in all copies.
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 */ 20 */
21 21
22 #include "engine.h" 22 #include "engine.hpp"
23 23
24 bool daemonize() 24 bool daemonize()
25 { 25 {
26 if (daemon (1, 1) != 0) { 26 if (daemon (1, 1) != 0) {
27 cout << "Error: unable to daemonize into background\n"; 27 cout << "Error: unable to daemonize into background\n";
36 { 36 {
37 time_t t; 37 time_t t;
38 return time (&t); 38 return time (&t);
39 } 39 }
40 40
41 char *eTime (time_t t) 41 char *eTime(time_t t)
42 { 42 {
43 char *nt = asctime (localtime (&t)); 43 char *nt = asctime(localtime(&t));
44 44
45 nt[strlen (nt) - 1] = 0; 45 nt[strlen(nt) - 1] = 0;
46 46
47 return nt; 47 return nt;
48 } 48 }
49 49
50 char *eCountry (char *c) 50 string getCountry(string c)
51 { 51 {
52 if (!*c) 52 if (c == "")
53 return "Enter the correct code of country"; 53 return "Enter the correct code of country";
54 else
55 sscanf (c, "%s", c);
56 54
57 struct countries { 55 struct countries {
58 char *code; 56 string code;
59 char *country; 57 string country;
60 } countries[] = { 58 } countries[] = {
61 "AC", "Ascension Island", 59 {"AC", "Ascension Island"},
62 "AD", "Andorra", 60 {"AD", "Andorra"},
63 "AE", "United Arab Emirates", 61 {"AE", "United Arab Emirates"},
64 "AF", "Afghanistan", 62 {"AF", "Afghanistan"},
65 "AG", "Antigua and Barbuda", 63 {"AG", "Antigua and Barbuda"},
66 "AI", "Anguilla", 64 {"AI", "Anguilla"},
67 "AL", "Albania", 65 {"AL", "Albania"},
68 "AM", "Armenia", 66 {"AM", "Armenia"},
69 "AN", "Netherlands Antilles", 67 {"AN", "Netherlands Antilles"},
70 "AO", "Angola", 68 {"AO", "Angola"},
71 "AQ", "Antarctica", 69 {"AQ", "Antarctica"},
72 "AR", "Argentina", 70 {"AR", "Argentina"},
73 "AS", "American Samoa", 71 {"AS", "American Samoa"},
74 "AT", "Austria", 72 {"AT", "Austria"},
75 "AU", "Australia", 73 {"AU", "Australia"},
76 "AW", "Aruba", 74 {"AW", "Aruba"},
77 "AX", "Aland Islands", 75 {"AX", "Aland Islands"},
78 "AZ", "Azerbaijan", 76 {"AZ", "Azerbaijan"},
79 "BA", "Bosnia and Herzegovina", 77 {"BA", "Bosnia and Herzegovina"},
80 "BB", "Barbados", 78 {"BB", "Barbados"},
81 "BD", "Bangladesh", 79 {"BD", "Bangladesh"},
82 "BE", "Belgium", 80 {"BE", "Belgium"},
83 "BF", "Burkina Faso", 81 {"BF", "Burkina Faso"},
84 "BG", "Bulgaria", 82 {"BG", "Bulgaria"},
85 "BH", "Bahrain", 83 {"BH", "Bahrain"},
86 "BI", "Burundi", 84 {"BI", "Burundi"},
87 "BJ", "Benin", 85 {"BJ", "Benin"},
88 "BM", "Bermuda", 86 {"BM", "Bermuda"},
89 "BN", "Brunei Darussalam", 87 {"BN", "Brunei Darussalam"},
90 "BO", "Bolivia", 88 {"BO", "Bolivia"},
91 "BR", "Brazil", 89 {"BR", "Brazil"},
92 "BS", "Bahamas", 90 {"BS", "Bahamas"},
93 "BT", "Bhutan", 91 {"BT", "Bhutan"},
94 "BU", "Burma", 92 {"BU", "Burma"},
95 "BV", "Bouvet Island", 93 {"BV", "Bouvet Island"},
96 "BW", "Botswana", 94 {"BW", "Botswana"},
97 "BY", "Belarus", 95 {"BY", "Belarus"},
98 "BZ", "Belize", 96 {"BZ", "Belize"},
99 "CA", "Canada", 97 {"CA", "Canada"},
100 "CC", "Cocos (Keeling) Islands", 98 {"CC", "Cocos (Keeling) Islands"},
101 "CD", "The Democratic Republic of the Congo", 99 {"CD", "The Democratic Republic of the Congo"},
102 "CF", "Central African Republic", 100 {"CF", "Central African Republic"},
103 "CG", "Congo", 101 {"CG", "Congo"},
104 "CH", "Switzerland", 102 {"CH", "Switzerland"},
105 "CI", "Cote d'Ivoire (Ivory Coast)", 103 {"CI", "Cote d'Ivoire (Ivory Coast)"},
106 "CK", "Cook Islands", 104 {"CK", "Cook Islands"},
107 "CL", "Chile", 105 {"CL", "Chile"},
108 "CM", "Cameroon", 106 {"CM", "Cameroon"},
109 "CN", "China", 107 {"CN", "China"},
110 "CO", "Colombia", 108 {"CO", "Colombia"},
111 "CR", "Costa Rica", 109 {"CR", "Costa Rica"},
112 "CS", "Serbia and Montenegro", 110 {"CS", "Serbia and Montenegro"},
113 "CU", "Cuba", 111 {"CU", "Cuba"},
114 "CV", "Cape Verde", 112 {"CV", "Cape Verde"},
115 "CX", "Christmas Island", 113 {"CX", "Christmas Island"},
116 "CY", "Cyprus", 114 {"CY", "Cyprus"},
117 "CZ", "Czech Republic", 115 {"CZ", "Czech Republic"},
118 "DE", "Germany", 116 {"DE", "Germany"},
119 "DJ", "Djibouti", 117 {"DJ", "Djibouti"},
120 "DK", "Denmark", 118 {"DK", "Denmark"},
121 "DM", "Dominica", 119 {"DM", "Dominica"},
122 "DO", "Dominican Republic", 120 {"DO", "Dominican Republic"},
123 "DZ", "Algeria", 121 {"DZ", "Algeria"},
124 "EC", "Ecuador", 122 {"EC", "Ecuador"},
125 "EE", "Estonia", 123 {"EE", "Estonia"},
126 "EG", "Egypt", 124 {"EG", "Egypt"},
127 "EH", "Western Sahara", 125 {"EH", "Western Sahara"},
128 "ER", "Eritrea", 126 {"ER", "Eritrea"},
129 "ES", "Spain (including Canary Islands, Ceuta and Melilla)", 127 {"ES", "Spain (inc. Canary Islands, Ceuta and Melilla)"},
130 "ET", "Ethiopia", 128 {"ET", "Ethiopia"},
131 "EU", "European Union", 129 {"EU", "European Union"},
132 "FI", "Finland", 130 {"FI", "Finland"},
133 "FJ", "Fiji", 131 {"FJ", "Fiji"},
134 "FK", "Falkland Islands (Malvinas)", 132 {"FK", "Falkland Islands (Malvinas)"},
135 "FM", "Federated States of Micronesia", 133 {"FM", "Federated States of Micronesia"},
136 "FO", "Faroe Islands", 134 {"FO", "Faroe Islands"},
137 "FR", "France", 135 {"FR", "France"},
138 "GA", "Gabon", 136 {"GA", "Gabon"},
139 "GD", "Grenada", 137 {"GD", "Grenada"},
140 "GE", "Georgia", 138 {"GE", "Georgia"},
141 "GF", "French Guiana", 139 {"GF", "French Guiana"},
142 "GG", "Guernsey", 140 {"GG", "Guernsey"},
143 "GH", "Ghana", 141 {"GH", "Ghana"},
144 "GI", "Gibraltar", 142 {"GI", "Gibraltar"},
145 "GL", "Greenland", 143 {"GL", "Greenland"},
146 "GM", "Gambia", 144 {"GM", "Gambia"},
147 "GN", "Guinea", 145 {"GN", "Guinea"},
148 "GP", "Guadeloupe", 146 {"GP", "Guadeloupe"},
149 "GQ", "Equatorial Guinea", 147 {"GQ", "Equatorial Guinea"},
150 "GR", "Greece", 148 {"GR", "Greece"},
151 "GS", "South Georgia and the South Sandwich Islands", 149 {"GS", "South Georgia and the South Sandwich Islands"},
152 "GT", "Guatemala", 150 {"GT", "Guatemala"},
153 "GU", "Guam", 151 {"GU", "Guam"},
154 "GW", "Guinea-Bissau", 152 {"GW", "Guinea-Bissau"},
155 "GY", "Guyana", 153 {"GY", "Guyana"},
156 "HK", "Hong Kong", 154 {"HK", "Hong Kong"},
157 "HM", "Heard Island and McDonald Islands", 155 {"HM", "Heard Island and McDonald Islands"},
158 "HN", "Honduras", 156 {"HN", "Honduras"},
159 "HR", "Croatia", 157 {"HR", "Croatia"},
160 "HT", "Haiti", 158 {"HT", "Haiti"},
161 "HU", "Hungary", 159 {"HU", "Hungary"},
162 "ID", "Indonesia", 160 {"ID", "Indonesia"},
163 "IE", "Ireland", 161 {"IE", "Ireland"},
164 "IL", "Israel", 162 {"IL", "Israel"},
165 "IM", "Isle of Man", 163 {"IM", "Isle of Man"},
166 "IN", "India", 164 {"IN", "India"},
167 "IO", "British Indian Ocean Territory (including Diego Garcia)", 165 {"IO", "British Indian Ocean Territory (inc. Diego Garcia)"},
168 "IQ", "Iraq", 166 {"IQ", "Iraq"},
169 "IR", "Islamic Republic of Iran", 167 {"IR", "Islamic Republic of Iran"},
170 "IS", "Iceland", 168 {"IS", "Iceland"},
171 "IT", "Italy", 169 {"IT", "Italy"},
172 "JE", "Jersey", 170 {"JE", "Jersey"},
173 "JM", "Jamaica", 171 {"JM", "Jamaica"},
174 "JO", "Jordan", 172 {"JO", "Jordan"},
175 "JP", "Japan", 173 {"JP", "Japan"},
176 "KE", "Kenya", 174 {"KE", "Kenya"},
177 "KG", "Kyrgyzstan", 175 {"KG", "Kyrgyzstan"},
178 "KH", "Cambodia", 176 {"KH", "Cambodia"},
179 "KI", "Kiribati", 177 {"KI", "Kiribati"},
180 "KM", "Comoros", 178 {"KM", "Comoros"},
181 "KN", "Saint Kitts and Nevis", 179 {"KN", "Saint Kitts and Nevis"},
182 "KP", "Democratic People's Republic of Korea (North Korea)", 180 {"KP", "Democratic People's Republic of Korea (North Korea)"},
183 "KR", "Republic of Korea (South Korea)", 181 {"KR", "Republic of Korea (South Korea)"},
184 "KW", "Kuwait", 182 {"KW", "Kuwait"},
185 "KY", "Cayman Islands", 183 {"KY", "Cayman Islands"},
186 "KZ", "Kazakhstan", 184 {"KZ", "Kazakhstan"},
187 "LA", "Lao People's Democratic Republic", 185 {"LA", "Lao People's Democratic Republic"},
188 "LB", "Lebanon", 186 {"LB", "Lebanon"},
189 "LC", "Saint Lucia", 187 {"LC", "Saint Lucia"},
190 "LI", "Liechtenstein", 188 {"LI", "Liechtenstein"},
191 "LK", "Sri Lanka", 189 {"LK", "Sri Lanka"},
192 "LR", "Liberia", 190 {"LR", "Liberia"},
193 "LS", "Lesotho", 191 {"LS", "Lesotho"},
194 "LT", "Lithuania", 192 {"LT", "Lithuania"},
195 "LU", "Luxembourg", 193 {"LU", "Luxembourg"},
196 "LV", "Latvia", 194 {"LV", "Latvia"},
197 "LY", "Libyan Arab Jamahiriya", 195 {"LY", "Libyan Arab Jamahiriya"},
198 "MA", "Morocco", 196 {"MA", "Morocco"},
199 "MC", "Monaco", 197 {"MC", "Monaco"},
200 "MD", "Republic of Moldova", 198 {"MD", "Republic of Moldova"},
201 "MG", "Madagascar", 199 {"MG", "Madagascar"},
202 "MH", "Marshall Islands", 200 {"MH", "Marshall Islands"},
203 "MK", "Macedonia", 201 {"MK", "Macedonia"},
204 "ML", "Mali", 202 {"ML", "Mali"},
205 "MM", "Myanmar", 203 {"MM", "Myanmar"},
206 "MN", "Mongolia", 204 {"MN", "Mongolia"},
207 "MO", "Macao", 205 {"MO", "Macao"},
208 "MP", "Northern Mariana Islands", 206 {"MP", "Northern Mariana Islands"},
209 "MQ", "Martinique", 207 {"MQ", "Martinique"},
210 "MR", "Mauritania", 208 {"MR", "Mauritania"},
211 "MS", "Montserrat", 209 {"MS", "Montserrat"},
212 "MT", "Malta", 210 {"MT", "Malta"},
213 "MU", "Mauritius", 211 {"MU", "Mauritius"},
214 "MV", "Maldives", 212 {"MV", "Maldives"},
215 "MW", "Malawi", 213 {"MW", "Malawi"},
216 "MX", "Mexico", 214 {"MX", "Mexico"},
217 "MY", "Malaysia", 215 {"MY", "Malaysia"},
218 "MZ", "Mozambique", 216 {"MZ", "Mozambique"},
219 "NA", "Namibia", 217 {"NA", "Namibia"},
220 "NC", "New Caledonia", 218 {"NC", "New Caledonia"},
221 "NE", "Niger", 219 {"NE", "Niger"},
222 "NF", "Norfolk Island", 220 {"NF", "Norfolk Island"},
223 "NG", "Nigeria", 221 {"NG", "Nigeria"},
224 "NI", "Nicaragua", 222 {"NI", "Nicaragua"},
225 "NL", "Netherlands", 223 {"NL", "Netherlands"},
226 "NO", "Norway", 224 {"NO", "Norway"},
227 "NP", "Nepal", 225 {"NP", "Nepal"},
228 "NR", "Nauru", 226 {"NR", "Nauru"},
229 "NU", "Niue", 227 {"NU", "Niue"},
230 "NZ", "New Zealand", 228 {"NZ", "New Zealand"},
231 "OM", "Oman", 229 {"OM", "Oman"},
232 "PA", "Panama", 230 {"PA", "Panama"},
233 "PE", "Peru", 231 {"PE", "Peru"},
234 "PF", "French Polynesia (including Clipperton Island)", 232 {"PF", "French Polynesia (inc. Clipperton Island)"},
235 "PG", "Papua New Guinea", 233 {"PG", "Papua New Guinea"},
236 "PH", "Philippines", 234 {"PH", "Philippines"},
237 "PK", "Pakistan", 235 {"PK", "Pakistan"},
238 "PL", "Poland", 236 {"PL", "Poland"},
239 "PM", "Saint Pierre and Miquelon", 237 {"PM", "Saint Pierre and Miquelon"},
240 "PN", "Pitcairn", 238 {"PN", "Pitcairn"},
241 "PR", "Puerto Rico", 239 {"PR", "Puerto Rico"},
242 "PS", "Palestinian Territory, Occupied", 240 {"PS", "Palestinian Territory, Occupied"},
243 "PT", "Portugal", 241 {"PT", "Portugal"},
244 "PW", "Palau", 242 {"PW", "Palau"},
245 "PY", "Paraguay", 243 {"PY", "Paraguay"},
246 "QA", "Qatar", 244 {"QA", "Qatar"},
247 "RE", "Reunion", 245 {"RE", "Reunion"},
248 "RO", "Romania", 246 {"RO", "Romania"},
249 "RU", "Russian Federation", 247 {"RU", "Russian Federation"},
250 "RW", "Rwanda", 248 {"RW", "Rwanda"},
251 "SA", "Saudi Arabia", 249 {"SA", "Saudi Arabia"},
252 "SB", "Solomon Islands", 250 {"SB", "Solomon Islands"},
253 "SC", "Seychelles", 251 {"SC", "Seychelles"},
254 "SD", "Sudan", 252 {"SD", "Sudan"},
255 "SE", "Sweden", 253 {"SE", "Sweden"},
256 "SG", "Singapore", 254 {"SG", "Singapore"},
257 "SH", "Saint Helena (including Ascension Island and Tristan da Cunha)", 255 {"SH", "Saint Helena (inc. Ascension Island and Tristan da Cunha)"},
258 "SI", "Slovenia", 256 {"SI", "Slovenia"},
259 "SJ", "Svalbard and Jan Mayen consisting of Svalbard and Jan Mayen", 257 {"SJ", "Svalbard and Jan Mayen consisting of Svalbard and Jan Mayen"},
260 "SK", "Slovakia", 258 {"SK", "Slovakia"},
261 "SL", "Sierra Leone", 259 {"SL", "Sierra Leone"},
262 "SM", "San Marino", 260 {"SM", "San Marino"},
263 "SN", "Senegal", 261 {"SN", "Senegal"},
264 "SO", "Somalia", 262 {"SO", "Somalia"},
265 "SR", "Suriname", 263 {"SR", "Suriname"},
266 "ST", "Sao Tome and Principe", 264 {"ST", "Sao Tome and Principe"},
267 "SU", "Soviet Union", 265 {"SU", "Soviet Union"},
268 "SV", "El Salvador", 266 {"SV", "El Salvador"},
269 "SY", "Syrian Arab Republic", 267 {"SY", "Syrian Arab Republic"},
270 "SZ", "Swaziland", 268 {"SZ", "Swaziland"},
271 "TC", "Turks and Caicos Islands", 269 {"TC", "Turks and Caicos Islands"},
272 "TD", "Chad", 270 {"TD", "Chad"},
273 "TF", "French Southern Territories", 271 {"TF", "French Southern Territories"},
274 "TG", "Togo", 272 {"TG", "Togo"},
275 "TH", "Thailand", 273 {"TH", "Thailand"},
276 "TJ", "Tajikistan", 274 {"TJ", "Tajikistan"},
277 "TK", "Tokelau", 275 {"TK", "Tokelau"},
278 "TL", "Timor-Leste (East Timor)", 276 {"TL", "Timor-Leste (East Timor)"},
279 "TM", "Turkmenistan", 277 {"TM", "Turkmenistan"},
280 "TN", "Tunisia", 278 {"TN", "Tunisia"},
281 "TO", "Tonga", 279 {"TO", "Tonga"},
282 "TR", "Turkey", 280 {"TR", "Turkey"},
283 "TT", "Trinidad and Tobago", 281 {"TT", "Trinidad and Tobago"},
284 "TV", "Tuvalu", 282 {"TV", "Tuvalu"},
285 "TW", "Taiwan, Province of China", 283 {"TW", "Taiwan, Province of China"},
286 "TZ", "United Republic of Tanzania", 284 {"TZ", "United Republic of Tanzania"},
287 "UA", "Ukraine", 285 {"UA", "Ukraine"},
288 "UG", "Uganda", 286 {"UG", "Uganda"},
289 "UK", "United Kingdom", 287 {"UK", "United Kingdom"},
290 "UM", "United States Minor Outlying Islands", 288 {"UM", "United States Minor Outlying Islands"},
291 "US", "United States", 289 {"US", "United States"},
292 "UY", "Uruguay", 290 {"UY", "Uruguay"},
293 "UZ", "Uzbekistan", 291 {"UZ", "Uzbekistan"},
294 "VA", "Holy See (Vatican City State)", 292 {"VA", "Holy See (Vatican City State)"},
295 "VC", "Saint Vincent and the Grenadines", 293 {"VC", "Saint Vincent and the Grenadines"},
296 "VE", "Venezuela", 294 {"VE", "Venezuela"},
297 "VG", "Virgin Islands, British", 295 {"VG", "Virgin Islands, British"},
298 "VI", "Virgin Islands, U.S.", 296 {"VI", "Virgin Islands, U.S."},
299 "VN", "Viet Nam", 297 {"VN", "Viet Nam"},
300 "VU", "Vanuatu", 298 {"VU", "Vanuatu"},
301 "WF", "Wallis and Futuna", 299 {"WF", "Wallis and Futuna"},
302 "WS", "Samoa", 300 {"WS", "Samoa"},
303 "YE", "Yemen", 301 {"YE", "Yemen"},
304 "YT", "Mayotte", 302 {"YT", "Mayotte"},
305 "ZA", "South Africa", 303 {"ZA", "South Africa"},
306 "ZM", "Zambia", 304 {"ZM", "Zambia"},
307 "ZW", "Zimbabwe", 305 {"ZW", "Zimbabwe"},
308 0
309 }; 306 };
310 307
311 for (int e = 0; countries[e].code; e++) 308 for (int e = 0; countries[e].code != ""; e++)
312 if (!strcasecmp (countries[e].code, c)) 309 if (countries[e].code == c)
313 return countries[e].country; 310 return countries[e].country;
314 311
315 return "Incorrect country code, try again"; 312 return "Incorrect country code, try again";
316 } 313 }