/[zanavi_public1]/navit/navit/country.c
ZANavi

Contents of /navit/navit/country.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 18718 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include <string.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <glib.h>
24 #include "debug.h"
25 #include "item.h"
26 #include "country.h"
27 #include "search.h"
28 #include "navit_nls.h"
29
30 struct country {
31 int id;
32 char *car;
33 char *iso2;
34 char *iso3;
35 char *name;
36 };
37
38 static struct country country[]= {
39 { 20, "AND", "AD", "AND", /* 020 */ "Andorra"},
40 {784, "UAE", "AE", "ARE", /* 784 */ "United Arab Emirates"},
41 { 4, "AFG", "AF", "AFG", /* 004 */ "Afghanistan"},
42 { 28, "AG", "AG", "ATG", /* 028 */ "Antigua and Barbuda"},
43 {660, NULL, "AI", "AIA", /* 660 */ "Anguilla"},
44 { 8, "AL", "AL", "ALB", /* 008 */ "Albania"},
45 { 51, "ARM", "AM", "ARM", /* 051 */ "Armenia"},
46 {530, "NA", "AN", "ANT", /* 530 */ "Netherlands Antilles"},
47 { 24, "ANG", "AO", "AGO", /* 024 */ "Angola"},
48 { 10, NULL, "AQ", "ATA", /* 010 */ "Antarctica"},
49 { 32, "RA", "AR", "ARG", /* 032 */ "Argentina"},
50 { 16, NULL, "AS", "ASM", /* 016 */ "American Samoa"},
51 { 40, "A", "AT", "AUT", /* 040 */ "Austria"},
52 { 36, "AUS", "AU", "AUS", /* 036 */ "Australia"},
53 {533, "ARU", "AW", "ABW", /* 533 */ "Aruba"},
54 {248, "AX", "AX", "ALA", /* 248 */ "Aland Islands"},
55 { 31, "AZ", "AZ", "AZE", /* 031 */ "Azerbaijan"},
56 { 70, "BiH", "BA", "BIH", /* 070 */ "Bosnia and Herzegovina"},
57 { 52, "BDS", "BB", "BRB", /* 052 */ "Barbados"},
58 { 50, "BD", "BD", "BGD", /* 050 */ "Bangladesh"},
59 { 56, "B", "BE", "BEL", /* 056 */ "Belgium"},
60 {854, "BF", "BF", "BFA", /* 854 */ "Burkina Faso"},
61 {100, "BG", "BG", "BGR", /* 100 */ "Bulgaria"},
62 { 48, "BRN", "BH", "BHR", /* 048 */ "Bahrain"},
63 {108, "RU", "BI", "BDI", /* 108 */ "Burundi"},
64 {204, "BJ", "BJ", "BEN", /* 204 */ "Benin"},
65 {652, NULL, "BL", "BLM", /* 652 */ "Saint Barthelemy"},
66 { 60, NULL, "BM", "BMU", /* 060 */ "Bermuda"},
67 { 96, "BRU", "BN", "BRN", /* 096 */ "Brunei Darussalam"},
68 { 68, "BOL", "BO", "BOL", /* 068 */ "Bolivia"},
69 { 76, "BR", "BR", "BRA", /* 076 */ "Brazil"},
70 { 44, "BS", "BS", "BHS", /* 044 */ "Bahamas"},
71 { 64, "BHT", "BT", "BTN", /* 064 */ "Bhutan"},
72 { 74, NULL, "BV", "BVT", /* 074 */ "Bouvet Island"},
73 { 72, "RB", "BW", "BWA", /* 072 */ "Botswana"},
74 {112, "BY", "BY", "BLR", /* 112 */ "Belarus"},
75 { 84, "BZ", "BZ", "BLZ", /* 084 */ "Belize"},
76 {124, "CDN", "CA", "CAN", /* 124 */ "Canada"},
77 {166, NULL, "CC", "CCK", /* 166 */ "Cocos (Keeling) Islands"},
78 {180, "CGO", "CD", "COD", /* 180 */ "Congo, Democratic Republic of the"},
79 {140, "RCA", "CF", "CAF", /* 140 */ "Central African Republic"},
80 {178, NULL, "CG", "COG", /* 178 */ "Congo"},
81 {756, "CH", "CH", "CHE", /* 756 */ "Switzerland"},
82 {384, "CI", "CI", "CIV", /* 384 */ "Cote d'Ivoire"},
83 {184, NULL, "CK", "COK", /* 184 */ "Cook Islands"},
84 {152, "RCH", "CL", "CHL", /* 152 */ "Chile"},
85 {120, "CAM", "CM", "CMR", /* 120 */ "Cameroon"},
86 {156, "RC", "CN", "CHN", /* 156 */ "China"},
87 {170, "CO", "CO", "COL", /* 170 */ "Colombia"},
88 {188, "CR", "CR", "CRI", /* 188 */ "Costa Rica"},
89 {192, "C", "CU", "CUB", /* 192 */ "Cuba"},
90 {132, "CV", "CV", "CPV", /* 132 */ "Cape Verde"},
91 {162, NULL, "CX", "CXR", /* 162 */ "Christmas Island"},
92 {196, "CY", "CY", "CYP", /* 196 */ "Cyprus"},
93 {203, "CZ", "CZ", "CZE", /* 203 */ "Czech Republic"},
94 {276, "D", "DE", "DEU", /* 276 */ "Germany"},
95 {262, "DJI", "DJ", "DJI", /* 262 */ "Djibouti"},
96 {208, "DK", "DK", "DNK", /* 208 */ "Denmark"},
97 {212, "WD", "DM", "DMA", /* 212 */ "Dominica"},
98 {214, "DOM", "DO", "DOM", /* 214 */ "Dominican Republic"},
99 { 12, "DZ", "DZ", "DZA", /* 012 */ "Algeria"},
100 {218, "EC", "EC", "ECU", /* 218 */ "Ecuador"},
101 {233, "EST", "EE", "EST", /* 233 */ "Estonia"},
102 {818, "ET", "EG", "EGY", /* 818 */ "Egypt"},
103 {732, "WSA", "EH", "ESH", /* 732 */ "Western Sahara"},
104 {232, "ER", "ER", "ERI", /* 232 */ "Eritrea"},
105 {724, "E", "ES", "ESP", /* 724 */ "Spain"},
106 {231, "ETH", "ET", "ETH", /* 231 */ "Ethiopia"},
107 {246, "FIN", "FI", "FIN", /* 246 */ "Finland"},
108 {242, "FJI", "FJ", "FJI", /* 242 */ "Fiji"},
109 {238, NULL, "FK", "FLK", /* 238 */ "Falkland Islands (Malvinas)"},
110 {583, "FSM", "FM", "FSM", /* 583 */ "Micronesia, Federated States of"},
111 {234, "FO", "FO", "FRO", /* 234 */ "Faroe Islands"},
112 {250, "F", "FR", "FRA", /* 250 */ "France"},
113 {266, "G", "GA", "GAB", /* 266 */ "Gabon"},
114 {826, "GB", "GB", "GBR", /* 826 */ "United Kingdom"},
115 {308, "WG", "GD", "GRD", /* 308 */ "Grenada"},
116 {268, "GE", "GE", "GEO", /* 268 */ "Georgia"},
117 {254, NULL, "GF", "GUF", /* 254 */ "French Guiana"},
118 {831, NULL, "GG", "GGY", /* 831 */ "Guernsey"},
119 {288, "GH", "GH", "GHA", /* 288 */ "Ghana"},
120 {292, "GBZ", "GI", "GIB", /* 292 */ "Gibraltar"},
121 {304, "KN", "GL", "GRL", /* 304 */ "Greenland"},
122 {270, "WAG", "GM", "GMB", /* 270 */ "Gambia"},
123 {324, "RG", "GN", "GIN", /* 324 */ "Guinea"},
124 {312, NULL, "GP", "GLP", /* 312 */ "Guadeloupe"},
125 {226, "GQ", "GQ", "GNQ", /* 226 */ "Equatorial Guinea"},
126 {300, "GR", "GR", "GRC", /* 300 */ "Greece"},
127 {239, NULL, "GS", "SGS", /* 239 */ "South Georgia and the South Sandwich Islands"},
128 {320, "GCA", "GT", "GTM", /* 320 */ "Guatemala"},
129 {316, NULL, "GU", "GUM", /* 316 */ "Guam"},
130 {624, "GUB", "GW", "GNB", /* 624 */ "Guinea-Bissau"},
131 {328, "GUY", "GY", "GUY", /* 328 */ "Guyana"},
132 {344, "HK", "HK", "HKG", /* 344 */ "Hong Kong"},
133 {334, NULL, "HM", "HMD", /* 334 */ "Heard Island and McDonald Islands"},
134 {340, "HN", "HN", "HND", /* 340 */ "Honduras"},
135 {191, "HR", "HR", "HRV", /* 191 */ "Croatia"},
136 {332, "RH", "HT", "HTI", /* 332 */ "Haiti"},
137 {348, "H", "HU", "HUN", /* 348 */ "Hungary"},
138 {360, "RI", "ID", "IDN", /* 360 */ "Indonesia"},
139 {372, "IRL", "IE", "IRL", /* 372 */ "Ireland"},
140 {376, "IL", "IL", "ISR", /* 376 */ "Israel"},
141 {833, NULL, "IM", "IMN", /* 833 */ "Isle of Man"},
142 {356, "IND", "IN", "IND", /* 356 */ "India"},
143 { 86, NULL, "IO", "IOT", /* 086 */ "British Indian Ocean Territory"},
144 {368, "IRQ", "IQ", "IRQ", /* 368 */ "Iraq"},
145 {364, "IR", "IR", "IRN", /* 364 */ "Iran, Islamic Republic of"},
146 {352, "IS", "IS", "ISL", /* 352 */ "Iceland"},
147 {380, "I", "IT", "ITA", /* 380 */ "Italy"},
148 {832, NULL, "JE", "JEY", /* 832 */ "Jersey"},
149 {388, "JA", "JM", "JAM", /* 388 */ "Jamaica"},
150 {400, "JOR", "JO", "JOR", /* 400 */ "Jordan"},
151 {392, "J", "JP", "JPN", /* 392 */ "Japan"},
152 {404, "EAK", "KE", "KEN", /* 404 */ "Kenya"},
153 {417, "KS", "KG", "KGZ", /* 417 */ "Kyrgyzstan"},
154 {116, "K", "KH", "KHM", /* 116 */ "Cambodia"},
155 {296, "KIR", "KI", "KIR", /* 296 */ "Kiribati"},
156 {174, "COM", "KM", "COM", /* 174 */ "Comoros"},
157 {659, "KAN", "KN", "KNA", /* 659 */ "Saint Kitts and Nevis"},
158 {408, "KP", "KP", "PRK", /* 408 */ "Korea, Democratic People's Republic of"},
159 {410, "ROK", "KR", "KOR", /* 410 */ "Korea, Republic of"},
160 {414, "KWT", "KW", "KWT", /* 414 */ "Kuwait"},
161 {136, NULL, "KY", "CYM", /* 136 */ "Cayman Islands"},
162 {398, "KZ", "KZ", "KAZ", /* 398 */ "Kazakhstan"},
163 {418, "LAO", "LA", "LAO", /* 418 */ "Lao People's Democratic Republic"},
164 {422, "RL", "LB", "LBN", /* 422 */ "Lebanon"},
165 {662, "WL", "LC", "LCA", /* 662 */ "Saint Lucia"},
166 {438, "FL", "LI", "LIE", /* 438 */ "Liechtenstein"},
167 {144, "CL", "LK", "LKA", /* 144 */ "Sri Lanka"},
168 {430, "LB", "LR", "LBR", /* 430 */ "Liberia"},
169 {426, "LS", "LS", "LSO", /* 426 */ "Lesotho"},
170 {440, "LT", "LT", "LTU", /* 440 */ "Lithuania"},
171 {442, "L", "LU", "LUX", /* 442 */ "Luxembourg"},
172 {428, "LV", "LV", "LVA", /* 428 */ "Latvia"},
173 {434, "LAR", "LY", "LBY", /* 434 */ "Libyan Arab Jamahiriya"},
174 {504, "MA", "MA", "MAR", /* 504 */ "Morocco"},
175 {492, "MC", "MC", "MCO", /* 492 */ "Monaco"},
176 {498, "MD", "MD", "MDA", /* 498 */ "Moldova, Republic of"},
177 {499, "MNE", "ME", "MNE", /* 499 */ "Montenegro"},
178 {663, NULL, "MF", "MAF", /* 663 */ "Saint Martin (French part)"},
179 {450, "RM", "MG", "MDG", /* 450 */ "Madagascar"},
180 {584, "MH", "MH", "MHL", /* 584 */ "Marshall Islands"},
181 {807, "MK", "MK", "MKD", /* 807 */ "Macedonia, the former Yugoslav Republic of"},
182 {466, "RMM", "ML", "MLI", /* 466 */ "Mali"},
183 {104, "MYA", "MM", "MMR", /* 104 */ "Myanmar"},
184 {496, "MGL", "MN", "MNG", /* 496 */ "Mongolia"},
185 {446, NULL, "MO", "MAC", /* 446 */ "Macao"},
186 {580, NULL, "MP", "MNP", /* 580 */ "Northern Mariana Islands"},
187 {474, NULL, "MQ", "MTQ", /* 474 */ "Martinique"},
188 {478, "RIM", "MR", "MRT", /* 478 */ "Mauritania"},
189 {500, NULL, "MS", "MSR", /* 500 */ "Montserrat"},
190 {470, "M", "MT", "MLT", /* 470 */ "Malta"},
191 {480, "MS", "MU", "MUS", /* 480 */ "Mauritius"},
192 {462, "MV", "MV", "MDV", /* 462 */ "Maldives"},
193 {454, "MW", "MW", "MWI", /* 454 */ "Malawi"},
194 {484, "MEX", "MX", "MEX", /* 484 */ "Mexico"},
195 {458, "MAL", "MY", "MYS", /* 458 */ "Malaysia"},
196 {508, "MOC", "MZ", "MOZ", /* 508 */ "Mozambique"},
197 {516, "NAM", "NA", "NAM", /* 516 */ "Namibia"},
198 {540, "NCL", "NC", "NCL", /* 540 */ "New Caledonia"},
199 {562, "RN", "NE", "NER", /* 562 */ "Niger"},
200 {574, NULL, "NF", "NFK", /* 574 */ "Norfolk Island"},
201 {566, "NGR", "NG", "NGA", /* 566 */ "Nigeria"},
202 {558, "NIC", "NI", "NIC", /* 558 */ "Nicaragua"},
203 {528, "NL", "NL", "NLD", /* 528 */ "Netherlands"},
204 {578, "N", "NO", "NOR", /* 578 */ "Norway"},
205 {524, "NEP", "NP", "NPL", /* 524 */ "Nepal"},
206 {520, "NAU", "NR", "NRU", /* 520 */ "Nauru"},
207 {570, NULL, "NU", "NIU", /* 570 */ "Niue"},
208 {554, "NZ", "NZ", "NZL", /* 554 */ "New Zealand"},
209 {512, "OM", "OM", "OMN", /* 512 */ "Oman"},
210 {591, "PA", "PA", "PAN", /* 591 */ "Panama"},
211 {604, "PE", "PE", "PER", /* 604 */ "Peru"},
212 {258, NULL, "PF", "PYF", /* 258 */ "French Polynesia"},
213 {598, "PNG", "PG", "PNG", /* 598 */ "Papua New Guinea"},
214 {608, "RP", "PH", "PHL", /* 608 */ "Philippines"},
215 {586, "PK", "PK", "PAK", /* 586 */ "Pakistan"},
216 {616, "PL", "PL", "POL", /* 616 */ "Poland"},
217 {666, NULL, "PM", "SPM", /* 666 */ "Saint Pierre and Miquelon"},
218 {612, NULL, "PN", "PCN", /* 612 */ "Pitcairn"},
219 {630, "PRI", "PR", "PRI", /* 630 */ "Puerto Rico"},
220 {275, "AUT", "PS", "PSE", /* 275 */ "Palestinian Territory, Occupied"},
221 {620, "P", "PT", "PRT", /* 620 */ "Portugal"},
222 {585, "PAL", "PW", "PLW", /* 585 */ "Palau"},
223 {600, "PY", "PY", "PRY", /* 600 */ "Paraguay"},
224 {634, "Q", "QA", "QAT", /* 634 */ "Qatar"},
225 {638, NULL, "RE", "REU", /* 638 */ "Reunion"},
226 {642, "RO", "RO", "ROU", /* 642 */ "Romania"},
227 {688, "SRB", "RS", "SRB", /* 688 */ "Serbia"},
228 {643, "RUS", "RU", "RUS", /* 643 */ "Russian Federation"},
229 {646, "RWA", "RW", "RWA", /* 646 */ "Rwanda"},
230 {682, "KSA", "SA", "SAU", /* 682 */ "Saudi Arabia"},
231 { 90, "SOL", "SB", "SLB", /* 090 */ "Solomon Islands"},
232 {690, "SY", "SC", "SYC", /* 690 */ "Seychelles"},
233 {736, "SUD", "SD", "SDN", /* 736 */ "Sudan"},
234 {752, "S", "SE", "SWE", /* 752 */ "Sweden"},
235 {702, "SGP", "SG", "SGP", /* 702 */ "Singapore"},
236 {654, NULL, "SH", "SHN", /* 654 */ "Saint Helena"},
237 {705, "SLO", "SI", "SVN", /* 705 */ "Slovenia"},
238 {744, NULL, "SJ", "SJM", /* 744 */ "Svalbard and Jan Mayen"},
239 {703, "SK", "SK", "SVK", /* 703 */ "Slovakia"},
240 {694, "WAL", "SL", "SLE", /* 694 */ "Sierra Leone"},
241 {674, "RSM", "SM", "SMR", /* 674 */ "San Marino"},
242 {686, "SN", "SN", "SEN", /* 686 */ "Senegal"},
243 {706, "SO", "SO", "SOM", /* 706 */ "Somalia"},
244 {740, "SME", "SR", "SUR", /* 740 */ "Suriname"},
245 {678, "STP", "ST", "STP", /* 678 */ "Sao Tome and Principe"},
246 {222, "ES", "SV", "SLV", /* 222 */ "El Salvador"},
247 {760, "SYR", "SY", "SYR", /* 760 */ "Syrian Arab Republic"},
248 {748, "SD", "SZ", "SWZ", /* 748 */ "Swaziland"},
249 {796, NULL, "TC", "TCA", /* 796 */ "Turks and Caicos Islands"},
250 {148, "TD", "TD", "TCD", /* 148 */ "Chad"},
251 {260, "ARK", "TF", "ATF", /* 260 */ "French Southern Territories"},
252 {768, "RT", "TG", "TGO", /* 768 */ "Togo"},
253 {764, "T", "TH", "THA", /* 764 */ "Thailand"},
254 {762, "TJ", "TJ", "TJK", /* 762 */ "Tajikistan"},
255 {772, NULL, "TK", "TKL", /* 772 */ "Tokelau"},
256 {626, "TL", "TL", "TLS", /* 626 */ "Timor-Leste"},
257 {795, "TM", "TM", "TKM", /* 795 */ "Turkmenistan"},
258 {788, "TN", "TN", "TUN", /* 788 */ "Tunisia"},
259 {776, "TON", "TO", "TON", /* 776 */ "Tonga"},
260 {792, "TR", "TR", "TUR", /* 792 */ "Turkey"},
261 {780, "TT", "TT", "TTO", /* 780 */ "Trinidad and Tobago"},
262 {798, "TUV", "TV", "TUV", /* 798 */ "Tuvalu"},
263 {158, NULL, "TW", "TWN", /* 158 */ "Taiwan, Province of China"},
264 {834, "EAT", "TZ", "TZA", /* 834 */ "Tanzania, United Republic of"},
265 {804, "UA", "UA", "UKR", /* 804 */ "Ukraine"},
266 {800, "EAU", "UG", "UGA", /* 800 */ "Uganda"},
267 {581, NULL, "UM", "UMI", /* 581 */ "United States Minor Outlying Islands"},
268 {840, "USA", "US", "USA", /* 840 */ "United States"},
269 {858, "ROU", "UY", "URY", /* 858 */ "Uruguay"},
270 {860, "UZ", "UZ", "UZB", /* 860 */ "Uzbekistan"},
271 {336, "SCV", "VA", "VAT", /* 336 */ "Holy See (Vatican City State)"},
272 {670, "WV", "VC", "VCT", /* 670 */ "Saint Vincent and the Grenadines"},
273 {862, "YV", "VE", "VEN", /* 862 */ "Venezuela"},
274 { 92, NULL, "VG", "VGB", /* 092 */ "Virgin Islands, British"},
275 {850, NULL, "VI", "VIR", /* 850 */ "Virgin Islands, U.S."},
276 {704, "VN", "VN", "VNM", /* 704 */ "Viet Nam"},
277 {548, "VAN", "VU", "VUT", /* 548 */ "Vanuatu"},
278 {876, NULL, "WF", "WLF", /* 876 */ "Wallis and Futuna"},
279 {882, "WS", "WS", "WSM", /* 882 */ "Samoa"},
280 {887, "YAR", "YE", "YEM", /* 887 */ "Yemen"},
281 {175, NULL, "YT", "MYT", /* 175 */ "Mayotte"},
282 {710, "ZA", "ZA", "ZAF", /* 710 */ "South Africa"},
283 {894, "Z", "ZM", "ZMB", /* 894 */ "Zambia"},
284 {716, "ZW", "ZW", "ZWE", /* 716 */ "Zimbabwe"},
285 {999, "*", "*", "*", "Unknown"},
286 };
287
288
289 struct country_search {
290 struct attr search;
291 int len;
292 int partial;
293 struct item item;
294 int count;
295 struct country *country;
296 enum attr_type attr_next;
297 };
298
299 static int
300 country_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
301 {
302 struct country_search *this_=priv_data;
303 struct country *country=this_->country;
304
305 attr->type=attr_type;
306 switch (attr_type) {
307 case attr_any:
308 while (this_->attr_next != attr_none) {
309 if (country_attr_get(this_, this_->attr_next, attr))
310 return 1;
311 }
312 return 0;
313 case attr_label:
314 attr->u.str=gettext(country->name);
315 this_->attr_next=attr_country_id;
316 return 1;
317 case attr_country_id:
318 attr->u.num=country->id;
319 this_->attr_next=country->car ? attr_country_car : attr_country_iso2;
320 return 1;
321 case attr_country_car:
322 attr->u.str=country->car;
323 this_->attr_next=attr_country_iso2;
324 return attr->u.str ? 1 : 0;
325 case attr_country_iso2:
326 attr->u.str=country->iso2;
327 this_->attr_next=attr_country_iso3;
328 return 1;
329 case attr_country_iso3:
330 attr->u.str=country->iso3;
331 this_->attr_next=attr_country_name;
332 return 1;
333 case attr_country_name:
334 attr->u.str=gettext(country->name);
335 this_->attr_next=attr_none;
336 return 1;
337 default:
338 return 0;
339 }
340 }
341
342
343
344 struct item_methods country_meth = {
345 NULL, /* coord_rewind */
346 NULL, /* coord_get */
347 NULL, /* attr_rewind */
348 country_attr_get, /* attr_get */
349 };
350
351 struct country_search *
352 country_search_new(struct attr *search, int partial)
353 {
354 struct country_search *ret=g_new(struct country_search, 1);
355 ret->search=*search;
356 if (search->type != attr_country_id)
357 ret->len=strlen(search->u.str);
358 else
359 ret->len=0;
360 ret->partial=partial;
361 ret->count=0;
362
363 ret->item.type=type_country_label;
364 ret->item.id_hi=0;
365 ret->item.map=NULL;
366 ret->item.meth=&country_meth;
367 ret->item.priv_data=ret;
368
369 return ret;
370 }
371
372 char* str_tolower(char *name)
373 {
374 int i;
375 char *str;
376 str = g_strdup(name);
377 for(i = 0; str[i]; i++)
378 {
379 str[i] = tolower(str[i]);
380 }
381 return str;
382 }
383
384 static int
385 match(struct country_search *this_, enum attr_type type, const char *name)
386 {
387 int ret;
388 char *s1 = NULL;
389 char *s2 = NULL;
390
391 if (!name)
392 return 0;
393
394 if (!this_->search.u.str)
395 {
396 return 0;
397 }
398
399 if (this_->search.type != type && this_->search.type != attr_country_all)
400 return 0;
401
402
403 //fprintf(stderr, "1 name=%s str=%s\n", name, this_->search.u.str);
404
405 //s1=linguistics_casefold(this_->search.u.str);
406 s1=str_tolower(this_->search.u.str);
407
408 //fprintf(stderr, "2 name=%s str=%s\n", name, this_->search.u.str);
409 //fprintf(stderr, "3 s1=%s\n", s1);
410
411 //s2=linguistics_casefold(name);
412 s2=str_tolower(name);
413
414 //fprintf(stderr, "4 name=%s str=%s\n", name, this_->search.u.str);
415 //fprintf(stderr, "5 s2=%s\n", s2);
416
417 //if ((s1 == NULL)||(s2 == NULL))
418 //{
419 // // ok i give up, i cant find the damn bug. so here is a stupid!! stupid!! workaround
420 // fprintf(stderr, "2 name=%s str=%s\n", name, this_->search.u.str);
421 // fprintf(stderr, "3 s1=%s\n", s1);
422 // fprintf(stderr, "5 s2=%s\n", s2);
423 // return 0;
424 //}
425 //else
426 //{
427 ret=linguistics_compare(s2,s1,this_->partial)==0;
428 //}
429 //fprintf(stderr, "6 s1=%s\n", s1);
430 //fprintf(stderr, "7 s2=%s\n", s2);
431
432 if (s1)
433 {
434 g_free(s1);
435 }
436
437 if (s2)
438 {
439 g_free(s2);
440 }
441
442 return ret;
443 }
444
445
446 struct item *
447 country_search_get_item(struct country_search *this_)
448 {
449 for (;;) {
450 if (this_->count >= sizeof(country)/sizeof(struct country))
451 return NULL;
452 this_->country=&country[this_->count++];
453 if ((this_->search.type == attr_country_id && this_->search.u.num == this_->country->id) ||
454 match(this_, attr_country_iso3, this_->country->iso3) ||
455 match(this_, attr_country_iso2, this_->country->iso2) ||
456 match(this_, attr_country_car, this_->country->car) ||
457 match(this_, attr_country_name, gettext(this_->country->name))) {
458 this_->item.id_lo=this_->country->id;
459 return &this_->item;
460 }
461 }
462 }
463
464 static struct attr country_default_attr;
465 static char iso2[3];
466
467 struct attr *
468 country_default(void)
469 {
470 char *lang;
471 if (country_default_attr.u.str)
472 return &country_default_attr;
473 lang=getenv("LANG");
474 if (!lang || strlen(lang) < 5)
475 return NULL;
476 strncpy(iso2, lang+3, 2);
477 country_default_attr.type=attr_country_iso2;
478 country_default_attr.u.str=iso2;
479 return &country_default_attr;
480 }
481
482 void
483 country_search_destroy(struct country_search *this_)
484 {
485 g_free(this_);
486 }

   
Visit the ZANavi Wiki