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

Diff of /navit/navit/search.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 30 Revision 31
86 struct search_list_result last_result; 86 struct search_list_result last_result;
87 int last_result_valid; 87 int last_result_valid;
88 char *postal; 88 char *postal;
89 struct interpolation inter; 89 struct interpolation inter;
90}; 90};
91
92// func definition
93static int ascii_cmp_local_faster(char *name, char *match, int partial);
94// func definition
91 95
92static guint search_item_hash_hash(gconstpointer key) 96static guint search_item_hash_hash(gconstpointer key)
93{ 97{
94 const struct item *itm = key; 98 const struct item *itm = key;
95 gconstpointer hashkey = (gconstpointer) GINT_TO_POINTER(itm->id_hi ^ itm->id_lo); 99 gconstpointer hashkey = (gconstpointer) GINT_TO_POINTER(itm->id_hi ^ itm->id_lo);
536 hn_length = 2; 540 hn_length = 2;
537 hn_pos = 1; 541 hn_pos = 1;
538 } 542 }
539 if (count == max) 543 if (count == max)
540 // dbg(0, "coordinate overflow\n"); 544 // dbg(0, "coordinate overflow\n");
541 for (i = 0; i < count - 1; i++) 545 for (i = 0; i < count - 1; i++)
542 { 546 {
543 distances[i] = navit_sqrt(transform_distance_sq(&c[i], &c[i + 1])); 547 distances[i] = navit_sqrt(transform_distance_sq(&c[i], &c[i + 1]));
544 distance_sum += distances[i]; 548 distance_sum += distances[i];
545 // dbg(1, "distance[%d]=%d\n", i, distances[i]); 549 // dbg(1, "distance[%d]=%d\n", i, distances[i]);
546 } 550 }
547 // dbg(1, "sum=%d\n", distance_sum); 551 // dbg(1, "sum=%d\n", distance_sum);
548 hn_distance = distance_sum * hn_pos / hn_length; 552 hn_distance = distance_sum * hn_pos / hn_length;
549 // dbg(1, "hn_distance=%d\n", hn_distance); 553 // dbg(1, "hn_distance=%d\n", hn_distance);
550 i = 0; 554 i = 0;
551 while (i < count - 1 && hn_distance > distances[i]) 555 while (i < count - 1 && hn_distance > distances[i])
1049 } 1053 }
1050 while (*s != '\0'); 1054 while (*s != '\0');
1051 return ret; 1055 return ret;
1052} 1056}
1053 1057
1058static void search_address_housenumber_for_street(char *hn_name_match, char *street_name_match, char *town_string, struct coord *c, int partial, struct jni_object *jni)
1059{
1060 struct item *item;
1061 struct map_rect *mr = NULL;
1062 struct mapset *ms;
1063 struct mapset_handle *msh;
1064 struct map* map = NULL;
1065 struct attr map_name_attr;
1066 struct attr attr;
1067 struct pcoord center99;
1068 struct map_selection *sel;
1069 int search_radius_this;
1070 int search_order;
1071 struct attr att;
1072 struct attr att2;
1073 char *town_string2;
1074 char *hn_fold = NULL;
1075 char *street_name_fold = NULL;
1076
1077 ms = global_navit->mapsets->data;
1078 msh = mapset_open(ms);
1079
1080 search_order = 18;
1081 search_radius_this = 20;
1082
1083 hn_fold = linguistics_fold_and_prepare_complete(hn_name_match, 0);
1084 street_name_fold = linguistics_fold_and_prepare_complete(street_name_match, 0);
1085
1086 if (!street_name_fold)
1087 {
1088 return;
1089 }
1090
1091 if (!hn_fold)
1092 {
1093 return;
1094 }
1095
1096 if (strlen(street_name_fold) < 1)
1097 {
1098 if (hn_fold)
1099 {
1100 g_free(hn_fold);
1101 }
1102
1103 if (street_name_fold)
1104 {
1105 g_free(street_name_fold);
1106 }
1107 return;
1108 }
1109
1110 if (strlen(hn_fold) < 1)
1111 {
1112 if (hn_fold)
1113 {
1114 g_free(hn_fold);
1115 }
1116
1117 if (street_name_fold)
1118 {
1119 g_free(street_name_fold);
1120 }
1121 return;
1122 }
1123
1124 if (strlen(town_string) > 100)
1125 {
1126 town_string2 = town_string;
1127 town_string2[101] = '\0';
1128 town_string2 = linguistics_check_utf8_string(town_string2);
1129 }
1130 else
1131 {
1132 town_string2 = town_string;
1133 }
1134
1135
1136 center99.x = c->x;
1137 center99.y = c->y;
1138 sel = map_selection_rect_new(&center99, search_radius_this, search_order);
1139 sel->range.min = type_house_number;
1140 sel->range.max = type_house_number;
1141 sel->u.c_rect.lu.x = center99.x - search_radius_this;
1142 sel->u.c_rect.lu.y = center99.y + search_radius_this;
1143 sel->u.c_rect.rl.x = center99.x + search_radius_this;
1144 sel->u.c_rect.rl.y = center99.y - search_radius_this;
1145
1146 // dbg(0, "hn=%s sn=%s\n", hn_name_match, street_name_match);
1147 // dbg(0, "cx=%d cy=%d\n", c->x, c->y);
1148
1149 while (msh && (map = mapset_next(msh, 0)))
1150 {
1151 if (offline_search_break_searching == 1)
1152 {
1153 break;
1154 }
1155
1156 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
1157 {
1158 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
1159 {
1160 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
1161 {
1162 // its an sdcard map
1163 mr = map_rect_new(map, sel);
1164 if (mr)
1165 {
1166 while ((item = map_rect_get_item(mr)))
1167 {
1168 if (offline_search_break_searching == 1)
1169 {
1170 break;
1171 }
1172
1173#ifdef DEBUG_GLIB_MEM_FUNCTIONS
1174 g_mem_profile();
1175#endif
1176
1177 if (item->type == type_house_number)
1178 {
1179 // does it have a housenumber?
1180 if (item_attr_get(item, attr_house_number, &att))
1181 {
1182 // match housenumber to our string
1183 if (!ascii_cmp_local_faster(att.u.str, hn_fold, partial))
1184 {
1185 // if this housenumber has a streetname tag, compare it now
1186 if (item_attr_get(item, attr_street_name, &att2))
1187 {
1188 if (!ascii_cmp_local_faster(att2.u.str, street_name_fold, partial))
1189 {
1190 // coords of result
1191 struct coord c2;
1192 char *buffer;
1193
1194 if (item_coord_get(item, &c2, 1))
1195 {
1196 // SHN -> street with house number
1197 // return a string like: "SHN:H111L5555:16.766:48.76:full address name is at the end"
1198 // ca. 9 chars : ca. 9 chars : max. 100 max. 100 max. 100 max. 15 chars -> this sould be max. about 335 chars long
1199 if (town_string)
1200 {
1201 buffer = g_strdup_printf("SHN:H0L0:%d:%d:%s %s, %.101s", c2.y, c2.x, att2.u.str, att.u.str, town_string);
1202 }
1203 else
1204 {
1205 buffer = g_strdup_printf("SHN:H0L0:%d:%d:%s %s", c2.y, c2.x, att2.u.str, att.u.str);
1206 }
1207
1208#ifdef HAVE_API_ANDROID
1209 // return results to android as they come in ...
1210 android_return_search_result(jni,buffer);
1211#endif
1212 g_free(buffer);
1213 }
1214 }
1215 }
1216 }
1217 }
1218 }
1219 }
1220 map_rect_destroy(mr);
1221 }
1222 }
1223 }
1224 }
1225 }
1226 map_selection_destroy(sel);
1227 mapset_close(msh);
1228
1229 if (hn_fold)
1230 {
1231 g_free(hn_fold);
1232 }
1233
1234 if (street_name_fold)
1235 {
1236 g_free(street_name_fold);
1237 }
1238
1239
1240#ifdef DEBUG_GLIB_MEM_FUNCTIONS
1241 g_mem_profile();
1242#endif
1243}
1244
1054static GList * 1245static GList *
1055search_address_housenumber_real(GList *result_list, struct search_list *sl, char *street_name, GList *phrases, GList *exclude1, GList *exclude2, GList *exclude3, int partial, struct jni_object *jni) 1246search_address_housenumber_real(GList *result_list, struct search_list *sl, char *street_name, GList *phrases, GList *exclude1, GList *exclude2, GList *exclude3, int partial, struct jni_object *jni)
1056{ 1247{
1057 struct search_list_result *slr; 1248 struct search_list_result *slr;
1058 struct coord_geo g; 1249 struct coord_geo g;
1089 { 1280 {
1090 buffer = g_strdup_printf("SHN:H%dL%d:%f:%f:%.101s,%.101s, %.101s %.15s", slr->street->common.item.id_hi, slr->street->common.item.id_lo, g.lat, g.lng, slr->country->name, slr->town->common.town_name, slr->street->name, slr->house_number->house_number); 1281 buffer = g_strdup_printf("SHN:H%dL%d:%f:%f:%.101s,%.101s, %.101s %.15s", slr->street->common.item.id_hi, slr->street->common.item.id_lo, g.lat, g.lng, slr->country->name, slr->town->common.town_name, slr->street->name, slr->house_number->house_number);
1091 } 1282 }
1092 else 1283 else
1093 { 1284 {
1094 buffer = g_strdup_printf("SHN:H%dL%d:%f:%f:%.101s,%.7s %.101s, %.101s %.15s", slr->street->common.item.id_hi, slr->street->common.item.id_lo, g.lat, g.lng, slr->country->name, slr->town->common.postal, slr->town->common.town_name, slr->street->name, 1285 buffer = g_strdup_printf("SHN:H%dL%d:%f:%f:%.101s,%.7s %.101s, %.101s %.15s", slr->street->common.item.id_hi, slr->street->common.item.id_lo, g.lat, g.lng, slr->country->name, slr->town->common.postal, slr->town->common.town_name, slr->street->name, slr->house_number->house_number);
1095 slr->house_number->house_number);
1096 } 1286 }
1097 1287
1098 //// dbg(0,"res=%s\n",buffer); 1288 //// dbg(0,"res=%s\n",buffer);
1099 1289
1100 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer)); 1290 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer));
1269 android_return_search_result(jni,buffer); 1459 android_return_search_result(jni,buffer);
1270#endif 1460#endif
1271 1461
1272 count++; 1462 count++;
1273 if (buffer) 1463 if (buffer)
1464 {
1274 g_free(buffer); 1465 g_free(buffer);
1466 }
1275 1467
1276 save_item = sl->item; 1468 save_item = sl->item;
1277 save_level = sl->level; 1469 save_level = sl->level;
1278 save_last_result_valid = sl->last_result_valid; 1470 save_last_result_valid = sl->last_result_valid;
1279 1471
1358 char *iso2; 1550 char *iso2;
1359 char *iso3; 1551 char *iso3;
1360 char *name; 1552 char *name;
1361}; 1553};
1362 1554
1363static struct country2 all_country_list[] = 1555static struct country2
1364{ 1556 all_country_list[] =
1365{ 20, "AND", "AD", "AND", /* 020 */"Andorra" }, 1557 { { 20, "AND", "AD", "AND", /* 020 */"Andorra" }, { 784, "UAE", "AE", "ARE", /* 784 */
1366{ 784, "UAE", "AE", "ARE", /* 784 */ 1558 "United Arab Emirates" }, { 4, "AFG", "AF", "AFG", /* 004 */"Afghanistan" }, { 28, "AG", "AG", "ATG", /* 028 */"Antigua and Barbuda" }, { 660, NULL, "AI", "AIA", /* 660 */"Anguilla" }, { 8, "AL", "AL", "ALB", /* 008 */"Albania" }, { 51, "ARM", "AM", "ARM", /* 051 */"Armenia" }, { 530, "NA", "AN", "ANT", /* 530 */
1367"United Arab Emirates" }, 1559 "Netherlands Antilles" }, { 24, "ANG", "AO", "AGO", /* 024 */"Angola" }, { 10, NULL, "AQ", "ATA", /* 010 */"Antarctica" }, { 32, "RA", "AR", "ARG", /* 032 */"Argentina" }, { 16, NULL, "AS", "ASM", /* 016 */"American Samoa" }, { 40, "A", "AT", "AUT", /* 040 */"Austria" }, { 36, "AUS", "AU", "AUS", /* 036 */"Australia" }, { 533, "ARU", "AW", "ABW", /* 533 */"Aruba" }, { 248, "AX", "AX", "ALA", /* 248 */"Aland Islands" }, { 31, "AZ", "AZ", "AZE", /* 031 */"Azerbaijan" }, { 70, "BiH", "BA", "BIH", /* 070 */
1368{ 4, "AFG", "AF", "AFG", /* 004 */"Afghanistan" }, 1560 "Bosnia and Herzegovina" }, { 52, "BDS", "BB", "BRB", /* 052 */"Barbados" }, { 50, "BD", "BD", "BGD", /* 050 */"Bangladesh" }, { 56, "B", "BE", "BEL", /* 056 */"Belgium" }, { 854, "BF", "BF", "BFA", /* 854 */"Burkina Faso" }, { 100, "BG", "BG", "BGR", /* 100 */"Bulgaria" }, { 48, "BRN", "BH", "BHR", /* 048 */"Bahrain" }, { 108, "RU", "BI", "BDI", /* 108 */"Burundi" }, { 204, "BJ", "BJ", "BEN", /* 204 */"Benin" }, { 652, NULL, "BL", "BLM", /* 652 */"Saint Barthelemy" }, { 60, NULL, "BM", "BMU", /* 060 */"Bermuda" }, { 96, "BRU", "BN", "BRN", /* 096 */"Brunei Darussalam" }, { 68, "BOL", "BO", "BOL", /* 068 */"Bolivia" }, { 76, "BR", "BR", "BRA", /* 076 */"Brazil" }, { 44, "BS", "BS", "BHS", /* 044 */"Bahamas" }, { 64, "BHT", "BT", "BTN", /* 064 */"Bhutan" }, { 74, NULL, "BV", "BVT", /* 074 */"Bouvet Island" }, { 72, "RB", "BW", "BWA", /* 072 */"Botswana" }, { 112, "BY", "BY", "BLR", /* 112 */"Belarus" }, { 84, "BZ", "BZ", "BLZ", /* 084 */"Belize" }, { 124, "CDN", "CA", "CAN", /* 124 */"Canada" }, { 166, NULL, "CC", "CCK", /* 166 */
1369{ 28, "AG", "AG", "ATG", /* 028 */"Antigua and Barbuda" }, 1561 "Cocos (Keeling) Islands" }, { 180, "CGO", "CD", "COD", /* 180 */
1370{ 660, NULL, "AI", "AIA", /* 660 */"Anguilla" }, 1562 "Congo, Democratic Republic of the" }, { 140, "RCA", "CF", "CAF", /* 140 */
1371{ 8, "AL", "AL", "ALB", /* 008 */"Albania" }, 1563 "Central African Republic" }, { 178, NULL, "CG", "COG", /* 178 */"Congo" }, { 756, "CH", "CH", "CHE", /* 756 */"Switzerland" }, { 384, "CI", "CI", "CIV", /* 384 */"Cote d'Ivoire" }, { 184, NULL, "CK", "COK", /* 184 */"Cook Islands" }, { 152, "RCH", "CL", "CHL", /* 152 */"Chile" }, { 120, "CAM", "CM", "CMR", /* 120 */"Cameroon" }, { 156, "RC", "CN", "CHN", /* 156 */"China" }, { 170, "CO", "CO", "COL", /* 170 */"Colombia" }, { 188, "CR", "CR", "CRI", /* 188 */"Costa Rica" }, { 192, "C", "CU", "CUB", /* 192 */"Cuba" }, { 132, "CV", "CV", "CPV", /* 132 */"Cape Verde" }, { 162, NULL, "CX", "CXR", /* 162 */"Christmas Island" }, { 196, "CY", "CY", "CYP", /* 196 */"Cyprus" }, { 203, "CZ", "CZ", "CZE", /* 203 */"Czech Republic" }, { 276, "D", "DE", "DEU", /* 276 */"Germany" }, { 262, "DJI", "DJ", "DJI", /* 262 */"Djibouti" }, { 208, "DK", "DK", "DNK", /* 208 */"Denmark" }, { 212, "WD", "DM", "DMA", /* 212 */"Dominica" }, { 214, "DOM", "DO", "DOM", /* 214 */
1372{ 51, "ARM", "AM", "ARM", /* 051 */"Armenia" }, 1564 "Dominican Republic" }, { 12, "DZ", "DZ", "DZA", /* 012 */"Algeria" }, { 218, "EC", "EC", "ECU", /* 218 */"Ecuador" }, { 233, "EST", "EE", "EST", /* 233 */"Estonia" }, { 818, "ET", "EG", "EGY", /* 818 */"Egypt" }, { 732, "WSA", "EH", "ESH", /* 732 */"Western Sahara" }, { 232, "ER", "ER", "ERI", /* 232 */"Eritrea" }, { 724, "E", "ES", "ESP", /* 724 */"Spain" }, { 231, "ETH", "ET", "ETH", /* 231 */"Ethiopia" }, { 246, "FIN", "FI", "FIN", /* 246 */"Finland" }, { 242, "FJI", "FJ", "FJI", /* 242 */"Fiji" }, { 238, NULL, "FK", "FLK", /* 238 */
1373{ 530, "NA", "AN", "ANT", /* 530 */ 1565 "Falkland Islands (Malvinas)" }, { 583, "FSM", "FM", "FSM", /* 583 */
1374"Netherlands Antilles" }, 1566 "Micronesia, Federated States of" }, { 234, "FO", "FO", "FRO", /* 234 */"Faroe Islands" }, { 250, "F", "FR", "FRA", /* 250 */"France" }, { 266, "G", "GA", "GAB", /* 266 */"Gabon" }, { 826, "GB", "GB", "GBR", /* 826 */"United Kingdom" }, { 308, "WG", "GD", "GRD", /* 308 */"Grenada" }, { 268, "GE", "GE", "GEO", /* 268 */"Georgia" }, { 254, NULL, "GF", "GUF", /* 254 */"French Guiana" }, { 831, NULL, "GG", "GGY", /* 831 */"Guernsey" }, { 288, "GH", "GH", "GHA", /* 288 */"Ghana" }, { 292, "GBZ", "GI", "GIB", /* 292 */"Gibraltar" }, { 304, "KN", "GL", "GRL", /* 304 */"Greenland" }, { 270, "WAG", "GM", "GMB", /* 270 */"Gambia" }, { 324, "RG", "GN", "GIN", /* 324 */"Guinea" }, { 312, NULL, "GP", "GLP", /* 312 */"Guadeloupe" }, { 226, "GQ", "GQ", "GNQ", /* 226 */"Equatorial Guinea" }, { 300, "GR", "GR", "GRC", /* 300 */"Greece" }, { 239, NULL, "GS", "SGS", /* 239 */
1375{ 24, "ANG", "AO", "AGO", /* 024 */"Angola" }, 1567 "South Georgia and the South Sandwich Islands" }, { 320, "GCA", "GT", "GTM", /* 320 */"Guatemala" }, { 316, NULL, "GU", "GUM", /* 316 */"Guam" }, { 624, "GUB", "GW", "GNB", /* 624 */"Guinea-Bissau" }, { 328, "GUY", "GY", "GUY", /* 328 */"Guyana" }, { 344, "HK", "HK", "HKG", /* 344 */"Hong Kong" }, { 334, NULL, "HM", "HMD", /* 334 */
1376{ 10, NULL, "AQ", "ATA", /* 010 */"Antarctica" }, 1568 "Heard Island and McDonald Islands" }, { 340, "HN", "HN", "HND", /* 340 */"Honduras" }, { 191, "HR", "HR", "HRV", /* 191 */"Croatia" }, { 332, "RH", "HT", "HTI", /* 332 */"Haiti" }, { 348, "H", "HU", "HUN", /* 348 */"Hungary" }, { 360, "RI", "ID", "IDN", /* 360 */"Indonesia" }, { 372, "IRL", "IE", "IRL", /* 372 */"Ireland" }, { 376, "IL", "IL", "ISR", /* 376 */"Israel" }, { 833, NULL, "IM", "IMN", /* 833 */"Isle of Man" }, { 356, "IND", "IN", "IND", /* 356 */"India" }, { 86, NULL, "IO", "IOT", /* 086 */
1377{ 32, "RA", "AR", "ARG", /* 032 */"Argentina" }, 1569 "British Indian Ocean Territory" }, { 368, "IRQ", "IQ", "IRQ", /* 368 */"Iraq" }, { 364, "IR", "IR", "IRN", /* 364 */
1378{ 16, NULL, "AS", "ASM", /* 016 */"American Samoa" }, 1570 "Iran, Islamic Republic of" }, { 352, "IS", "IS", "ISL", /* 352 */"Iceland" }, { 380, "I", "IT", "ITA", /* 380 */"Italy" }, { 832, NULL, "JE", "JEY", /* 832 */"Jersey" }, { 388, "JA", "JM", "JAM", /* 388 */"Jamaica" }, { 400, "JOR", "JO", "JOR", /* 400 */"Jordan" }, { 392, "J", "JP", "JPN", /* 392 */"Japan" }, { 404, "EAK", "KE", "KEN", /* 404 */"Kenya" }, { 417, "KS", "KG", "KGZ", /* 417 */"Kyrgyzstan" }, { 116, "K", "KH", "KHM", /* 116 */"Cambodia" }, { 296, "KIR", "KI", "KIR", /* 296 */"Kiribati" }, { 174, "COM", "KM", "COM", /* 174 */"Comoros" }, { 659, "KAN", "KN", "KNA", /* 659 */
1379{ 40, "A", "AT", "AUT", /* 040 */"Austria" }, 1571 "Saint Kitts and Nevis" }, { 408, "KP", "KP", "PRK", /* 408 */
1380{ 36, "AUS", "AU", "AUS", /* 036 */"Australia" }, 1572 "Korea, Democratic People's Republic of" }, { 410, "ROK", "KR", "KOR", /* 410 */
1381{ 533, "ARU", "AW", "ABW", /* 533 */"Aruba" }, 1573 "Korea, Republic of" }, { 414, "KWT", "KW", "KWT", /* 414 */"Kuwait" }, { 136, NULL, "KY", "CYM", /* 136 */"Cayman Islands" }, { 398, "KZ", "KZ", "KAZ", /* 398 */"Kazakhstan" }, { 418, "LAO", "LA", "LAO", /* 418 */
1382{ 248, "AX", "AX", "ALA", /* 248 */"Aland Islands" }, 1574 "Lao People's Democratic Republic" }, { 422, "RL", "LB", "LBN", /* 422 */"Lebanon" }, { 662, "WL", "LC", "LCA", /* 662 */"Saint Lucia" }, { 438, "FL", "LI", "LIE", /* 438 */"Liechtenstein" }, { 144, "CL", "LK", "LKA", /* 144 */"Sri Lanka" }, { 430, "LB", "LR", "LBR", /* 430 */"Liberia" }, { 426, "LS", "LS", "LSO", /* 426 */"Lesotho" }, { 440, "LT", "LT", "LTU", /* 440 */"Lithuania" }, { 442, "L", "LU", "LUX", /* 442 */"Luxembourg" }, { 428, "LV", "LV", "LVA", /* 428 */"Latvia" }, { 434, "LAR", "LY", "LBY", /* 434 */
1383{ 31, "AZ", "AZ", "AZE", /* 031 */"Azerbaijan" }, 1575 "Libyan Arab Jamahiriya" }, { 504, "MA", "MA", "MAR", /* 504 */"Morocco" }, { 492, "MC", "MC", "MCO", /* 492 */"Monaco" }, { 498, "MD", "MD", "MDA", /* 498 */
1384{ 70, "BiH", "BA", "BIH", /* 070 */ 1576 "Moldova, Republic of" }, { 499, "MNE", "ME", "MNE", /* 499 */"Montenegro" }, { 663, NULL, "MF", "MAF", /* 663 */
1385"Bosnia and Herzegovina" }, 1577 "Saint Martin (French part)" }, { 450, "RM", "MG", "MDG", /* 450 */"Madagascar" }, { 584, "MH", "MH", "MHL", /* 584 */"Marshall Islands" }, { 807, "MK", "MK", "MKD", /* 807 */
1386{ 52, "BDS", "BB", "BRB", /* 052 */"Barbados" }, 1578 "Macedonia, the former Yugoslav Republic of" }, { 466, "RMM", "ML", "MLI", /* 466 */"Mali" }, { 104, "MYA", "MM", "MMR", /* 104 */"Myanmar" }, { 496, "MGL", "MN", "MNG", /* 496 */"Mongolia" }, { 446, NULL, "MO", "MAC", /* 446 */"Macao" }, { 580, NULL, "MP", "MNP", /* 580 */
1387{ 50, "BD", "BD", "BGD", /* 050 */"Bangladesh" }, 1579 "Northern Mariana Islands" }, { 474, NULL, "MQ", "MTQ", /* 474 */"Martinique" }, { 478, "RIM", "MR", "MRT", /* 478 */"Mauritania" }, { 500, NULL, "MS", "MSR", /* 500 */"Montserrat" }, { 470, "M", "MT", "MLT", /* 470 */"Malta" }, { 480, "MS", "MU", "MUS", /* 480 */"Mauritius" }, { 462, "MV", "MV", "MDV", /* 462 */"Maldives" }, { 454, "MW", "MW", "MWI", /* 454 */"Malawi" }, { 484, "MEX", "MX", "MEX", /* 484 */"Mexico" }, { 458, "MAL", "MY", "MYS", /* 458 */"Malaysia" }, { 508, "MOC", "MZ", "MOZ", /* 508 */"Mozambique" }, { 516, "NAM", "NA", "NAM", /* 516 */"Namibia" }, { 540, "NCL", "NC", "NCL", /* 540 */"New Caledonia" }, { 562, "RN", "NE", "NER", /* 562 */"Niger" }, { 574, NULL, "NF", "NFK", /* 574 */"Norfolk Island" }, { 566, "NGR", "NG", "NGA", /* 566 */"Nigeria" }, { 558, "NIC", "NI", "NIC", /* 558 */"Nicaragua" }, { 528, "NL", "NL", "NLD", /* 528 */"Netherlands" }, { 578, "N", "NO", "NOR", /* 578 */"Norway" }, { 524, "NEP", "NP", "NPL", /* 524 */"Nepal" }, { 520, "NAU", "NR", "NRU", /* 520 */"Nauru" }, { 570, NULL, "NU", "NIU", /* 570 */"Niue" }, { 554, "NZ", "NZ", "NZL", /* 554 */"New Zealand" }, { 512, "OM", "OM", "OMN", /* 512 */"Oman" }, { 591, "PA", "PA", "PAN", /* 591 */"Panama" }, { 604, "PE", "PE", "PER", /* 604 */"Peru" }, { 258, NULL, "PF", "PYF", /* 258 */"French Polynesia" }, { 598, "PNG", "PG", "PNG", /* 598 */"Papua New Guinea" }, { 608, "RP", "PH", "PHL", /* 608 */"Philippines" }, { 586, "PK", "PK", "PAK", /* 586 */"Pakistan" }, { 616, "PL", "PL", "POL", /* 616 */"Poland" }, { 666, NULL, "PM", "SPM", /* 666 */
1388{ 56, "B", "BE", "BEL", /* 056 */"Belgium" }, 1580 "Saint Pierre and Miquelon" }, { 612, NULL, "PN", "PCN", /* 612 */"Pitcairn" }, { 630, "PRI", "PR", "PRI", /* 630 */"Puerto Rico" }, { 275, "AUT", "PS", "PSE", /* 275 */
1389{ 854, "BF", "BF", "BFA", /* 854 */"Burkina Faso" }, 1581 "Palestinian Territory, Occupied" }, { 620, "P", "PT", "PRT", /* 620 */"Portugal" }, { 585, "PAL", "PW", "PLW", /* 585 */"Palau" }, { 600, "PY", "PY", "PRY", /* 600 */"Paraguay" }, { 634, "Q", "QA", "QAT", /* 634 */"Qatar" }, { 638, NULL, "RE", "REU", /* 638 */"Reunion" }, { 642, "RO", "RO", "ROU", /* 642 */"Romania" }, { 688, "SRB", "RS", "SRB", /* 688 */"Serbia" }, { 643, "RUS", "RU", "RUS", /* 643 */
1390{ 100, "BG", "BG", "BGR", /* 100 */"Bulgaria" }, 1582 "Russian Federation" }, { 646, "RWA", "RW", "RWA", /* 646 */"Rwanda" }, { 682, "KSA", "SA", "SAU", /* 682 */"Saudi Arabia" }, { 90, "SOL", "SB", "SLB", /* 090 */"Solomon Islands" }, { 690, "SY", "SC", "SYC", /* 690 */"Seychelles" }, { 736, "SUD", "SD", "SDN", /* 736 */"Sudan" }, { 752, "S", "SE", "SWE", /* 752 */"Sweden" }, { 702, "SGP", "SG", "SGP", /* 702 */"Singapore" }, { 654, NULL, "SH", "SHN", /* 654 */"Saint Helena" }, { 705, "SLO", "SI", "SVN", /* 705 */"Slovenia" }, { 744, NULL, "SJ", "SJM", /* 744 */
1391{ 48, "BRN", "BH", "BHR", /* 048 */"Bahrain" }, 1583 "Svalbard and Jan Mayen" }, { 703, "SK", "SK", "SVK", /* 703 */"Slovakia" }, { 694, "WAL", "SL", "SLE", /* 694 */"Sierra Leone" }, { 674, "RSM", "SM", "SMR", /* 674 */"San Marino" }, { 686, "SN", "SN", "SEN", /* 686 */"Senegal" }, { 706, "SO", "SO", "SOM", /* 706 */"Somalia" }, { 740, "SME", "SR", "SUR", /* 740 */"Suriname" }, { 678, "STP", "ST", "STP", /* 678 */
1392{ 108, "RU", "BI", "BDI", /* 108 */"Burundi" }, 1584 "Sao Tome and Principe" }, { 222, "ES", "SV", "SLV", /* 222 */"El Salvador" }, { 760, "SYR", "SY", "SYR", /* 760 */
1393{ 204, "BJ", "BJ", "BEN", /* 204 */"Benin" }, 1585 "Syrian Arab Republic" }, { 748, "SD", "SZ", "SWZ", /* 748 */"Swaziland" }, { 796, NULL, "TC", "TCA", /* 796 */
1394{ 652, NULL, "BL", "BLM", /* 652 */"Saint Barthelemy" }, 1586 "Turks and Caicos Islands" }, { 148, "TD", "TD", "TCD", /* 148 */"Chad" }, { 260, "ARK", "TF", "ATF", /* 260 */
1395{ 60, NULL, "BM", "BMU", /* 060 */"Bermuda" }, 1587 "French Southern Territories" }, { 768, "RT", "TG", "TGO", /* 768 */"Togo" }, { 764, "T", "TH", "THA", /* 764 */"Thailand" }, { 762, "TJ", "TJ", "TJK", /* 762 */"Tajikistan" }, { 772, NULL, "TK", "TKL", /* 772 */"Tokelau" }, { 626, "TL", "TL", "TLS", /* 626 */"Timor-Leste" }, { 795, "TM", "TM", "TKM", /* 795 */"Turkmenistan" }, { 788, "TN", "TN", "TUN", /* 788 */"Tunisia" }, { 776, "TON", "TO", "TON", /* 776 */"Tonga" }, { 792, "TR", "TR", "TUR", /* 792 */"Turkey" }, { 780, "TT", "TT", "TTO", /* 780 */
1396{ 96, "BRU", "BN", "BRN", /* 096 */"Brunei Darussalam" }, 1588 "Trinidad and Tobago" }, { 798, "TUV", "TV", "TUV", /* 798 */"Tuvalu" }, { 158, NULL, "TW", "TWN", /* 158 */
1397{ 68, "BOL", "BO", "BOL", /* 068 */"Bolivia" }, 1589 "Taiwan, Province of China" }, { 834, "EAT", "TZ", "TZA", /* 834 */
1398{ 76, "BR", "BR", "BRA", /* 076 */"Brazil" }, 1590 "Tanzania, United Republic of" }, { 804, "UA", "UA", "UKR", /* 804 */"Ukraine" }, { 800, "EAU", "UG", "UGA", /* 800 */"Uganda" }, { 581, NULL, "UM", "UMI", /* 581 */
1399{ 44, "BS", "BS", "BHS", /* 044 */"Bahamas" }, 1591 "United States Minor Outlying Islands" }, { 840, "USA", "US", "USA", /* 840 */"United States" }, { 858, "ROU", "UY", "URY", /* 858 */"Uruguay" }, { 860, "UZ", "UZ", "UZB", /* 860 */"Uzbekistan" }, { 336, "SCV", "VA", "VAT", /* 336 */
1400{ 64, "BHT", "BT", "BTN", /* 064 */"Bhutan" }, 1592 "Holy See (Vatican City State)" }, { 670, "WV", "VC", "VCT", /* 670 */"Saint Vincent and the Grenadines" }, { 862, "YV", "VE", "VEN", /* 862 */"Venezuela" }, { 92, NULL, "VG", "VGB", /* 092 */"Virgin Islands, British" }, { 850, NULL, "VI", "VIR", /* 850 */"Virgin Islands, U.S." }, { 704, "VN", "VN", "VNM", /* 704 */"Viet Nam" }, { 548, "VAN", "VU", "VUT", /* 548 */"Vanuatu" }, { 876, NULL, "WF", "WLF", /* 876 */"Wallis and Futuna" }, { 882, "WS", "WS", "WSM", /* 882 */"Samoa" }, { 887, "YAR", "YE", "YEM", /* 887 */"Yemen" }, { 175, NULL, "YT", "MYT", /* 175 */"Mayotte" }, { 710, "ZA", "ZA", "ZAF", /* 710 */"South Africa" }, { 894, "Z", "ZM", "ZMB", /* 894 */"Zambia" }, { 716, "ZW", "ZW", "ZWE", /* 716 */"Zimbabwe" }, { 999, "*", "*", "*", /* 999 */"Unknown" }, };
1401{ 74, NULL, "BV", "BVT", /* 074 */"Bouvet Island" },
1402{ 72, "RB", "BW", "BWA", /* 072 */"Botswana" },
1403{ 112, "BY", "BY", "BLR", /* 112 */"Belarus" },
1404{ 84, "BZ", "BZ", "BLZ", /* 084 */"Belize" },
1405{ 124, "CDN", "CA", "CAN", /* 124 */"Canada" },
1406{ 166, NULL, "CC", "CCK", /* 166 */
1407"Cocos (Keeling) Islands" },
1408{ 180, "CGO", "CD", "COD", /* 180 */
1409"Congo, Democratic Republic of the" },
1410{ 140, "RCA", "CF", "CAF", /* 140 */
1411"Central African Republic" },
1412{ 178, NULL, "CG", "COG", /* 178 */"Congo" },
1413{ 756, "CH", "CH", "CHE", /* 756 */"Switzerland" },
1414{ 384, "CI", "CI", "CIV", /* 384 */"Cote d'Ivoire" },
1415{ 184, NULL, "CK", "COK", /* 184 */"Cook Islands" },
1416{ 152, "RCH", "CL", "CHL", /* 152 */"Chile" },
1417{ 120, "CAM", "CM", "CMR", /* 120 */"Cameroon" },
1418{ 156, "RC", "CN", "CHN", /* 156 */"China" },
1419{ 170, "CO", "CO", "COL", /* 170 */"Colombia" },
1420{ 188, "CR", "CR", "CRI", /* 188 */"Costa Rica" },
1421{ 192, "C", "CU", "CUB", /* 192 */"Cuba" },
1422{ 132, "CV", "CV", "CPV", /* 132 */"Cape Verde" },
1423{ 162, NULL, "CX", "CXR", /* 162 */"Christmas Island" },
1424{ 196, "CY", "CY", "CYP", /* 196 */"Cyprus" },
1425{ 203, "CZ", "CZ", "CZE", /* 203 */"Czech Republic" },
1426{ 276, "D", "DE", "DEU", /* 276 */"Germany" },
1427{ 262, "DJI", "DJ", "DJI", /* 262 */"Djibouti" },
1428{ 208, "DK", "DK", "DNK", /* 208 */"Denmark" },
1429{ 212, "WD", "DM", "DMA", /* 212 */"Dominica" },
1430{ 214, "DOM", "DO", "DOM", /* 214 */
1431"Dominican Republic" },
1432{ 12, "DZ", "DZ", "DZA", /* 012 */"Algeria" },
1433{ 218, "EC", "EC", "ECU", /* 218 */"Ecuador" },
1434{ 233, "EST", "EE", "EST", /* 233 */"Estonia" },
1435{ 818, "ET", "EG", "EGY", /* 818 */"Egypt" },
1436{ 732, "WSA", "EH", "ESH", /* 732 */"Western Sahara" },
1437{ 232, "ER", "ER", "ERI", /* 232 */"Eritrea" },
1438{ 724, "E", "ES", "ESP", /* 724 */"Spain" },
1439{ 231, "ETH", "ET", "ETH", /* 231 */"Ethiopia" },
1440{ 246, "FIN", "FI", "FIN", /* 246 */"Finland" },
1441{ 242, "FJI", "FJ", "FJI", /* 242 */"Fiji" },
1442{ 238, NULL, "FK", "FLK", /* 238 */
1443"Falkland Islands (Malvinas)" },
1444{ 583, "FSM", "FM", "FSM", /* 583 */
1445"Micronesia, Federated States of" },
1446{ 234, "FO", "FO", "FRO", /* 234 */"Faroe Islands" },
1447{ 250, "F", "FR", "FRA", /* 250 */"France" },
1448{ 266, "G", "GA", "GAB", /* 266 */"Gabon" },
1449{ 826, "GB", "GB", "GBR", /* 826 */"United Kingdom" },
1450{ 308, "WG", "GD", "GRD", /* 308 */"Grenada" },
1451{ 268, "GE", "GE", "GEO", /* 268 */"Georgia" },
1452{ 254, NULL, "GF", "GUF", /* 254 */"French Guiana" },
1453{ 831, NULL, "GG", "GGY", /* 831 */"Guernsey" },
1454{ 288, "GH", "GH", "GHA", /* 288 */"Ghana" },
1455{ 292, "GBZ", "GI", "GIB", /* 292 */"Gibraltar" },
1456{ 304, "KN", "GL", "GRL", /* 304 */"Greenland" },
1457{ 270, "WAG", "GM", "GMB", /* 270 */"Gambia" },
1458{ 324, "RG", "GN", "GIN", /* 324 */"Guinea" },
1459{ 312, NULL, "GP", "GLP", /* 312 */"Guadeloupe" },
1460{ 226, "GQ", "GQ", "GNQ", /* 226 */"Equatorial Guinea" },
1461{ 300, "GR", "GR", "GRC", /* 300 */"Greece" },
1462{ 239, NULL, "GS", "SGS", /* 239 */
1463"South Georgia and the South Sandwich Islands" },
1464{ 320, "GCA", "GT", "GTM", /* 320 */"Guatemala" },
1465{ 316, NULL, "GU", "GUM", /* 316 */"Guam" },
1466{ 624, "GUB", "GW", "GNB", /* 624 */"Guinea-Bissau" },
1467{ 328, "GUY", "GY", "GUY", /* 328 */"Guyana" },
1468{ 344, "HK", "HK", "HKG", /* 344 */"Hong Kong" },
1469{ 334, NULL, "HM", "HMD", /* 334 */
1470"Heard Island and McDonald Islands" },
1471{ 340, "HN", "HN", "HND", /* 340 */"Honduras" },
1472{ 191, "HR", "HR", "HRV", /* 191 */"Croatia" },
1473{ 332, "RH", "HT", "HTI", /* 332 */"Haiti" },
1474{ 348, "H", "HU", "HUN", /* 348 */"Hungary" },
1475{ 360, "RI", "ID", "IDN", /* 360 */"Indonesia" },
1476{ 372, "IRL", "IE", "IRL", /* 372 */"Ireland" },
1477{ 376, "IL", "IL", "ISR", /* 376 */"Israel" },
1478{ 833, NULL, "IM", "IMN", /* 833 */"Isle of Man" },
1479{ 356, "IND", "IN", "IND", /* 356 */"India" },
1480{ 86, NULL, "IO", "IOT", /* 086 */
1481"British Indian Ocean Territory" },
1482{ 368, "IRQ", "IQ", "IRQ", /* 368 */"Iraq" },
1483{ 364, "IR", "IR", "IRN", /* 364 */
1484"Iran, Islamic Republic of" },
1485{ 352, "IS", "IS", "ISL", /* 352 */"Iceland" },
1486{ 380, "I", "IT", "ITA", /* 380 */"Italy" },
1487{ 832, NULL, "JE", "JEY", /* 832 */"Jersey" },
1488{ 388, "JA", "JM", "JAM", /* 388 */"Jamaica" },
1489{ 400, "JOR", "JO", "JOR", /* 400 */"Jordan" },
1490{ 392, "J", "JP", "JPN", /* 392 */"Japan" },
1491{ 404, "EAK", "KE", "KEN", /* 404 */"Kenya" },
1492{ 417, "KS", "KG", "KGZ", /* 417 */"Kyrgyzstan" },
1493{ 116, "K", "KH", "KHM", /* 116 */"Cambodia" },
1494{ 296, "KIR", "KI", "KIR", /* 296 */"Kiribati" },
1495{ 174, "COM", "KM", "COM", /* 174 */"Comoros" },
1496{ 659, "KAN", "KN", "KNA", /* 659 */
1497"Saint Kitts and Nevis" },
1498{ 408, "KP", "KP", "PRK", /* 408 */
1499"Korea, Democratic People's Republic of" },
1500{ 410, "ROK", "KR", "KOR", /* 410 */
1501"Korea, Republic of" },
1502{ 414, "KWT", "KW", "KWT", /* 414 */"Kuwait" },
1503{ 136, NULL, "KY", "CYM", /* 136 */"Cayman Islands" },
1504{ 398, "KZ", "KZ", "KAZ", /* 398 */"Kazakhstan" },
1505{ 418, "LAO", "LA", "LAO", /* 418 */
1506"Lao People's Democratic Republic" },
1507{ 422, "RL", "LB", "LBN", /* 422 */"Lebanon" },
1508{ 662, "WL", "LC", "LCA", /* 662 */"Saint Lucia" },
1509{ 438, "FL", "LI", "LIE", /* 438 */"Liechtenstein" },
1510{ 144, "CL", "LK", "LKA", /* 144 */"Sri Lanka" },
1511{ 430, "LB", "LR", "LBR", /* 430 */"Liberia" },
1512{ 426, "LS", "LS", "LSO", /* 426 */"Lesotho" },
1513{ 440, "LT", "LT", "LTU", /* 440 */"Lithuania" },
1514{ 442, "L", "LU", "LUX", /* 442 */"Luxembourg" },
1515{ 428, "LV", "LV", "LVA", /* 428 */"Latvia" },
1516{ 434, "LAR", "LY", "LBY", /* 434 */
1517"Libyan Arab Jamahiriya" },
1518{ 504, "MA", "MA", "MAR", /* 504 */"Morocco" },
1519{ 492, "MC", "MC", "MCO", /* 492 */"Monaco" },
1520{ 498, "MD", "MD", "MDA", /* 498 */
1521"Moldova, Republic of" },
1522{ 499, "MNE", "ME", "MNE", /* 499 */"Montenegro" },
1523{ 663, NULL, "MF", "MAF", /* 663 */
1524"Saint Martin (French part)" },
1525{ 450, "RM", "MG", "MDG", /* 450 */"Madagascar" },
1526{ 584, "MH", "MH", "MHL", /* 584 */"Marshall Islands" },
1527{ 807, "MK", "MK", "MKD", /* 807 */
1528"Macedonia, the former Yugoslav Republic of" },
1529{ 466, "RMM", "ML", "MLI", /* 466 */"Mali" },
1530{ 104, "MYA", "MM", "MMR", /* 104 */"Myanmar" },
1531{ 496, "MGL", "MN", "MNG", /* 496 */"Mongolia" },
1532{ 446, NULL, "MO", "MAC", /* 446 */"Macao" },
1533{ 580, NULL, "MP", "MNP", /* 580 */
1534"Northern Mariana Islands" },
1535{ 474, NULL, "MQ", "MTQ", /* 474 */"Martinique" },
1536{ 478, "RIM", "MR", "MRT", /* 478 */"Mauritania" },
1537{ 500, NULL, "MS", "MSR", /* 500 */"Montserrat" },
1538{ 470, "M", "MT", "MLT", /* 470 */"Malta" },
1539{ 480, "MS", "MU", "MUS", /* 480 */"Mauritius" },
1540{ 462, "MV", "MV", "MDV", /* 462 */"Maldives" },
1541{ 454, "MW", "MW", "MWI", /* 454 */"Malawi" },
1542{ 484, "MEX", "MX", "MEX", /* 484 */"Mexico" },
1543{ 458, "MAL", "MY", "MYS", /* 458 */"Malaysia" },
1544{ 508, "MOC", "MZ", "MOZ", /* 508 */"Mozambique" },
1545{ 516, "NAM", "NA", "NAM", /* 516 */"Namibia" },
1546{ 540, "NCL", "NC", "NCL", /* 540 */"New Caledonia" },
1547{ 562, "RN", "NE", "NER", /* 562 */"Niger" },
1548{ 574, NULL, "NF", "NFK", /* 574 */"Norfolk Island" },
1549{ 566, "NGR", "NG", "NGA", /* 566 */"Nigeria" },
1550{ 558, "NIC", "NI", "NIC", /* 558 */"Nicaragua" },
1551{ 528, "NL", "NL", "NLD", /* 528 */"Netherlands" },
1552{ 578, "N", "NO", "NOR", /* 578 */"Norway" },
1553{ 524, "NEP", "NP", "NPL", /* 524 */"Nepal" },
1554{ 520, "NAU", "NR", "NRU", /* 520 */"Nauru" },
1555{ 570, NULL, "NU", "NIU", /* 570 */"Niue" },
1556{ 554, "NZ", "NZ", "NZL", /* 554 */"New Zealand" },
1557{ 512, "OM", "OM", "OMN", /* 512 */"Oman" },
1558{ 591, "PA", "PA", "PAN", /* 591 */"Panama" },
1559{ 604, "PE", "PE", "PER", /* 604 */"Peru" },
1560{ 258, NULL, "PF", "PYF", /* 258 */"French Polynesia" },
1561{ 598, "PNG", "PG", "PNG", /* 598 */"Papua New Guinea" },
1562{ 608, "RP", "PH", "PHL", /* 608 */"Philippines" },
1563{ 586, "PK", "PK", "PAK", /* 586 */"Pakistan" },
1564{ 616, "PL", "PL", "POL", /* 616 */"Poland" },
1565{ 666, NULL, "PM", "SPM", /* 666 */
1566"Saint Pierre and Miquelon" },
1567{ 612, NULL, "PN", "PCN", /* 612 */"Pitcairn" },
1568{ 630, "PRI", "PR", "PRI", /* 630 */"Puerto Rico" },
1569{ 275, "AUT", "PS", "PSE", /* 275 */
1570"Palestinian Territory, Occupied" },
1571{ 620, "P", "PT", "PRT", /* 620 */"Portugal" },
1572{ 585, "PAL", "PW", "PLW", /* 585 */"Palau" },
1573{ 600, "PY", "PY", "PRY", /* 600 */"Paraguay" },
1574{ 634, "Q", "QA", "QAT", /* 634 */"Qatar" },
1575{ 638, NULL, "RE", "REU", /* 638 */"Reunion" },
1576{ 642, "RO", "RO", "ROU", /* 642 */"Romania" },
1577{ 688, "SRB", "RS", "SRB", /* 688 */"Serbia" },
1578{ 643, "RUS", "RU", "RUS", /* 643 */
1579"Russian Federation" },
1580{ 646, "RWA", "RW", "RWA", /* 646 */"Rwanda" },
1581{ 682, "KSA", "SA", "SAU", /* 682 */"Saudi Arabia" },
1582{ 90, "SOL", "SB", "SLB", /* 090 */"Solomon Islands" },
1583{ 690, "SY", "SC", "SYC", /* 690 */"Seychelles" },
1584{ 736, "SUD", "SD", "SDN", /* 736 */"Sudan" },
1585{ 752, "S", "SE", "SWE", /* 752 */"Sweden" },
1586{ 702, "SGP", "SG", "SGP", /* 702 */"Singapore" },
1587{ 654, NULL, "SH", "SHN", /* 654 */"Saint Helena" },
1588{ 705, "SLO", "SI", "SVN", /* 705 */"Slovenia" },
1589{ 744, NULL, "SJ", "SJM", /* 744 */
1590"Svalbard and Jan Mayen" },
1591{ 703, "SK", "SK", "SVK", /* 703 */"Slovakia" },
1592{ 694, "WAL", "SL", "SLE", /* 694 */"Sierra Leone" },
1593{ 674, "RSM", "SM", "SMR", /* 674 */"San Marino" },
1594{ 686, "SN", "SN", "SEN", /* 686 */"Senegal" },
1595{ 706, "SO", "SO", "SOM", /* 706 */"Somalia" },
1596{ 740, "SME", "SR", "SUR", /* 740 */"Suriname" },
1597{ 678, "STP", "ST", "STP", /* 678 */
1598"Sao Tome and Principe" },
1599{ 222, "ES", "SV", "SLV", /* 222 */"El Salvador" },
1600{ 760, "SYR", "SY", "SYR", /* 760 */
1601"Syrian Arab Republic" },
1602{ 748, "SD", "SZ", "SWZ", /* 748 */"Swaziland" },
1603{ 796, NULL, "TC", "TCA", /* 796 */
1604"Turks and Caicos Islands" },
1605{ 148, "TD", "TD", "TCD", /* 148 */"Chad" },
1606{ 260, "ARK", "TF", "ATF", /* 260 */
1607"French Southern Territories" },
1608{ 768, "RT", "TG", "TGO", /* 768 */"Togo" },
1609{ 764, "T", "TH", "THA", /* 764 */"Thailand" },
1610{ 762, "TJ", "TJ", "TJK", /* 762 */"Tajikistan" },
1611{ 772, NULL, "TK", "TKL", /* 772 */"Tokelau" },
1612{ 626, "TL", "TL", "TLS", /* 626 */"Timor-Leste" },
1613{ 795, "TM", "TM", "TKM", /* 795 */"Turkmenistan" },
1614{ 788, "TN", "TN", "TUN", /* 788 */"Tunisia" },
1615{ 776, "TON", "TO", "TON", /* 776 */"Tonga" },
1616{ 792, "TR", "TR", "TUR", /* 792 */"Turkey" },
1617{ 780, "TT", "TT", "TTO", /* 780 */
1618"Trinidad and Tobago" },
1619{ 798, "TUV", "TV", "TUV", /* 798 */"Tuvalu" },
1620{ 158, NULL, "TW", "TWN", /* 158 */
1621"Taiwan, Province of China" },
1622{ 834, "EAT", "TZ", "TZA", /* 834 */
1623"Tanzania, United Republic of" },
1624{ 804, "UA", "UA", "UKR", /* 804 */"Ukraine" },
1625{ 800, "EAU", "UG", "UGA", /* 800 */"Uganda" },
1626{ 581, NULL, "UM", "UMI", /* 581 */
1627"United States Minor Outlying Islands" },
1628{ 840, "USA", "US", "USA", /* 840 */"United States" },
1629{ 858, "ROU", "UY", "URY", /* 858 */"Uruguay" },
1630{ 860, "UZ", "UZ", "UZB", /* 860 */"Uzbekistan" },
1631{ 336, "SCV", "VA", "VAT", /* 336 */
1632"Holy See (Vatican City State)" },
1633{ 670, "WV", "VC", "VCT", /* 670 */"Saint Vincent and the Grenadines" },
1634{ 862, "YV", "VE", "VEN", /* 862 */"Venezuela" },
1635{ 92, NULL, "VG", "VGB", /* 092 */ "Virgin Islands, British" },
1636{ 850, NULL, "VI", "VIR", /* 850 */ "Virgin Islands, U.S." },
1637{ 704, "VN", "VN", "VNM", /* 704 */"Viet Nam" },
1638{ 548, "VAN", "VU", "VUT", /* 548 */"Vanuatu" },
1639{ 876, NULL, "WF", "WLF", /* 876 */"Wallis and Futuna" },
1640{ 882, "WS", "WS", "WSM", /* 882 */"Samoa" },
1641{ 887, "YAR", "YE", "YEM", /* 887 */"Yemen" },
1642{ 175, NULL, "YT", "MYT", /* 175 */"Mayotte" },
1643{ 710, "ZA", "ZA", "ZAF", /* 710 */"South Africa" },
1644{ 894, "Z", "ZM", "ZMB", /* 894 */"Zambia" },
1645{ 716, "ZW", "ZW", "ZWE", /* 716 */"Zimbabwe" },
1646{ 999, "*", "*", "*", /* 999 */"Unknown" }, };
1647 1593
1594// @return =0 strings matched, =1 not matched
1648static int ascii_cmp_local(char *name, char *match, int partial) 1595static int ascii_cmp_local(char *name, char *match, int partial)
1649{ 1596{
1597 char *s1_a;
1598 char *s2_a;
1599
1650 char *s1 = linguistics_casefold(name); 1600 char *s1 = linguistics_casefold(name);
1651 char *s2 = linguistics_casefold(match); 1601 char *s2 = linguistics_casefold(match);
1602
1603 if (s1)
1604 {
1605 s1_a = linguistics_remove_all_specials(s1);
1606 if (s1_a)
1607 {
1608 g_free(s1);
1609 s1 = s1_a;
1610 }
1611 s1_a = linguistics_expand_special(s1, 1);
1612 if (s1_a)
1613 {
1614 g_free(s1);
1615 s1 = s1_a;
1616 }
1617 }
1618
1619 if (s2)
1620 {
1621 s2_a = linguistics_remove_all_specials(s2);
1622 if (s2_a)
1623 {
1624 g_free(s2);
1625 s2 = s2_a;
1626 }
1627 s2_a = linguistics_expand_special(s2, 1);
1628 if (s2_a)
1629 {
1630 g_free(s2);
1631 s2 = s2_a;
1632 }
1633 }
1634
1652 int ret = linguistics_compare(s1, s2, partial); 1635 int ret = linguistics_compare(s1, s2, partial);
1636
1637 if (s1)
1638 {
1653 g_free(s1); 1639 g_free(s1);
1640 }
1641
1642 if (s2)
1643 {
1654 g_free(s2); 1644 g_free(s2);
1645 }
1646
1647 return ret;
1648}
1649
1650// @return =0 strings matched, =1 not matched
1651static int ascii_cmp_local_faster(char *name, char *match, int partial)
1652{
1653 char *s1_a;
1654 char *s1 = name;
1655 int ret;
1656
1657 s1_a = linguistics_fold_and_prepare_complete(s1, 0);
1658
1659 if (!s1_a)
1660 {
1661 return 1;
1662 }
1663
1664 // dbg(0,"s1=%s match=%s\n", s1_a, match);
1665
1666 if (strlen(s1_a) == 0)
1667 {
1668 // only special chars in string, return "no match"
1669 return 1;
1670 }
1671
1672
1673 // --- old ---
1674 //ret = linguistics_compare(s1, match, partial);
1675 // --- old ---
1676
1677 if (partial == 1)
1678 {
1679 ret = strncmp(s1_a, match, strlen(match));
1680 }
1681 else
1682 {
1683 if (strlen(s1_a) == strlen(match))
1684 {
1685 ret = strncmp(s1_a, match, strlen(match));
1686 }
1687 else
1688 {
1689 ret = 1;
1690 }
1691 }
1692
1693
1694 if (s1_a)
1695 {
1696 g_free(s1_a);
1697 }
1698
1655 return ret; 1699 return ret;
1656} 1700}
1657 1701
1658struct navit *global_navit; 1702struct navit *global_navit;
1659 1703
1698 sel->range.min = type_town_label; 1742 sel->range.min = type_town_label;
1699 sel->range.max = type_area; 1743 sel->range.max = type_area;
1700 1744
1701 while (msh && (map = mapset_next(msh, 0))) 1745 while (msh && (map = mapset_next(msh, 0)))
1702 { 1746 {
1747 if (offline_search_break_searching == 1)
1748 {
1749 break;
1750 }
1751
1703 if (map_get_attr(map, attr_name, &map_name_attr, NULL)) 1752 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
1704 { 1753 {
1705 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0) 1754 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
1706 { 1755 {
1707 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0) 1756 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
1719 1768
1720 if (offline_search_break_searching == 1) 1769 if (offline_search_break_searching == 1)
1721 { 1770 {
1722 break; 1771 break;
1723 } 1772 }
1773
1774#ifdef DEBUG_GLIB_MEM_FUNCTIONS
1775 g_mem_profile();
1776#endif
1724 1777
1725 if ((item_is_town(*item)) || (item_is_district(*item))) 1778 if ((item_is_town(*item)) || (item_is_district(*item)))
1726 { 1779 {
1727 struct search_list_town *p = NULL; 1780 struct search_list_town *p = NULL;
1728 1781
1771#endif 1824#endif
1772 } 1825 }
1773 phrases = g_list_next(phrases); 1826 phrases = g_list_next(phrases);
1774 1827
1775 } 1828 }
1829
1776 if (buffer) 1830 if (buffer)
1777 { 1831 {
1778 g_free(buffer); 1832 g_free(buffer);
1779 } 1833 }
1780 search_list_town_destroy(p); 1834 search_list_town_destroy(p);
1824#endif 1878#endif
1825 } 1879 }
1826 phrases = g_list_next(phrases); 1880 phrases = g_list_next(phrases);
1827 1881
1828 } 1882 }
1883
1829 if (buffer) 1884 if (buffer)
1830 { 1885 {
1831 g_free(buffer); 1886 g_free(buffer);
1832 } 1887 }
1833 search_list_town_destroy(p); 1888 search_list_town_destroy(p);
2012 g_list_free(phrases); 2067 g_list_free(phrases);
2013 } 2068 }
2014 g_free(str); 2069 g_free(str);
2015 2070
2016 mapset_close(msh); 2071 mapset_close(msh);
2072
2073#ifdef DEBUG_GLIB_MEM_FUNCTIONS
2074 g_mem_profile();
2075#endif
2017} 2076}
2018 2077
2019GList * 2078GList *
2020search_by_address(GList *result_list, struct mapset *ms, char *addr, int partial, struct jni_object *jni, int search_country_flags, char *search_country_string) 2079search_by_address(GList *result_list, struct mapset *ms, char *addr, int partial, struct jni_object *jni, int search_country_flags, char *search_country_string)
2021{ 2080{
2105 2164
2106 g_free(str); 2165 g_free(str);
2107 return ret; 2166 return ret;
2108} 2167}
2109 2168
2169// IN_BUF_SIZE2 is the size of the file read buffer.
2170// IN_BUF_SIZE2 must be >= 1
2171//#define IN_BUF_SIZE2 (1024*16)
2172int IN_BUF_SIZE2 = sizeof(struct streets_index_data_block) * 1024;
2173int t_IN_BUF_SIZE2 = sizeof(struct town_index_data_block) * 1024;
2174static uint8 s_inbuf[(sizeof(struct streets_index_data_block) * 1024)];
2175static uint8 t_s_inbuf[(sizeof(struct town_index_data_block) * 1024)];
2176//static uint8 s_inbuf[IN_BUF_SIZE2];
2177
2178// OUT_BUF_SIZE2 is the size of the output buffer used during decompression.
2179// OUT_BUF_SIZE2 must be a power of 2 >= TINFL_LZ_DICT_SIZE (because the low-level decompressor
2180// not only writes, but reads from the output buffer as it decompresses)
2181//#define OUT_BUF_SIZE2 (TINFL_LZ_DICT_SIZE)
2182//#define OUT_BUF_SIZE2 (1024*32)
2183int OUT_BUF_SIZE2 = sizeof(struct streets_index_data_block) * 1024;
2184int t_OUT_BUF_SIZE2 = sizeof(struct town_index_data_block) * 1024;
2185static uint8 s_outbuf[(sizeof(struct streets_index_data_block) * 1024)];
2186static uint8 t_s_outbuf[(sizeof(struct town_index_data_block) * 1024)];
2187//static uint8 s_outbuf[OUT_BUF_SIZE2];
2188
2189static long long street_index_size = 0; // this is the offset for town index start
2190// street index starts at "+sizeof(long long)"
2191
2192#define my_min(a,b) (((a) < (b)) ? (a) : (b))
2193#define NUMBER_OF_TOWNS_TO_CACHE 10
2194
2195static struct town_index_data_block_c *town_lookup_cache = NULL;
2196static struct town_index_data_block_c *town_lookup_cache_cur = NULL;
2197static struct town_index_data_block_c *town_lookup_cache_found = NULL;
2198static int town_lookup_cache_items = 0;
2199static int town_lookup_cache_cur_item = 0;
2200
2201void town_index_init_cache()
2202{
2203 int s = sizeof(struct town_index_data_block_c) * NUMBER_OF_TOWNS_TO_CACHE;
2204 // dbg(0, "cache size=%d\n", s);
2205
2206 town_lookup_cache = g_malloc(s);
2207 town_lookup_cache_cur = town_lookup_cache;
2208 town_lookup_cache_found = NULL;
2209 town_lookup_cache_items = 0;
2210 town_lookup_cache_cur_item = 0;
2211}
2212
2213void town_index_insert_cache(struct town_index_data_block* t, char* townname_long)
2214{
2215 if (town_lookup_cache_items < NUMBER_OF_TOWNS_TO_CACHE)
2216 {
2217 // fill up cache until all slots are filled
2218 town_lookup_cache_cur->town_id = t->town_id;
2219 town_lookup_cache_cur->country_id = t->country_id;
2220 sprintf(town_lookup_cache_cur->town_name, "%s", townname_long);
2221 town_lookup_cache_items++;
2222 }
2223 else
2224 {
2225 // just fill cache and rotate if at end
2226 town_lookup_cache_cur->town_id = t->town_id;
2227 town_lookup_cache_cur->country_id = t->country_id;
2228 sprintf(town_lookup_cache_cur->town_name, "%s", townname_long);
2229 }
2230
2231 if (town_lookup_cache_items == NUMBER_OF_TOWNS_TO_CACHE)
2232 {
2233 town_lookup_cache_cur_item = 0;
2234 town_lookup_cache_cur = town_lookup_cache;
2235 }
2236 else
2237 {
2238 town_lookup_cache_cur_item++;
2239 town_lookup_cache_cur++;
2240 }
2241}
2242
2243int town_index_lookup_cache(long long townid)
2244{
2245 int i;
2246 struct town_index_data_block_c* t;
2247
2248 if (town_lookup_cache_items < 1)
2249 {
2250 return 0;
2251 }
2252
2253 t = town_lookup_cache;
2254 for (i = 0; i < town_lookup_cache_items; i++)
2255 {
2256 if (t->town_id == townid)
2257 {
2258 // set pointer to found datablock
2259 town_lookup_cache_found = t;
2260 return 1;
2261 }
2262 t++;
2263 }
2264
2265 return 0;
2266}
2267
2268char* town_index_lookup(struct street_index_head *sih, long long townid)
2269{
2270 char *townname = NULL;
2271 char *townname2 = NULL;
2272 int found = 0;
2273 int i;
2274 int split = 0;
2275 int split_count = 0;
2276 long long save_town_id;
2277 int save_country_id;
2278
2279 if (townid == 0)
2280 {
2281 return townname;
2282 }
2283
2284 if (town_lookup_cache == NULL)
2285 {
2286 town_index_init_cache();
2287 }
2288
2289 if (town_index_lookup_cache(townid) == 1)
2290 {
2291 townname = g_strdup_printf("%s", town_lookup_cache_found->town_name);
2292 return townname;
2293 }
2294
2295 sih->ti_ib = sih->ti_ib_mem;
2296
2297 // find townid block
2298 found = sih->ti_ibs.count_of_index_blocks - 1; // set to last block
2299 for (i = 0; i < sih->ti_ibs.count_of_index_blocks; i++)
2300 {
2301 //dbg(0, "i=%d %lld %lld\n", i, townid, sih->ti_ib->first_id);
2302
2303 if (townid < sih->ti_ib->first_id)
2304 {
2305 found = i - 1;
2306 break;
2307 }
2308
2309 sih->ti_ib++;
2310 }
2311
2312 if (found != -1)
2313 {
2314 //dbg(0, "found town block num=%d\n", found);
2315
2316 town_index_setpos(sih, found); // move to correct index block
2317
2318 while (town_index_read_data(sih))
2319 {
2320 if (offline_search_break_searching == 1)
2321 {
2322 break;
2323 }
2324
2325 //dbg(0, "id=%lld\n", sih->ti_db_ptr->town_id);
2326
2327 if (sih->ti_db_ptr->town_id == townid)
2328 {
2329 townname = g_strdup_printf("%s", sih->ti_db_ptr->town_name);
2330 //dbg(0,"found town:%s\n", townname);
2331 save_town_id = sih->ti_db_ptr->town_id;
2332 save_country_id = sih->ti_db_ptr->country_id;
2333 split = 1;
2334 split_count = 0;
2335 while ((town_index_read_data(sih))&&(split == 1))
2336 {
2337 split_count++;
2338 if ((split_count + 1) > MAX_TOWNNAME_SPLIT)
2339 {
2340 break;
2341 }
2342
2343 if (sih->ti_db_ptr->town_id == 0)
2344 {
2345 //dbg(0," town-split:%s\n", sih->ti_db_ptr->town_name);
2346 townname2 = g_strdup_printf("%s%s", townname, sih->ti_db_ptr->town_name);
2347 g_free(townname);
2348 townname = townname2;
2349 }
2350 else
2351 {
2352 split = 0;
2353 }
2354 }
2355 break;
2356 }
2357 }
2358 }
2359
2360 if (townname != NULL)
2361 {
2362 sih->ti_db_ptr->town_id = save_town_id; // set town and country to values before we read the "split"-blocks!
2363 sih->ti_db_ptr->country_id = save_country_id;
2364 town_index_insert_cache(sih->ti_db_ptr, townname);
2365 }
2366
2367 //dbg(0, "return\n");
2368
2369 return townname;
2370}
2371
2372struct street_index_head* street_index_init(const char* idxfile_name)
2373{
2374 struct street_index_head *ret=g_new0(struct street_index_head, 1);
2375 long s1;
2376 int b;
2377 char *index_file;
2378
2379 index_file = g_strdup_printf("%s%s", navit_maps_dir, idxfile_name);
2380 ret->sif = fopen(index_file, "rb");
2381 g_free(index_file);
2382
2383 fread(&street_index_size, sizeof(struct streets_index_index_block_start), 1, ret->sif);
2384 //dbg(0, "street_index_size=%lld\n", street_index_size);
2385
2386 b = fread(&ret->si_ibs, sizeof(struct streets_index_index_block_start), 1, ret->sif);
2387 //dbg(0, "ftell=%d\n", ftell(ret->sif));
2388 //dbg(0, "items read=%d\n", b);
2389
2390 //dbg(0, "struct size=%d\n", sizeof(struct streets_index_data_block));
2391
2392 //dbg(0, "index entries=%d\n", ret->si_ibs.count_of_index_blocks);
2393 //dbg(0, "index entry size=%d\n", sizeof(struct streets_index_index_block));
2394 s1 = sizeof(struct streets_index_index_block) * ret->si_ibs.count_of_index_blocks;
2395 //dbg(0, "s1=%ld\n", s1);
2396
2397 ret->si_ib_mem = g_malloc(s1);
2398 ret->si_ib = ret->si_ib_mem;
2399
2400 ret->comp_status = 0;
2401 ret->t_comp_status = 0;
2402
2403 //dbg(0, "ftell=%d\n", ftell(ret->sif));
2404 fread(ret->si_ib_mem, sizeof(struct streets_index_index_block), ret->si_ibs.count_of_index_blocks, ret->sif);
2405 //dbg(0, "ftell=%d\n", ftell(ret->sif));
2406
2407 //dbg(0, "len=%lld\n", ret->si_ib->len);
2408 //dbg(0, "offset=%lld\n", ret->si_ib->offset);
2409
2410 fseek(ret->sif, street_index_size + sizeof(long long), SEEK_SET); // seek to townindex header
2411 fread(&ret->ti_ibs, sizeof(struct town_index_index_block_start), 1, ret->sif);
2412 //dbg(0, "len=%lld\n", ret->ti_ibs.count_of_index_blocks);
2413
2414 //dbg(0, "town index entries=%d\n", ret->ti_ibs.count_of_index_blocks);
2415 //dbg(0, "town index entry size=%d\n", sizeof(struct town_index_index_block));
2416 s1 = sizeof(struct town_index_index_block) * ret->ti_ibs.count_of_index_blocks;
2417 //dbg(0, "s1=%ld\n", s1);
2418
2419 ret->ti_ib_mem = g_malloc(s1);
2420 ret->ti_ib = ret->ti_ib_mem;
2421
2422 //dbg(0, "ftell=%d\n", ftell(ret->sif));
2423 fread(ret->ti_ib_mem, sizeof(struct town_index_index_block), ret->ti_ibs.count_of_index_blocks, ret->sif);
2424 //dbg(0, "ftell=%d\n", ftell(ret->sif));
2425
2426 //dbg(0, "town len=%lld\n", ret->ti_ib->len);
2427 //dbg(0, "town offset=%lld\n", ret->ti_ib->offset);
2428
2429 return ret;
2430}
2431
2432void town_index_setpos(struct street_index_head *sih, int town_data_block_num)
2433{
2434 if (sih->t_comp_status == 1)
2435 {
2436 town_index_close_compr(sih);
2437 }
2438
2439 sih->ti_ib = (sih->ti_ib_mem + town_data_block_num);
2440
2441 town_index_init_compr(sih, sih->ti_ib->len);
2442
2443 //dbg(0, "len=%lld\n", sih->ti_ib->len);
2444 //dbg(0, "fid=%lld\n", sih->ti_ib->first_id);
2445 //dbg(0, "off=%lld\n", sih->ti_ib->offset);
2446
2447 // if (sih->ti_ib->len >= sizeof(struct town_index_data_block))
2448 if (sih->ti_ib->len > 1)
2449 {
2450 //dbg(0, "fpos1=%d\n", ftell(sih->sif));
2451 fseek(sih->sif, sih->ti_ib->offset + sizeof(long long) + street_index_size, SEEK_SET);
2452 //dbg(0, "fpos2=%d\n", ftell(sih->sif));
2453
2454 sih->t_data_count = 0;
2455 // move ptr to first data
2456 sih->ti_db_ptr = t_s_outbuf;
2457 }
2458
2459}
2460
2461void street_index_setpos(struct street_index_head *sih, int data_block_num)
2462{
2463
2464 if (sih->comp_status == 1)
2465 {
2466 street_index_close_compr(sih);
2467 }
2468
2469 sih->si_ib = (sih->si_ib_mem + data_block_num);
2470
2471 //dbg(0, "len=%lld\n", sih->si_ib->len);
2472 //dbg(0, "fl=%c off=%lld\n", sih->si_ib->first_letter, sih->si_ib->offset);
2473
2474 street_index_init_compr(sih, sih->si_ib->len);
2475
2476 //if (sih->si_ib->len >= sizeof(struct streets_index_data_block))
2477 if (sih->si_ib->len > 1) // what is the minimum compressed block size? (about 55 bytes now)
2478 {
2479 //dbg(0, "mem start=%d, cur pos=%d\n", sih->si_ib_mem, sih->si_ib);
2480 //dbg(0, "file offset=%d\n", sih->si_ib->offset);
2481 //dbg(0, "fpos s1=%d\n", ftell(sih->sif));
2482 fseek(sih->sif, sih->si_ib->offset + sizeof(long long), SEEK_SET); // add the "long long" from start of file to offset
2483 //dbg(0, "fpos s2=%d\n", ftell(sih->sif));
2484
2485 sih->data_count = 0;
2486 // move ptr to first data
2487 sih->si_db_ptr = s_outbuf;
2488 }
2489}
2490
2491int street_index_read_data(struct street_index_head *sih)
2492{
2493 // fread(&sih->si_db, sizeof(struct streets_index_data_block), 1, sih->sif);
2494
2495
2496 //if (sih->si_ib->len < sizeof(struct streets_index_data_block))
2497 if (sih->si_ib->len <= 1) // minimum size of compressed block?
2498 {
2499 //dbg(0, "len=%d sof=%d\n", sih->si_ib->len, sizeof(struct streets_index_data_block));
2500 // no data for this letter
2501 return 0;
2502 }
2503
2504 if (sih->data_count == 0)
2505 {
2506 // init
2507 sih->next_out = s_outbuf;
2508 sih->avail_out = OUT_BUF_SIZE2;
2509
2510 // read data
2511 sih->data_count = street_index_decompress_data_block(sih);
2512 //dbg(0, "stat=%d\n", sih->data_count);
2513
2514 if (sih->data_count <= 0)
2515 {
2516 // end of data
2517 return 0;
2518 }
2519
2520 // move ptr to next data
2521 sih->si_db_ptr = s_outbuf;
2522 }
2523 else
2524 {
2525 sih->data_count = sih->data_count - sizeof(struct streets_index_data_block);
2526
2527 if (sih->data_count > 0)
2528 {
2529 sih->si_db_ptr++;
2530 //dbg(0, "dc=%d ptr=%p\n", sih->data_count, sih->si_db_ptr);
2531 }
2532 else
2533 {
2534 // init
2535 sih->next_out = s_outbuf;
2536 sih->avail_out = OUT_BUF_SIZE2;
2537
2538 // read data
2539 sih->data_count = street_index_decompress_data_block(sih);
2540 //dbg(0, "stat2=%d\n", sih->data_count);
2541
2542 if (sih->data_count <= 0)
2543 {
2544 // end of data
2545 return 0;
2546 }
2547
2548 // move ptr to next data
2549 sih->si_db_ptr = s_outbuf;
2550 }
2551 }
2552
2553 //dbg(0, "data=%s, %d, %d, %lld\n", sih->si_db_ptr->street_name, sih->si_db_ptr->lat, sih->si_db_ptr->lon, sih->si_db_ptr->town_id);
2554
2555 return 1;
2556
2557 //if (ftell(sih->sif) > (sih->si_ib->offset + sih->si_ib->len))
2558 //{
2559 // // end of data
2560 // return 0;
2561 //}
2562
2563 // more data found
2564 // return 1;
2565}
2566
2567int town_index_read_data(struct street_index_head *sih)
2568{
2569 // fread(&sih->si_db, sizeof(struct streets_index_data_block), 1, sih->sif);
2570
2571
2572 // if (sih->ti_ib->len < sizeof(struct town_index_data_block))
2573 if (sih->ti_ib->len <= 1)
2574 {
2575 // no data for this block
2576 //fprintf(stderr, "no data for this block\n");
2577 return 0;
2578 }
2579
2580 if (sih->t_data_count == 0)
2581 {
2582 // init
2583 sih->t_next_out = t_s_outbuf;
2584 sih->t_avail_out = t_OUT_BUF_SIZE2;
2585
2586 // read data
2587 sih->t_data_count = town_index_decompress_data_block(sih);
2588 //dbg(0, "stat=%d\n", sih->data_count);
2589
2590 if (sih->t_data_count <= 0)
2591 {
2592 // end of data
2593 //fprintf(stderr, "end of data\n");
2594 return 0;
2595 }
2596
2597 // move ptr to next data
2598 sih->ti_db_ptr = t_s_outbuf;
2599 }
2600 else
2601 {
2602 sih->t_data_count = sih->t_data_count - sizeof(struct town_index_data_block);
2603
2604 if (sih->t_data_count > 0)
2605 {
2606 sih->ti_db_ptr++;
2607 //dbg(0, "dc=%d ptr=%p\n", sih->data_count, sih->si_db_ptr);
2608 }
2609 else
2610 {
2611 // init
2612 sih->t_next_out = t_s_outbuf;
2613 sih->t_avail_out = t_OUT_BUF_SIZE2;
2614
2615 // read data
2616 sih->t_data_count = town_index_decompress_data_block(sih);
2617 //dbg(0, "stat2=%d\n", sih->data_count);
2618
2619 if (sih->t_data_count <= 0)
2620 {
2621 // end of data
2622 //fprintf(stderr, "end of data (2)\n");
2623 return 0;
2624 }
2625
2626 // move ptr to next data
2627 sih->ti_db_ptr = t_s_outbuf;
2628 }
2629 }
2630
2631 //dbg(0, "data=%s, %d, %d, %lld\n", sih->si_db_ptr->street_name, sih->si_db_ptr->lat, sih->si_db_ptr->lon, sih->si_db_ptr->town_id);
2632
2633 return 1;
2634
2635 //if (ftell(sih->sif) > (sih->si_ib->offset + sih->si_ib->len))
2636 //{
2637 // // end of data
2638 // return 0;
2639 //}
2640
2641 // more data found
2642 // return 1;
2643}
2644
2645void street_index_close_compr(struct street_index_head *sih)
2646{
2647 g_free(sih->inflator);
2648 sih->comp_status = 2;
2649}
2650
2651void town_index_close_compr(struct street_index_head *sih)
2652{
2653 g_free(sih->t_inflator);
2654 sih->t_comp_status = 2;
2655}
2656
2657void street_index_init_compr(struct street_index_head *sih, long long size)
2658{
2659 // decompress structure
2660 sih->inflator = g_new0(tinfl_decompressor, 1);
2661 sih->comp_status = 1;
2662 // decompress structure
2663
2664 // Decompression.
2665 sih->infile_size = (uint) size;
2666 sih->infile_remaining = sih->infile_size;
2667
2668 sih->next_in = s_inbuf;
2669 sih->avail_in = 0;
2670 sih->next_out = s_outbuf;
2671 sih->avail_out = OUT_BUF_SIZE2;
2672
2673 sih->data_count = 0;
2674
2675 tinfl_init(sih->inflator);
2676}
2677
2678void town_index_init_compr(struct street_index_head *sih, long long size)
2679{
2680 // decompress structure
2681 sih->t_inflator = g_new0(tinfl_decompressor, 1);
2682 sih->t_comp_status = 1;
2683 // decompress structure
2684
2685 // Decompression.
2686 sih->t_infile_size = (uint) size;
2687 sih->t_infile_remaining = sih->t_infile_size;
2688
2689 sih->t_next_in = t_s_inbuf;
2690 sih->t_avail_in = 0;
2691 sih->t_next_out = t_s_outbuf;
2692 sih->t_avail_out = t_OUT_BUF_SIZE2;
2693
2694 sih->t_data_count = 0;
2695
2696 tinfl_init(sih->t_inflator);
2697}
2698
2699int street_index_decompress_data_block(struct street_index_head *sih)
2700{
2701 // size_t total_in = 0, total_out = 0;
2702 // long file_loc;
2703
2704 // Decompression.
2705 for (;;)
2706 {
2707 sih->in_bytes = 0;
2708 sih->out_bytes = 0;
2709 if (!sih->avail_in)
2710 {
2711 // Input buffer is empty, so read more bytes from input file.
2712 uint n = my_min(IN_BUF_SIZE2, sih->infile_remaining);
2713
2714 //dbg(0, "reading bytes:%d remain=%d\n", n, sih->infile_remaining);
2715
2716 if (fread(s_inbuf, 1, n, sih->sif) != n)
2717 {
2718 //printf("Failed reading from input file!\n");
2719 dbg(0, "Failed reading from input file!\n");
2720 //g_free(sih->inflator);
2721 return -1;
2722 }
2723
2724 sih->next_in = s_inbuf;
2725 sih->avail_in = n;
2726
2727 sih->infile_remaining -= n;
2728 }
2729
2730 sih->in_bytes = sih->avail_in;
2731 sih->out_bytes = sih->avail_out;
2732 sih->miniz_status = tinfl_decompress(sih->inflator, (const mz_uint8 *) sih->next_in, &sih->in_bytes, s_outbuf, (mz_uint8 *) sih->next_out, &sih->out_bytes, (sih->infile_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0) | TINFL_FLAG_PARSE_ZLIB_HEADER);
2733
2734 sih->avail_in -= sih->in_bytes;
2735 sih->next_in = (const mz_uint8 *) sih->next_in + sih->in_bytes;
2736 //total_in += sih->in_bytes;
2737
2738 sih->avail_out -= sih->out_bytes;
2739 sih->next_out = (mz_uint8 *) sih->next_out + sih->out_bytes;
2740 //total_out += sih->out_bytes;
2741
2742 if ((sih->miniz_status <= TINFL_STATUS_DONE) || (!sih->avail_out))
2743 {
2744 // Output buffer is full, or decompression is done, so write buffer to output file.
2745 uint n = OUT_BUF_SIZE2 - (uint) sih->avail_out;
2746
2747 //dbg(0, "decompr: start=%p len=%d\n", (void *) sih->next_out, (int) n);
2748 //dbg(0, "decompr: start=%p len=%d\n", (void *) s_outbuf, (int) n);
2749 //dbg(0, "decompr: av in=%d av out=%d\n", sih->avail_in, sih->avail_out);
2750 //dbg(0, "decompr: nx in=%d nx out=%d\n", sih->next_in, sih->next_out);
2751
2752 //struct streets_index_data_block *tmp = (struct streets_index_data_block *)s_outbuf;
2753 //dbg(0,"data=%s, %d, %d, %lld\n", tmp->street_name, tmp->lat, tmp->lon, tmp->town_id);
2754
2755 //sih->next_out = s_outbuf;
2756 //sih->avail_out = OUT_BUF_SIZE2;
2757
2758 return (int) n;
2759
2760 //if (fwrite(s_outbuf, 1, n, pOutfile) != n)
2761 //{
2762 // // printf("Failed writing to output file!\n");
2763 // //g_free(inflator);
2764 // return;
2765 //}
2766 }
2767
2768 // If sih->miniz_status is <= TINFL_STATUS_DONE then either decompression is done or something went wrong.
2769 if (sih->miniz_status <= TINFL_STATUS_DONE)
2770 {
2771 if (sih->miniz_status == TINFL_STATUS_DONE)
2772 {
2773 // Decompression completed successfully.
2774 //dbg(0, "Decompression completed successfully\n");
2775 //break;
2776 return -2;
2777 }
2778 else
2779 {
2780 // Decompression failed.
2781 //printf("tinfl_decompress() failed with status %i!\n", sih->miniz_status);
2782 dbg(0, "tinfl_decompress() failed with status %i!\n", sih->miniz_status);
2783
2784 //g_free(inflator);
2785 return -1;
2786 }
2787 }
2788 }
2789
2790 //g_free(inflator);
2791 return -3;
2792
2793}
2794
2795int town_index_decompress_data_block(struct street_index_head *sih)
2796{
2797 // size_t total_in = 0, total_out = 0;
2798 // long file_loc;
2799
2800 // Decompression.
2801 for (;;)
2802 {
2803 sih->t_in_bytes = 0;
2804 sih->t_out_bytes = 0;
2805 if (!sih->t_avail_in)
2806 {
2807 // Input buffer is empty, so read more bytes from input file.
2808 uint n = my_min(t_IN_BUF_SIZE2, sih->t_infile_remaining);
2809
2810 //dbg(0, "reading bytes:%d remain=%d\n", n, sih->t_infile_remaining);
2811
2812 if (fread(t_s_inbuf, 1, n, sih->sif) != n)
2813 {
2814 //printf("Failed reading from input file!\n");
2815 dbg(0, "Failed reading from input file!\n");
2816 //g_free(sih->inflator);
2817 return -1;
2818 }
2819
2820 sih->t_next_in = t_s_inbuf;
2821 sih->t_avail_in = n;
2822
2823 sih->t_infile_remaining -= n;
2824 }
2825
2826 sih->t_in_bytes = sih->t_avail_in;
2827 sih->t_out_bytes = sih->t_avail_out;
2828 sih->t_miniz_status = tinfl_decompress(sih->t_inflator, (const mz_uint8 *) sih->t_next_in, &sih->t_in_bytes, t_s_outbuf, (mz_uint8 *) sih->t_next_out, &sih->t_out_bytes, (sih->t_infile_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0) | TINFL_FLAG_PARSE_ZLIB_HEADER);
2829
2830 sih->t_avail_in -= sih->t_in_bytes;
2831 sih->t_next_in = (const mz_uint8 *) sih->t_next_in + sih->t_in_bytes;
2832 //total_in += sih->in_bytes;
2833
2834 sih->t_avail_out -= sih->t_out_bytes;
2835 sih->t_next_out = (mz_uint8 *) sih->t_next_out + sih->t_out_bytes;
2836 //total_out += sih->out_bytes;
2837
2838 if ((sih->t_miniz_status <= TINFL_STATUS_DONE) || (!sih->t_avail_out))
2839 {
2840 // Output buffer is full, or decompression is done, so write buffer to output file.
2841 uint n = t_OUT_BUF_SIZE2 - (uint) sih->t_avail_out;
2842
2843 //dbg(0, "decompr: start=%p len=%d\n", (void *) sih->next_out, (int) n);
2844 //dbg(0, "decompr: start=%p len=%d\n", (void *) s_outbuf, (int) n);
2845 //dbg(0, "decompr: av in=%d av out=%d\n", sih->avail_in, sih->avail_out);
2846 //dbg(0, "decompr: nx in=%d nx out=%d\n", sih->next_in, sih->next_out);
2847
2848 //struct town_index_data_block *tmpt = (struct town_index_data_block *)t_s_outbuf;
2849 //dbg(0,"data=%lld %s\n", tmpt->town_id, tmpt->town_name);
2850
2851 //sih->next_out = s_outbuf;
2852 //sih->avail_out = t_OUT_BUF_SIZE2;
2853
2854 return (int) n;
2855
2856 //if (fwrite(s_outbuf, 1, n, pOutfile) != n)
2857 //{
2858 // // printf("Failed writing to output file!\n");
2859 // //g_free(inflator);
2860 // return;
2861 //}
2862 }
2863
2864 // If sih->miniz_status is <= TINFL_STATUS_DONE then either decompression is done or something went wrong.
2865 if (sih->t_miniz_status <= TINFL_STATUS_DONE)
2866 {
2867 if (sih->t_miniz_status == TINFL_STATUS_DONE)
2868 {
2869 // Decompression completed successfully.
2870 //dbg(0, "Decompression completed successfully\n");
2871 //break;
2872 return -2;
2873 }
2874 else
2875 {
2876 // Decompression failed.
2877 //printf("tinfl_decompress() failed with status %i!\n", sih->miniz_status);
2878 dbg(0, "tinfl_decompress() failed with status %i!\n", sih->t_miniz_status);
2879
2880 //g_free(inflator);
2881 return -1;
2882 }
2883 }
2884 }
2885
2886 //g_free(inflator);
2887 return -3;
2888
2889}
2890
2891void street_index_close(struct street_index_head *sih)
2892{
2893 g_free(sih->si_ib_mem);
2894 g_free(sih->ti_ib_mem);
2895 if (town_lookup_cache)
2896 {
2897 g_free(town_lookup_cache);
2898 town_lookup_cache = NULL;
2899 }
2900 fclose(sih->sif);
2901 g_free(sih);
2902}
2903
2904
2905// func defs
2906void search_v2_work(char *addr, char *town, char* hn, int partial, struct jni_object *jni, const char* idxfile_name);
2907void search_v2(char *addr, char *town, char* hn, int partial, struct jni_object *jni);
2908// func defs
2909
2910
2911#include <sys/types.h>
2912#include <dirent.h>
2913
2914void search_v2(char *addr, char *town, char* hn, int partial, struct jni_object *jni)
2915{
2916 int len;
2917 int len2;
2918 int len3;
2919 char *last_four;
2920 DIR* dirp;
2921 struct dirent *dp;
2922
2923 len2 = strlen("navitmap_");
2924 len = len2 + 11; // should be 21 'navitmap_0%%.bin.idx'
2925
2926 // look for all the navitmap_0**.bin.idx files in mapdir, then call search in all of them
2927 dirp = opendir(navit_maps_dir);
2928 while ((dp = readdir(dirp)) != NULL)
2929 {
2930 if ((strlen(dp->d_name) == len) && (!strncmp(dp->d_name, "navitmap_", len2)))
2931 {
2932 //dbg(0, "2 file=%s\n", dp->d_name);
2933 len3 = strlen(dp->d_name);
2934 last_four = &dp->d_name[len3-4];
2935 //dbg(0, "3 l4=%s\n", last_four);
2936 if (!strcmp(last_four, ".idx"))
2937 {
2938 search_v2_work(addr, town, hn, partial, jni, dp->d_name);
2939 }
2940 }
2941 }
2942 closedir(dirp);
2943
2944}
2945
2946void search_v2_work(char *addr, char *town, char* hn, int partial, struct jni_object *jni, const char* idxfile_name)
2947{
2948 char *buffer = NULL;
2949 float lat;
2950 float lng;
2951 char *address;
2952 char *address2;
2953 char *townname = NULL;
2954 char *addr_copy;
2955 char *addr2;
2956 char *addr3;
2957 char *addr3a;
2958 char *town_fold;
2959 char *tt;
2960 int i;
2961 int j;
2962 int br;
2963 int charlen;
2964 int found;
2965 int starts_with_utf8 = 0;
2966 int nd_with_utf8 = 0;
2967 int want_result;
2968 struct coord c3;
2969 static const char *alpha = "abcdefghijklmnopqrstuvwxyz";
2970 char tmp_letter[STREET_INDEX_STREET_NAME_SIZE];
2971 struct street_index_head *sih;
2972
2973
2974 if ((!addr) || (strlen(addr) < 1))
2975 {
2976 return;
2977 }
2978
2979 // prepare search string
2980 addr2 = linguistics_casefold(addr);
2981 if (addr2)
2982 {
2983 addr3 = linguistics_remove_all_specials(addr2);
2984 if (addr3)
2985 {
2986 g_free(addr2);
2987 addr2 = addr3;
2988 }
2989 addr3 = linguistics_expand_special(addr2, 1);
2990 if (addr3)
2991 {
2992 g_free(addr2);
2993 addr2 = addr3;
2994 }
2995 addr_copy = addr2;
2996 }
2997 else
2998 {
2999 addr2 = g_strdup(addr);
3000 addr_copy = addr2;
3001 }
3002
3003 // prepare town search string
3004 town_fold = linguistics_fold_and_prepare_complete(town, 0);
3005
3006
3007 //dbg(0,"town=%s townfold=%s street=%s hn=%s\n", town, town_fold, addr_copy, hn);
3008
3009 sih = street_index_init(idxfile_name);
3010
3011 // is first letter ascii or UTF-8?
3012 addr3 = g_utf8_find_next_char(addr_copy, NULL);
3013 charlen = addr3 - addr_copy;
3014 if (charlen > 1)
3015 {
3016 starts_with_utf8 = 1;
3017 }
3018 //dbg(0, "charlen=%d starts_with_utf8=%d\n", charlen, starts_with_utf8);
3019
3020 // is second letter ascii or UTF-8?
3021 addr3a = g_utf8_find_next_char(addr3, NULL);
3022 charlen = addr3a - addr3;
3023 if (charlen > 1)
3024 {
3025 nd_with_utf8 = 1;
3026 }
3027 //dbg(0, "charlen=%d nd_with_utf8=%d\n", charlen, nd_with_utf8);
3028
3029
3030 // find starting letter of search string
3031 found = (703 - 1); // 26+1 letters ((26+1)*26 + 1) = 703
3032 br = 0;
3033 if (starts_with_utf8 == 0)
3034 {
3035 // check the first letter
3036 for (i = 0; i < 26; i++)
3037 {
3038 if (addr_copy[0] == alpha[i])
3039 {
3040 if ((strlen(addr_copy) > 1) && (nd_with_utf8 == 0))
3041 {
3042 //dbg(0, "i=%d\n", i);
3043 // check the second letter
3044 for (j = 0; j < 26; j++)
3045 {
3046 //dbg(0, "j=%d\n", j);
3047 if (addr_copy[1] == alpha[j])
3048 {
3049 found = (27 * i) + j;
3050 br = 1;
3051 break;
3052 }
3053 }
3054 if (br == 0)
3055 {
3056 // second letter has no match, use generic first letter block
3057 found = (27 * i) + 26;
3058 }
3059 br = 1;
3060 break;
3061 }
3062 else
3063 {
3064 // use generic first letter block
3065 found = (27 * i) + 26;
3066 br = 1;
3067 break;
3068 }
3069 }
3070
3071 if (br)
3072 {
3073 break;
3074 }
3075 }
3076 }
3077
3078 //dbg(0, "found pos=%d\n", found);
3079
3080 street_index_setpos(sih, found);
3081 int found_data = 0;
3082 //int ddd = 0;
3083
3084 while (street_index_read_data(sih))
3085 {
3086 //ddd++;
3087
3088 //if (ddd > 3)
3089 //{
3090 // break;
3091 //}
3092
3093 if (offline_search_break_searching == 1)
3094 {
3095 break;
3096 }
3097
3098 //dbg(0,"data=%s addr=%s\n", sih->si_db_ptr->street_name, addr_copy);
3099 if (!ascii_cmp_local_faster(sih->si_db_ptr->street_name, addr_copy, 1))
3100 {
3101 found_data = 1;
3102 if ((partial == 1) || (!ascii_cmp_local_faster(sih->si_db_ptr->street_name, addr_copy, partial)))
3103 {
3104 townname = town_index_lookup(sih, sih->si_db_ptr->town_id);
3105
3106 // if we also have a search-town-name then check here
3107 if ((!town_fold)||(strlen(town_fold) < 1))
3108 {
3109 want_result = 1;
3110 }
3111 else
3112 {
3113 tt = linguistics_fold_and_prepare_complete(townname, 0);
3114 want_result = 1-(linguistics_compare_anywhere(tt, town_fold));
3115 //dbg(0, "want_result=%d tt=%s\n", want_result, tt);
3116 }
3117
3118 if (want_result == 1)
3119 {
3120
3121 // check for housenumber
3122 if ((hn != NULL) && (strlen(hn) > 0))
3123 {
3124 // now set coord of this item/street
3125 c3.y = sih->si_db_ptr->lat;
3126 c3.x = sih->si_db_ptr->lon;
3127 search_address_housenumber_for_street(hn, sih->si_db_ptr->street_name, townname, &c3, partial, jni);
3128 }
3129
3130 if (townname != NULL)
3131 {
3132 address = g_strdup_printf("%s, %s", sih->si_db_ptr->street_name, townname);
3133 }
3134 else
3135 {
3136 address = g_strdup_printf("%s", sih->si_db_ptr->street_name);
3137 }
3138
3139
3140 if (strlen(address) > 100)
3141 {
3142 address2 = address;
3143 address2[101] = '\0';
3144 address2 = linguistics_check_utf8_string(address2);
3145 }
3146 else
3147 {
3148 address2 = address;
3149 }
3150 buffer = g_strdup_printf("STR:H0L0:%d:%d:%.101s", sih->si_db_ptr->lat, sih->si_db_ptr->lon, address2);
3151#ifdef HAVE_API_ANDROID
3152 // return results to android as they come in ...
3153 android_return_search_result(jni, buffer);
3154#endif
3155 if (townname)
3156 {
3157 g_free(townname);
3158 townname = NULL;
3159 }
3160
3161 if (address)
3162 {
3163 g_free(address);
3164 address = NULL;
3165 }
3166
3167 if (buffer)
3168 {
3169 g_free(buffer);
3170 buffer = NULL;
3171 }
3172 }
3173 }
3174 }
3175 else
3176 {
3177 if (found_data == 1)
3178 {
3179 // no more matching data, stop searching
3180 break;
3181 }
3182 }
3183 }
3184 g_free(addr_copy);
3185 street_index_close(sih);
3186
3187}
3188

Legend:
Removed from v.30  
changed lines
  Added in v.31

   
Visit the ZANavi Wiki