static int item_bin_sort_compare(const void *p1, const void *p2) { struct item_bin *ib1=*((struct item_bin **)p1),*ib2=*((struct item_bin **)p2); struct attr_bin *attr1,*attr2; char *s1,*s2; int ret; attr1=item_bin_get_attr_bin(ib1, attr_tile_name, NULL); attr2=item_bin_get_attr_bin(ib2, attr_tile_name, NULL); if(attr1&&attr2) { s1=(char *)(attr1+1); s2=(char *)(attr2+1); ret=strcmp(s1,s2); if(ret) return ret; } #if 0 dbg_assert(ib1->clen==2); dbg_assert(ib2->clen==2); attr1=(struct attr_bin *)((int *)(ib1+1)+ib1->clen); attr2=(struct attr_bin *)((int *)(ib2+1)+ib1->clen); #else attr1=item_bin_get_attr_bin_last(ib1); attr2=item_bin_get_attr_bin_last(ib2); #endif #if 0 dbg_assert(attr1->type == attr_town_name || attr1->type == attr_town_name_match); dbg_assert(attr2->type == attr_town_name || attr2->type == attr_town_name_match); #endif s1=(char *)(attr1+1); s2=(char *)(attr2+1); if (attr1->type == attr_house_number && attr2->type == attr_house_number) { ret=atoi(s1)-atoi(s2); if (ret) return ret; } s1=linguistics_casefold(s1); s2=linguistics_casefold(s2); ret=strcmp(s1, s2); g_free(s1); g_free(s2); if (!ret) { int match1=0,match2=0; match1=(attr1->type == attr_town_name_match || attr1->type == attr_district_name_match); match2=(attr2->type == attr_town_name_match || attr2->type == attr_district_name_match); ret=match1-match2; } #if 0 fprintf(stderr,"sort_countries_compare p1=%p p2=%p %s %s\n",p1,p2,s1,s2); #endif return ret; }
struct country_search * country_search_new(struct attr *search, int partial) { struct country_search *ret=g_new(struct country_search, 1); ret->search=*search; ret->search.u.str=linguistics_casefold(ret->search.u.str); if (search->type != attr_country_id) ret->len=strlen(ret->search.u.str); else ret->len=0; ret->partial=partial; ret->count=0; ret->item.type=type_country_label; ret->item.id_hi=0; ret->item.map=NULL; ret->item.meth=&country_meth; ret->item.priv_data=ret; return ret; }