Bugfixing in Searching
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 6 Nov 2007 22:43:18 +0000 (22:43 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 6 Nov 2007 22:43:18 +0000 (22:43 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@544 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/src/data/mg/block.c
navit/src/data/mg/map.c
navit/src/data/mg/street.c
navit/src/data/mg/tree.c
navit/src/map.c

index e438e57..75b3892 100644 (file)
@@ -148,19 +148,25 @@ block_next_lin(struct map_rect_priv *mr)
                        mr->b.p=mr->file->begin+0x2000;
                else
                        mr->b.p=mr->b.block_start+mr->b.b->blocks*512;
-               if (mr->b.p >= mr->file->end)
+               if (mr->b.p >= mr->file->end) {
+                       dbg(1,"end of blocks %p vs %p\n", mr->b.p, mr->file->end);
                        return 0;
+               }
                mr->b.block_start=mr->b.p;
                mr->b.b=block_get(&mr->b.p);
                mr->b.p_start=mr->b.p;
                mr->b.end=mr->b.block_start+mr->b.b->size;
-               if (mr->b.b->count == -1)
+               if (mr->b.b->count == -1) {
+                       dbg(1,"empty blocks\n");
                        return 0;
+               }
                if (!mr->cur_sel || coord_rect_overlap(&mr->cur_sel->rect, &mr->b.b->r)) {
                        block_active_count++;
                        block_active_mem+=mr->b.b->blocks*512-sizeof(struct block *);
+                       dbg(1,"block ok\n");
                        return 1;
                }
+               dbg(2,"block not in cur_sel\n");
        }
 }
 
index 83e9ff0..bfde0df 100644 (file)
@@ -197,12 +197,14 @@ map_search_new_mg(struct map_priv *map, struct item *item, struct attr *search,
                if (item->type != type_country_label)
                        return NULL;
                tree_search_init(map->dirname, "town.b2", &mr->ts, 0x1000);
+               mr->current_file=file_town_twn;
                break;
        case attr_street_name:
                if (item->type != type_town_streets)
                        return NULL;
                dbg(1,"street_assoc=0x%x\n", item->id_lo);
                tree_search_init(map->dirname, "strname.b1", &mr->ts, 0);
+               mr->current_file=file_strname_stn;
                break;
        default:
                dbg(0,"unknown search\n");
@@ -213,8 +215,8 @@ map_search_new_mg(struct map_priv *map, struct item *item, struct attr *search,
        mr->search_country=item->id_lo;
        mr->search_str=search->u.str;
        mr->search_partial=partial;
-       mr->current_file=file_town_twn-1;
-       file_next(mr);
+       mr->file=mr->m->file[mr->current_file];
+       block_init(mr);
        return (struct map_search_priv *)mr;
 }
 
index 29d5f1a..0bd0bfe 100644 (file)
@@ -567,7 +567,7 @@ street_name_coord_get(void *priv_data, struct coord *c, int count)
        struct street_name_numbers snns;
        unsigned char *p=mr->street.name.aux_data;
 
-       dbg(0,"aux_data=%p\n", p);
+       dbg(1,"aux_data=%p\n", p);
        if (count) {
                street_name_numbers_get(&snns, &p);
                *c=*(snns.c);
@@ -674,9 +674,11 @@ street_search_get_item(struct map_rect_priv *mr)
                while ((leaf=tree_search_next(&mr->ts, &mr->search_p, dir)) != -1) {
                        dir=street_search_compare(&mr->search_p, mr);
                }
+               dbg(1,"dir=%d mr->search_block=0x%x\n", dir, mr->search_block);
                if (mr->search_block == -1)
                        return NULL;
-               dbg(1,"mr->search_block=0x%x\n", mr->search_block);
+               if (dir > 0)
+                       mr->search_block++;
                mr->search_blk_count=1;
                block_get_byindex(mr->m->file[file_strname_stn], mr->search_block, &mr->b);
                mr->b.p=mr->b.block_start+12;
@@ -684,31 +686,35 @@ street_search_get_item(struct map_rect_priv *mr)
        dbg(1,"name id 0x%x\n", mr->b.p-mr->m->file[file_strname_stn]->begin);
        if (! mr->search_blk_count)
                return NULL;
-       if (mr->b.p >= mr->b.end) {
-               if (!block_next_lin(mr))
-                       return NULL;
-               mr->b.p=mr->b.block_start+12;
-       }
-       while (mr->b.p < mr->b.end) {
-               last=mr->b.p;
-               street_name_get(&mr->street.name, &mr->b.p);
-               dir=street_search_compare_do(mr, mr->street.name.country, mr->street.name.townassoc, mr->street.name.name2);
-               dbg(1,"country 0x%x assoc 0x%x name1 '%s' name2 '%s' dir=%d\n", mr->street.name.country, mr->street.name.townassoc, mr->street.name.name1, mr->street.name.name2, dir);
-               if (dir < 0) {
-                       mr->search_blk_count=0;
-                       return NULL;
+       for (;;) {
+               if (mr->b.p >= mr->b.end) {
+                       if (!block_next_lin(mr)) {
+                               dbg(1,"end of blocks in %p, %p\n", mr->m->file[file_strname_stn]->begin, mr->m->file[file_strname_stn]->end);
+                               return NULL;
+                       }
+                       mr->b.p=mr->b.block_start+12;
                }
-               if (!dir) {
-                       dbg(0,"result country 0x%x assoc 0x%x name1 '%s' name2 '%s' dir=%d aux_data=%p len=0x%x\n", mr->street.name.country, mr->street.name.townassoc, mr->street.name.name1, mr->street.name.name2, dir, mr->street.name.aux_data, mr->street.name.aux_len);
-                       mr->item.type = type_street_name;
-                       mr->item.id_hi=mr->street.name.country | (mr->current_file << 16) | 0x10000000;
-                       mr->item.id_lo=last-mr->m->file[mr->current_file]->begin;
-                       mr->item.meth=&street_name_meth;
-                       mr->item.map=NULL;
-                       mr->item.priv_data=mr;
-                       return &mr->item;
+               while (mr->b.p < mr->b.end) {
+                       last=mr->b.p;
+                       street_name_get(&mr->street.name, &mr->b.p);
+                       dir=street_search_compare_do(mr, mr->street.name.country, mr->street.name.townassoc, mr->street.name.name2);
+                       dbg(1,"country 0x%x assoc 0x%x name1 '%s' name2 '%s' dir=%d\n", mr->street.name.country, mr->street.name.townassoc, mr->street.name.name1, mr->street.name.name2, dir);
+                       if (dir < 0) {
+                               dbg(1,"end of data\n");
+                               mr->search_blk_count=0;
+                               return NULL;
+                       }
+                       if (!dir) {
+                               dbg(1,"result country 0x%x assoc 0x%x name1 '%s' name2 '%s' dir=%d aux_data=%p len=0x%x\n", mr->street.name.country, mr->street.name.townassoc, mr->street.name.name1, mr->street.name.name2, dir, mr->street.name.aux_data, mr->street.name.aux_len);
+                               mr->item.type = type_street_name;
+                               mr->item.id_hi=mr->street.name.country | (mr->current_file << 16) | 0x10000000;
+                               mr->item.id_lo=last-mr->m->file[mr->current_file]->begin;
+                               mr->item.meth=&street_name_meth;
+                               mr->item.map=NULL;
+                               mr->item.priv_data=mr;
+                               return &mr->item;
+                       }
                }
        }
-       return NULL;
 }
  
index 30852d2..4913b39 100644 (file)
@@ -170,7 +170,7 @@ int tree_search_next(struct tree_search *ts, unsigned char **p, int dir)
        dbg(1,"saving last3 %d %p\n", ts->curr_node, tsn->last);
        if (*p < tsn->end)
                return (tsn->low == 0xffffffff ? 1 : 0);
-       dbg(1,"end reached\n");
+       dbg(1,"end reached high=0x%x\n",tsn->high);
        if (tsn->low != 0xffffffff) {
                dbg(1,"low 0x%x\n", tsn->low);
                tsn=tree_search_enter(ts, tsn->low);
index 4888597..8b515b4 100644 (file)
@@ -169,9 +169,11 @@ map_search_new(struct map *m, struct item *item, struct attr *search_attr, int p
        if (search_attr->type >= attr_country_all && search_attr->type <= attr_country_name)
                this->priv=country_search_new(&this->search_attr, partial);
        else {
-               if (m->meth.map_search_new)
-                       this->priv=m->meth.map_search_new(m->priv, item, search_attr, partial);
-               else {
+               if (m->meth.map_search_new) {
+                       if (m->meth.charset) 
+                               this->search_attr.u.str=g_convert(this->search_attr.u.str, -1,m->meth.charset,"utf-8",NULL,NULL,NULL);
+                       this->priv=m->meth.map_search_new(m->priv, item, &this->search_attr, partial);
+               } else {
                        g_free(this);
                        this=NULL;
                }
@@ -201,7 +203,10 @@ map_search_destroy(struct map_search *this)
                return;
        if (this->search_attr.type >= attr_country_all && this->search_attr.type <= attr_country_name)
                country_search_destroy(this->priv);
-       else
+       else {
+               if (this->m->meth.charset) 
+                               g_free(this->search_attr.u.str);
                this->m->meth.map_search_destroy(this->priv);
+       }
        g_free(this);
 }