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