/[zanavi_public1]/navit/navit/map/binfile/binfile.c
ZANavi

Diff of /navit/navit/map/binfile/binfile.c

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

Revision 28 Revision 31
555 return g_strdup_printf("%s/%s", dir, filename); 555 return g_strdup_printf("%s/%s", dir, filename);
556} 556}
557 557
558static int binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) 558static 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
649struct binfile_hash_entry 681struct 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
1834static struct item * 1866static struct item *
1835map_rect_get_item_binfile(struct map_rect_priv *mr) 1867map_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
1897static struct item * 1975static struct item *
1898map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo) 1976map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo)
1899{ 1977{
2105 { 2183 {
2106 struct coord c; 2184 struct coord c;
2107 2185
2108 if (binmap_search_by_index(map, town, &msp->mr)) 2186 if (binmap_search_by_index(map, town, &msp->mr))
2109 { 2187 {
2110 dbg(0, "search:mode=1\n"); 2188 //dbg(0, "search:mode=1\n");
2111 msp->mode = 1; 2189 msp->mode = 1;
2112 } 2190 }
2113 else 2191 else
2114 { 2192 {
2115 if (item_coord_get(town, &c, 1)) 2193 if (item_coord_get(town, &c, 1))
2116 { 2194 {
2117 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)))
2118 { 2196 {
2119 dbg(0, "search:mode=2\n"); 2197 //dbg(0, "search:mode=2\n");
2120 msp->mode = 2; 2198 msp->mode = 2;
2121 } 2199 }
2122 else 2200 else
2123 { 2201 {
2124 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);
2125 dbg(0, "search:mode=3\n"); 2203 //dbg(0, "search:mode=3\n");
2126 msp->mode = 3; 2204 msp->mode = 3;
2127 } 2205 }
2128 } 2206 }
2129 } 2207 }
2130 map_rect_destroy_binfile(map_rec); 2208 map_rect_destroy_binfile(map_rec);
2253 2331
2254static int duplicate(struct map_search_priv *msp, struct item *item, enum attr_type attr_type) 2332static 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;
2866 { 2944 {
2867 while ((item = map_rect_get_item_binfile(mr)) == &busy_item) 2945 while ((item = map_rect_get_item_binfile(mr)) == &busy_item)
2868 { 2946 {
2869 ; 2947 ;
2870 } 2948 }
2949
2871 if (item && item->type == type_map_information) 2950 if (item && item->type == type_map_information)
2872 { 2951 {
2873 if (binfile_attr_get(item->priv_data, attr_version, &attr)) 2952 if (binfile_attr_get(item->priv_data, attr_version, &attr))
2874 { 2953 {
2875 m->map_version = attr.u.num; 2954 m->map_version = attr.u.num;
2880 m->map_release = g_strdup(attr.u.str); 2959 m->map_release = g_strdup(attr.u.str);
2881 dbg(0, "map_release=%s\n", m->map_release); 2960 dbg(0, "map_release=%s\n", m->map_release);
2882 } 2961 }
2883 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))
2884 { 2963 {
2885 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);
2886 if (strcmp(m->url, attr.u.str)) 2965 if (strcmp(m->url, attr.u.str))
2887 { 2966 {
2888 m->update_available = 1; 2967 m->update_available = 1;
2889 } 2968 }
2890 g_free(m->url); 2969 g_free(m->url);
2891 m->url = g_strdup(attr.u.str); 2970 m->url = g_strdup(attr.u.str);
2892 } 2971 }
2893 } 2972 }
2973
2894 map_rect_destroy_binfile(mr); 2974 map_rect_destroy_binfile(mr);
2975
2895 if (m->map_version >= 16) 2976 if (m->map_version >= 16)
2896 { 2977 {
2897 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");
2898 return 0; 2979 return 0;
2899 } 2980 }
2952 struct file_wordexp *wexp; 3033 struct file_wordexp *wexp;
2953 char **wexp_data; 3034 char **wexp_data;
2954 if (!data) 3035 if (!data)
2955 return NULL; 3036 return NULL;
2956 3037
2957 wexp = file_wordexp_new(data->u.str); 3038 // wexp = file_wordexp_new(data->u.str);
2958 wexp_data = file_wordexp_get_array(wexp); 3039 // wexp_data = file_wordexp_get_array(wexp);
2959 // dbg(0, "map_new_binfile %s\n", data->u.str); 3040 // dbg(0, "map_new_binfile %s\n", data->u.str);
2960 *meth = map_methods_binfile; 3041 *meth = map_methods_binfile;
2961 3042
2962 m=g_new0(struct map_priv, 1); 3043 m=g_new0(struct map_priv, 1);
2963 m->cbl = cbl; 3044 m->cbl = cbl;
2964 m->id = ++map_id; 3045 m->id = ++map_id;
2965 m->filename = g_strdup(wexp_data[0]); 3046 m->filename = g_strdup(data->u.str);
2966 file_wordexp_destroy(wexp); 3047 // file_wordexp_destroy(wexp);
2967 check_version = attr_search(attrs, NULL, attr_check_version); 3048 check_version = attr_search(attrs, NULL, attr_check_version);
2968 if (check_version) 3049 if (check_version)
2969 m->check_version = check_version->u.num; 3050 m->check_version = check_version->u.num;
2970 map_pass = attr_search(attrs, NULL, attr_map_pass); 3051 map_pass = attr_search(attrs, NULL, attr_map_pass);
2971 if (map_pass) 3052 if (map_pass)

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

   
Visit the ZANavi Wiki