/[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 26 Revision 27
1/**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
1/** 20/**
2 * Navit, a modular navigation system. 21 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team 22 * Copyright (C) 2005-2008 Navit Team
4 * 23 *
5 * This program is free software; you can redistribute it and/or 24 * This program is free software; you can redistribute it and/or
37#endif 56#endif
38#include "layout.h" 57#include "layout.h"
39#include "map.h" 58#include "map.h"
40#include "linguistics.h" 59#include "linguistics.h"
41 60
42struct search_list_level { 61struct search_list_level
62{
43 struct mapset *ms; 63 struct mapset *ms;
44 struct search_list_common *parent; 64 struct search_list_common *parent;
45 struct attr *attr; 65 struct attr *attr;
46 int partial; 66 int partial;
47 int selected; 67 int selected;
48 struct mapset_search *search; 68 struct mapset_search *search;
49 GHashTable *hash; 69 GHashTable *hash;
50 GList *list,*curr,*last; 70 GList *list, *curr, *last;
51}; 71};
52 72
53struct interpolation { 73struct interpolation
74{
54 int side, mode, rev; 75 int side, mode, rev;
55 char *first, *last, *curr; 76 char *first, *last, *curr;
56}; 77};
57 78
58struct search_list { 79struct search_list
80{
59 struct mapset *ms; 81 struct mapset *ms;
60 struct item *item; 82 struct item *item;
61 int level; 83 int level;
62 struct search_list_level levels[4]; 84 struct search_list_level levels[4];
63 struct search_list_result result; 85 struct search_list_result result;
65 int last_result_valid; 87 int last_result_valid;
66 char *postal; 88 char *postal;
67 struct interpolation inter; 89 struct interpolation inter;
68}; 90};
69 91
70static guint
71search_item_hash_hash(gconstpointer key) 92static guint search_item_hash_hash(gconstpointer key)
72{ 93{
73 const struct item *itm=key; 94 const struct item *itm = key;
74 gconstpointer hashkey=(gconstpointer)GINT_TO_POINTER(itm->id_hi^itm->id_lo); 95 gconstpointer hashkey = (gconstpointer) GINT_TO_POINTER(itm->id_hi ^ itm->id_lo);
75 return g_direct_hash(hashkey); 96 return g_direct_hash(hashkey);
76} 97}
77 98
78static gboolean
79search_item_hash_equal(gconstpointer a, gconstpointer b) 99static gboolean search_item_hash_equal(gconstpointer a, gconstpointer b)
80{ 100{
81 const struct item *itm_a=a; 101 const struct item *itm_a = a;
82 const struct item *itm_b=b; 102 const struct item *itm_b = b;
83 if (item_is_equal_id(*itm_a, *itm_b)) 103 if (item_is_equal_id(*itm_a, *itm_b))
84 return TRUE; 104 return TRUE;
85 return FALSE; 105 return FALSE;
86} 106}
87 107
89search_list_new(struct mapset *ms) 109search_list_new(struct mapset *ms)
90{ 110{
91 struct search_list *ret; 111 struct search_list *ret;
92 112
93 ret=g_new0(struct search_list, 1); 113 ret=g_new0(struct search_list, 1);
94 ret->ms=ms; 114 ret->ms = ms;
95 115
96 return ret; 116 return ret;
97} 117}
98 118
99static void search_list_search_free(struct search_list *sl, int level); 119static void search_list_search_free(struct search_list *sl, int level);
100 120
101static int
102search_list_level(enum attr_type attr_type) 121static int search_list_level(enum attr_type attr_type)
103{ 122{
104 switch(attr_type) { 123 switch (attr_type)
124 {
105 case attr_country_all: 125 case attr_country_all:
106 case attr_country_id: 126 case attr_country_id:
107 case attr_country_iso2: 127 case attr_country_iso2:
108 case attr_country_iso3: 128 case attr_country_iso3:
109 case attr_country_car: 129 case attr_country_car:
110 case attr_country_name: 130 case attr_country_name:
111 return 0; 131 return 0;
112 case attr_town_postal: 132 case attr_town_postal:
113 return 1; 133 return 1;
114 case attr_town_name: 134 case attr_town_name:
115 case attr_district_name: 135 case attr_district_name:
116 case attr_town_or_district_name: 136 case attr_town_or_district_name:
117 return 1; 137 return 1;
118 case attr_street_name: 138 case attr_street_name:
119 return 2; 139 return 2;
120 case attr_house_number: 140 case attr_house_number:
121 return 3; 141 return 3;
122 case attr_postal: 142 case attr_postal:
123 return -1; 143 return -1;
124 default: 144 default:
125 dbg(0,"unknown search '%s'\n",attr_to_name(attr_type)); 145 dbg(0, "unknown search '%s'\n", attr_to_name(attr_type));
126 return -1; 146 return -1;
127 } 147 }
128} 148}
129 149
130static void
131interpolation_clear(struct interpolation *inter) 150static void interpolation_clear(struct interpolation *inter)
132{ 151{
133 inter->mode=inter->side=0; 152 inter->mode = inter->side = 0;
134 g_free(inter->first); 153 g_free(inter->first);
135 g_free(inter->last); 154 g_free(inter->last);
136 g_free(inter->curr); 155 g_free(inter->curr);
137 inter->first=inter->last=inter->curr=NULL; 156 inter->first = inter->last = inter->curr = NULL;
138} 157}
139 158
140void
141search_list_search(struct search_list *this_, struct attr *search_attr, int partial) 159void search_list_search(struct search_list *this_, struct attr *search_attr, int partial)
142{ 160{
143 struct search_list_level *le; 161 struct search_list_level *le;
144 int level=search_list_level(search_attr->type); 162 int level = search_list_level(search_attr->type);
145 this_->item=NULL; 163 this_->item = NULL;
146 interpolation_clear(&this_->inter); 164 interpolation_clear(&this_->inter);
147 //dbg(0,"## enter\n"); 165 //dbg(0,"## enter\n");
148 //dbg(0,"## level=%d\n", level); 166 //dbg(0,"## level=%d\n", level);
149 if (level != -1) 167 if (level != -1)
150 { 168 {
151 this_->result.id=0; 169 this_->result.id = 0;
152 this_->level=level; 170 this_->level = level;
153 le=&this_->levels[level]; 171 le = &this_->levels[level];
154 search_list_search_free(this_, level); 172 search_list_search_free(this_, level);
155 le->attr=attr_dup(search_attr); 173 le->attr = attr_dup(search_attr);
156 le->partial=partial; 174 le->partial = partial;
157 if (level > 0) 175 if (level > 0)
158 { 176 {
159 le=&this_->levels[level-1]; 177 le = &this_->levels[level - 1];
160 le->curr=le->list; 178 le->curr = le->list;
161 } 179 }
162 //dbg(0,"## le=%p partial=%d\n", le, partial); 180 //dbg(0,"## le=%p partial=%d\n", le, partial);
163 } 181 }
164 else if (search_attr->type == attr_postal) 182 else if (search_attr->type == attr_postal)
165 { 183 {
166 g_free(this_->postal); 184 g_free(this_->postal);
167 this_->postal=g_strdup(search_attr->u.str); 185 this_->postal = g_strdup(search_attr->u.str);
168 } 186 }
169 //dbg(0,"## return\n"); 187 //dbg(0,"## return\n");
170} 188}
171 189
172struct search_list_common * 190struct search_list_common *
173search_list_select(struct search_list *this_, enum attr_type attr_type, int id, int mode) 191search_list_select(struct search_list *this_, enum attr_type attr_type, int id, int mode)
174{ 192{
175 int level=search_list_level(attr_type); 193 int level = search_list_level(attr_type);
176 int num=0; 194 int num = 0;
177 struct search_list_level *le; 195 struct search_list_level *le;
178 struct search_list_common *slc; 196 struct search_list_common *slc;
179 GList *curr; 197 GList *curr;
180 le=&this_->levels[level]; 198 le = &this_->levels[level];
181 curr=le->list; 199 curr = le->list;
182 if (mode > 0 || !id) 200 if (mode > 0 || !id)
183 le->selected=mode; 201 le->selected = mode;
184 //dbg(0,"enter level=%d %d %d %p\n", level, id, mode, curr); 202 //dbg(0,"enter level=%d %d %d %p\n", level, id, mode, curr);
185 while (curr) { 203 while (curr)
204 {
186 num++; 205 num++;
187 if (! id || num == id) { 206 if (!id || num == id)
207 {
188 slc=curr->data; 208 slc = curr->data;
189 slc->selected=mode; 209 slc->selected = mode;
190 if (id) { 210 if (id)
211 {
191 le->last=curr; 212 le->last = curr;
192 //dbg(0,"found\n"); 213 //dbg(0,"found\n");
193 return slc; 214 return slc;
194 } 215 }
195 } 216 }
196 curr=g_list_next(curr); 217 curr = g_list_next(curr);
197 } 218 }
198 //dbg(0,"not found\n"); 219 //dbg(0,"not found\n");
199 return NULL; 220 return NULL;
200} 221}
201 222
202static void
203search_list_common_new(struct item *item, struct search_list_common *common) 223static void search_list_common_new(struct item *item, struct search_list_common *common)
204{ 224{
205 struct attr attr; 225 struct attr attr;
206 if (item_attr_get(item, attr_town_name, &attr)) 226 if (item_attr_get(item, attr_town_name, &attr))
207 common->town_name=map_convert_string(item->map, attr.u.str); 227 common->town_name = map_convert_string(item->map, attr.u.str);
208 else 228 else
209 common->town_name=NULL; 229 common->town_name = NULL;
210 if (item_attr_get(item, attr_county_name, &attr)) 230 if (item_attr_get(item, attr_county_name, &attr))
211 common->county_name=map_convert_string(item->map, attr.u.str); 231 common->county_name = map_convert_string(item->map, attr.u.str);
212 else 232 else
213 common->county_name=NULL; 233 common->county_name = NULL;
214 if (item_attr_get(item, attr_district_name, &attr)) 234 if (item_attr_get(item, attr_district_name, &attr))
215 common->district_name=map_convert_string(item->map, attr.u.str); 235 common->district_name = map_convert_string(item->map, attr.u.str);
216 else 236 else
217 common->district_name=NULL; 237 common->district_name = NULL;
218 if (item_attr_get(item, attr_postal, &attr)) 238 if (item_attr_get(item, attr_postal, &attr))
219 common->postal=map_convert_string(item->map, attr.u.str); 239 common->postal = map_convert_string(item->map, attr.u.str);
220 else if (item_attr_get(item, attr_town_postal, &attr)) 240 else if (item_attr_get(item, attr_town_postal, &attr))
221 common->postal=map_convert_string(item->map, attr.u.str); 241 common->postal = map_convert_string(item->map, attr.u.str);
222 else 242 else
223 common->postal=NULL; 243 common->postal = NULL;
224 if (item_attr_get(item, attr_postal_mask, &attr)) 244 if (item_attr_get(item, attr_postal_mask, &attr))
225 common->postal_mask=map_convert_string(item->map, attr.u.str); 245 common->postal_mask = map_convert_string(item->map, attr.u.str);
226 else 246 else
227 common->postal_mask=NULL; 247 common->postal_mask = NULL;
228} 248}
229 249
230static void
231search_list_common_destroy(struct search_list_common *common) 250static void search_list_common_destroy(struct search_list_common *common)
232{ 251{
233 map_convert_free(common->town_name); 252 map_convert_free(common->town_name);
234 map_convert_free(common->district_name); 253 map_convert_free(common->district_name);
235 map_convert_free(common->county_name); 254 map_convert_free(common->county_name);
236 map_convert_free(common->postal); 255 map_convert_free(common->postal);
241search_list_country_new(struct item *item) 260search_list_country_new(struct item *item)
242{ 261{
243 struct search_list_country *ret=g_new0(struct search_list_country, 1); 262 struct search_list_country *ret=g_new0(struct search_list_country, 1);
244 struct attr attr; 263 struct attr attr;
245 264
246 ret->common.item=ret->common.unique=*item; 265 ret->common.item = ret->common.unique = *item;
247 if (item_attr_get(item, attr_country_car, &attr)) 266 if (item_attr_get(item, attr_country_car, &attr))
248 ret->car=g_strdup(attr.u.str); 267 ret->car = g_strdup(attr.u.str);
249 if (item_attr_get(item, attr_country_iso2, &attr)) { 268 if (item_attr_get(item, attr_country_iso2, &attr))
269 {
250#if HAVE_API_ANDROID 270#if HAVE_API_ANDROID
251 ret->iso2=g_malloc(strlen(attr.u.str)+1); 271 ret->iso2=g_malloc(strlen(attr.u.str)+1);
252 strtolower(ret->iso2, attr.u.str); 272 strtolower(ret->iso2, attr.u.str);
253#else 273#else
254 ret->iso2=g_strdup(attr.u.str); 274 ret->iso2 = g_strdup(attr.u.str);
255#endif 275#endif
256 ret->flag=g_strdup_printf("country_%s", ret->iso2); 276 ret->flag = g_strdup_printf("country_%s", ret->iso2);
257 } 277 }
258 if (item_attr_get(item, attr_country_iso3, &attr)) 278 if (item_attr_get(item, attr_country_iso3, &attr))
259 ret->iso3=g_strdup(attr.u.str); 279 ret->iso3 = g_strdup(attr.u.str);
260 if (item_attr_get(item, attr_country_name, &attr)) 280 if (item_attr_get(item, attr_country_name, &attr))
261 ret->name=g_strdup(attr.u.str); 281 ret->name = g_strdup(attr.u.str);
262 return ret; 282 return ret;
263} 283}
264 284
265static void
266search_list_country_destroy(struct search_list_country *this_) 285static void search_list_country_destroy(struct search_list_country *this_)
267{ 286{
268 g_free(this_->car); 287 g_free(this_->car);
269 g_free(this_->iso2); 288 g_free(this_->iso2);
270 g_free(this_->iso3); 289 g_free(this_->iso3);
271 g_free(this_->flag); 290 g_free(this_->flag);
277search_list_town_new(struct item *item) 296search_list_town_new(struct item *item)
278{ 297{
279 struct search_list_town *ret=g_new0(struct search_list_town, 1); 298 struct search_list_town *ret=g_new0(struct search_list_town, 1);
280 struct attr attr; 299 struct attr attr;
281 struct coord c; 300 struct coord c;
282 301
283 ret->itemt=*item; 302 ret->itemt = *item;
284 ret->common.item=ret->common.unique=*item; 303 ret->common.item = ret->common.unique = *item;
304
285 if (item_attr_get(item, attr_town_streets_item, &attr)) { 305 if (item_attr_get(item, attr_town_streets_item, &attr))
306 {
286 dbg(1,"town_assoc 0x%x 0x%x\n", attr.u.item->id_hi, attr.u.item->id_lo); 307 //dbg(1, "town_assoc 0x%x 0x%x\n", attr.u.item->id_hi, attr.u.item->id_lo);
287 ret->common.unique=*attr.u.item; 308 ret->common.unique = *attr.u.item;
288 } 309 }
310
289 search_list_common_new(item, &ret->common); 311 search_list_common_new(item, &ret->common);
312
290 if (item_attr_get(item, attr_county_name, &attr)) 313 if (item_attr_get(item, attr_county_name, &attr))
314 {
291 ret->county=map_convert_string(item->map,attr.u.str); 315 ret->county = map_convert_string(item->map, attr.u.str);
316 }
292 else 317 else
318 {
293 ret->county=NULL; 319 ret->county = NULL;
320 }
321
294 if (item_coord_get(item, &c, 1)) { 322 if (item_coord_get(item, &c, 1))
323 {
295 ret->common.c=g_new(struct pcoord, 1); 324 ret->common.c=g_new(struct pcoord, 1);
296 ret->common.c->x=c.x; 325 ret->common.c->x = c.x;
297 ret->common.c->y=c.y; 326 ret->common.c->y = c.y;
298 ret->common.c->pro = map_projection(item->map); 327 ret->common.c->pro = map_projection(item->map);
299 } 328 }
329 else
330 {
331 // some error with lat/lng !!
332 // but still return something, or app will crash
333 ret->common.c=g_new(struct pcoord, 1);
334 ret->common.c->x = 0;
335 ret->common.c->y = 0;
336 ret->common.c->pro = map_projection(item->map);
337 }
300 return ret; 338 return ret;
301} 339}
302 340
303static void
304search_list_town_destroy(struct search_list_town *this_) 341static void search_list_town_destroy(struct search_list_town *this_)
305{ 342{
306 map_convert_free(this_->county); 343 map_convert_free(this_->county);
307 search_list_common_destroy(&this_->common); 344 search_list_common_destroy(&this_->common);
308 if (this_->common.c) 345 if (this_->common.c)
309 g_free(this_->common.c); 346 g_free(this_->common.c);
310 g_free(this_); 347 g_free(this_);
311} 348}
312 349
313
314static struct search_list_street * 350static struct search_list_street *
315search_list_street_new(struct item *item) 351search_list_street_new(struct item *item)
316{ 352{
317 struct search_list_street *ret=g_new0(struct search_list_street, 1); 353 struct search_list_street *ret=g_new0(struct search_list_street, 1);
318 struct attr attr; 354 struct attr attr;
319 struct coord c; 355 struct coord c;
320 356
321 ret->common.item=ret->common.unique=*item; 357 ret->common.item = ret->common.unique = *item;
322 if (item_attr_get(item, attr_street_name, &attr)) 358 if (item_attr_get(item, attr_street_name, &attr))
359 {
323 ret->name=map_convert_string(item->map, attr.u.str); 360 ret->name = map_convert_string(item->map, attr.u.str);
361 }
324 else 362 else
363 {
325 ret->name=NULL; 364 ret->name = NULL;
365 }
326 search_list_common_new(item, &ret->common); 366 search_list_common_new(item, &ret->common);
327 if (item_coord_get(item, &c, 1)) { 367 if (item_coord_get(item, &c, 1))
368 {
328 ret->common.c=g_new(struct pcoord, 1); 369 ret->common.c=g_new(struct pcoord, 1);
329 ret->common.c->x=c.x; 370 ret->common.c->x = c.x;
330 ret->common.c->y=c.y; 371 ret->common.c->y = c.y;
331 ret->common.c->pro = map_projection(item->map); 372 ret->common.c->pro = map_projection(item->map);
332 } 373 }
374 else
375 {
376 // some error with lat/lng !!
377 // but still return something, or app will crash
378 ret->common.c=g_new(struct pcoord, 1);
379 ret->common.c->x = 0;
380 ret->common.c->y = 0;
381 ret->common.c->pro = map_projection(item->map);
382 }
333 return ret; 383 return ret;
334} 384}
335 385
336
337static void
338search_list_street_destroy(struct search_list_street *this_) 386static void search_list_street_destroy(struct search_list_street *this_)
339{ 387{
340 map_convert_free(this_->name); 388 map_convert_free(this_->name);
341 search_list_common_destroy(&this_->common); 389 search_list_common_destroy(&this_->common);
342 if (this_->common.c) 390 if (this_->common.c)
343 { 391 {
347} 395}
348 396
349static char * 397static char *
350search_interpolate(struct interpolation *inter) 398search_interpolate(struct interpolation *inter)
351{ 399{
352 dbg(1,"interpolate %s-%s %s\n",inter->first,inter->last,inter->curr); 400 dbg(1, "interpolate %s-%s %s\n", inter->first, inter->last, inter->curr);
353 if (!inter->first || !inter->last) 401 if (!inter->first || !inter->last)
354 return NULL; 402 return NULL;
355 if (!inter->curr) 403 if (!inter->curr)
356 inter->curr=g_strdup(inter->first); 404 inter->curr = g_strdup(inter->first);
357 else { 405 else
406 {
358 if (strcmp(inter->curr, inter->last)) { 407 if (strcmp(inter->curr, inter->last))
408 {
359 int next=atoi(inter->curr)+(inter->mode?2:1); 409 int next = atoi(inter->curr) + (inter->mode ? 2 : 1);
360 g_free(inter->curr); 410 g_free(inter->curr);
361 if (next == atoi(inter->last)) 411 if (next == atoi(inter->last))
362 inter->curr=g_strdup(inter->last); 412 inter->curr = g_strdup(inter->last);
363 else 413 else
364 inter->curr=g_strdup_printf("%d",next); 414 inter->curr = g_strdup_printf("%d", next);
415 }
365 } else { 416 else
417 {
366 g_free(inter->curr); 418 g_free(inter->curr);
367 inter->curr=NULL; 419 inter->curr = NULL;
368 }
369 } 420 }
421 }
370 dbg(1,"interpolate result %s\n",inter->curr); 422 dbg(1, "interpolate result %s\n", inter->curr);
371 return inter->curr; 423 return inter->curr;
372} 424}
373 425
374static void
375search_interpolation_split(char *str, struct interpolation *inter) 426static void search_interpolation_split(char *str, struct interpolation *inter)
376{ 427{
377 char *pos=strchr(str,'-'); 428 char *pos = strchr(str, '-');
378 char *first,*last; 429 char *first, *last;
379 int len; 430 int len;
380 if (!pos) { 431 if (!pos)
432 {
381 inter->first=g_strdup(str); 433 inter->first = g_strdup(str);
382 inter->last=g_strdup(str); 434 inter->last = g_strdup(str);
383 inter->rev=0; 435 inter->rev = 0;
384 return; 436 return;
385 } 437 }
386 len=pos-str; 438 len = pos - str;
387 first=g_malloc(len+1); 439 first = g_malloc(len + 1);
388 strncpy(first, str, len); 440 strncpy(first, str, len);
389 first[len]='\0'; 441 first[len] = '\0';
390 last=g_strdup(pos+1); 442 last = g_strdup(pos + 1);
391 dbg(1,"%s = %s - %s\n",str, first, last); 443 dbg(1, "%s = %s - %s\n", str, first, last);
392 if (atoi(first) > atoi(last)) { 444 if (atoi(first) > atoi(last))
445 {
393 inter->first=last; 446 inter->first = last;
394 inter->last=first; 447 inter->last = first;
395 inter->rev=1; 448 inter->rev = 1;
396 } else { 449 }
450 else
451 {
397 inter->first=first; 452 inter->first = first;
398 inter->last=last; 453 inter->last = last;
399 inter->rev=0; 454 inter->rev = 0;
400 } 455 }
401} 456}
402 457
403static int
404search_setup_interpolation(struct item *item, enum attr_type i0, enum attr_type i1, enum attr_type i2, struct interpolation *inter) 458static int search_setup_interpolation(struct item *item, enum attr_type i0, enum attr_type i1, enum attr_type i2, struct interpolation *inter)
405{ 459{
406 struct attr attr; 460 struct attr attr;
407 g_free(inter->first); 461 g_free(inter->first);
408 g_free(inter->last); 462 g_free(inter->last);
409 g_free(inter->curr); 463 g_free(inter->curr);
410 inter->first=inter->last=inter->curr=NULL; 464 inter->first = inter->last = inter->curr = NULL;
411 dbg(1,"setup %s\n",attr_to_name(i0)); 465 dbg(1, "setup %s\n", attr_to_name(i0));
412 if (item_attr_get(item, i0, &attr)) { 466 if (item_attr_get(item, i0, &attr))
467 {
413 search_interpolation_split(attr.u.str, inter); 468 search_interpolation_split(attr.u.str, inter);
414 inter->mode=0; 469 inter->mode = 0;
470 }
415 } else if (item_attr_get(item, i1, &attr)) { 471 else if (item_attr_get(item, i1, &attr))
472 {
416 search_interpolation_split(attr.u.str, inter); 473 search_interpolation_split(attr.u.str, inter);
417 inter->mode=1; 474 inter->mode = 1;
475 }
418 } else if (item_attr_get(item, i2, &attr)) { 476 else if (item_attr_get(item, i2, &attr))
477 {
419 search_interpolation_split(attr.u.str, inter); 478 search_interpolation_split(attr.u.str, inter);
420 inter->mode=2; 479 inter->mode = 2;
480 }
421 } else 481 else
422 return 0; 482 return 0;
423 return 1; 483 return 1;
424} 484}
425 485
426static int
427search_match(char *str, char *search, int partial) 486static int search_match(char *str, char *search, int partial)
428{ 487{
429 if (!partial) 488 if (!partial)
430 return (!g_strcasecmp(str, search)); 489 return (!g_strcasecmp(str, search));
431 else 490 else
432 return (!g_strncasecmp(str, search, strlen(search))); 491 return (!g_strncasecmp(str, search, strlen(search)));
435static struct pcoord * 494static struct pcoord *
436search_house_number_coordinate(struct item *item, struct interpolation *inter) 495search_house_number_coordinate(struct item *item, struct interpolation *inter)
437{ 496{
438 struct pcoord *ret=g_new(struct pcoord, 1); 497 struct pcoord *ret=g_new(struct pcoord, 1);
439 ret->pro = map_projection(item->map); 498 ret->pro = map_projection(item->map);
440 if (item_is_point(*item)) { 499 if (item_is_point(*item))
500 {
441 struct coord c; 501 struct coord c;
442 if (item_coord_get(item, &c, 1)) { 502 if (item_coord_get(item, &c, 1))
503 {
443 ret->x=c.x; 504 ret->x = c.x;
444 ret->y=c.y; 505 ret->y = c.y;
506 }
445 } else { 507 else
508 {
446 g_free(ret); 509 g_free(ret);
447 ret=NULL; 510 ret = NULL;
511 }
448 } 512 }
449 } else { 513 else
514 {
450 int count,max=1024; 515 int count, max = 1024;
451 int hn_pos,hn_length; 516 int hn_pos, hn_length;
452 struct coord *c=g_alloca(sizeof(struct coord)*max); 517 struct coord *c = g_alloca(sizeof(struct coord) * max);
453 item_coord_rewind(item); 518 item_coord_rewind(item);
454 count=item_coord_get(item, c, max); 519 count = item_coord_get(item, c, max);
455 hn_length=atoi(inter->last)-atoi(inter->first); 520 hn_length = atoi(inter->last) - atoi(inter->first);
456 if (inter->rev) 521 if (inter->rev)
457 hn_pos=atoi(inter->last)-atoi(inter->curr); 522 hn_pos = atoi(inter->last) - atoi(inter->curr);
458 else 523 else
459 hn_pos=atoi(inter->curr)-atoi(inter->first); 524 hn_pos = atoi(inter->curr) - atoi(inter->first);
460 if (count) { 525 if (count)
526 {
461 int i,distance_sum=0,hn_distance; 527 int i, distance_sum = 0, hn_distance;
462 int *distances=g_alloca(sizeof(int)*(count-1)); 528 int *distances = g_alloca(sizeof(int) * (count - 1));
463 dbg(1,"count=%d hn_length=%d hn_pos=%d (%s of %s-%s)\n",count,hn_length,hn_pos,inter->curr,inter->first,inter->last); 529 dbg(1, "count=%d hn_length=%d hn_pos=%d (%s of %s-%s)\n", count, hn_length, hn_pos, inter->curr, inter->first, inter->last);
464 if (!hn_length) { 530 if (!hn_length)
531 {
465 hn_length=2; 532 hn_length = 2;
466 hn_pos=1; 533 hn_pos = 1;
467 } 534 }
468 if (count == max) 535 if (count == max)
469 dbg(0,"coordinate overflow\n"); 536 dbg(0, "coordinate overflow\n");
470 for (i = 0 ; i < count-1 ; i++) { 537 for (i = 0; i < count - 1; i++)
538 {
471 distances[i]=navit_sqrt(transform_distance_sq(&c[i],&c[i+1])); 539 distances[i] = navit_sqrt(transform_distance_sq(&c[i], &c[i + 1]));
472 distance_sum+=distances[i]; 540 distance_sum += distances[i];
473 dbg(1,"distance[%d]=%d\n",i,distances[i]); 541 dbg(1, "distance[%d]=%d\n", i, distances[i]);
474 } 542 }
475 dbg(1,"sum=%d\n",distance_sum); 543 dbg(1, "sum=%d\n", distance_sum);
476 hn_distance=distance_sum*hn_pos/hn_length; 544 hn_distance = distance_sum * hn_pos / hn_length;
477 dbg(1,"hn_distance=%d\n",hn_distance); 545 dbg(1, "hn_distance=%d\n", hn_distance);
478 i=0; 546 i = 0;
479 while (i < count-1 && hn_distance > distances[i]) 547 while (i < count - 1 && hn_distance > distances[i])
480 hn_distance-=distances[i++]; 548 hn_distance -= distances[i++];
481 dbg(1,"remaining distance=%d from %d\n",hn_distance,distances[i]); 549 dbg(1, "remaining distance=%d from %d\n", hn_distance, distances[i]);
482 ret->x=(c[i+1].x-c[i].x)*hn_distance/distances[i]+c[i].x; 550 ret->x = (c[i + 1].x - c[i].x) * hn_distance / distances[i] + c[i].x;
483 ret->y=(c[i+1].y-c[i].y)*hn_distance/distances[i]+c[i].y; 551 ret->y = (c[i + 1].y - c[i].y) * hn_distance / distances[i] + c[i].y;
484 } 552 }
485 } 553 }
486 return ret; 554 return ret;
487} 555}
488 556
493 struct attr attr; 561 struct attr attr;
494 char *hn; 562 char *hn;
495 563
496 // dbg(0,"@@@@ enter @@@@\n"); 564 // dbg(0,"@@@@ enter @@@@\n");
497 565
498 ret->common.item=ret->common.unique=*item; 566 ret->common.item = ret->common.unique = *item;
499 //if (item_attr_get(item, attr_street_name, &attr)) 567 //if (item_attr_get(item, attr_street_name, &attr))
500 // dbg(0,"xx1 %s\n",attr.u.str); 568 // dbg(0,"xx1 %s\n",attr.u.str);
501 if (item_attr_get(item, attr_house_number, &attr)) 569 if (item_attr_get(item, attr_house_number, &attr))
502 ret->house_number=map_convert_string(item->map, attr.u.str); 570 ret->house_number = map_convert_string(item->map, attr.u.str);
503 else { 571 else
572 {
504 //if (item_attr_get(item, attr_street_name, &attr)) 573 //if (item_attr_get(item, attr_street_name, &attr))
505 // dbg(0,"xx2 %s\n",attr.u.str); 574 // dbg(0,"xx2 %s\n",attr.u.str);
506 for (;;) { 575 for (;;)
576 {
507 //dbg(0,"interpolate 11"); 577 //dbg(0,"interpolate 11");
508 ret->interpolation=1; 578 ret->interpolation = 1;
509 switch(inter->side) { 579 switch (inter->side)
580 {
510 case 0: 581 case 0:
511 //dbg(0,"interpolate 11 0"); 582 //dbg(0,"interpolate 11 0");
512 inter->side=-1; 583 inter->side = -1;
513 search_setup_interpolation(item, attr_house_number_left, attr_house_number_left_odd, attr_house_number_left_even, inter); 584 search_setup_interpolation(item, attr_house_number_left, attr_house_number_left_odd, attr_house_number_left_even, inter);
514 case -1: 585 case -1:
515 //dbg(0,"interpolate 11 -1"); 586 //dbg(0,"interpolate 11 -1");
516 if ((hn=search_interpolate(inter))) 587 if ((hn = search_interpolate(inter)))
517 break; 588 break;
518 inter->side=1; 589 inter->side = 1;
519 search_setup_interpolation(item, attr_house_number_right, attr_house_number_right_odd, attr_house_number_right_even, inter); 590 search_setup_interpolation(item, attr_house_number_right, attr_house_number_right_odd, attr_house_number_right_even, inter);
520 case 1: 591 case 1:
521 //dbg(0,"interpolate 11 1"); 592 //dbg(0,"interpolate 11 1");
522 if ((hn=search_interpolate(inter))) 593 if ((hn = search_interpolate(inter)))
523 break; 594 break;
524 default: 595 default:
525 //dbg(0,"interpolate 11 default"); 596 //dbg(0,"interpolate 11 default");
526 g_free(ret); 597 g_free(ret);
527 return NULL; 598 return NULL;
528 } 599 }
529 if (search_match(hn, inter_match, inter_partial)) 600 if (search_match(hn, inter_match, inter_partial))
530 { 601 {
531 //dbg(0,"interpolate 22"); 602 //dbg(0,"interpolate 22");
532 //dbg(0,"match %s %s-%s\n",hn, inter->first, inter->last); 603 //dbg(0,"match %s %s-%s\n",hn, inter->first, inter->last);
533 ret->house_number=map_convert_string(item->map, hn); 604 ret->house_number = map_convert_string(item->map, hn);
534 break; 605 break;
535 } 606 }
536 } 607 }
537 } 608 }
538 //dbg(0,"interpolate 33"); 609 //dbg(0,"interpolate 33");
539 search_list_common_new(item, &ret->common); 610 search_list_common_new(item, &ret->common);
540 ret->common.c=search_house_number_coordinate(item, ret->interpolation?inter:NULL); 611 ret->common.c = search_house_number_coordinate(item, ret->interpolation ? inter : NULL);
541 //dbg(0,"interpolate 44"); 612 //dbg(0,"interpolate 44");
542 return ret; 613 return ret;
543} 614}
544 615
545static void
546search_list_house_number_destroy(struct search_list_house_number *this_) 616static void search_list_house_number_destroy(struct search_list_house_number *this_)
547{ 617{
548 map_convert_free(this_->house_number); 618 map_convert_free(this_->house_number);
549 search_list_common_destroy(&this_->common); 619 search_list_common_destroy(&this_->common);
550 if (this_->common.c) 620 if (this_->common.c)
551 g_free(this_->common.c); 621 g_free(this_->common.c);
552 g_free(this_); 622 g_free(this_);
553} 623}
554 624
555static void
556search_list_result_destroy(int level, void *p) 625static void search_list_result_destroy(int level, void *p)
557{ 626{
558 switch (level) { 627 switch (level)
628 {
559 case 0: 629 case 0:
560 search_list_country_destroy(p); 630 search_list_country_destroy(p);
561 break; 631 break;
562 case 1: 632 case 1:
563 search_list_town_destroy(p); 633 search_list_town_destroy(p);
564 break; 634 break;
565 case 2: 635 case 2:
566 search_list_street_destroy(p); 636 search_list_street_destroy(p);
567 break; 637 break;
568 case 3: 638 case 3:
569 search_list_house_number_destroy(p); 639 search_list_house_number_destroy(p);
570 break; 640 break;
571 } 641 }
572} 642}
573 643
574static void
575search_list_search_free(struct search_list *sl, int level) 644static void search_list_search_free(struct search_list *sl, int level)
576{ 645{
577 //dbg(0,"enter\n"); 646 //dbg(0,"enter\n");
578 647
579 struct search_list_level *le=&sl->levels[level]; 648 struct search_list_level *le = &sl->levels[level];
580 GList *next,*curr; 649 GList *next, *curr;
581 if (le->search) 650 if (le->search)
582 { 651 {
583 mapset_search_destroy(le->search); 652 mapset_search_destroy(le->search);
584 le->search=NULL; 653 le->search = NULL;
585 } 654 }
586#if 0 /* FIXME */ 655#if 0 /* FIXME */
587 if (le->hash) { 656 if (le->hash)
657 {
588 g_hash_table_destroy(le->hash); 658 g_hash_table_destroy(le->hash);
589 le->hash=NULL; 659 le->hash=NULL;
590 } 660 }
591#endif 661#endif
592 curr=le->list; 662 curr = le->list;
593 while (curr) 663 while (curr)
594 { 664 {
595 search_list_result_destroy(level, curr->data); 665 search_list_result_destroy(level, curr->data);
596 next=g_list_next(curr); 666 next = g_list_next(curr);
597 curr=next; 667 curr = next;
598 } 668 }
599 attr_free(le->attr); 669 attr_free(le->attr);
600 g_list_free(le->list); 670 g_list_free(le->list);
601 le->list=NULL; 671 le->list = NULL;
602 le->curr=NULL; 672 le->curr = NULL;
603 le->last=NULL; 673 le->last = NULL;
604 674
605 //dbg(0,"return\n"); 675 //dbg(0,"return\n");
606} 676}
607 677
608char * 678char *
609search_postal_merge(char *mask, char *new) 679search_postal_merge(char *mask, char *new)
610{ 680{
611 int i; 681 int i;
612 char *ret=NULL; 682 char *ret = NULL;
613 dbg(1,"enter %s %s\n", mask, new); 683 dbg(1, "enter %s %s\n", mask, new);
614 if (!new) 684 if (!new)
615 return NULL; 685 return NULL;
616 if (!mask) 686 if (!mask)
617 return g_strdup(new); 687 return g_strdup(new);
618 i=0; 688 i = 0;
619 while (mask[i] && new[i]) { 689 while (mask[i] && new[i])
690 {
620 if (mask[i] != '.' && mask[i] != new[i]) 691 if (mask[i] != '.' && mask[i] != new[i])
621 break; 692 break;
622 i++; 693 i++;
623 694
624 } 695 }
625 if (mask[i]) { 696 if (mask[i])
697 {
626 ret=g_strdup(mask); 698 ret = g_strdup(mask);
627 while (mask[i]) 699 while (mask[i])
628 ret[i++]='.'; 700 ret[i++] = '.';
629 } 701 }
630 dbg(1,"merged %s with %s as %s\n", mask, new, ret); 702 dbg(1, "merged %s with %s as %s\n", mask, new, ret);
631 return ret; 703 return ret;
632} 704}
633 705
634char * 706char *
635search_postal_merge_replace(char *mask, char *new) 707search_postal_merge_replace(char *mask, char *new)
636{ 708{
637 char *ret=search_postal_merge(mask, new); 709 char *ret = search_postal_merge(mask, new);
638 if (!ret) 710 if (!ret)
639 return mask; 711 return mask;
640 g_free(mask); 712 g_free(mask);
641 return ret; 713 return ret;
642} 714}
643 715
644
645static int
646postal_match(char *postal, char *mask) 716static int postal_match(char *postal, char *mask)
647{ 717{
648 for (;;) { 718 for (;;)
719 {
649 if ((*postal != *mask) && (*mask != '.')) 720 if ((*postal != *mask) && (*mask != '.'))
650 return 0; 721 return 0;
651 if (!*postal) { 722 if (!*postal)
723 {
652 if (!*mask) 724 if (!*mask)
653 return 1; 725 return 1;
654 else 726 else
655 return 0; 727 return 0;
656 } 728 }
657 postal++; 729 postal++;
658 mask++; 730 mask++;
659 } 731 }
660} 732}
661 733
662static int
663search_add_result(struct search_list_level *le, struct search_list_common *slc) 734static int search_add_result(struct search_list_level *le, struct search_list_common *slc)
664{ 735{
665 struct search_list_common *slo; 736 struct search_list_common *slo;
666 char *merged; 737 char *merged;
667 738
668 //dbg(0,"enter\n"); 739 //dbg(0,"enter\n");
669 740
670 //slo=g_hash_table_lookup(le->hash, &slc->unique); 741 //slo=g_hash_table_lookup(le->hash, &slc->unique);
671 //if (!slo) { 742 //if (!slo) {
672 //g_hash_table_insert(le->hash, &slc->unique, slc); 743 //g_hash_table_insert(le->hash, &slc->unique, slc);
673 if (slc->postal && !slc->postal_mask) 744 if (slc->postal && !slc->postal_mask)
674 { 745 {
675 slc->postal_mask=g_strdup(slc->postal); 746 slc->postal_mask = g_strdup(slc->postal);
676 } 747 }
677 // ****** 748 // ******
678 g_list_free(le->list); 749 g_list_free(le->list);
679 le->list=NULL; 750 le->list = NULL;
680 // ****** 751 // ******
681 le->list=g_list_append(le->list, slc); 752 le->list = g_list_append(le->list, slc);
682 return 1; 753 return 1;
683 //} 754 //}
684 merged=search_postal_merge(slo->postal_mask, slc->postal); 755 merged = search_postal_merge(slo->postal_mask, slc->postal);
685 if (merged) 756 if (merged)
686 { 757 {
687 g_free(slo->postal_mask); 758 g_free(slo->postal_mask);
688 slo->postal_mask=merged; 759 slo->postal_mask = merged;
689 } 760 }
690 return 0; 761 return 0;
691} 762}
692 763
693struct search_list_result * 764struct search_list_result *
694search_list_get_result(struct search_list *this_) 765search_list_get_result(struct search_list *this_)
695{ 766{
696 struct search_list_level *le,*leu; 767 struct search_list_level *le, *leu;
697 int level=this_->level; 768 int level = this_->level;
698 struct attr attr2; 769 struct attr attr2;
699 int has_street_name=0; 770 int has_street_name = 0;
700 771
701 //dbg(0,"******* enter *******\n"); 772 //dbg(0,"******* enter *******\n");
702 le=&this_->levels[level]; 773 le = &this_->levels[level];
703 //dbg(0,"le=%p\n", le); 774 //dbg(0,"le=%p\n", le);
704 for (;;) 775 for (;;)
705 { 776 {
706 //dbg(0,"le->search=%p\n", le->search); 777 //dbg(0,"le->search=%p\n", le->search);
707 if (! le->search) 778 if (!le->search)
708 { 779 {
709 //dbg(0,"partial=%d level=%d\n", le->partial, level); 780 //dbg(0,"partial=%d level=%d\n", le->partial, level);
710 if (! level) 781 if (!level)
711 le->parent=NULL; 782 le->parent = NULL;
712 else 783 else
713 { 784 {
714 leu=&this_->levels[level-1]; 785 leu = &this_->levels[level - 1];
715 //dbg(0,"leu->curr=%p\n", leu->curr); 786 //dbg(0,"leu->curr=%p\n", leu->curr);
716 for (;;) 787 for (;;)
717 { 788 {
718 //dbg(0,"*********########"); 789 //dbg(0,"*********########");
719 790
720 struct search_list_common *slc; 791 struct search_list_common *slc;
721 if (! leu->curr) 792 if (!leu->curr)
722 { 793 {
723 return NULL; 794 return NULL;
724 } 795 }
725 le->parent=leu->curr->data; 796 le->parent = leu->curr->data;
726 leu->last=leu->curr; 797 leu->last = leu->curr;
727 leu->curr=g_list_next(leu->curr); 798 leu->curr = g_list_next(leu->curr);
728 slc=(struct search_list_common *)(le->parent); 799 slc = (struct search_list_common *) (le->parent);
729 if (!slc) 800 if (!slc)
730 break; 801 break;
731 if (slc->selected == leu->selected) 802 if (slc->selected == leu->selected)
732 break; 803 break;
733 } 804 }
741 { 812 {
742 dbg(0,"NO parent!!\n"); 813 dbg(0,"NO parent!!\n");
743 } 814 }
744 dbg(0,"############## attr=%s\n", attr_to_name(le->attr->type)); 815 dbg(0,"############## attr=%s\n", attr_to_name(le->attr->type));
745#endif 816#endif
746 le->search=mapset_search_new(this_->ms, &le->parent->item, le->attr, le->partial); 817 le->search = mapset_search_new(this_->ms, &le->parent->item, le->attr, le->partial);
747 // ** DOC ** mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial) 818 // ** DOC ** mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial)
748 le->hash=g_hash_table_new(search_item_hash_hash, search_item_hash_equal); 819 le->hash = g_hash_table_new(search_item_hash_hash, search_item_hash_equal);
749 } 820 }
750 821
751 //dbg(0,"le->search=%p\n", le->search); 822 //dbg(0,"le->search=%p\n", le->search);
752 823
753 if (!this_->item) 824 if (!this_->item)
754 { 825 {
755 //dbg(0,"sssss 1"); 826 //dbg(0,"sssss 1");
756 this_->item=mapset_search_get_item(le->search); 827 this_->item = mapset_search_get_item(le->search);
757 //dbg(0,"sssss 1 %p\n",this_->item); 828 //dbg(0,"sssss 1 %p\n",this_->item);
758 } 829 }
759 830
760 if (this_->item) 831 if (this_->item)
761 { 832 {
762 void *p=NULL; 833 void *p = NULL;
763 //dbg(0,"id_hi=%d id_lo=%d\n", this_->item->id_hi, this_->item->id_lo); 834 //dbg(0,"id_hi=%d id_lo=%d\n", this_->item->id_hi, this_->item->id_lo);
764 if (this_->postal) 835 if (this_->postal)
765 { 836 {
766 struct attr postal; 837 struct attr postal;
767 if (item_attr_get(this_->item, attr_postal_mask, &postal)) { 838 if (item_attr_get(this_->item, attr_postal_mask, &postal))
839 {
768 if (!postal_match(this_->postal, postal.u.str)) 840 if (!postal_match(this_->postal, postal.u.str))
769 continue; 841 continue;
842 }
770 } else if (item_attr_get(this_->item, attr_postal, &postal)) { 843 else if (item_attr_get(this_->item, attr_postal, &postal))
844 {
771 if (strcmp(this_->postal, postal.u.str)) 845 if (strcmp(this_->postal, postal.u.str))
772 continue; 846 continue;
773 } 847 }
774 } 848 }
775 this_->result.country=NULL; 849 this_->result.country = NULL;
776 this_->result.town=NULL; 850 this_->result.town = NULL;
777 this_->result.street=NULL; 851 this_->result.street = NULL;
778 this_->result.c=NULL; 852 this_->result.c = NULL;
779 //dbg(0,"case x LEVEL start %d\n",level); 853 //dbg(0,"case x LEVEL start %d\n",level);
780 switch (level) 854 switch (level)
781 { 855 {
782 case 0: 856 case 0:
783 //dbg(0,"case 0 COUNTRY"); 857 //dbg(0,"case 0 COUNTRY");
784 p=search_list_country_new(this_->item); 858 p = search_list_country_new(this_->item);
785 this_->result.country=p; 859 this_->result.country = p;
786 this_->result.country->common.parent=NULL; 860 this_->result.country->common.parent = NULL;
787 this_->item=NULL; 861 this_->item = NULL;
788 break; 862 break;
789 case 1: 863 case 1:
790 //dbg(0,"case 1 TOWN"); 864 //dbg(0,"case 1 TOWN");
791 p=search_list_town_new(this_->item); 865 p = search_list_town_new(this_->item);
792 this_->result.town=p; 866 this_->result.town = p;
793 this_->result.town->common.parent=this_->levels[0].last->data; 867 this_->result.town->common.parent = this_->levels[0].last->data;
794 this_->result.country=this_->result.town->common.parent; 868 this_->result.country = this_->result.town->common.parent;
795 this_->result.c=this_->result.town->common.c; 869 this_->result.c = this_->result.town->common.c;
796 this_->item=NULL; 870 this_->item = NULL;
797 break; 871 break;
798 case 2: 872 case 2:
799 //dbg(0,"case 2 STREET"); 873 //dbg(0,"case 2 STREET");
800 p=search_list_street_new(this_->item); 874 p = search_list_street_new(this_->item);
801 this_->result.street=p; 875 this_->result.street = p;
802 this_->result.street->common.parent=this_->levels[1].last->data; 876 this_->result.street->common.parent = this_->levels[1].last->data;
803 this_->result.town=this_->result.street->common.parent; 877 this_->result.town = this_->result.street->common.parent;
804 this_->result.country=this_->result.town->common.parent; 878 this_->result.country = this_->result.town->common.parent;
805 this_->result.c=this_->result.street->common.c; 879 this_->result.c = this_->result.street->common.c;
806 this_->item=NULL; 880 this_->item = NULL;
807 break; 881 break;
808 case 3: 882 case 3:
809 //dbg(0,"case 3 HOUSENUMBER"); 883 //dbg(0,"case 3 HOUSENUMBER");
810 has_street_name=0; 884 has_street_name = 0;
811 885
812 // if this housenumber has a streetname tag, set the name now 886 // if this housenumber has a streetname tag, set the name now
813 if (item_attr_get(this_->item, attr_street_name, &attr2)) 887 if (item_attr_get(this_->item, attr_street_name, &attr2))
814 { 888 {
815 // dbg(0,"streetname: %s\n",attr2.u.str); 889 // dbg(0,"streetname: %s\n",attr2.u.str);
816 has_street_name=1; 890 has_street_name = 1;
817 } 891 }
818 892
819 //dbg(0,"case 3 XXXX 1\n"); 893 //dbg(0,"case 3 XXXX 1\n");
820 p=search_list_house_number_new(this_->item, &this_->inter, le->attr->u.str, le->partial); 894 p = search_list_house_number_new(this_->item, &this_->inter, le->attr->u.str, le->partial);
821 //dbg(0,"case 3 XXXX 2\n"); 895 //dbg(0,"case 3 XXXX 2\n");
822 if (!p) 896 if (!p)
823 { 897 {
824 interpolation_clear(&this_->inter); 898 interpolation_clear(&this_->inter);
825 this_->item=NULL; 899 this_->item = NULL;
826 continue; 900 continue;
827 } 901 }
828 //dbg(0,"case 3 XXXX 3\n"); 902 //dbg(0,"case 3 XXXX 3\n");
829 this_->result.house_number=p; 903 this_->result.house_number = p;
830 if (!this_->result.house_number->interpolation) 904 if (!this_->result.house_number->interpolation)
831 { 905 {
832 this_->item=NULL; 906 this_->item = NULL;
833 } 907 }
834 908
835 this_->result.house_number->common.parent=this_->levels[2].last->data; 909 this_->result.house_number->common.parent = this_->levels[2].last->data;
836 this_->result.street=this_->result.house_number->common.parent; 910 this_->result.street = this_->result.house_number->common.parent;
837 this_->result.town=this_->result.street->common.parent; 911 this_->result.town = this_->result.street->common.parent;
838 this_->result.country=this_->result.town->common.parent; 912 this_->result.country = this_->result.town->common.parent;
839 this_->result.c=this_->result.house_number->common.c; 913 this_->result.c = this_->result.house_number->common.c;
840 914
841 //dbg(0,"case 3 XXXX 4\n"); 915 //dbg(0,"case 3 XXXX 4\n");
842 if (has_street_name==1) 916 if (has_street_name == 1)
843 { 917 {
844 gchar *tmp_name=g_strdup(attr2.u.str); 918 gchar *tmp_name = g_strdup(attr2.u.str);
845 this_->result.street->name=tmp_name; 919 this_->result.street->name = tmp_name;
846 //dbg(0,"res streetname=%s\n",this_->result.street->name); 920 //dbg(0,"res streetname=%s\n",this_->result.street->name);
847 } 921 }
848 else 922 else
849 { 923 {
850 // 924 //
851 // this crashes all the time -> so dont use! 925 // this crashes all the time -> so dont use!
852 //static struct search_list_street null_street; 926 //static struct search_list_street null_street;
853 //this_->result.street=&null_street; 927 //this_->result.street=&null_street;
854 // this crashes all the time -> so dont use! 928 // this crashes all the time -> so dont use!
855 // 929 //
856 this_->result.street->name=NULL; 930 this_->result.street->name = NULL;
857 } 931 }
858 //dbg(0,"case 3 XXXX 5\n"); 932 //dbg(0,"case 3 XXXX 5\n");
859 break; 933 break;
860 } 934 }
861 // CASE END ********* 935 // CASE END *********
862 936
863 937
864 if (p) 938 if (p)
865 { 939 {
866 if (search_add_result(le, p)) 940 if (search_add_result(le, p))
867 { 941 {
868 //** this_->result.id++; 942 //** this_->result.id++;
869 this_->result.id=0; 943 this_->result.id = 0;
870 //dbg(0,"++++ return result\n"); 944 //dbg(0,"++++ return result\n");
871 return &this_->result; 945 return &this_->result;
872 } 946 }
873 else 947 else
874 { 948 {
878 } 952 }
879 } 953 }
880 else 954 else
881 { 955 {
882 mapset_search_destroy(le->search); 956 mapset_search_destroy(le->search);
883 le->search=NULL; 957 le->search = NULL;
884 g_hash_table_destroy(le->hash); 958 g_hash_table_destroy(le->hash);
885 if (! level) 959 if (!level)
886 { 960 {
887 break; 961 break;
888 } 962 }
889 } 963 }
890 } 964 }
891 return NULL; 965 return NULL;
892} 966}
893 967
894void
895search_list_destroy(struct search_list *this_) 968void search_list_destroy(struct search_list *this_)
896{ 969{
897 g_free(this_->postal); 970 g_free(this_->postal);
898 g_free(this_); 971 g_free(this_);
899} 972}
900 973
901void
902search_init(void) 974void search_init(void)
903{ 975{
904} 976}
905
906 977
907static char * 978static char *
908search_fix_spaces(char *str) 979search_fix_spaces(char *str)
909{ 980{
910 int i; 981 int i;
911 int len=strlen(str); 982 int len = strlen(str);
912 char c,*s,*d,*ret=g_strdup(str); 983 char c, *s, *d, *ret = g_strdup(str);
913 984
914 for (i = 0 ; i < len ; i++) { 985 for (i = 0; i < len; i++)
986 {
915 if (ret[i] == ',' || ret[i] == ',' || ret[i] == '/') 987 if (ret[i] == ',' || ret[i] == ',' || ret[i] == '/')
916 ret[i]=' '; 988 ret[i] = ' ';
917 } 989 }
918 s=ret; 990 s = ret;
919 d=ret; 991 d = ret;
920 len=0; 992 len = 0;
921 do { 993 do
994 {
922 c=*s++; 995 c = *s++;
923 if (c != ' ' || len != 0) { 996 if (c != ' ' || len != 0)
997 {
924 *d++=c; 998 *d++ = c;
925 len++; 999 len++;
926 } 1000 }
927 while (c == ' ' && *s == ' ') 1001 while (c == ' ' && *s == ' ')
928 s++; 1002 s++;
929 if (c == ' ' && *s == '\0') { 1003 if (c == ' ' && *s == '\0')
1004 {
930 d--; 1005 d--;
931 len--; 1006 len--;
932 } 1007 }
1008 }
933 } while (c); 1009 while (c);
934 return ret; 1010 return ret;
935} 1011}
936 1012
937static GList * 1013static GList *
938search_split_phrases(char *str) 1014search_split_phrases(char *str)
939{ 1015{
940 char *tmp,*s,*d; 1016 char *tmp, *s, *d;
941 GList *ret=NULL; 1017 GList *ret = NULL;
942 s=str; 1018 s = str;
943 do { 1019 do
1020 {
944 tmp=g_strdup(s); 1021 tmp = g_strdup(s);
945 d=tmp+strlen(s)-1; 1022 d = tmp + strlen(s) - 1;
946 ret=g_list_append(ret, g_strdup(s)); 1023 ret = g_list_append(ret, g_strdup(s));
947 while (d >= tmp) { 1024 while (d >= tmp)
1025 {
948 if (*d == ' ') { 1026 if (*d == ' ')
1027 {
949 *d = '\0'; 1028 *d = '\0';
950 ret=g_list_append(ret, g_strdup(tmp)); 1029 ret = g_list_append(ret, g_strdup(tmp));
951 } 1030 }
952 d--; 1031 d--;
953 } 1032 }
954 g_free(tmp); 1033 g_free(tmp);
955 do { 1034 do
1035 {
956 s++; 1036 s++;
957 if (*s == ' ') { 1037 if (*s == ' ')
1038 {
958 s++; 1039 s++;
959 break; 1040 break;
960 } 1041 }
1042 }
961 } while (*s != '\0'); 1043 while (*s != '\0');
1044 }
962 } while (*s != '\0'); 1045 while (*s != '\0');
963 return ret; 1046 return ret;
964} 1047}
965 1048
966static GList * 1049static GList *
967search_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) 1050search_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)
970 struct coord_geo g; 1053 struct coord_geo g;
971 struct coord c; 1054 struct coord c;
972 1055
973 //dbg(0,"enter\n"); 1056 //dbg(0,"enter\n");
974 1057
975 while ((slr=search_list_get_result(sl))) 1058 while ((slr = search_list_get_result(sl)))
976 { 1059 {
977 if (offline_search_break_searching==1) 1060 if (offline_search_break_searching == 1)
978 { 1061 {
979 break; 1062 break;
980 } 1063 }
981 1064
982 // does the streetname of the housenumber match the street we want? 1065 // does the streetname of the housenumber match the street we want?
983 if (slr != NULL) 1066 if (slr != NULL)
984 { 1067 {
985 if (slr->street != NULL) 1068 if (slr->street != NULL)
986 if ((street_name != NULL)&&(slr->street->name != NULL)) 1069 if ((street_name != NULL) && (slr->street->name != NULL))
987 {
988
989 if (strcmp(slr->street->name, street_name)==0)
990 { 1070 {
991 char *buffer; 1071
992 // coords of result 1072 if (strcmp(slr->street->name, street_name) == 0)
993 c.x=slr->house_number->common.c->x;
994 c.y=slr->house_number->common.c->y;
995 transform_to_geo(slr->house_number->common.c->pro, &c, &g);
996 // SHN -> street with house number
997 // return a string like: "SHN:H111L5555:16.766:48.76:full address name is at the end"
998 // ca. 9 chars : ca. 9 chars : max. 100 max. 100 max. 100 max. 15 chars -> this sould be max. about 335 chars long
999 if (slr->town->common.postal == NULL)
1000 { 1073 {
1001 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); 1074 char *buffer;
1075 // coords of result
1076 c.x = slr->house_number->common.c->x;
1077 c.y = slr->house_number->common.c->y;
1078 transform_to_geo(slr->house_number->common.c->pro, &c, &g);
1079 // SHN -> street with house number
1080 // return a string like: "SHN:H111L5555:16.766:48.76:full address name is at the end"
1081 // ca. 9 chars : ca. 9 chars : max. 100 max. 100 max. 100 max. 15 chars -> this sould be max. about 335 chars long
1082 if (slr->town->common.postal == NULL)
1083 {
1084 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);
1085 }
1086 else
1087 {
1088 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,
1089 slr->house_number->house_number);
1090 }
1091
1092 //dbg(0,"res=%s\n",buffer);
1093
1094 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer));
1095#ifdef HAVE_API_ANDROID
1096 // return results to android as they come in ...
1097 android_return_search_result(jni,buffer);
1098#endif
1099 g_free(buffer);
1002 } 1100 }
1003 else
1004 {
1005 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);
1006 }
1007
1008 //dbg(0,"res=%s\n",buffer);
1009
1010 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer));
1011 #ifdef HAVE_API_ANDROID
1012 // return results to android as they come in ...
1013 android_return_search_result(jni,buffer);
1014 #endif
1015 g_free(buffer);
1016 } 1101 }
1017 }
1018 } 1102 }
1019 } 1103 }
1020 1104
1021 //dbg(0,"return 2\n"); 1105 //dbg(0,"return 2\n");
1022 return result_list; 1106 return result_list;
1026search_address__street(GList *result_list, struct search_list *sl, GList *phrases, GList *exclude1, GList *exclude2, GList *exclude3, int partial, struct jni_object *jni) 1110search_address__street(GList *result_list, struct search_list *sl, GList *phrases, GList *exclude1, GList *exclude2, GList *exclude3, int partial, struct jni_object *jni)
1027{ 1111{
1028 //dbg(0,"enter\n"); 1112 //dbg(0,"enter\n");
1029 1113
1030 struct search_list_result *slr = NULL; 1114 struct search_list_result *slr = NULL;
1031 GList *tmp=phrases; 1115 GList *tmp = phrases;
1032 int count=0; 1116 int count = 0;
1033 struct coord_geo g; 1117 struct coord_geo g;
1034 struct coord c; 1118 struct coord c;
1035 struct attr attr2; 1119 struct attr attr2;
1036 1120
1037 struct item *save_item; 1121 struct item *save_item;
1038 int save_level; 1122 int save_level;
1039 int save_last_result_valid; 1123 int save_last_result_valid;
1040 1124
1041 while ((slr=search_list_get_result(sl))) 1125 while ((slr = search_list_get_result(sl)))
1042 { 1126 {
1043 char *buffer; 1127 char *buffer;
1044 char *buffer2; 1128 char *buffer2;
1045 1129
1046 if (offline_search_break_searching==1) 1130 if (offline_search_break_searching == 1)
1047 { 1131 {
1048 break; 1132 break;
1049 } 1133 }
1050 1134
1051 if (slr->street) 1135 if (slr->street)
1052 { 1136 {
1053 // coords of result 1137 // coords of result
1054 c.x=slr->street->common.c->x; 1138 c.x = slr->street->common.c->x;
1055 c.y=slr->street->common.c->y; 1139 c.y = slr->street->common.c->y;
1056 transform_to_geo(slr->street->common.c->pro, &c, &g); 1140 transform_to_geo(slr->street->common.c->pro, &c, &g);
1057 1141
1058 // STR -> street 1142 // STR -> street
1059 // return a string like: "STR:H1111L5555:16.766:-48.76:full address name is at the end" 1143 // return a string like: "STR:H1111L5555:16.766:-48.76:full address name is at the end"
1060 // ca. 9 chars : ca. 9 chars : max. 100 max. 100 max. 100 chars -> this sould be max. about 320 chars long 1144 // ca. 9 chars : ca. 9 chars : max. 100 max. 100 max. 100 chars -> this sould be max. about 320 chars long
1061 if (slr->town->common.postal == NULL) 1145 if (slr->town->common.postal == NULL)
1062 { 1146 {
1063 buffer=g_strdup_printf("STR:H%dL%d:%f:%f:%.101s,%.101s, %.101s",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); 1147 buffer = g_strdup_printf("STR:H%dL%d:%f:%f:%.101s,%.101s, %.101s", 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);
1064 } 1148 }
1065 else 1149 else
1066 { 1150 {
1067 buffer=g_strdup_printf("STR:H%dL%d:%f:%f:%.101s,%.7s %.101s, %.101s",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); 1151 buffer = g_strdup_printf("STR:H%dL%d:%f:%f:%.101s,%.7s %.101s, %.101s", 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);
1068 } 1152 }
1069 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer)); 1153 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer));
1070 1154
1071 //dbg(0,"res=%s\n",buffer); 1155 //dbg(0,"res=%s\n",buffer);
1072 1156
1073 #ifdef HAVE_API_ANDROID 1157#ifdef HAVE_API_ANDROID
1074 // return results to android as they come in ... 1158 // return results to android as they come in ...
1075 android_return_search_result(jni,buffer); 1159 android_return_search_result(jni,buffer);
1076 #endif 1160#endif
1077 count++; 1161 count++;
1078 1162
1079 buffer2=g_strdup_printf("%s", slr->street->name); 1163 buffer2 = g_strdup_printf("%s", slr->street->name);
1080 //dbg(0,"b2:%s\n",buffer2); 1164 //dbg(0,"b2:%s\n",buffer2);
1081 1165
1082 1166
1083 save_item=sl->item; 1167 save_item = sl->item;
1084 save_level=sl->level; 1168 save_level = sl->level;
1085 save_last_result_valid=sl->last_result_valid; 1169 save_last_result_valid = sl->last_result_valid;
1086
1087 1170
1088#if 1 1171#if 1
1089 // put words back to start!! 1172 // put words back to start!!
1090 tmp=phrases; 1173 tmp = phrases;
1091 while (tmp) 1174 while (tmp)
1092 { 1175 {
1093 //dbg(0,"s0=%s\n",tmp->data); 1176 //dbg(0,"s0=%s\n",tmp->data);
1094 if (tmp != exclude1 && tmp != exclude2 && tmp != exclude3) 1177 if (tmp != exclude1 && tmp != exclude2 && tmp != exclude3)
1095 { 1178 {
1096 //dbg(0,"s=%s\n",tmp->data); 1179 //dbg(0,"s=%s\n",tmp->data);
1097 1180
1098 attr2.type=attr_house_number; 1181 attr2.type = attr_house_number;
1099 attr2.u.str=tmp->data; 1182 attr2.u.str = tmp->data;
1100 search_list_search(sl, &attr2, partial); 1183 search_list_search(sl, &attr2, partial);
1101 1184
1102 result_list=search_address_housenumber_real(result_list, sl, buffer2, phrases, exclude1, exclude2, exclude3, partial, jni); 1185 result_list = search_address_housenumber_real(result_list, sl, buffer2, phrases, exclude1, exclude2, exclude3, partial, jni);
1103 } 1186 }
1104 tmp=g_list_next(tmp); 1187 tmp = g_list_next(tmp);
1105 } 1188 }
1106#endif 1189#endif
1107 1190
1108 // restore again 1191 // restore again
1109 sl->item=save_item; 1192 sl->item = save_item;
1110 sl->level=save_level; 1193 sl->level = save_level;
1111 sl->last_result_valid=save_last_result_valid; 1194 sl->last_result_valid = save_last_result_valid;
1112 1195
1113 } 1196 }
1114 1197
1115 if (buffer2) 1198 if (buffer2)
1116 { 1199 {
1130static GList * 1213static GList *
1131search_address__town(GList *result_list, struct search_list *sl, GList *phrases, GList *exclude1, GList *exclude2, int partial, struct jni_object *jni) 1214search_address__town(GList *result_list, struct search_list *sl, GList *phrases, GList *exclude1, GList *exclude2, int partial, struct jni_object *jni)
1132{ 1215{
1133 //dbg(0,"enter\n"); 1216 //dbg(0,"enter\n");
1134 struct search_list_result *slr; 1217 struct search_list_result *slr;
1135 GList *tmp=phrases; 1218 GList *tmp = phrases;
1136 int count=0; 1219 int count = 0;
1137 struct coord_geo g; 1220 struct coord_geo g;
1138 struct coord c; 1221 struct coord c;
1139 struct attr attr; 1222 struct attr attr;
1140 struct attr attrx; 1223 struct attr attrx;
1141 // struct search_list *sl2=search_list_new(sl->ms); 1224 // struct search_list *sl2=search_list_new(sl->ms);
1142 struct item *save_item; 1225 struct item *save_item;
1143 int save_level; 1226 int save_level;
1144 int save_last_result_valid; 1227 int save_last_result_valid;
1145 // int first=1; 1228 // int first=1;
1146 1229
1147 while ((slr=search_list_get_result(sl))) 1230 while ((slr = search_list_get_result(sl)))
1148 { 1231 {
1149 char *buffer; 1232 char *buffer;
1150 1233
1151 if (offline_search_break_searching==1) 1234 if (offline_search_break_searching == 1)
1152 { 1235 {
1153 break; 1236 break;
1154 } 1237 }
1155 1238
1156 // coords of result 1239 // coords of result
1157 c.x=slr->town->common.c->x; 1240 c.x = slr->town->common.c->x;
1158 c.y=slr->town->common.c->y; 1241 c.y = slr->town->common.c->y;
1159 transform_to_geo(slr->town->common.c->pro, &c, &g); 1242 transform_to_geo(slr->town->common.c->pro, &c, &g);
1160 1243
1161 // TWN -> town 1244 // TWN -> town
1162 if (slr->town->common.postal == NULL) 1245 if (slr->town->common.postal == NULL)
1163 { 1246 {
1164 buffer=g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s,%.101s",slr->town->common.item.id_hi,slr->town->common.item.id_lo,g.lat,g.lng,slr->country->name,slr->town->common.town_name); 1247 buffer = g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s,%.101s", slr->town->common.item.id_hi, slr->town->common.item.id_lo, g.lat, g.lng, slr->country->name, slr->town->common.town_name);
1165 } 1248 }
1166 else 1249 else
1167 { 1250 {
1168 buffer=g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s,%.7s %.101s",slr->town->common.item.id_hi,slr->town->common.item.id_lo,g.lat,g.lng,slr->country->name,slr->town->common.postal,slr->town->common.town_name); 1251 buffer = g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s,%.7s %.101s", slr->town->common.item.id_hi, slr->town->common.item.id_lo, g.lat, g.lng, slr->country->name, slr->town->common.postal, slr->town->common.town_name);
1169 } 1252 }
1170 1253
1171 //dbg(0,"**res=%s\n",buffer); 1254 //dbg(0,"**res=%s\n",buffer);
1172 1255
1173 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer)); 1256 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer));
1178 1261
1179 count++; 1262 count++;
1180 if (buffer) 1263 if (buffer)
1181 g_free(buffer); 1264 g_free(buffer);
1182 1265
1183
1184 save_item=sl->item; 1266 save_item = sl->item;
1185 save_level=sl->level; 1267 save_level = sl->level;
1186 save_last_result_valid=sl->last_result_valid; 1268 save_last_result_valid = sl->last_result_valid;
1187 1269
1188 // put words back to start!! 1270 // put words back to start!!
1189 tmp=phrases; 1271 tmp = phrases;
1190 1272
1191 while (tmp) 1273 while (tmp)
1192 { 1274 {
1193 if (tmp != exclude1 && tmp != exclude2) 1275 if (tmp != exclude1 && tmp != exclude2)
1194 { 1276 {
1195 //dbg(0,"s=%s\n",tmp->data); 1277 //dbg(0,"s=%s\n",tmp->data);
1196 attr.type=attr_street_name; 1278 attr.type = attr_street_name;
1197 attr.u.str=tmp->data; 1279 attr.u.str = tmp->data;
1198 search_list_search(sl, &attr, partial); 1280 search_list_search(sl, &attr, partial);
1199 result_list=search_address__street(result_list, sl, phrases, exclude1, exclude2, tmp, partial, jni); 1281 result_list = search_address__street(result_list, sl, phrases, exclude1, exclude2, tmp, partial, jni);
1200 } 1282 }
1201 tmp=g_list_next(tmp); 1283 tmp = g_list_next(tmp);
1202 } 1284 }
1203 1285
1204 // restore again 1286 // restore again
1205 sl->item=save_item; 1287 sl->item = save_item;
1206 sl->level=save_level; 1288 sl->level = save_level;
1207 sl->last_result_valid=save_last_result_valid; 1289 sl->last_result_valid = save_last_result_valid;
1208 } 1290 }
1209 1291
1210 //dbg(0,"return 2\n"); 1292 //dbg(0,"return 2\n");
1211 return result_list; 1293 return result_list;
1212} 1294}
1213 1295
1214static GList * 1296static GList *
1215search_address__country(GList *result_list, struct search_list *sl, GList *phrases, GList *exclude, int partial, struct jni_object *jni) 1297search_address__country(GList *result_list, struct search_list *sl, GList *phrases, GList *exclude, int partial, struct jni_object *jni)
1216{ 1298{
1217 GList *tmp=phrases; 1299 GList *tmp = phrases;
1218 int count=0; 1300 int count = 0;
1219 struct attr attr; 1301 struct attr attr;
1220 struct search_list_result *slr; 1302 struct search_list_result *slr;
1221 //dbg(0,"enter\n"); 1303 //dbg(0,"enter\n");
1222 1304
1223 while ((slr=search_list_get_result(sl))) 1305 while ((slr = search_list_get_result(sl)))
1224 { 1306 {
1225 //dbg(0,"1 slr=%p\n",slr->country); 1307 //dbg(0,"1 slr=%p\n",slr->country);
1226 //dbg(0,"2 slr=%s\n",slr->country->name); 1308 //dbg(0,"2 slr=%s\n",slr->country->name);
1227 //dbg(0,"3 slr=%s\n",slr->country->iso2); 1309 //dbg(0,"3 slr=%s\n",slr->country->iso2);
1228 count++; 1310 count++;
1237 while (tmp) 1319 while (tmp)
1238 { 1320 {
1239 if (tmp != exclude) 1321 if (tmp != exclude)
1240 { 1322 {
1241 //dbg(0,"Is=%s\n",tmp->data); 1323 //dbg(0,"Is=%s\n",tmp->data);
1242 attr.type=attr_town_or_district_name; 1324 attr.type = attr_town_or_district_name;
1243 attr.u.str=tmp->data; 1325 attr.u.str = tmp->data;
1244 search_list_search(sl, &attr, partial); 1326 search_list_search(sl, &attr, partial);
1245 result_list=search_address__town(result_list, sl, phrases, exclude, tmp, partial, jni); 1327 result_list = search_address__town(result_list, sl, phrases, exclude, tmp, partial, jni);
1246 } 1328 }
1247 //else 1329 //else
1248 //{ 1330 //{
1249 //dbg(0,"Xs=%s\n",tmp->data); 1331 //dbg(0,"Xs=%s\n",tmp->data);
1250 //} 1332 //}
1251 tmp=g_list_next(tmp); 1333 tmp = g_list_next(tmp);
1252 } 1334 }
1253 //dbg(0,"return 2"); 1335 //dbg(0,"return 2");
1254 return result_list; 1336 return result_list;
1255} 1337}
1256 1338
1257
1258struct country2 { 1339struct country2
1340{
1259 int id; 1341 int id;
1260 char *car; 1342 char *car;
1261 char *iso2; 1343 char *iso2;
1262 char *iso3; 1344 char *iso3;
1263 char *name; 1345 char *name;
1264}; 1346};
1265 1347
1266static struct country2 all_country_list[]= { 1348static struct country2 all_country_list[] =
1349{
1267 { 20, "AND", "AD", "AND", /* 020 */ "Andorra"}, 1350{ 20, "AND", "AD", "AND", /* 020 */"Andorra" },
1268 {784, "UAE", "AE", "ARE", /* 784 */ "United Arab Emirates"}, 1351{ 784, "UAE", "AE", "ARE", /* 784 */
1352"United Arab Emirates" },
1269 { 4, "AFG", "AF", "AFG", /* 004 */ "Afghanistan"}, 1353{ 4, "AFG", "AF", "AFG", /* 004 */"Afghanistan" },
1270 { 28, "AG", "AG", "ATG", /* 028 */ "Antigua and Barbuda"}, 1354{ 28, "AG", "AG", "ATG", /* 028 */"Antigua and Barbuda" },
1271 {660, NULL, "AI", "AIA", /* 660 */ "Anguilla"}, 1355{ 660, NULL, "AI", "AIA", /* 660 */"Anguilla" },
1272 { 8, "AL", "AL", "ALB", /* 008 */ "Albania"}, 1356{ 8, "AL", "AL", "ALB", /* 008 */"Albania" },
1273 { 51, "ARM", "AM", "ARM", /* 051 */ "Armenia"}, 1357{ 51, "ARM", "AM", "ARM", /* 051 */"Armenia" },
1274 {530, "NA", "AN", "ANT", /* 530 */ "Netherlands Antilles"}, 1358{ 530, "NA", "AN", "ANT", /* 530 */
1359"Netherlands Antilles" },
1275 { 24, "ANG", "AO", "AGO", /* 024 */ "Angola"}, 1360{ 24, "ANG", "AO", "AGO", /* 024 */"Angola" },
1276 { 10, NULL, "AQ", "ATA", /* 010 */ "Antarctica"}, 1361{ 10, NULL, "AQ", "ATA", /* 010 */"Antarctica" },
1277 { 32, "RA", "AR", "ARG", /* 032 */ "Argentina"}, 1362{ 32, "RA", "AR", "ARG", /* 032 */"Argentina" },
1278 { 16, NULL, "AS", "ASM", /* 016 */ "American Samoa"}, 1363{ 16, NULL, "AS", "ASM", /* 016 */"American Samoa" },
1279 { 40, "A", "AT", "AUT", /* 040 */ "Austria"}, 1364{ 40, "A", "AT", "AUT", /* 040 */"Austria" },
1280 { 36, "AUS", "AU", "AUS", /* 036 */ "Australia"}, 1365{ 36, "AUS", "AU", "AUS", /* 036 */"Australia" },
1281 {533, "ARU", "AW", "ABW", /* 533 */ "Aruba"}, 1366{ 533, "ARU", "AW", "ABW", /* 533 */"Aruba" },
1282 {248, "AX", "AX", "ALA", /* 248 */ "Aland Islands"}, 1367{ 248, "AX", "AX", "ALA", /* 248 */"Aland Islands" },
1283 { 31, "AZ", "AZ", "AZE", /* 031 */ "Azerbaijan"}, 1368{ 31, "AZ", "AZ", "AZE", /* 031 */"Azerbaijan" },
1284 { 70, "BiH", "BA", "BIH", /* 070 */ "Bosnia and Herzegovina"}, 1369{ 70, "BiH", "BA", "BIH", /* 070 */
1370"Bosnia and Herzegovina" },
1285 { 52, "BDS", "BB", "BRB", /* 052 */ "Barbados"}, 1371{ 52, "BDS", "BB", "BRB", /* 052 */"Barbados" },
1286 { 50, "BD", "BD", "BGD", /* 050 */ "Bangladesh"}, 1372{ 50, "BD", "BD", "BGD", /* 050 */"Bangladesh" },
1287 { 56, "B", "BE", "BEL", /* 056 */ "Belgium"}, 1373{ 56, "B", "BE", "BEL", /* 056 */"Belgium" },
1288 {854, "BF", "BF", "BFA", /* 854 */ "Burkina Faso"}, 1374{ 854, "BF", "BF", "BFA", /* 854 */"Burkina Faso" },
1289 {100, "BG", "BG", "BGR", /* 100 */ "Bulgaria"}, 1375{ 100, "BG", "BG", "BGR", /* 100 */"Bulgaria" },
1290 { 48, "BRN", "BH", "BHR", /* 048 */ "Bahrain"}, 1376{ 48, "BRN", "BH", "BHR", /* 048 */"Bahrain" },
1291 {108, "RU", "BI", "BDI", /* 108 */ "Burundi"}, 1377{ 108, "RU", "BI", "BDI", /* 108 */"Burundi" },
1292 {204, "BJ", "BJ", "BEN", /* 204 */ "Benin"}, 1378{ 204, "BJ", "BJ", "BEN", /* 204 */"Benin" },
1293 {652, NULL, "BL", "BLM", /* 652 */ "Saint Barthelemy"}, 1379{ 652, NULL, "BL", "BLM", /* 652 */"Saint Barthelemy" },
1294 { 60, NULL, "BM", "BMU", /* 060 */ "Bermuda"}, 1380{ 60, NULL, "BM", "BMU", /* 060 */"Bermuda" },
1295 { 96, "BRU", "BN", "BRN", /* 096 */ "Brunei Darussalam"}, 1381{ 96, "BRU", "BN", "BRN", /* 096 */"Brunei Darussalam" },
1296 { 68, "BOL", "BO", "BOL", /* 068 */ "Bolivia"}, 1382{ 68, "BOL", "BO", "BOL", /* 068 */"Bolivia" },
1297 { 76, "BR", "BR", "BRA", /* 076 */ "Brazil"}, 1383{ 76, "BR", "BR", "BRA", /* 076 */"Brazil" },
1298 { 44, "BS", "BS", "BHS", /* 044 */ "Bahamas"}, 1384{ 44, "BS", "BS", "BHS", /* 044 */"Bahamas" },
1299 { 64, "BHT", "BT", "BTN", /* 064 */ "Bhutan"}, 1385{ 64, "BHT", "BT", "BTN", /* 064 */"Bhutan" },
1300 { 74, NULL, "BV", "BVT", /* 074 */ "Bouvet Island"}, 1386{ 74, NULL, "BV", "BVT", /* 074 */"Bouvet Island" },
1301 { 72, "RB", "BW", "BWA", /* 072 */ "Botswana"}, 1387{ 72, "RB", "BW", "BWA", /* 072 */"Botswana" },
1302 {112, "BY", "BY", "BLR", /* 112 */ "Belarus"}, 1388{ 112, "BY", "BY", "BLR", /* 112 */"Belarus" },
1303 { 84, "BZ", "BZ", "BLZ", /* 084 */ "Belize"}, 1389{ 84, "BZ", "BZ", "BLZ", /* 084 */"Belize" },
1304 {124, "CDN", "CA", "CAN", /* 124 */ "Canada"}, 1390{ 124, "CDN", "CA", "CAN", /* 124 */"Canada" },
1305 {166, NULL, "CC", "CCK", /* 166 */ "Cocos (Keeling) Islands"}, 1391{ 166, NULL, "CC", "CCK", /* 166 */
1306 {180, "CGO", "CD", "COD", /* 180 */ "Congo, Democratic Republic of the"}, 1392"Cocos (Keeling) Islands" },
1307 {140, "RCA", "CF", "CAF", /* 140 */ "Central African Republic"}, 1393{ 180, "CGO", "CD", "COD", /* 180 */
1394"Congo, Democratic Republic of the" },
1395{ 140, "RCA", "CF", "CAF", /* 140 */
1396"Central African Republic" },
1308 {178, NULL, "CG", "COG", /* 178 */ "Congo"}, 1397{ 178, NULL, "CG", "COG", /* 178 */"Congo" },
1309 {756, "CH", "CH", "CHE", /* 756 */ "Switzerland"}, 1398{ 756, "CH", "CH", "CHE", /* 756 */"Switzerland" },
1310 {384, "CI", "CI", "CIV", /* 384 */ "Cote d'Ivoire"}, 1399{ 384, "CI", "CI", "CIV", /* 384 */"Cote d'Ivoire" },
1311 {184, NULL, "CK", "COK", /* 184 */ "Cook Islands"}, 1400{ 184, NULL, "CK", "COK", /* 184 */"Cook Islands" },
1312 {152, "RCH", "CL", "CHL", /* 152 */ "Chile"}, 1401{ 152, "RCH", "CL", "CHL", /* 152 */"Chile" },
1313 {120, "CAM", "CM", "CMR", /* 120 */ "Cameroon"}, 1402{ 120, "CAM", "CM", "CMR", /* 120 */"Cameroon" },
1314 {156, "RC", "CN", "CHN", /* 156 */ "China"}, 1403{ 156, "RC", "CN", "CHN", /* 156 */"China" },
1315 {170, "CO", "CO", "COL", /* 170 */ "Colombia"}, 1404{ 170, "CO", "CO", "COL", /* 170 */"Colombia" },
1316 {188, "CR", "CR", "CRI", /* 188 */ "Costa Rica"}, 1405{ 188, "CR", "CR", "CRI", /* 188 */"Costa Rica" },
1317 {192, "C", "CU", "CUB", /* 192 */ "Cuba"}, 1406{ 192, "C", "CU", "CUB", /* 192 */"Cuba" },
1318 {132, "CV", "CV", "CPV", /* 132 */ "Cape Verde"}, 1407{ 132, "CV", "CV", "CPV", /* 132 */"Cape Verde" },
1319 {162, NULL, "CX", "CXR", /* 162 */ "Christmas Island"}, 1408{ 162, NULL, "CX", "CXR", /* 162 */"Christmas Island" },
1320 {196, "CY", "CY", "CYP", /* 196 */ "Cyprus"}, 1409{ 196, "CY", "CY", "CYP", /* 196 */"Cyprus" },
1321 {203, "CZ", "CZ", "CZE", /* 203 */ "Czech Republic"}, 1410{ 203, "CZ", "CZ", "CZE", /* 203 */"Czech Republic" },
1322 {276, "D", "DE", "DEU", /* 276 */ "Germany"}, 1411{ 276, "D", "DE", "DEU", /* 276 */"Germany" },
1323 {262, "DJI", "DJ", "DJI", /* 262 */ "Djibouti"}, 1412{ 262, "DJI", "DJ", "DJI", /* 262 */"Djibouti" },
1324 {208, "DK", "DK", "DNK", /* 208 */ "Denmark"}, 1413{ 208, "DK", "DK", "DNK", /* 208 */"Denmark" },
1325 {212, "WD", "DM", "DMA", /* 212 */ "Dominica"}, 1414{ 212, "WD", "DM", "DMA", /* 212 */"Dominica" },
1326 {214, "DOM", "DO", "DOM", /* 214 */ "Dominican Republic"}, 1415{ 214, "DOM", "DO", "DOM", /* 214 */
1416"Dominican Republic" },
1327 { 12, "DZ", "DZ", "DZA", /* 012 */ "Algeria"}, 1417{ 12, "DZ", "DZ", "DZA", /* 012 */"Algeria" },
1328 {218, "EC", "EC", "ECU", /* 218 */ "Ecuador"}, 1418{ 218, "EC", "EC", "ECU", /* 218 */"Ecuador" },
1329 {233, "EST", "EE", "EST", /* 233 */ "Estonia"}, 1419{ 233, "EST", "EE", "EST", /* 233 */"Estonia" },
1330 {818, "ET", "EG", "EGY", /* 818 */ "Egypt"}, 1420{ 818, "ET", "EG", "EGY", /* 818 */"Egypt" },
1331 {732, "WSA", "EH", "ESH", /* 732 */ "Western Sahara"}, 1421{ 732, "WSA", "EH", "ESH", /* 732 */"Western Sahara" },
1332 {232, "ER", "ER", "ERI", /* 232 */ "Eritrea"}, 1422{ 232, "ER", "ER", "ERI", /* 232 */"Eritrea" },
1333 {724, "E", "ES", "ESP", /* 724 */ "Spain"}, 1423{ 724, "E", "ES", "ESP", /* 724 */"Spain" },
1334 {231, "ETH", "ET", "ETH", /* 231 */ "Ethiopia"}, 1424{ 231, "ETH", "ET", "ETH", /* 231 */"Ethiopia" },
1335 {246, "FIN", "FI", "FIN", /* 246 */ "Finland"}, 1425{ 246, "FIN", "FI", "FIN", /* 246 */"Finland" },
1336 {242, "FJI", "FJ", "FJI", /* 242 */ "Fiji"}, 1426{ 242, "FJI", "FJ", "FJI", /* 242 */"Fiji" },
1337 {238, NULL, "FK", "FLK", /* 238 */ "Falkland Islands (Malvinas)"}, 1427{ 238, NULL, "FK", "FLK", /* 238 */
1338 {583, "FSM", "FM", "FSM", /* 583 */ "Micronesia, Federated States of"}, 1428"Falkland Islands (Malvinas)" },
1429{ 583, "FSM", "FM", "FSM", /* 583 */
1430"Micronesia, Federated States of" },
1339 {234, "FO", "FO", "FRO", /* 234 */ "Faroe Islands"}, 1431{ 234, "FO", "FO", "FRO", /* 234 */"Faroe Islands" },
1340 {250, "F", "FR", "FRA", /* 250 */ "France"}, 1432{ 250, "F", "FR", "FRA", /* 250 */"France" },
1341 {266, "G", "GA", "GAB", /* 266 */ "Gabon"}, 1433{ 266, "G", "GA", "GAB", /* 266 */"Gabon" },
1342 {826, "GB", "GB", "GBR", /* 826 */ "United Kingdom"}, 1434{ 826, "GB", "GB", "GBR", /* 826 */"United Kingdom" },
1343 {308, "WG", "GD", "GRD", /* 308 */ "Grenada"}, 1435{ 308, "WG", "GD", "GRD", /* 308 */"Grenada" },
1344 {268, "GE", "GE", "GEO", /* 268 */ "Georgia"}, 1436{ 268, "GE", "GE", "GEO", /* 268 */"Georgia" },
1345 {254, NULL, "GF", "GUF", /* 254 */ "French Guiana"}, 1437{ 254, NULL, "GF", "GUF", /* 254 */"French Guiana" },
1346 {831, NULL, "GG", "GGY", /* 831 */ "Guernsey"}, 1438{ 831, NULL, "GG", "GGY", /* 831 */"Guernsey" },
1347 {288, "GH", "GH", "GHA", /* 288 */ "Ghana"}, 1439{ 288, "GH", "GH", "GHA", /* 288 */"Ghana" },
1348 {292, "GBZ", "GI", "GIB", /* 292 */ "Gibraltar"}, 1440{ 292, "GBZ", "GI", "GIB", /* 292 */"Gibraltar" },
1349 {304, "KN", "GL", "GRL", /* 304 */ "Greenland"}, 1441{ 304, "KN", "GL", "GRL", /* 304 */"Greenland" },
1350 {270, "WAG", "GM", "GMB", /* 270 */ "Gambia"}, 1442{ 270, "WAG", "GM", "GMB", /* 270 */"Gambia" },
1351 {324, "RG", "GN", "GIN", /* 324 */ "Guinea"}, 1443{ 324, "RG", "GN", "GIN", /* 324 */"Guinea" },
1352 {312, NULL, "GP", "GLP", /* 312 */ "Guadeloupe"}, 1444{ 312, NULL, "GP", "GLP", /* 312 */"Guadeloupe" },
1353 {226, "GQ", "GQ", "GNQ", /* 226 */ "Equatorial Guinea"}, 1445{ 226, "GQ", "GQ", "GNQ", /* 226 */"Equatorial Guinea" },
1354 {300, "GR", "GR", "GRC", /* 300 */ "Greece"}, 1446{ 300, "GR", "GR", "GRC", /* 300 */"Greece" },
1355 {239, NULL, "GS", "SGS", /* 239 */ "South Georgia and the South Sandwich Islands"}, 1447{ 239, NULL, "GS", "SGS", /* 239 */
1448"South Georgia and the South Sandwich Islands" },
1356 {320, "GCA", "GT", "GTM", /* 320 */ "Guatemala"}, 1449{ 320, "GCA", "GT", "GTM", /* 320 */"Guatemala" },
1357 {316, NULL, "GU", "GUM", /* 316 */ "Guam"}, 1450{ 316, NULL, "GU", "GUM", /* 316 */"Guam" },
1358 {624, "GUB", "GW", "GNB", /* 624 */ "Guinea-Bissau"}, 1451{ 624, "GUB", "GW", "GNB", /* 624 */"Guinea-Bissau" },
1359 {328, "GUY", "GY", "GUY", /* 328 */ "Guyana"}, 1452{ 328, "GUY", "GY", "GUY", /* 328 */"Guyana" },
1360 {344, "HK", "HK", "HKG", /* 344 */ "Hong Kong"}, 1453{ 344, "HK", "HK", "HKG", /* 344 */"Hong Kong" },
1361 {334, NULL, "HM", "HMD", /* 334 */ "Heard Island and McDonald Islands"}, 1454{ 334, NULL, "HM", "HMD", /* 334 */
1455"Heard Island and McDonald Islands" },
1362 {340, "HN", "HN", "HND", /* 340 */ "Honduras"}, 1456{ 340, "HN", "HN", "HND", /* 340 */"Honduras" },
1363 {191, "HR", "HR", "HRV", /* 191 */ "Croatia"}, 1457{ 191, "HR", "HR", "HRV", /* 191 */"Croatia" },
1364 {332, "RH", "HT", "HTI", /* 332 */ "Haiti"}, 1458{ 332, "RH", "HT", "HTI", /* 332 */"Haiti" },
1365 {348, "H", "HU", "HUN", /* 348 */ "Hungary"}, 1459{ 348, "H", "HU", "HUN", /* 348 */"Hungary" },
1366 {360, "RI", "ID", "IDN", /* 360 */ "Indonesia"}, 1460{ 360, "RI", "ID", "IDN", /* 360 */"Indonesia" },
1367 {372, "IRL", "IE", "IRL", /* 372 */ "Ireland"}, 1461{ 372, "IRL", "IE", "IRL", /* 372 */"Ireland" },
1368 {376, "IL", "IL", "ISR", /* 376 */ "Israel"}, 1462{ 376, "IL", "IL", "ISR", /* 376 */"Israel" },
1369 {833, NULL, "IM", "IMN", /* 833 */ "Isle of Man"}, 1463{ 833, NULL, "IM", "IMN", /* 833 */"Isle of Man" },
1370 {356, "IND", "IN", "IND", /* 356 */ "India"}, 1464{ 356, "IND", "IN", "IND", /* 356 */"India" },
1371 { 86, NULL, "IO", "IOT", /* 086 */ "British Indian Ocean Territory"}, 1465{ 86, NULL, "IO", "IOT", /* 086 */
1466"British Indian Ocean Territory" },
1372 {368, "IRQ", "IQ", "IRQ", /* 368 */ "Iraq"}, 1467{ 368, "IRQ", "IQ", "IRQ", /* 368 */"Iraq" },
1373 {364, "IR", "IR", "IRN", /* 364 */ "Iran, Islamic Republic of"}, 1468{ 364, "IR", "IR", "IRN", /* 364 */
1469"Iran, Islamic Republic of" },
1374 {352, "IS", "IS", "ISL", /* 352 */ "Iceland"}, 1470{ 352, "IS", "IS", "ISL", /* 352 */"Iceland" },
1375 {380, "I", "IT", "ITA", /* 380 */ "Italy"}, 1471{ 380, "I", "IT", "ITA", /* 380 */"Italy" },
1376 {832, NULL, "JE", "JEY", /* 832 */ "Jersey"}, 1472{ 832, NULL, "JE", "JEY", /* 832 */"Jersey" },
1377 {388, "JA", "JM", "JAM", /* 388 */ "Jamaica"}, 1473{ 388, "JA", "JM", "JAM", /* 388 */"Jamaica" },
1378 {400, "JOR", "JO", "JOR", /* 400 */ "Jordan"}, 1474{ 400, "JOR", "JO", "JOR", /* 400 */"Jordan" },
1379 {392, "J", "JP", "JPN", /* 392 */ "Japan"}, 1475{ 392, "J", "JP", "JPN", /* 392 */"Japan" },
1380 {404, "EAK", "KE", "KEN", /* 404 */ "Kenya"}, 1476{ 404, "EAK", "KE", "KEN", /* 404 */"Kenya" },
1381 {417, "KS", "KG", "KGZ", /* 417 */ "Kyrgyzstan"}, 1477{ 417, "KS", "KG", "KGZ", /* 417 */"Kyrgyzstan" },
1382 {116, "K", "KH", "KHM", /* 116 */ "Cambodia"}, 1478{ 116, "K", "KH", "KHM", /* 116 */"Cambodia" },
1383 {296, "KIR", "KI", "KIR", /* 296 */ "Kiribati"}, 1479{ 296, "KIR", "KI", "KIR", /* 296 */"Kiribati" },
1384 {174, "COM", "KM", "COM", /* 174 */ "Comoros"}, 1480{ 174, "COM", "KM", "COM", /* 174 */"Comoros" },
1385 {659, "KAN", "KN", "KNA", /* 659 */ "Saint Kitts and Nevis"}, 1481{ 659, "KAN", "KN", "KNA", /* 659 */
1386 {408, "KP", "KP", "PRK", /* 408 */ "Korea, Democratic People's Republic of"}, 1482"Saint Kitts and Nevis" },
1387 {410, "ROK", "KR", "KOR", /* 410 */ "Korea, Republic of"}, 1483{ 408, "KP", "KP", "PRK", /* 408 */
1484"Korea, Democratic People's Republic of" },
1485{ 410, "ROK", "KR", "KOR", /* 410 */
1486"Korea, Republic of" },
1388 {414, "KWT", "KW", "KWT", /* 414 */ "Kuwait"}, 1487{ 414, "KWT", "KW", "KWT", /* 414 */"Kuwait" },
1389 {136, NULL, "KY", "CYM", /* 136 */ "Cayman Islands"}, 1488{ 136, NULL, "KY", "CYM", /* 136 */"Cayman Islands" },
1390 {398, "KZ", "KZ", "KAZ", /* 398 */ "Kazakhstan"}, 1489{ 398, "KZ", "KZ", "KAZ", /* 398 */"Kazakhstan" },
1391 {418, "LAO", "LA", "LAO", /* 418 */ "Lao People's Democratic Republic"}, 1490{ 418, "LAO", "LA", "LAO", /* 418 */
1491"Lao People's Democratic Republic" },
1392 {422, "RL", "LB", "LBN", /* 422 */ "Lebanon"}, 1492{ 422, "RL", "LB", "LBN", /* 422 */"Lebanon" },
1393 {662, "WL", "LC", "LCA", /* 662 */ "Saint Lucia"}, 1493{ 662, "WL", "LC", "LCA", /* 662 */"Saint Lucia" },
1394 {438, "FL", "LI", "LIE", /* 438 */ "Liechtenstein"}, 1494{ 438, "FL", "LI", "LIE", /* 438 */"Liechtenstein" },
1395 {144, "CL", "LK", "LKA", /* 144 */ "Sri Lanka"}, 1495{ 144, "CL", "LK", "LKA", /* 144 */"Sri Lanka" },
1396 {430, "LB", "LR", "LBR", /* 430 */ "Liberia"}, 1496{ 430, "LB", "LR", "LBR", /* 430 */"Liberia" },
1397 {426, "LS", "LS", "LSO", /* 426 */ "Lesotho"}, 1497{ 426, "LS", "LS", "LSO", /* 426 */"Lesotho" },
1398 {440, "LT", "LT", "LTU", /* 440 */ "Lithuania"}, 1498{ 440, "LT", "LT", "LTU", /* 440 */"Lithuania" },
1399 {442, "L", "LU", "LUX", /* 442 */ "Luxembourg"}, 1499{ 442, "L", "LU", "LUX", /* 442 */"Luxembourg" },
1400 {428, "LV", "LV", "LVA", /* 428 */ "Latvia"}, 1500{ 428, "LV", "LV", "LVA", /* 428 */"Latvia" },
1401 {434, "LAR", "LY", "LBY", /* 434 */ "Libyan Arab Jamahiriya"}, 1501{ 434, "LAR", "LY", "LBY", /* 434 */
1502"Libyan Arab Jamahiriya" },
1402 {504, "MA", "MA", "MAR", /* 504 */ "Morocco"}, 1503{ 504, "MA", "MA", "MAR", /* 504 */"Morocco" },
1403 {492, "MC", "MC", "MCO", /* 492 */ "Monaco"}, 1504{ 492, "MC", "MC", "MCO", /* 492 */"Monaco" },
1404 {498, "MD", "MD", "MDA", /* 498 */ "Moldova, Republic of"}, 1505{ 498, "MD", "MD", "MDA", /* 498 */
1506"Moldova, Republic of" },
1405 {499, "MNE", "ME", "MNE", /* 499 */ "Montenegro"}, 1507{ 499, "MNE", "ME", "MNE", /* 499 */"Montenegro" },
1406 {663, NULL, "MF", "MAF", /* 663 */ "Saint Martin (French part)"}, 1508{ 663, NULL, "MF", "MAF", /* 663 */
1509"Saint Martin (French part)" },
1407 {450, "RM", "MG", "MDG", /* 450 */ "Madagascar"}, 1510{ 450, "RM", "MG", "MDG", /* 450 */"Madagascar" },
1408 {584, "MH", "MH", "MHL", /* 584 */ "Marshall Islands"}, 1511{ 584, "MH", "MH", "MHL", /* 584 */"Marshall Islands" },
1409 {807, "MK", "MK", "MKD", /* 807 */ "Macedonia, the former Yugoslav Republic of"}, 1512{ 807, "MK", "MK", "MKD", /* 807 */
1513"Macedonia, the former Yugoslav Republic of" },
1410 {466, "RMM", "ML", "MLI", /* 466 */ "Mali"}, 1514{ 466, "RMM", "ML", "MLI", /* 466 */"Mali" },
1411 {104, "MYA", "MM", "MMR", /* 104 */ "Myanmar"}, 1515{ 104, "MYA", "MM", "MMR", /* 104 */"Myanmar" },
1412 {496, "MGL", "MN", "MNG", /* 496 */ "Mongolia"}, 1516{ 496, "MGL", "MN", "MNG", /* 496 */"Mongolia" },
1413 {446, NULL, "MO", "MAC", /* 446 */ "Macao"}, 1517{ 446, NULL, "MO", "MAC", /* 446 */"Macao" },
1414 {580, NULL, "MP", "MNP", /* 580 */ "Northern Mariana Islands"}, 1518{ 580, NULL, "MP", "MNP", /* 580 */
1519"Northern Mariana Islands" },
1415 {474, NULL, "MQ", "MTQ", /* 474 */ "Martinique"}, 1520{ 474, NULL, "MQ", "MTQ", /* 474 */"Martinique" },
1416 {478, "RIM", "MR", "MRT", /* 478 */ "Mauritania"}, 1521{ 478, "RIM", "MR", "MRT", /* 478 */"Mauritania" },
1417 {500, NULL, "MS", "MSR", /* 500 */ "Montserrat"}, 1522{ 500, NULL, "MS", "MSR", /* 500 */"Montserrat" },
1418 {470, "M", "MT", "MLT", /* 470 */ "Malta"}, 1523{ 470, "M", "MT", "MLT", /* 470 */"Malta" },
1419 {480, "MS", "MU", "MUS", /* 480 */ "Mauritius"}, 1524{ 480, "MS", "MU", "MUS", /* 480 */"Mauritius" },
1420 {462, "MV", "MV", "MDV", /* 462 */ "Maldives"}, 1525{ 462, "MV", "MV", "MDV", /* 462 */"Maldives" },
1421 {454, "MW", "MW", "MWI", /* 454 */ "Malawi"}, 1526{ 454, "MW", "MW", "MWI", /* 454 */"Malawi" },
1422 {484, "MEX", "MX", "MEX", /* 484 */ "Mexico"}, 1527{ 484, "MEX", "MX", "MEX", /* 484 */"Mexico" },
1423 {458, "MAL", "MY", "MYS", /* 458 */ "Malaysia"}, 1528{ 458, "MAL", "MY", "MYS", /* 458 */"Malaysia" },
1424 {508, "MOC", "MZ", "MOZ", /* 508 */ "Mozambique"}, 1529{ 508, "MOC", "MZ", "MOZ", /* 508 */"Mozambique" },
1425 {516, "NAM", "NA", "NAM", /* 516 */ "Namibia"}, 1530{ 516, "NAM", "NA", "NAM", /* 516 */"Namibia" },
1426 {540, "NCL", "NC", "NCL", /* 540 */ "New Caledonia"}, 1531{ 540, "NCL", "NC", "NCL", /* 540 */"New Caledonia" },
1427 {562, "RN", "NE", "NER", /* 562 */ "Niger"}, 1532{ 562, "RN", "NE", "NER", /* 562 */"Niger" },
1428 {574, NULL, "NF", "NFK", /* 574 */ "Norfolk Island"}, 1533{ 574, NULL, "NF", "NFK", /* 574 */"Norfolk Island" },
1429 {566, "NGR", "NG", "NGA", /* 566 */ "Nigeria"}, 1534{ 566, "NGR", "NG", "NGA", /* 566 */"Nigeria" },
1430 {558, "NIC", "NI", "NIC", /* 558 */ "Nicaragua"}, 1535{ 558, "NIC", "NI", "NIC", /* 558 */"Nicaragua" },
1431 {528, "NL", "NL", "NLD", /* 528 */ "Netherlands"}, 1536{ 528, "NL", "NL", "NLD", /* 528 */"Netherlands" },
1432 {578, "N", "NO", "NOR", /* 578 */ "Norway"}, 1537{ 578, "N", "NO", "NOR", /* 578 */"Norway" },
1433 {524, "NEP", "NP", "NPL", /* 524 */ "Nepal"}, 1538{ 524, "NEP", "NP", "NPL", /* 524 */"Nepal" },
1434 {520, "NAU", "NR", "NRU", /* 520 */ "Nauru"}, 1539{ 520, "NAU", "NR", "NRU", /* 520 */"Nauru" },
1435 {570, NULL, "NU", "NIU", /* 570 */ "Niue"}, 1540{ 570, NULL, "NU", "NIU", /* 570 */"Niue" },
1436 {554, "NZ", "NZ", "NZL", /* 554 */ "New Zealand"}, 1541{ 554, "NZ", "NZ", "NZL", /* 554 */"New Zealand" },
1437 {512, "OM", "OM", "OMN", /* 512 */ "Oman"}, 1542{ 512, "OM", "OM", "OMN", /* 512 */"Oman" },
1438 {591, "PA", "PA", "PAN", /* 591 */ "Panama"}, 1543{ 591, "PA", "PA", "PAN", /* 591 */"Panama" },
1439 {604, "PE", "PE", "PER", /* 604 */ "Peru"}, 1544{ 604, "PE", "PE", "PER", /* 604 */"Peru" },
1440 {258, NULL, "PF", "PYF", /* 258 */ "French Polynesia"}, 1545{ 258, NULL, "PF", "PYF", /* 258 */"French Polynesia" },
1441 {598, "PNG", "PG", "PNG", /* 598 */ "Papua New Guinea"}, 1546{ 598, "PNG", "PG", "PNG", /* 598 */"Papua New Guinea" },
1442 {608, "RP", "PH", "PHL", /* 608 */ "Philippines"}, 1547{ 608, "RP", "PH", "PHL", /* 608 */"Philippines" },
1443 {586, "PK", "PK", "PAK", /* 586 */ "Pakistan"}, 1548{ 586, "PK", "PK", "PAK", /* 586 */"Pakistan" },
1444 {616, "PL", "PL", "POL", /* 616 */ "Poland"}, 1549{ 616, "PL", "PL", "POL", /* 616 */"Poland" },
1445 {666, NULL, "PM", "SPM", /* 666 */ "Saint Pierre and Miquelon"}, 1550{ 666, NULL, "PM", "SPM", /* 666 */
1551"Saint Pierre and Miquelon" },
1446 {612, NULL, "PN", "PCN", /* 612 */ "Pitcairn"}, 1552{ 612, NULL, "PN", "PCN", /* 612 */"Pitcairn" },
1447 {630, "PRI", "PR", "PRI", /* 630 */ "Puerto Rico"}, 1553{ 630, "PRI", "PR", "PRI", /* 630 */"Puerto Rico" },
1448 {275, "AUT", "PS", "PSE", /* 275 */ "Palestinian Territory, Occupied"}, 1554{ 275, "AUT", "PS", "PSE", /* 275 */
1555"Palestinian Territory, Occupied" },
1449 {620, "P", "PT", "PRT", /* 620 */ "Portugal"}, 1556{ 620, "P", "PT", "PRT", /* 620 */"Portugal" },
1450 {585, "PAL", "PW", "PLW", /* 585 */ "Palau"}, 1557{ 585, "PAL", "PW", "PLW", /* 585 */"Palau" },
1451 {600, "PY", "PY", "PRY", /* 600 */ "Paraguay"}, 1558{ 600, "PY", "PY", "PRY", /* 600 */"Paraguay" },
1452 {634, "Q", "QA", "QAT", /* 634 */ "Qatar"}, 1559{ 634, "Q", "QA", "QAT", /* 634 */"Qatar" },
1453 {638, NULL, "RE", "REU", /* 638 */ "Reunion"}, 1560{ 638, NULL, "RE", "REU", /* 638 */"Reunion" },
1454 {642, "RO", "RO", "ROU", /* 642 */ "Romania"}, 1561{ 642, "RO", "RO", "ROU", /* 642 */"Romania" },
1455 {688, "SRB", "RS", "SRB", /* 688 */ "Serbia"}, 1562{ 688, "SRB", "RS", "SRB", /* 688 */"Serbia" },
1456 {643, "RUS", "RU", "RUS", /* 643 */ "Russian Federation"}, 1563{ 643, "RUS", "RU", "RUS", /* 643 */
1564"Russian Federation" },
1457 {646, "RWA", "RW", "RWA", /* 646 */ "Rwanda"}, 1565{ 646, "RWA", "RW", "RWA", /* 646 */"Rwanda" },
1458 {682, "KSA", "SA", "SAU", /* 682 */ "Saudi Arabia"}, 1566{ 682, "KSA", "SA", "SAU", /* 682 */"Saudi Arabia" },
1459 { 90, "SOL", "SB", "SLB", /* 090 */ "Solomon Islands"}, 1567{ 90, "SOL", "SB", "SLB", /* 090 */"Solomon Islands" },
1460 {690, "SY", "SC", "SYC", /* 690 */ "Seychelles"}, 1568{ 690, "SY", "SC", "SYC", /* 690 */"Seychelles" },
1461 {736, "SUD", "SD", "SDN", /* 736 */ "Sudan"}, 1569{ 736, "SUD", "SD", "SDN", /* 736 */"Sudan" },
1462 {752, "S", "SE", "SWE", /* 752 */ "Sweden"}, 1570{ 752, "S", "SE", "SWE", /* 752 */"Sweden" },
1463 {702, "SGP", "SG", "SGP", /* 702 */ "Singapore"}, 1571{ 702, "SGP", "SG", "SGP", /* 702 */"Singapore" },
1464 {654, NULL, "SH", "SHN", /* 654 */ "Saint Helena"}, 1572{ 654, NULL, "SH", "SHN", /* 654 */"Saint Helena" },
1465 {705, "SLO", "SI", "SVN", /* 705 */ "Slovenia"}, 1573{ 705, "SLO", "SI", "SVN", /* 705 */"Slovenia" },
1466 {744, NULL, "SJ", "SJM", /* 744 */ "Svalbard and Jan Mayen"}, 1574{ 744, NULL, "SJ", "SJM", /* 744 */
1575"Svalbard and Jan Mayen" },
1467 {703, "SK", "SK", "SVK", /* 703 */ "Slovakia"}, 1576{ 703, "SK", "SK", "SVK", /* 703 */"Slovakia" },
1468 {694, "WAL", "SL", "SLE", /* 694 */ "Sierra Leone"}, 1577{ 694, "WAL", "SL", "SLE", /* 694 */"Sierra Leone" },
1469 {674, "RSM", "SM", "SMR", /* 674 */ "San Marino"}, 1578{ 674, "RSM", "SM", "SMR", /* 674 */"San Marino" },
1470 {686, "SN", "SN", "SEN", /* 686 */ "Senegal"}, 1579{ 686, "SN", "SN", "SEN", /* 686 */"Senegal" },
1471 {706, "SO", "SO", "SOM", /* 706 */ "Somalia"}, 1580{ 706, "SO", "SO", "SOM", /* 706 */"Somalia" },
1472 {740, "SME", "SR", "SUR", /* 740 */ "Suriname"}, 1581{ 740, "SME", "SR", "SUR", /* 740 */"Suriname" },
1473 {678, "STP", "ST", "STP", /* 678 */ "Sao Tome and Principe"}, 1582{ 678, "STP", "ST", "STP", /* 678 */
1583"Sao Tome and Principe" },
1474 {222, "ES", "SV", "SLV", /* 222 */ "El Salvador"}, 1584{ 222, "ES", "SV", "SLV", /* 222 */"El Salvador" },
1475 {760, "SYR", "SY", "SYR", /* 760 */ "Syrian Arab Republic"}, 1585{ 760, "SYR", "SY", "SYR", /* 760 */
1586"Syrian Arab Republic" },
1476 {748, "SD", "SZ", "SWZ", /* 748 */ "Swaziland"}, 1587{ 748, "SD", "SZ", "SWZ", /* 748 */"Swaziland" },
1477 {796, NULL, "TC", "TCA", /* 796 */ "Turks and Caicos Islands"}, 1588{ 796, NULL, "TC", "TCA", /* 796 */
1589"Turks and Caicos Islands" },
1478 {148, "TD", "TD", "TCD", /* 148 */ "Chad"}, 1590{ 148, "TD", "TD", "TCD", /* 148 */"Chad" },
1479 {260, "ARK", "TF", "ATF", /* 260 */ "French Southern Territories"}, 1591{ 260, "ARK", "TF", "ATF", /* 260 */
1592"French Southern Territories" },
1480 {768, "RT", "TG", "TGO", /* 768 */ "Togo"}, 1593{ 768, "RT", "TG", "TGO", /* 768 */"Togo" },
1481 {764, "T", "TH", "THA", /* 764 */ "Thailand"}, 1594{ 764, "T", "TH", "THA", /* 764 */"Thailand" },
1482 {762, "TJ", "TJ", "TJK", /* 762 */ "Tajikistan"}, 1595{ 762, "TJ", "TJ", "TJK", /* 762 */"Tajikistan" },
1483 {772, NULL, "TK", "TKL", /* 772 */ "Tokelau"}, 1596{ 772, NULL, "TK", "TKL", /* 772 */"Tokelau" },
1484 {626, "TL", "TL", "TLS", /* 626 */ "Timor-Leste"}, 1597{ 626, "TL", "TL", "TLS", /* 626 */"Timor-Leste" },
1485 {795, "TM", "TM", "TKM", /* 795 */ "Turkmenistan"}, 1598{ 795, "TM", "TM", "TKM", /* 795 */"Turkmenistan" },
1486 {788, "TN", "TN", "TUN", /* 788 */ "Tunisia"}, 1599{ 788, "TN", "TN", "TUN", /* 788 */"Tunisia" },
1487 {776, "TON", "TO", "TON", /* 776 */ "Tonga"}, 1600{ 776, "TON", "TO", "TON", /* 776 */"Tonga" },
1488 {792, "TR", "TR", "TUR", /* 792 */ "Turkey"}, 1601{ 792, "TR", "TR", "TUR", /* 792 */"Turkey" },
1489 {780, "TT", "TT", "TTO", /* 780 */ "Trinidad and Tobago"}, 1602{ 780, "TT", "TT", "TTO", /* 780 */
1603"Trinidad and Tobago" },
1490 {798, "TUV", "TV", "TUV", /* 798 */ "Tuvalu"}, 1604{ 798, "TUV", "TV", "TUV", /* 798 */"Tuvalu" },
1491 {158, NULL, "TW", "TWN", /* 158 */ "Taiwan, Province of China"}, 1605{ 158, NULL, "TW", "TWN", /* 158 */
1492 {834, "EAT", "TZ", "TZA", /* 834 */ "Tanzania, United Republic of"}, 1606"Taiwan, Province of China" },
1607{ 834, "EAT", "TZ", "TZA", /* 834 */
1608"Tanzania, United Republic of" },
1493 {804, "UA", "UA", "UKR", /* 804 */ "Ukraine"}, 1609{ 804, "UA", "UA", "UKR", /* 804 */"Ukraine" },
1494 {800, "EAU", "UG", "UGA", /* 800 */ "Uganda"}, 1610{ 800, "EAU", "UG", "UGA", /* 800 */"Uganda" },
1495 {581, NULL, "UM", "UMI", /* 581 */ "United States Minor Outlying Islands"}, 1611{ 581, NULL, "UM", "UMI", /* 581 */
1612"United States Minor Outlying Islands" },
1496 {840, "USA", "US", "USA", /* 840 */ "United States"}, 1613{ 840, "USA", "US", "USA", /* 840 */"United States" },
1497 {858, "ROU", "UY", "URY", /* 858 */ "Uruguay"}, 1614{ 858, "ROU", "UY", "URY", /* 858 */"Uruguay" },
1498 {860, "UZ", "UZ", "UZB", /* 860 */ "Uzbekistan"}, 1615{ 860, "UZ", "UZ", "UZB", /* 860 */"Uzbekistan" },
1499 {336, "SCV", "VA", "VAT", /* 336 */ "Holy See (Vatican City State)"}, 1616{ 336, "SCV", "VA", "VAT", /* 336 */
1617"Holy See (Vatican City State)" },
1500 {670, "WV", "VC", "VCT", /* 670 */ "Saint Vincent and the Grenadines"}, 1618{ 670, "WV", "VC", "VCT", /* 670 */"Saint Vincent and the Grenadines" },
1501 {862, "YV", "VE", "VEN", /* 862 */ "Venezuela"}, 1619{ 862, "YV", "VE", "VEN", /* 862 */"Venezuela" },
1502 { 92, NULL, "VG", "VGB", /* 092 */ "Virgin Islands, British"}, 1620{ 92, NULL, "VG", "VGB", /* 092 */ "Virgin Islands, British" },
1503 {850, NULL, "VI", "VIR", /* 850 */ "Virgin Islands, U.S."}, 1621{ 850, NULL, "VI", "VIR", /* 850 */ "Virgin Islands, U.S." },
1504 {704, "VN", "VN", "VNM", /* 704 */ "Viet Nam"}, 1622{ 704, "VN", "VN", "VNM", /* 704 */"Viet Nam" },
1505 {548, "VAN", "VU", "VUT", /* 548 */ "Vanuatu"}, 1623{ 548, "VAN", "VU", "VUT", /* 548 */"Vanuatu" },
1506 {876, NULL, "WF", "WLF", /* 876 */ "Wallis and Futuna"}, 1624{ 876, NULL, "WF", "WLF", /* 876 */"Wallis and Futuna" },
1507 {882, "WS", "WS", "WSM", /* 882 */ "Samoa"}, 1625{ 882, "WS", "WS", "WSM", /* 882 */"Samoa" },
1508 {887, "YAR", "YE", "YEM", /* 887 */ "Yemen"}, 1626{ 887, "YAR", "YE", "YEM", /* 887 */"Yemen" },
1509 {175, NULL, "YT", "MYT", /* 175 */ "Mayotte"}, 1627{ 175, NULL, "YT", "MYT", /* 175 */"Mayotte" },
1510 {710, "ZA", "ZA", "ZAF", /* 710 */ "South Africa"}, 1628{ 710, "ZA", "ZA", "ZAF", /* 710 */"South Africa" },
1511 {894, "Z", "ZM", "ZMB", /* 894 */ "Zambia"}, 1629{ 894, "Z", "ZM", "ZMB", /* 894 */"Zambia" },
1512 {716, "ZW", "ZW", "ZWE", /* 716 */ "Zimbabwe"}, 1630{ 716, "ZW", "ZW", "ZWE", /* 716 */"Zimbabwe" },
1513 {999, "*", "*", "*", "Unknown"}, 1631{ 999, "*", "*", "*", /* 999 */"Unknown" }, };
1514};
1515 1632
1516
1517static int
1518ascii_cmp_local(char *name, char *match, int partial) 1633static int ascii_cmp_local(char *name, char *match, int partial)
1519{ 1634{
1520 char *s1=linguistics_casefold(name); 1635 char *s1 = linguistics_casefold(name);
1521 char *s2=linguistics_casefold(match); 1636 char *s2 = linguistics_casefold(match);
1522 int ret=linguistics_compare(s1,s2,partial); 1637 int ret = linguistics_compare(s1, s2, partial);
1523 g_free(s1); 1638 g_free(s1);
1524 g_free(s2); 1639 g_free(s2);
1525 return ret; 1640 return ret;
1526} 1641}
1527 1642
1528struct navit *global_navit; 1643struct navit *global_navit;
1529 1644
1530
1531void
1532search_full_world(char *addr, int partial, int search_order, struct jni_object *jni,struct coord_geo *search_center, int search_radius) 1645void search_full_world(char *addr, int partial, int search_order, struct jni_object *jni, struct coord_geo *search_center, int search_radius)
1533{ 1646{
1534 struct item *item; 1647 struct item *item;
1535 struct map_rect *mr=NULL; 1648 struct map_rect *mr = NULL;
1536 struct mapset *ms; 1649 struct mapset *ms;
1537 struct mapset_handle *msh; 1650 struct mapset_handle *msh;
1538 struct map* map = NULL; 1651 struct map* map = NULL;
1539 struct attr map_name_attr; 1652 struct attr map_name_attr;
1540 struct attr attr; 1653 struct attr attr;
1541 1654
1542 char *str=search_fix_spaces(addr); 1655 char *str = search_fix_spaces(addr);
1543 GList *phrases=search_split_phrases(str); 1656 GList *phrases = search_split_phrases(str);
1544 GList *phrases_first; 1657 GList *phrases_first;
1545 phrases_first=phrases; 1658 phrases_first = phrases;
1546 1659
1547 ms=global_navit->mapsets->data; 1660 ms = global_navit->mapsets->data;
1548 msh=mapset_open(ms); 1661 msh = mapset_open(ms);
1549 1662
1550 struct pcoord center99; 1663 struct pcoord center99;
1551 int search_radius_this=0; 1664 int search_radius_this = 0;
1552 dbg(0,"in lat=%f,lng=%f\n",search_center->lat,search_center->lng); 1665 dbg(0, "in lat=%f,lng=%f\n", search_center->lat, search_center->lng);
1553 if ((search_center->lat == 0)&&(search_center->lng == 0)) 1666 if ((search_center->lat == 0) && (search_center->lng == 0))
1554 { 1667 {
1555 center99.x=0; 1668 center99.x = 0;
1556 center99.y=0; 1669 center99.y = 0;
1557 search_radius_this=21000000; 1670 search_radius_this = 21000000;
1558 } 1671 }
1559 else 1672 else
1560 { 1673 {
1561 struct coord c99; 1674 struct coord c99;
1562 transform_from_geo(projection_mg, search_center, &c99); 1675 transform_from_geo(projection_mg, search_center, &c99);
1563 center99.x=c99.x; 1676 center99.x = c99.x;
1564 center99.y=c99.y; 1677 center99.y = c99.y;
1565 search_radius_this=search_radius; 1678 search_radius_this = search_radius;
1566 } 1679 }
1567 dbg(0,"out x=%d,y=%d,r=%d\n",center99.x,center99.y,search_radius_this); 1680 dbg(0, "out x=%d,y=%d,r=%d\n", center99.x, center99.y, search_radius_this);
1568 1681
1569 struct map_selection *sel=map_selection_rect_new(&center99, search_radius_this, search_order); 1682 struct map_selection *sel = map_selection_rect_new(&center99, search_radius_this, search_order);
1570 sel->range.min=type_town_label; 1683 sel->range.min = type_town_label;
1571 sel->range.max=type_area; 1684 sel->range.max = type_area;
1572 1685
1573 while (msh && (map=mapset_next(msh, 0))) 1686 while (msh && (map = mapset_next(msh, 0)))
1574 { 1687 {
1575 if(map_get_attr(map,attr_name, &map_name_attr,NULL)) 1688 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
1576 { 1689 {
1577 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0) 1690 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
1578 { 1691 {
1579 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0) 1692 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
1580 { 1693 {
1581 // its an sdcard map 1694 // its an sdcard map
1582 //dbg(0,"map name=%s",map_name_attr.u.str); 1695 //dbg(0,"map name=%s",map_name_attr.u.str);
1583 // mr=map_rect_new(map, NULL); 1696 // mr=map_rect_new(map, NULL);
1584 mr=map_rect_new(map, sel); 1697 mr = map_rect_new(map, sel);
1585 if (mr) 1698 if (mr)
1586 { 1699 {
1587 char *streetname_last=NULL; 1700 char *streetname_last = NULL;
1588 1701
1589 while ((item=map_rect_get_item(mr))) 1702 while ((item = map_rect_get_item(mr)))
1590 { 1703 {
1591 if ( (item_is_town(*item)) || (item_is_district(*item)) ) 1704 if ((item_is_town(*item)) || (item_is_district(*item)))
1705 {
1706 struct search_list_town *p = NULL;
1707
1708 if (item_attr_get(item, attr_town_name, &attr))
1592 { 1709 {
1593 struct search_list_town *p=NULL; 1710 p = search_list_town_new(item);
1711 char *buffer = NULL;
1712 // coords of result
1713 struct coord_geo g;
1714 struct coord c;
1715 c.x = p->common.c->x;
1716 c.y = p->common.c->y;
1717 int calc_geo = 0;
1594 1718
1595 if (item_attr_get(item, attr_town_name, &attr)) 1719 // dbg(0,"town name=%s\n", attr.u.str);
1720
1721 phrases = phrases_first;
1722 while (phrases)
1596 { 1723 {
1724 if (!ascii_cmp_local(attr.u.str, phrases->data, partial))
1725 {
1726 // dbg(0,"matched town name=%s want=%s\n", attr.u.str, phrases->data);
1727 if (calc_geo == 0)
1728 {
1729 transform_to_geo(p->common.c->pro, &c, &g);
1730 // TWN -> town
1731 calc_geo = 1;
1732 }
1733 if (p->common.postal == NULL)
1734 {
1735 buffer = g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, p->common.town_name);
1736 }
1737 else
1738 {
1739 buffer = g_strdup_printf("TWN:H%dL%d:%f:%f:%.7s %.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, p->common.postal, p->common.town_name);
1740 }
1741#ifdef HAVE_API_ANDROID
1742 // return results to android as they come in ...
1743 android_return_search_result(jni,buffer);
1744#endif
1745 }
1746 phrases = g_list_next(phrases);
1747
1748 }
1749 if (buffer)
1750 {
1751 g_free(buffer);
1752 }
1753 search_list_town_destroy(p);
1754 }
1755
1756 if (item_attr_get(item, attr_town_name_match, &attr))
1757 {
1597 p=search_list_town_new(item); 1758 p = search_list_town_new(item);
1759 char *buffer = NULL;
1760 // coords of result
1761 struct coord_geo g;
1762 struct coord c;
1763 c.x = p->common.c->x;
1764 c.y = p->common.c->y;
1765 int calc_geo = 0;
1766
1767 // dbg(0,"town name=%s\n", attr.u.str);
1768
1769 phrases = phrases_first;
1770 while (phrases)
1771 {
1772 if (!ascii_cmp_local(attr.u.str, phrases->data, partial))
1773 {
1774 // dbg(0,"matched town name=%s want=%s\n", attr.u.str, phrases->data);
1775 if (calc_geo == 0)
1776 {
1777 transform_to_geo(p->common.c->pro, &c, &g);
1778 // TWN -> town
1779 calc_geo = 1;
1780 }
1781 if (p->common.postal == NULL)
1782 {
1783 buffer = g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, p->common.town_name);
1784 }
1785 else
1786 {
1787 buffer = g_strdup_printf("TWN:H%dL%d:%f:%f:%.7s %.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, p->common.postal, p->common.town_name);
1788 }
1789#ifdef HAVE_API_ANDROID
1790 // return results to android as they come in ...
1791 android_return_search_result(jni,buffer);
1792#endif
1793 }
1794 phrases = g_list_next(phrases);
1795
1796 }
1797 if (buffer)
1798 {
1799 g_free(buffer);
1800 }
1801 search_list_town_destroy(p);
1802 }
1803 }
1804 else if (item_is_street(*item))
1805 {
1806
1807 struct search_list_street *p = NULL;
1808
1809 if (item_attr_get(item, attr_label, &attr))
1810 {
1811 // dbg(0,"street1=%s\n",map_convert_string(item->map, attr.u.str));
1812 if ((streetname_last == NULL) || (strcmp(streetname_last, attr.u.str) != 0))
1813 {
1814 // dbg(0,"street2=%s\n",map_convert_string(item->map, attr.u.str));
1815 streetname_last = g_strdup_printf("%s", attr.u.str);
1816
1817 p = search_list_street_new(item);
1598 char *buffer=NULL; 1818 char *buffer = NULL;
1599 // coords of result 1819 // coords of result
1600 struct coord_geo g; 1820 struct coord_geo g;
1601 struct coord c; 1821 struct coord c;
1602 c.x=p->common.c->x; 1822 c.x = p->common.c->x;
1603 c.y=p->common.c->y; 1823 c.y = p->common.c->y;
1604 int calc_geo=0; 1824 int calc_geo = 0;
1605 1825
1606 // dbg(0,"town name=%s\n", attr.u.str);
1607
1608 phrases=phrases_first; 1826 phrases = phrases_first;
1609 while (phrases) 1827 while (phrases)
1610 { 1828 {
1611 if (!ascii_cmp_local(attr.u.str, phrases->data, partial)) 1829 if (!ascii_cmp_local(attr.u.str, phrases->data, partial))
1612 { 1830 {
1613 // dbg(0,"matched town name=%s want=%s\n", attr.u.str, phrases->data);
1614 if (calc_geo==0) 1831 if (calc_geo == 0)
1615 { 1832 {
1616 transform_to_geo(p->common.c->pro, &c, &g); 1833 transform_to_geo(p->common.c->pro, &c, &g);
1617 // TWN -> town
1618 calc_geo=1; 1834 calc_geo = 1;
1619 } 1835 }
1620 if (p->common.postal == NULL) 1836 if (p->common.postal == NULL)
1621 { 1837 {
1622 buffer=g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s",p->common.item.id_hi,p->common.item.id_lo,g.lat,g.lng,p->common.town_name); 1838 buffer = g_strdup_printf("STR:H%dL%d:%f:%f:%.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, attr.u.str);
1623 } 1839 }
1624 else 1840 else
1625 { 1841 {
1626 buffer=g_strdup_printf("TWN:H%dL%d:%f:%f:%.7s %.101s",p->common.item.id_hi,p->common.item.id_lo,g.lat,g.lng,p->common.postal,p->common.town_name); 1842 buffer = g_strdup_printf("STR:H%dL%d:%f:%f:%.7s %.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, p->common.postal, attr.u.str);
1627 } 1843 }
1844 //dbg(0,"street3=%s\n",buffer);
1628#ifdef HAVE_API_ANDROID 1845#ifdef HAVE_API_ANDROID
1629 // return results to android as they come in ... 1846 // return results to android as they come in ...
1630 android_return_search_result(jni,buffer); 1847 android_return_search_result(jni,buffer);
1631#endif 1848#endif
1632 } 1849 }
1633 phrases=g_list_next(phrases); 1850 phrases = g_list_next(phrases);
1634
1635 }
1636 if (buffer)
1637 {
1638 g_free(buffer);
1639 }
1640 search_list_town_destroy(p);
1641 }
1642 }
1643 else if (item_is_street(*item))
1644 {
1645
1646 struct search_list_street *p=NULL;
1647
1648 if (item_attr_get(item, attr_label, &attr))
1649 {
1650 // dbg(0,"street1=%s\n",map_convert_string(item->map, attr.u.str));
1651 if ( (streetname_last==NULL) || (strcmp(streetname_last,attr.u.str) != 0) )
1652 {
1653 // dbg(0,"street2=%s\n",map_convert_string(item->map, attr.u.str));
1654 streetname_last=g_strdup_printf("%s",attr.u.str);
1655
1656 p=search_list_street_new(item);
1657 char *buffer=NULL;
1658 // coords of result
1659 struct coord_geo g;
1660 struct coord c;
1661 c.x=p->common.c->x;
1662 c.y=p->common.c->y;
1663 int calc_geo=0;
1664
1665 phrases=phrases_first;
1666 while (phrases)
1667 {
1668 if (!ascii_cmp_local(attr.u.str, phrases->data, partial))
1669 {
1670 if (calc_geo==0)
1671 {
1672 transform_to_geo(p->common.c->pro, &c, &g);
1673 calc_geo=1;
1674 }
1675 if (p->common.postal == NULL)
1676 {
1677 buffer=g_strdup_printf("STR:H%dL%d:%f:%f:%.101s",p->common.item.id_hi,p->common.item.id_lo,g.lat,g.lng,attr.u.str);
1678 }
1679 else
1680 {
1681 buffer=g_strdup_printf("STR:H%dL%d:%f:%f:%.7s %.101s",p->common.item.id_hi,p->common.item.id_lo,g.lat,g.lng,p->common.postal,attr.u.str);
1682 }
1683 //dbg(0,"street3=%s\n",buffer);
1684#ifdef HAVE_API_ANDROID
1685 // return results to android as they come in ...
1686 android_return_search_result(jni,buffer);
1687#endif
1688 }
1689 phrases=g_list_next(phrases);
1690 }
1691 if (buffer)
1692 {
1693 g_free(buffer);
1694 }
1695 search_list_street_destroy(p);
1696 }
1697 }
1698 else if (item_attr_get(item, attr_street_name_systematic, &attr))
1699 {
1700 //dbg(0,"street systematic=%s\n",map_convert_string(item->map, attr.u.str));
1701
1702 p=search_list_street_new(item);
1703 char *buffer=NULL;
1704 // coords of result
1705 struct coord_geo g;
1706 struct coord c;
1707 c.x=p->common.c->x;
1708 c.y=p->common.c->y;
1709 int calc_geo=0;
1710
1711 phrases=phrases_first;
1712 while (phrases)
1713 {
1714 if (!ascii_cmp_local(attr.u.str, phrases->data, partial))
1715 {
1716 if (calc_geo==0)
1717 {
1718 transform_to_geo(p->common.c->pro, &c, &g);
1719 calc_geo=1;
1720 }
1721 if (p->common.postal == NULL)
1722 {
1723 buffer=g_strdup_printf("STR:H%dL%d:%f:%f:%.101s",p->common.item.id_hi,p->common.item.id_lo,g.lat,g.lng,attr.u.str);
1724 }
1725 else
1726 {
1727 buffer=g_strdup_printf("STR:H%dL%d:%f:%f:%.7s %.101s",p->common.item.id_hi,p->common.item.id_lo,g.lat,g.lng,p->common.postal,attr.u.str);
1728 }
1729#ifdef HAVE_API_ANDROID
1730 // return results to android as they come in ...
1731 android_return_search_result(jni,buffer);
1732#endif
1733 }
1734 phrases=g_list_next(phrases);
1735 } 1851 }
1736 if (buffer) 1852 if (buffer)
1737 { 1853 {
1738 g_free(buffer); 1854 g_free(buffer);
1739 } 1855 }
1740 search_list_street_destroy(p); 1856 search_list_street_destroy(p);
1741
1742 } 1857 }
1743 } 1858 }
1859
1860 if (item_attr_get(item, attr_street_name_match, &attr))
1861 {
1862 //dbg(0,"street systematic=%s\n",map_convert_string(item->map, attr.u.str));
1863
1864 p = search_list_street_new(item);
1865 char *buffer = NULL;
1866 // coords of result
1867 struct coord_geo g;
1868 struct coord c;
1869 c.x = p->common.c->x;
1870 c.y = p->common.c->y;
1871 int calc_geo = 0;
1872
1873 phrases = phrases_first;
1874 while (phrases)
1875 {
1876 if (!ascii_cmp_local(attr.u.str, phrases->data, partial))
1877 {
1878 if (calc_geo == 0)
1879 {
1880 transform_to_geo(p->common.c->pro, &c, &g);
1881 calc_geo = 1;
1882 }
1883 if (p->common.postal == NULL)
1884 {
1885 buffer = g_strdup_printf("STR:H%dL%d:%f:%f:%.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, attr.u.str);
1886 }
1887 else
1888 {
1889 buffer = g_strdup_printf("STR:H%dL%d:%f:%f:%.7s %.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, p->common.postal, attr.u.str);
1890 }
1891#ifdef HAVE_API_ANDROID
1892 // return results to android as they come in ...
1893 android_return_search_result(jni,buffer);
1894#endif
1895 }
1896 phrases = g_list_next(phrases);
1897 }
1898 if (buffer)
1899 {
1900 g_free(buffer);
1901 }
1902 search_list_street_destroy(p);
1903
1904 }
1905
1906 if (item_attr_get(item, attr_street_name_systematic, &attr))
1907 {
1908 //dbg(0,"street systematic=%s\n",map_convert_string(item->map, attr.u.str));
1909
1910 p = search_list_street_new(item);
1911 char *buffer = NULL;
1912 // coords of result
1913 struct coord_geo g;
1914 struct coord c;
1915 c.x = p->common.c->x;
1916 c.y = p->common.c->y;
1917 int calc_geo = 0;
1918
1919 phrases = phrases_first;
1920 while (phrases)
1921 {
1922 if (!ascii_cmp_local(attr.u.str, phrases->data, partial))
1923 {
1924 if (calc_geo == 0)
1925 {
1926 transform_to_geo(p->common.c->pro, &c, &g);
1927 calc_geo = 1;
1928 }
1929 if (p->common.postal == NULL)
1930 {
1931 buffer = g_strdup_printf("STR:H%dL%d:%f:%f:%.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, attr.u.str);
1932 }
1933 else
1934 {
1935 buffer = g_strdup_printf("STR:H%dL%d:%f:%f:%.7s %.101s", p->common.item.id_hi, p->common.item.id_lo, g.lat, g.lng, p->common.postal, attr.u.str);
1936 }
1937#ifdef HAVE_API_ANDROID
1938 // return results to android as they come in ...
1939 android_return_search_result(jni,buffer);
1940#endif
1941 }
1942 phrases = g_list_next(phrases);
1943 }
1944 if (buffer)
1945 {
1946 g_free(buffer);
1947 }
1948 search_list_street_destroy(p);
1949
1950 }
1951 }
1744 } 1952 }
1745 g_free(streetname_last); 1953 g_free(streetname_last);
1746 map_rect_destroy(mr); 1954 map_rect_destroy(mr);
1747 } 1955 }
1748 } 1956 }
1759 g_free(str); 1967 g_free(str);
1760 1968
1761 mapset_close(msh); 1969 mapset_close(msh);
1762} 1970}
1763 1971
1764
1765GList * 1972GList *
1766search_by_address(GList *result_list,struct mapset *ms, char *addr, int partial, struct jni_object *jni, int search_country_flags, char *search_country_string) 1973search_by_address(GList *result_list, struct mapset *ms, char *addr, int partial, struct jni_object *jni, int search_country_flags, char *search_country_string)
1767{ 1974{
1768 char *str=search_fix_spaces(addr); 1975 char *str = search_fix_spaces(addr);
1769 GList *tmp,*phrases=search_split_phrases(str); 1976 GList *tmp, *phrases = search_split_phrases(str);
1770 GList *phrases_first; 1977 GList *phrases_first;
1771 GList *ret = NULL; 1978 GList *ret = NULL;
1772 struct search_list *sl; 1979 struct search_list *sl;
1773 struct attr attr; 1980 struct attr attr;
1774 attr.type=attr_country_all; 1981 attr.type = attr_country_all;
1775 tmp=phrases; 1982 tmp = phrases;
1776 phrases_first=phrases; 1983 phrases_first = phrases;
1777 sl=search_list_new(ms); 1984 sl = search_list_new(ms);
1778 1985
1779 dbg(0,"-- START --\n"); 1986 dbg(0, "-- START --\n");
1780 1987
1781 // normal search stuff -------- START ---------- 1988 // normal search stuff -------- START ----------
1782 if (search_country_flags == 1) 1989 if (search_country_flags == 1)
1783 { 1990 {
1784 dbg(0,"-- country default start --\n"); 1991 dbg(0, "-- country default start --\n");
1785 //while (phrases) 1992 //while (phrases)
1786 //{ 1993 //{
1787 // dbg(0,"s=%s\n",phrases->data); 1994 // dbg(0,"s=%s\n",phrases->data);
1788 // set default country 1995 // set default country
1789 search_list_search(sl, country_default(), 0); 1996 search_list_search(sl, country_default(), 0);
1790 ret=search_address__country(ret, sl, phrases, NULL, partial, jni); 1997 ret = search_address__country(ret, sl, phrases, NULL, partial, jni);
1791 // phrases=g_list_next(phrases); 1998 // phrases=g_list_next(phrases);
1792 //} 1999 //}
1793 dbg(0,"-- country default end --\n"); 2000 dbg(0, "-- country default end --\n");
1794 } 2001 }
1795 else if (search_country_flags == 2) 2002 else if (search_country_flags == 2)
1796 { 2003 {
1797 dbg(0,"-- country sel:%s start --\n",search_country_string); 2004 dbg(0, "-- country sel:%s start --\n", search_country_string);
1798 // set a country 2005 // set a country
1799 struct attr country; 2006 struct attr country;
1800 country.type=attr_country_iso2; 2007 country.type = attr_country_iso2;
1801 country.u.str=search_country_string; 2008 country.u.str = search_country_string;
1802 //while (phrases) 2009 //while (phrases)
1803 //{ 2010 //{
1804 // dbg(0,"s=%s\n",phrases->data); 2011 // dbg(0,"s=%s\n",phrases->data);
1805 search_list_search(sl, &country, 0); 2012 search_list_search(sl, &country, 0);
1806 // set a country 2013 // set a country
1807 ret=search_address__country(ret, sl, phrases, NULL, partial, jni); 2014 ret = search_address__country(ret, sl, phrases, NULL, partial, jni);
1808 //phrases=g_list_next(phrases); 2015 //phrases=g_list_next(phrases);
1809 //} 2016 //}
1810 dbg(0,"-- country sel:%s end --\n",search_country_string); 2017 dbg(0, "-- country sel:%s end --\n", search_country_string);
1811 } 2018 }
1812 else // flags==3 2019 else // flags==3
1813 { 2020 {
1814 dbg(0,"-- country all start --\n"); 2021 dbg(0, "-- country all start --\n");
1815 // search all countries!! could take a really long time!! 2022 // search all countries!! could take a really long time!!
1816 struct attr country; 2023 struct attr country;
1817 int j2=sizeof(all_country_list) / sizeof(all_country_list[0]); 2024 int j2 = sizeof(all_country_list) / sizeof(all_country_list[0]);
1818 int j1; 2025 int j1;
1819 for(j1=0;j1 < j2;j1++) 2026 for (j1 = 0; j1 < j2; j1++)
1820 { 2027 {
1821 if (all_country_list[j1].iso2 != NULL) 2028 if (all_country_list[j1].iso2 != NULL)
1822 { 2029 {
1823 phrases=phrases_first; 2030 phrases = phrases_first;
1824 //while (phrases) 2031 //while (phrases)
1825 //{ 2032 //{
1826 // dbg(0,"s country=%s\n",all_country_list[j1].iso2); 2033 // dbg(0,"s country=%s\n",all_country_list[j1].iso2);
1827 // dbg(0,"s=%s\n",phrases->data); 2034 // dbg(0,"s=%s\n",phrases->data);
1828 country.type=attr_country_iso2; 2035 country.type = attr_country_iso2;
1829 country.u.str=all_country_list[j1].iso2; 2036 country.u.str = all_country_list[j1].iso2;
1830 search_list_search(sl, &country, 0); 2037 search_list_search(sl, &country, 0);
1831 ret=search_address__country(ret, sl, phrases, NULL, partial, jni); 2038 ret = search_address__country(ret, sl, phrases, NULL, partial, jni);
1832 //phrases=g_list_next(phrases); 2039 //phrases=g_list_next(phrases);
1833 //} 2040 //}
1834 2041
1835 if (offline_search_break_searching==1) 2042 if (offline_search_break_searching == 1)
1836 { 2043 {
1837 break; 2044 break;
1838 } 2045 }
1839 } 2046 }
1840 } 2047 }
1841 dbg(0,"-- country all end --\n"); 2048 dbg(0, "-- country all end --\n");
1842 } 2049 }
1843 // normal search stuff -------- END ---------- 2050 // normal search stuff -------- END ----------
1844 2051
1845 if (phrases_first) 2052 if (phrases_first)
1846 { 2053 {
1847 g_list_free(phrases_first); 2054 g_list_free(phrases_first);
1848 } 2055 }
1849 2056
1850 dbg(0,"-- END --\n"); 2057 dbg(0, "-- END --\n");
1851 2058
1852 g_free(str); 2059 g_free(str);
1853 return ret; 2060 return ret;
1854} 2061}
1855 2062
1856

Legend:
Removed from v.26  
changed lines
  Added in v.27

   
Visit the ZANavi Wiki