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