… | |
… | |
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 | { |
… | |
… | |
2253 | |
2331 | |
2254 | 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) |
2255 | { |
2333 | { |
2256 | struct attr attr; |
2334 | struct attr attr; |
2257 | if (!msp->search_results) |
2335 | if (!msp->search_results) |
2258 | 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); |
2259 | binfile_attr_rewind(item->priv_data); |
2337 | binfile_attr_rewind(item->priv_data); |
2260 | if (!item_attr_get(item, attr_type, &attr)) |
2338 | if (!item_attr_get(item, attr_type, &attr)) |
2261 | return 1; |
2339 | return 1; |
2262 | { |
2340 | { |
2263 | int len = sizeof(struct coord) + strlen(attr.u.str) + 1; |
2341 | int len = sizeof(struct coord) + strlen(attr.u.str) + 1; |
… | |
… | |
2955 | struct file_wordexp *wexp; |
3033 | struct file_wordexp *wexp; |
2956 | char **wexp_data; |
3034 | char **wexp_data; |
2957 | if (!data) |
3035 | if (!data) |
2958 | return NULL; |
3036 | return NULL; |
2959 | |
3037 | |
2960 | wexp = file_wordexp_new(data->u.str); |
3038 | // wexp = file_wordexp_new(data->u.str); |
2961 | wexp_data = file_wordexp_get_array(wexp); |
3039 | // wexp_data = file_wordexp_get_array(wexp); |
2962 | // dbg(0, "map_new_binfile %s\n", data->u.str); |
3040 | // dbg(0, "map_new_binfile %s\n", data->u.str); |
2963 | *meth = map_methods_binfile; |
3041 | *meth = map_methods_binfile; |
2964 | |
3042 | |
2965 | m=g_new0(struct map_priv, 1); |
3043 | m=g_new0(struct map_priv, 1); |
2966 | m->cbl = cbl; |
3044 | m->cbl = cbl; |
2967 | m->id = ++map_id; |
3045 | m->id = ++map_id; |
2968 | m->filename = g_strdup(wexp_data[0]); |
3046 | m->filename = g_strdup(data->u.str); |
2969 | file_wordexp_destroy(wexp); |
3047 | // file_wordexp_destroy(wexp); |
2970 | check_version = attr_search(attrs, NULL, attr_check_version); |
3048 | check_version = attr_search(attrs, NULL, attr_check_version); |
2971 | if (check_version) |
3049 | if (check_version) |
2972 | m->check_version = check_version->u.num; |
3050 | m->check_version = check_version->u.num; |
2973 | map_pass = attr_search(attrs, NULL, attr_map_pass); |
3051 | map_pass = attr_search(attrs, NULL, attr_map_pass); |
2974 | if (map_pass) |
3052 | if (map_pass) |