… | |
… | |
36 | #include "zipfile.h" |
36 | #include "zipfile.h" |
37 | #include "linguistics.h" |
37 | #include "linguistics.h" |
38 | #include "endianess.h" |
38 | #include "endianess.h" |
39 | #include "callback.h" |
39 | #include "callback.h" |
40 | #include "types.h" |
40 | #include "types.h" |
|
|
41 | #include "navit.h" |
41 | |
42 | |
42 | static int map_id; |
43 | static int map_id; |
43 | |
44 | |
44 | struct tile { |
45 | struct tile { |
45 | int *start; |
46 | int *start; |
… | |
… | |
1755 | |
1756 | |
1756 | static struct item * |
1757 | static struct item * |
1757 | map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo) |
1758 | map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo) |
1758 | { |
1759 | { |
1759 | struct tile *t; |
1760 | struct tile *t; |
1760 | if (mr->m->eoc) { |
1761 | if (mr->m->eoc) |
|
|
1762 | { |
1761 | while (pop_tile(mr)); |
1763 | while (pop_tile(mr)); |
1762 | push_zipfile_tile(mr, id_hi, 0, 0, 0); |
1764 | push_zipfile_tile(mr, id_hi, 0, 0, 0); |
1763 | } |
1765 | } |
1764 | t=mr->t; |
1766 | t=mr->t; |
1765 | t->pos=t->start+id_lo; |
1767 | t->pos=t->start+id_lo; |
1766 | mr->item.id_hi=id_hi; |
1768 | mr->item.id_hi=id_hi; |
1767 | mr->item.id_lo=id_lo; |
1769 | mr->item.id_lo=id_lo; |
1768 | if (mr->m->changes) |
1770 | if (mr->m->changes) |
|
|
1771 | { |
1769 | push_modified_item(mr); |
1772 | push_modified_item(mr); |
|
|
1773 | } |
1770 | setup_pos(mr); |
1774 | setup_pos(mr); |
1771 | binfile_coord_rewind(mr); |
1775 | binfile_coord_rewind(mr); |
1772 | binfile_attr_rewind(mr); |
1776 | binfile_attr_rewind(mr); |
|
|
1777 | |
1773 | return &mr->item; |
1778 | return &mr->item; |
1774 | } |
1779 | } |
1775 | |
1780 | |
1776 | static int |
1781 | static int |
1777 | binmap_search_by_index(struct map_priv *map, struct item *item, struct map_rect_priv **ret) |
1782 | binmap_search_by_index(struct map_priv *map, struct item *item, struct map_rect_priv **ret) |
… | |
… | |
1913 | msp->partial = partial; |
1918 | msp->partial = partial; |
1914 | /* |
1919 | /* |
1915 | * NOTE: If you implement search for other attributes than attr_town_name and attr_street_name, |
1920 | * NOTE: If you implement search for other attributes than attr_town_name and attr_street_name, |
1916 | * please update this comment and the documentation for map_search_new() in map.c |
1921 | * please update this comment and the documentation for map_search_new() in map.c |
1917 | */ |
1922 | */ |
1918 | switch (search->type) { |
1923 | switch (search->type) |
|
|
1924 | { |
1919 | case attr_country_name: |
1925 | case attr_country_name: |
1920 | break; |
1926 | break; |
1921 | case attr_town_name: |
1927 | case attr_town_name: |
1922 | case attr_town_or_district_name: |
1928 | case attr_town_or_district_name: |
1923 | map_rec = map_rect_new_binfile(map, NULL); |
1929 | map_rec = map_rect_new_binfile(map, NULL); |
… | |
… | |
1934 | break; |
1940 | break; |
1935 | if (!map_priv_is(item->map, map)) |
1941 | if (!map_priv_is(item->map, map)) |
1936 | break; |
1942 | break; |
1937 | map_rec = map_rect_new_binfile(map, NULL); |
1943 | map_rec = map_rect_new_binfile(map, NULL); |
1938 | town = map_rect_get_item_byid_binfile(map_rec, item->id_hi, item->id_lo); |
1944 | town = map_rect_get_item_byid_binfile(map_rec, item->id_hi, item->id_lo); |
1939 | if (town) { |
1945 | if (town) |
|
|
1946 | { |
1940 | struct coord c; |
1947 | struct coord c; |
1941 | |
1948 | |
1942 | if (binmap_search_by_index(map, town, &msp->mr)) |
1949 | if (binmap_search_by_index(map, town, &msp->mr)) |
|
|
1950 | { |
1943 | msp->mode = 1; |
1951 | msp->mode = 1; |
|
|
1952 | } |
1944 | else { |
1953 | else |
|
|
1954 | { |
1945 | if (item_coord_get(town, &c, 1)) { |
1955 | if (item_coord_get(town, &c, 1)) |
|
|
1956 | { |
1946 | if ((msp->mr=binmap_search_street_by_place(map, town, &c, &msp->ms))) |
1957 | if ((msp->mr=binmap_search_street_by_place(map, town, &c, &msp->ms))) |
|
|
1958 | { |
1947 | msp->mode = 2; |
1959 | msp->mode = 2; |
|
|
1960 | } |
1948 | else { |
1961 | else |
|
|
1962 | { |
1949 | msp->mr=binmap_search_street_by_estimate(map, town, &c, &msp->ms); |
1963 | msp->mr=binmap_search_street_by_estimate(map, town, &c, &msp->ms); |
1950 | msp->mode = 3; |
1964 | msp->mode = 3; |
1951 | } |
1965 | } |
1952 | } |
1966 | } |
1953 | } |
1967 | } |
1954 | map_rect_destroy_binfile(map_rec); |
1968 | map_rect_destroy_binfile(map_rec); |
1955 | if (!msp->mr) |
1969 | if (!msp->mr) |
|
|
1970 | { |
1956 | break; |
1971 | break; |
|
|
1972 | } |
1957 | willsearch=1; |
1973 | willsearch=1; |
1958 | break; |
1974 | break; |
1959 | } |
1975 | } |
1960 | map_rect_destroy_binfile(map_rec); |
1976 | map_rect_destroy_binfile(map_rec); |
1961 | break; |
1977 | break; |
… | |
… | |
1966 | if (!map_priv_is(item->map, map)) |
1982 | if (!map_priv_is(item->map, map)) |
1967 | break; |
1983 | break; |
1968 | msp->map=map; |
1984 | msp->map=map; |
1969 | msp->mr_item = map_rect_new_binfile(map, NULL); |
1985 | msp->mr_item = map_rect_new_binfile(map, NULL); |
1970 | msp->item = map_rect_get_item_byid_binfile(msp->mr_item, item->id_hi, item->id_lo); |
1986 | msp->item = map_rect_get_item_byid_binfile(msp->mr_item, item->id_hi, item->id_lo); |
1971 | if (binmap_search_by_index(map, msp->item, &msp->mr) != 3) { |
1987 | if (binmap_search_by_index(map, msp->item, &msp->mr) != 3) |
|
|
1988 | { |
1972 | struct coord c; |
1989 | struct coord c; |
1973 | if (item_coord_get(msp->item, &c, 1)) |
1990 | if (item_coord_get(msp->item, &c, 1)) |
1974 | { |
1991 | { |
1975 | msp->mr=binmap_search_housenumber_by_estimate(map, &c, &msp->ms); |
1992 | msp->mr=binmap_search_housenumber_by_estimate(map, &c, &msp->ms); |
1976 | msp->mode = 2; |
1993 | msp->mode = 2; |
… | |
… | |
1985 | willsearch=1; |
2002 | willsearch=1; |
1986 | break; |
2003 | break; |
1987 | default: |
2004 | default: |
1988 | break; |
2005 | break; |
1989 | } |
2006 | } |
|
|
2007 | |
1990 | if(!willsearch) { |
2008 | if (!willsearch) |
|
|
2009 | { |
1991 | g_free(msp); |
2010 | g_free(msp); |
1992 | msp=NULL; |
2011 | msp=NULL; |
1993 | } else { |
2012 | } |
|
|
2013 | else |
|
|
2014 | { |
1994 | msp->str=linguistics_casefold(search->u.str); |
2015 | msp->str=linguistics_casefold(search->u.str); |
1995 | } |
2016 | } |
1996 | return msp; |
2017 | return msp; |
1997 | } |
2018 | } |
1998 | |
2019 | |
1999 | static int |
2020 | static int |
2000 | ascii_cmp(char *name, char *match, int partial) |
2021 | ascii_cmp(char *name, char *match, int partial) |
2001 | { |
2022 | { |
|
|
2023 | int ret=1; |
|
|
2024 | |
|
|
2025 | if (name==NULL) |
|
|
2026 | { |
|
|
2027 | return ret; |
|
|
2028 | } |
|
|
2029 | |
|
|
2030 | if (match==NULL) |
|
|
2031 | { |
|
|
2032 | return ret; |
|
|
2033 | } |
|
|
2034 | |
|
|
2035 | char *s2=linguistics_casefold(match); // user entered search string |
2002 | char *s=linguistics_casefold(name); |
2036 | char *s1=linguistics_casefold(name); // string from mapfile |
|
|
2037 | char *s1_1=linguistics_expand_special(s1, 1); |
|
|
2038 | char *s2_1=linguistics_expand_special(s2, 1); |
|
|
2039 | |
|
|
2040 | if (s1_1) |
|
|
2041 | { |
|
|
2042 | if (s2_1) |
|
|
2043 | { |
|
|
2044 | ret=linguistics_compare(s1_1,s2_1,partial); |
|
|
2045 | } |
|
|
2046 | else |
|
|
2047 | { |
|
|
2048 | ret=linguistics_compare(s1_1,s2,partial); |
|
|
2049 | } |
|
|
2050 | } |
|
|
2051 | else |
|
|
2052 | { |
|
|
2053 | if (s2_1) |
|
|
2054 | { |
|
|
2055 | ret=linguistics_compare(s1,s2_1,partial); |
|
|
2056 | } |
|
|
2057 | else |
|
|
2058 | { |
2003 | int ret=linguistics_compare(s,match,partial); |
2059 | ret=linguistics_compare(s1,s2,partial); |
|
|
2060 | } |
|
|
2061 | } |
|
|
2062 | |
|
|
2063 | if (s1_1) |
|
|
2064 | g_free(s1_1); |
|
|
2065 | if (s2_1) |
|
|
2066 | g_free(s2_1); |
|
|
2067 | if (s1) |
2004 | g_free(s); |
2068 | g_free(s1); |
|
|
2069 | if (s2) |
|
|
2070 | g_free(s2); |
2005 | return ret; |
2071 | return ret; |
2006 | } |
2072 | } |
2007 | |
2073 | |
2008 | struct duplicate |
2074 | struct duplicate |
2009 | { |
2075 | { |
… | |
… | |
2060 | binmap_search_get_item(struct map_search_priv *map_search) |
2126 | binmap_search_get_item(struct map_search_priv *map_search) |
2061 | { |
2127 | { |
2062 | struct item* it; |
2128 | struct item* it; |
2063 | struct attr at; |
2129 | struct attr at; |
2064 | |
2130 | |
2065 | for (;;) { |
2131 | for (;;) |
|
|
2132 | { |
2066 | while ((it = map_rect_get_item_binfile(map_search->mr))) { |
2133 | while ((it = map_rect_get_item_binfile(map_search->mr))) |
|
|
2134 | { |
2067 | switch (map_search->search->type) { |
2135 | switch (map_search->search->type) |
|
|
2136 | { |
2068 | case attr_town_name: |
2137 | case attr_town_name: |
2069 | case attr_district_name: |
2138 | case attr_district_name: |
2070 | case attr_town_or_district_name: |
2139 | case attr_town_or_district_name: |
|
|
2140 | |
|
|
2141 | #if 0 |
2071 | if (map_search->mr->tile_depth > 1 && item_is_town(*it) && !item_is_district(*it) && map_search->search->type != attr_district_name) { |
2142 | if (map_search->mr->tile_depth > 1 && item_is_town(*it) && !item_is_district(*it) && map_search->search->type != attr_district_name) { |
2072 | if (binfile_attr_get(it->priv_data, attr_town_name_match, &at) || binfile_attr_get(it->priv_data, attr_town_name, &at)) { |
2143 | if (binfile_attr_get(it->priv_data, attr_town_name_match, &at) || binfile_attr_get(it->priv_data, attr_town_name, &at)) { |
2073 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_town_name)) |
2144 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_town_name)) |
2074 | return it; |
2145 | return it; |
2075 | } |
2146 | } |
2076 | } |
2147 | } |
|
|
2148 | #endif |
|
|
2149 | |
|
|
2150 | #if 1 |
|
|
2151 | if (map_search->mr->tile_depth > 1 && item_is_town(*it) && !item_is_district(*it) && map_search->search->type != attr_district_name) |
|
|
2152 | { |
|
|
2153 | if (binfile_attr_get(it->priv_data, attr_town_name, &at)) |
|
|
2154 | { |
|
|
2155 | //dbg(0,"22town n:%s\n",at.u.str); |
|
|
2156 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) |
|
|
2157 | // && !duplicate(map_search, it, attr_town_name) |
|
|
2158 | ) |
|
|
2159 | { |
|
|
2160 | //dbg(0,"town n:%s\n",at.u.str); |
|
|
2161 | return it; |
|
|
2162 | } |
|
|
2163 | } |
|
|
2164 | |
|
|
2165 | if (binfile_attr_get(it->priv_data, attr_town_name_match, &at)) |
|
|
2166 | { |
|
|
2167 | //dbg(0,"11town M:%s\n",at.u.str); |
|
|
2168 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) |
|
|
2169 | // && !duplicate(map_search, it, attr_town_name) |
|
|
2170 | ) |
|
|
2171 | { |
|
|
2172 | //dbg(0,"town M:%s\n",at.u.str); |
|
|
2173 | return it; |
|
|
2174 | } |
|
|
2175 | } |
|
|
2176 | } |
|
|
2177 | #endif |
|
|
2178 | |
2077 | if (map_search->mr->tile_depth > 1 && item_is_district(*it) && map_search->search->type != attr_town_name) { |
2179 | if (map_search->mr->tile_depth > 1 && item_is_district(*it) && map_search->search->type != attr_town_name) { |
2078 | if (binfile_attr_get(it->priv_data, attr_district_name_match, &at) || binfile_attr_get(it->priv_data, attr_district_name, &at)) { |
2180 | if (binfile_attr_get(it->priv_data, attr_district_name_match, &at) || binfile_attr_get(it->priv_data, attr_district_name, &at)) { |
2079 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_town_name)) |
2181 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_town_name)) |
2080 | return it; |
2182 | return it; |
2081 | } |
2183 | } |
2082 | } |
2184 | } |
2083 | break; |
2185 | break; |
2084 | case attr_street_name: |
2186 | case attr_street_name: |
2085 | if (map_search->mode == 1) { |
2187 | if (map_search->mode == 1) |
|
|
2188 | { |
2086 | if (binfile_attr_get(it->priv_data, attr_street_name_match, &at) || binfile_attr_get(it->priv_data, attr_street_name, &at)) { |
2189 | //if (binfile_attr_get(it->priv_data, attr_street_name_match, &at) || binfile_attr_get(it->priv_data, attr_street_name, &at)) { |
2087 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_street_name)) { |
2190 | // if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_street_name)) { |
|
|
2191 | // return it; |
|
|
2192 | // } |
|
|
2193 | //} |
|
|
2194 | |
|
|
2195 | if (binfile_attr_get(it->priv_data, attr_street_name, &at)) |
|
|
2196 | { |
|
|
2197 | //dbg(0,"str AA:%s\n", at.u.str); |
|
|
2198 | |
|
|
2199 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial)) |
|
|
2200 | { |
|
|
2201 | if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_street_name))) |
|
|
2202 | { |
2088 | return it; |
2203 | return it; |
|
|
2204 | } |
|
|
2205 | else |
|
|
2206 | { |
|
|
2207 | //dbg(0,"dup street 1:%s\n",at.u.str); |
|
|
2208 | } |
2089 | } |
2209 | } |
2090 | } |
2210 | } |
|
|
2211 | |
|
|
2212 | if (binfile_attr_get(it->priv_data, attr_street_name_match, &at)) |
|
|
2213 | { |
|
|
2214 | //dbg(0,"str BB:%s\n", at.u.str); |
|
|
2215 | |
|
|
2216 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial)) |
|
|
2217 | { |
|
|
2218 | if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_street_name))) |
|
|
2219 | { |
|
|
2220 | return it; |
|
|
2221 | } |
|
|
2222 | else |
|
|
2223 | { |
|
|
2224 | //dbg(0,"dup street 2:%s\n",at.u.str); |
|
|
2225 | } |
|
|
2226 | } |
|
|
2227 | } |
|
|
2228 | |
2091 | continue; |
2229 | continue; |
2092 | } |
2230 | } |
|
|
2231 | |
2093 | if (item_is_street(*it)) { |
2232 | if (item_is_street(*it)) |
|
|
2233 | { |
2094 | struct attr at; |
2234 | struct attr at; |
2095 | if (map_selection_contains_item_rect(map_search->mr->sel, it) && binfile_attr_get(it->priv_data, attr_label, &at)) { |
2235 | if (map_selection_contains_item_rect(map_search->mr->sel, it)) |
|
|
2236 | { |
|
|
2237 | if (binfile_attr_get(it->priv_data, attr_label, &at)) |
|
|
2238 | { |
2096 | int match=0; |
2239 | int match=0; |
2097 | char *str=g_strdup(at.u.str); |
2240 | char *str=g_strdup(at.u.str); |
2098 | char *word=str; |
2241 | |
2099 | do { |
2242 | //dbg(0,"search=%s str is:%s\n",map_search->str, at.u.str); |
|
|
2243 | |
2100 | if (!ascii_cmp(word, map_search->str, map_search->partial)) { |
2244 | if (!ascii_cmp(str, map_search->str, map_search->partial)) |
|
|
2245 | { |
2101 | match=1; |
2246 | match=1; |
2102 | break; |
|
|
2103 | } |
2247 | } |
|
|
2248 | |
|
|
2249 | #if 0 |
|
|
2250 | char *word=str; |
|
|
2251 | int first=1; |
|
|
2252 | do |
|
|
2253 | { |
|
|
2254 | if (!ascii_cmp(word, map_search->str, map_search->partial)) |
|
|
2255 | { |
|
|
2256 | match=1; |
|
|
2257 | break; |
|
|
2258 | } |
|
|
2259 | if (first==1) |
|
|
2260 | { |
|
|
2261 | first=0; |
2104 | word=linguistics_next_word(word); |
2262 | word=linguistics_next_word(word); |
|
|
2263 | } |
|
|
2264 | else |
|
|
2265 | { |
|
|
2266 | word=linguistics_next_word(NULL); |
|
|
2267 | } |
2105 | } while (word); |
2268 | } while (word); |
|
|
2269 | #endif |
2106 | g_free(str); |
2270 | g_free(str); |
2107 | if (match && !duplicate(map_search, it, attr_label)) { |
2271 | |
|
|
2272 | if (match) |
|
|
2273 | { |
|
|
2274 | if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_label))) |
|
|
2275 | { |
2108 | item_coord_rewind(it); |
2276 | item_coord_rewind(it); |
2109 | return it; |
2277 | return it; |
|
|
2278 | } |
|
|
2279 | } |
2110 | } |
2280 | } |
|
|
2281 | //else |
|
|
2282 | //{ |
|
|
2283 | // if (binfile_attr_get(it->priv_data, attr_street_name, &at)) |
|
|
2284 | // { |
|
|
2285 | // dbg(0,"---str X*X:%s\n", at.u.str); |
|
|
2286 | // } |
|
|
2287 | //} |
2111 | } |
2288 | } |
2112 | } |
2289 | } |
2113 | break; |
2290 | break; |
2114 | case attr_house_number: |
2291 | case attr_house_number: |
2115 | //if (it->type == type_house_number) |
2292 | //if (it->type == type_house_number) |
… | |
… | |
2124 | // match housenumber to our string |
2301 | // match housenumber to our string |
2125 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial)) |
2302 | if (!ascii_cmp(at.u.str, map_search->str, map_search->partial)) |
2126 | { |
2303 | { |
2127 | //binfile_attr_get(it->priv_data, attr_street_name, &at); |
2304 | //binfile_attr_get(it->priv_data, attr_street_name, &at); |
2128 | //dbg(0,"hnnn B1 street_name=%s",at.u.str); |
2305 | //dbg(0,"hnnn B1 street_name=%s",at.u.str); |
|
|
2306 | |
2129 | if (!duplicate(map_search, it, attr_house_number)) |
2307 | if (!duplicate(map_search, it, attr_house_number)) |
2130 | { |
2308 | { |
2131 | binfile_attr_rewind(it->priv_data); |
2309 | binfile_attr_rewind(it->priv_data); |
2132 | return it; |
2310 | return it; |
2133 | } |
2311 | } |
2134 | } |
2312 | } |
|
|
2313 | } |
2135 | } else |
2314 | else |
|
|
2315 | { |
2136 | return it; |
2316 | return it; |
|
|
2317 | } |
2137 | } |
2318 | } |
2138 | continue; |
2319 | continue; |
2139 | default: |
2320 | default: |
2140 | return NULL; |
2321 | return NULL; |
2141 | } |
2322 | } |