… | |
… | |
555 | return g_strdup_printf("%s/%s", dir, filename); |
555 | return g_strdup_printf("%s/%s", dir, filename); |
556 | } |
556 | } |
557 | |
557 | |
558 | static int binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) |
558 | static int binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) |
559 | { |
559 | { |
|
|
560 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
561 | dbg(0,"+#+:enter\n"); |
|
|
562 | #endif |
|
|
563 | |
|
|
564 | // try to return "0" on any problem, to avoid crash!! |
|
|
565 | |
560 | struct map_rect_priv *mr = priv_data; |
566 | struct map_rect_priv *mr = priv_data; |
561 | struct tile *t = mr->t; |
567 | struct tile *t = mr->t; |
562 | enum attr_type type; |
568 | enum attr_type type; |
563 | int i, size; |
569 | int i, size; |
564 | |
570 | |
565 | if (attr_type != mr->attr_last) |
571 | if (attr_type != mr->attr_last) |
566 | { |
572 | { |
567 | t->pos_attr = t->pos_attr_start; |
573 | t->pos_attr = t->pos_attr_start; |
568 | mr->attr_last = attr_type; |
574 | mr->attr_last = attr_type; |
569 | } |
575 | } |
|
|
576 | |
570 | while (t->pos_attr < t->pos_next) |
577 | while (t->pos_attr < t->pos_next) |
571 | { |
578 | { |
|
|
579 | //dbg(0,"batg:002 %d %d\n",t->pos_attr,(t->pos_attr+1)); |
572 | size = le32_to_cpu(*(t->pos_attr++)); |
580 | size = le32_to_cpu(*(t->pos_attr++)); |
|
|
581 | // dbg(0,"batg:002.1 %d %d\n",t->pos_attr, t->pos_attr[0]); |
573 | type = le32_to_cpu(t->pos_attr[0]); |
582 | type = le32_to_cpu(t->pos_attr[0]); |
|
|
583 | // dbg(0, "type=%d\n", type); |
|
|
584 | |
|
|
585 | #ifdef NAVIT_ATTR_SAFETY_CHECK |
|
|
586 | // safety check (always keep value in sync with "attr_def.h" !!) --------------- |
|
|
587 | if (type > 0x000effff) |
|
|
588 | { |
|
|
589 | return 0; |
|
|
590 | } |
|
|
591 | // safety check (always keep value in sync with "attr_def.h" !!) --------------- |
|
|
592 | #endif |
|
|
593 | |
|
|
594 | //dbg(0,"batg:002.2\n"); |
574 | if (type == attr_label) |
595 | if (type == attr_label) |
575 | mr->label = 1; |
596 | mr->label = 1; |
576 | if (type == attr_house_number) |
597 | if (type == attr_house_number) |
577 | mr->label_attr[0] = t->pos_attr; |
598 | mr->label_attr[0] = t->pos_attr; |
578 | if (type == attr_street_name) |
599 | if (type == attr_street_name) |
… | |
… | |
581 | mr->label_attr[2] = t->pos_attr; |
602 | mr->label_attr[2] = t->pos_attr; |
582 | if (type == attr_district_name && mr->item.type < type_line) |
603 | if (type == attr_district_name && mr->item.type < type_line) |
583 | mr->label_attr[3] = t->pos_attr; |
604 | mr->label_attr[3] = t->pos_attr; |
584 | if (type == attr_town_name && mr->item.type < type_line) |
605 | if (type == attr_town_name && mr->item.type < type_line) |
585 | mr->label_attr[4] = t->pos_attr; |
606 | mr->label_attr[4] = t->pos_attr; |
|
|
607 | |
586 | if (type == attr_type || attr_type == attr_any) |
608 | if (type == attr_type || attr_type == attr_any) |
587 | { |
609 | { |
588 | if (attr_type == attr_any) |
610 | if (attr_type == attr_any) |
589 | { |
611 | { |
590 | // dbg(1, "pos %p attr %s size %d\n", t->pos_attr - 1, attr_to_name(type), size); |
612 | // dbg(1, "pos %p attr %s size %d\n", t->pos_attr - 1, attr_to_name(type), size); |
… | |
… | |
604 | attr_data_set_le(&mr->attrs[i], subpos + 1); |
626 | attr_data_set_le(&mr->attrs[i], subpos + 1); |
605 | subpos += subsize; |
627 | subpos += subsize; |
606 | size_rem -= subsize + 1; |
628 | size_rem -= subsize + 1; |
607 | i++; |
629 | i++; |
608 | } |
630 | } |
|
|
631 | |
609 | mr->attrs[i].type = type_none; |
632 | mr->attrs[i].type = type_none; |
610 | mr->attrs[i].u.data = NULL; |
633 | mr->attrs[i].u.data = NULL; |
611 | attr->u.attrs = mr->attrs; |
634 | attr->u.attrs = mr->attrs; |
612 | } |
635 | } |
613 | else |
636 | else |
… | |
… | |
617 | { |
640 | { |
618 | g_free(mr->url); |
641 | g_free(mr->url); |
619 | mr->url = binfile_extract(mr->m, mr->m->cachedir, attr->u.str, 1); |
642 | mr->url = binfile_extract(mr->m, mr->m->cachedir, attr->u.str, 1); |
620 | attr->u.str = mr->url; |
643 | attr->u.str = mr->url; |
621 | } |
644 | } |
|
|
645 | |
622 | if (type == attr_flags && mr->m->map_version < 1) |
646 | if (type == attr_flags && mr->m->map_version < 1) |
|
|
647 | { |
623 | attr->u.num |= AF_CAR; |
648 | attr->u.num |= AF_CAR; |
|
|
649 | } |
624 | } |
650 | } |
625 | t->pos_attr += size; |
651 | t->pos_attr += size; |
626 | return 1; |
652 | return 1; |
627 | } |
653 | } |
628 | else |
654 | else |
629 | { |
655 | { |
630 | t->pos_attr += size; |
656 | t->pos_attr += size; |
631 | } |
657 | } |
632 | } |
658 | } |
|
|
659 | |
633 | if (!mr->label && (attr_type == attr_any || attr_type == attr_label)) |
660 | if (!mr->label && (attr_type == attr_any || attr_type == attr_label)) |
634 | { |
661 | { |
635 | for (i = 0; i < sizeof(mr->label_attr) / sizeof(int *); i++) |
662 | for (i = 0; i < sizeof(mr->label_attr) / sizeof(int *); i++) |
636 | { |
663 | { |
637 | if (mr->label_attr[i]) |
664 | if (mr->label_attr[i]) |
… | |
… | |
641 | attr_data_set_le(attr, mr->label_attr[i] + 1); |
668 | attr_data_set_le(attr, mr->label_attr[i] + 1); |
642 | return 1; |
669 | return 1; |
643 | } |
670 | } |
644 | } |
671 | } |
645 | } |
672 | } |
|
|
673 | |
|
|
674 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
675 | dbg(0,"+#+:leave\n"); |
|
|
676 | #endif |
|
|
677 | |
646 | return 0; |
678 | return 0; |
647 | } |
679 | } |
648 | |
680 | |
649 | struct binfile_hash_entry |
681 | struct binfile_hash_entry |
650 | { |
682 | { |
… | |
… | |
676 | entry->flags = 1; |
708 | entry->flags = 1; |
677 | // dbg(0, "id 0x%x,0x%x\n", entry->id.id_hi, entry->id.id_lo); |
709 | // dbg(0, "id 0x%x,0x%x\n", entry->id.id_hi, entry->id.id_lo); |
678 | |
710 | |
679 | memcpy(ret, t->pos, (size + 1) * sizeof(int)); |
711 | memcpy(ret, t->pos, (size + 1) * sizeof(int)); |
680 | if (!m->changes) |
712 | if (!m->changes) |
681 | m->changes = g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free, NULL); |
713 | m->changes = g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free_func, NULL); |
682 | g_hash_table_replace(m->changes, entry, entry); |
714 | g_hash_table_replace(m->changes, entry, entry); |
683 | // dbg(0, "ret %p\n", ret); |
715 | // dbg(0, "ret %p\n", ret); |
684 | return ret; |
716 | return ret; |
685 | } |
717 | } |
686 | |
718 | |
… | |
… | |
1692 | if (!changes) |
1724 | if (!changes) |
1693 | { |
1725 | { |
1694 | g_free(changes_file); |
1726 | g_free(changes_file); |
1695 | return; |
1727 | return; |
1696 | } |
1728 | } |
1697 | m->changes = g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free, NULL); |
1729 | m->changes = g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free_func, NULL); |
1698 | while (fread(&entry, sizeof(entry), 1, changes) == 1) |
1730 | while (fread(&entry, sizeof(entry), 1, changes) == 1) |
1699 | { |
1731 | { |
1700 | if (fread(&size, sizeof(size), 1, changes) != 1) |
1732 | if (fread(&size, sizeof(size), 1, changes) != 1) |
1701 | break; |
1733 | break; |
1702 | e = g_malloc(sizeof(struct binfile_hash_entry) + (le32_to_cpu(size) + 1) * 4); |
1734 | e = g_malloc(sizeof(struct binfile_hash_entry) + (le32_to_cpu(size) + 1) * 4); |
… | |
… | |
1832 | } |
1864 | } |
1833 | |
1865 | |
1834 | static struct item * |
1866 | static struct item * |
1835 | map_rect_get_item_binfile(struct map_rect_priv *mr) |
1867 | map_rect_get_item_binfile(struct map_rect_priv *mr) |
1836 | { |
1868 | { |
|
|
1869 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1870 | dbg(0,"+#+:enter\n"); |
|
|
1871 | #endif |
|
|
1872 | |
1837 | struct tile *t; |
1873 | struct tile *t; |
1838 | struct map_priv *m = mr->m; |
1874 | struct map_priv *m = mr->m; |
|
|
1875 | |
1839 | if (m->download) |
1876 | if (m->download) |
1840 | { |
1877 | { |
1841 | download(m, NULL, NULL, 0, 0, 0, 2); |
1878 | download(m, NULL, NULL, 0, 0, 0, 2); |
|
|
1879 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1880 | dbg(0,"+#+:leave9\n"); |
|
|
1881 | #endif |
1842 | return &busy_item; |
1882 | return &busy_item; |
1843 | } |
1883 | } |
|
|
1884 | |
1844 | if (mr->status == 1) |
1885 | if (mr->status == 1) |
1845 | { |
1886 | { |
1846 | mr->status = 0; |
1887 | mr->status = 0; |
1847 | if (push_zipfile_tile(mr, m->zip_members - 1, 0, 0, 1)) |
1888 | if (push_zipfile_tile(mr, m->zip_members - 1, 0, 0, 1)) |
|
|
1889 | { |
|
|
1890 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1891 | dbg(0,"+#+:leave8\n"); |
|
|
1892 | #endif |
1848 | return &busy_item; |
1893 | return &busy_item; |
1849 | } |
1894 | } |
|
|
1895 | } |
|
|
1896 | |
1850 | for (;;) |
1897 | for (;;) |
1851 | { |
1898 | { |
1852 | t = mr->t; |
1899 | t = mr->t; |
|
|
1900 | |
1853 | if (!t) |
1901 | if (!t) |
|
|
1902 | { |
|
|
1903 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1904 | dbg(0,"+#+:leave6\n"); |
|
|
1905 | #endif |
1854 | return NULL; |
1906 | return NULL; |
|
|
1907 | } |
|
|
1908 | |
1855 | t->pos = t->pos_next; |
1909 | t->pos = t->pos_next; |
|
|
1910 | |
1856 | if (t->pos >= t->end) |
1911 | if (t->pos >= t->end) |
1857 | { |
1912 | { |
1858 | if (pop_tile(mr)) |
1913 | if (pop_tile(mr)) |
|
|
1914 | { |
1859 | continue; |
1915 | continue; |
|
|
1916 | } |
|
|
1917 | |
|
|
1918 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1919 | dbg(0,"+#+:leave5\n"); |
|
|
1920 | #endif |
|
|
1921 | |
1860 | return NULL; |
1922 | return NULL; |
1861 | } |
1923 | } |
|
|
1924 | |
1862 | setup_pos(mr); |
1925 | setup_pos(mr); |
1863 | binfile_coord_rewind(mr); |
1926 | binfile_coord_rewind(mr); |
1864 | binfile_attr_rewind(mr); |
1927 | binfile_attr_rewind(mr); |
1865 | if ((mr->item.type == type_submap) && (!mr->country_id)) |
1928 | if ((mr->item.type == type_submap) && (!mr->country_id)) |
1866 | { |
1929 | { |
1867 | if (map_parse_submap(mr, 1)) |
1930 | if (map_parse_submap(mr, 1)) |
|
|
1931 | { |
|
|
1932 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1933 | dbg(0,"+#+:leave4\n"); |
|
|
1934 | #endif |
1868 | return &busy_item; |
1935 | return &busy_item; |
|
|
1936 | } |
1869 | continue; |
1937 | continue; |
1870 | } |
1938 | } |
1871 | if (t->mode != 2) |
1939 | if (t->mode != 2) |
1872 | { |
1940 | { |
1873 | mr->item.id_hi = t->zipfile_num; |
1941 | mr->item.id_hi = t->zipfile_num; |
… | |
… | |
1881 | { |
1949 | { |
1882 | map_parse_country_binfile(mr); |
1950 | map_parse_country_binfile(mr); |
1883 | } |
1951 | } |
1884 | if (item_is_town(mr->item)) |
1952 | if (item_is_town(mr->item)) |
1885 | { |
1953 | { |
|
|
1954 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1955 | dbg(0,"+#+:leave3\n"); |
|
|
1956 | #endif |
1886 | return &mr->item; |
1957 | return &mr->item; |
1887 | } |
1958 | } |
1888 | else |
1959 | else |
1889 | { |
1960 | { |
1890 | continue; |
1961 | continue; |
1891 | } |
1962 | } |
1892 | } |
1963 | } |
|
|
1964 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1965 | dbg(0,"+#+:leave 2\n"); |
|
|
1966 | #endif |
1893 | return &mr->item; |
1967 | return &mr->item; |
1894 | } |
1968 | } |
|
|
1969 | |
|
|
1970 | #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT |
|
|
1971 | dbg(0,"+#+:leave\n"); |
|
|
1972 | #endif |
1895 | } |
1973 | } |
1896 | |
1974 | |
1897 | static struct item * |
1975 | static struct item * |
1898 | map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo) |
1976 | map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo) |
1899 | { |
1977 | { |
… | |
… | |
2083 | break; |
2161 | break; |
2084 | case attr_town_name: |
2162 | case attr_town_name: |
2085 | case attr_town_or_district_name: |
2163 | case attr_town_or_district_name: |
2086 | map_rec = map_rect_new_binfile(map, NULL); |
2164 | map_rec = map_rect_new_binfile(map, NULL); |
2087 | if (!map_rec) |
2165 | if (!map_rec) |
|
|
2166 | { |
2088 | break; |
2167 | break; |
|
|
2168 | } |
2089 | map_rec->country_id = item->id_lo; |
2169 | map_rec->country_id = item->id_lo; |
2090 | msp->mr = map_rec; |
2170 | msp->mr = map_rec; |
2091 | willsearch = 1; |
2171 | willsearch = 1; |
2092 | break; |
2172 | break; |
2093 | case attr_town_postal: |
2173 | case attr_town_postal: |
… | |
… | |
2103 | { |
2183 | { |
2104 | struct coord c; |
2184 | struct coord c; |
2105 | |
2185 | |
2106 | if (binmap_search_by_index(map, town, &msp->mr)) |
2186 | if (binmap_search_by_index(map, town, &msp->mr)) |
2107 | { |
2187 | { |
2108 | dbg(0, "search:mode=1\n"); |
2188 | //dbg(0, "search:mode=1\n"); |
2109 | msp->mode = 1; |
2189 | msp->mode = 1; |
2110 | } |
2190 | } |
2111 | else |
2191 | else |
2112 | { |
2192 | { |
2113 | if (item_coord_get(town, &c, 1)) |
2193 | if (item_coord_get(town, &c, 1)) |
2114 | { |
2194 | { |
2115 | if ((msp->mr = binmap_search_street_by_place(map, town, &c, &msp->ms))) |
2195 | if ((msp->mr = binmap_search_street_by_place(map, town, &c, &msp->ms))) |
2116 | { |
2196 | { |
2117 | dbg(0, "search:mode=2\n"); |
2197 | //dbg(0, "search:mode=2\n"); |
2118 | msp->mode = 2; |
2198 | msp->mode = 2; |
2119 | } |
2199 | } |
2120 | else |
2200 | else |
2121 | { |
2201 | { |
2122 | msp->mr = binmap_search_street_by_estimate(map, town, &c, &msp->ms); |
2202 | msp->mr = binmap_search_street_by_estimate(map, town, &c, &msp->ms); |
2123 | dbg(0, "search:mode=3\n"); |
2203 | //dbg(0, "search:mode=3\n"); |
2124 | msp->mode = 3; |
2204 | msp->mode = 3; |
2125 | } |
2205 | } |
2126 | } |
2206 | } |
2127 | } |
2207 | } |
2128 | map_rect_destroy_binfile(map_rec); |
2208 | map_rect_destroy_binfile(map_rec); |
… | |
… | |
2251 | |
2331 | |
2252 | static int duplicate(struct map_search_priv *msp, struct item *item, enum attr_type attr_type) |
2332 | static int duplicate(struct map_search_priv *msp, struct item *item, enum attr_type attr_type) |
2253 | { |
2333 | { |
2254 | struct attr attr; |
2334 | struct attr attr; |
2255 | if (!msp->search_results) |
2335 | if (!msp->search_results) |
2256 | msp->search_results = g_hash_table_new_full(duplicate_hash, duplicate_equal, g_free, NULL); |
2336 | msp->search_results = g_hash_table_new_full(duplicate_hash, duplicate_equal, g_free_func, NULL); |
2257 | binfile_attr_rewind(item->priv_data); |
2337 | binfile_attr_rewind(item->priv_data); |
2258 | if (!item_attr_get(item, attr_type, &attr)) |
2338 | if (!item_attr_get(item, attr_type, &attr)) |
2259 | return 1; |
2339 | return 1; |
2260 | { |
2340 | { |
2261 | int len = sizeof(struct coord) + strlen(attr.u.str) + 1; |
2341 | int len = sizeof(struct coord) + strlen(attr.u.str) + 1; |
… | |
… | |
2864 | { |
2944 | { |
2865 | while ((item = map_rect_get_item_binfile(mr)) == &busy_item) |
2945 | while ((item = map_rect_get_item_binfile(mr)) == &busy_item) |
2866 | { |
2946 | { |
2867 | ; |
2947 | ; |
2868 | } |
2948 | } |
|
|
2949 | |
2869 | if (item && item->type == type_map_information) |
2950 | if (item && item->type == type_map_information) |
2870 | { |
2951 | { |
2871 | if (binfile_attr_get(item->priv_data, attr_version, &attr)) |
2952 | if (binfile_attr_get(item->priv_data, attr_version, &attr)) |
2872 | { |
2953 | { |
2873 | m->map_version = attr.u.num; |
2954 | m->map_version = attr.u.num; |
… | |
… | |
2878 | m->map_release = g_strdup(attr.u.str); |
2959 | m->map_release = g_strdup(attr.u.str); |
2879 | dbg(0, "map_release=%s\n", m->map_release); |
2960 | dbg(0, "map_release=%s\n", m->map_release); |
2880 | } |
2961 | } |
2881 | if (m->url && binfile_attr_get(item->priv_data, attr_url, &attr)) |
2962 | if (m->url && binfile_attr_get(item->priv_data, attr_url, &attr)) |
2882 | { |
2963 | { |
2883 | dbg(0, "url config %s map %s\n", m->url, attr.u.str); |
2964 | //dbg(0, "url config %s map %s\n", m->url, attr.u.str); |
2884 | if (strcmp(m->url, attr.u.str)) |
2965 | if (strcmp(m->url, attr.u.str)) |
2885 | { |
2966 | { |
2886 | m->update_available = 1; |
2967 | m->update_available = 1; |
2887 | } |
2968 | } |
2888 | g_free(m->url); |
2969 | g_free(m->url); |
2889 | m->url = g_strdup(attr.u.str); |
2970 | m->url = g_strdup(attr.u.str); |
2890 | } |
2971 | } |
2891 | } |
2972 | } |
|
|
2973 | |
2892 | map_rect_destroy_binfile(mr); |
2974 | map_rect_destroy_binfile(mr); |
|
|
2975 | |
2893 | if (m->map_version >= 16) |
2976 | if (m->map_version >= 16) |
2894 | { |
2977 | { |
2895 | dbg(0, "Warning: This map is incompatible with your versionof ZANavi. Please update ZANavi.\n"); |
2978 | dbg(0, "Warning: This map is incompatible with your versionof ZANavi. Please update ZANavi.\n"); |
2896 | return 0; |
2979 | return 0; |
2897 | } |
2980 | } |
… | |
… | |
2950 | struct file_wordexp *wexp; |
3033 | struct file_wordexp *wexp; |
2951 | char **wexp_data; |
3034 | char **wexp_data; |
2952 | if (!data) |
3035 | if (!data) |
2953 | return NULL; |
3036 | return NULL; |
2954 | |
3037 | |
2955 | wexp = file_wordexp_new(data->u.str); |
3038 | // wexp = file_wordexp_new(data->u.str); |
2956 | wexp_data = file_wordexp_get_array(wexp); |
3039 | // wexp_data = file_wordexp_get_array(wexp); |
2957 | // dbg(0, "map_new_binfile %s\n", data->u.str); |
3040 | // dbg(0, "map_new_binfile %s\n", data->u.str); |
2958 | *meth = map_methods_binfile; |
3041 | *meth = map_methods_binfile; |
2959 | |
3042 | |
2960 | m=g_new0(struct map_priv, 1); |
3043 | m=g_new0(struct map_priv, 1); |
2961 | m->cbl = cbl; |
3044 | m->cbl = cbl; |
2962 | m->id = ++map_id; |
3045 | m->id = ++map_id; |
2963 | m->filename = g_strdup(wexp_data[0]); |
3046 | m->filename = g_strdup(data->u.str); |
2964 | file_wordexp_destroy(wexp); |
3047 | // file_wordexp_destroy(wexp); |
2965 | check_version = attr_search(attrs, NULL, attr_check_version); |
3048 | check_version = attr_search(attrs, NULL, attr_check_version); |
2966 | if (check_version) |
3049 | if (check_version) |
2967 | m->check_version = check_version->u.num; |
3050 | m->check_version = check_version->u.num; |
2968 | map_pass = attr_search(attrs, NULL, attr_map_pass); |
3051 | map_pass = attr_search(attrs, NULL, attr_map_pass); |
2969 | if (map_pass) |
3052 | if (map_pass) |