summaryrefslogtreecommitdiff
path: root/navit
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-12-03 13:05:47 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-12-03 13:05:47 +0000
commitcbab3b007d4e97ae4fe00bd7dd6110cbcfe00615 (patch)
treeb7a87b0ad38e5c696c2fdbc8854325ee187d2a0b /navit
parent7fc55ab28187cca3f256a645a90d795d7fc2d1f5 (diff)
downloadnavit-svn-cbab3b007d4e97ae4fe00bd7dd6110cbcfe00615.tar.gz
Fix:maptool:Some cleanups
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@2828 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit')
-rw-r--r--navit/maptool/itembin.c97
-rw-r--r--navit/maptool/maptool.h3
-rw-r--r--navit/maptool/osm.c72
3 files changed, 108 insertions, 64 deletions
diff --git a/navit/maptool/itembin.c b/navit/maptool/itembin.c
index e57bb80d..bdc85c82 100644
--- a/navit/maptool/itembin.c
+++ b/navit/maptool/itembin.c
@@ -1,8 +1,12 @@
#include <string.h>
+#include <stdlib.h>
#include "maptool.h"
+#include "linguistics.h"
+#include "file.h"
#include "debug.h"
+
struct item_bin *
read_item(FILE *in)
{
@@ -136,6 +140,20 @@ item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last)
return NULL;
}
+struct attr_bin *
+item_bin_get_attr_bin_last(struct item_bin *ib)
+{
+ struct attr_bin *ab=NULL;
+ unsigned char *s=(unsigned char *)ib;
+ unsigned char *e=s+(ib->len+1)*4;
+ s+=sizeof(struct item_bin)+ib->clen*4;
+ while (s < e) {
+ ab=(struct attr_bin *)s;
+ s+=(ab->len+1)*4;
+ }
+ return ab;
+}
+
void
item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val)
{
@@ -369,3 +387,82 @@ item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type ma
words++;
} while (word);
}
+
+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;
+#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);
+ ret=strcmp(s1, 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;
+}
+
+int
+item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size)
+{
+ int j,count;
+ struct coord *c;
+ struct item_bin *ib;
+ FILE *f;
+ unsigned char *p,**idx,*buffer;
+ if (file_get_contents(in_file, &buffer, size)) {
+ ib=(struct item_bin *)buffer;
+ p=buffer;
+ count=0;
+ while (p < buffer+*size) {
+ count++;
+ p+=(*((int *)p)+1)*4;
+ }
+ idx=malloc(count*sizeof(void *));
+ dbg_assert(idx != NULL);
+ p=buffer;
+ for (j = 0 ; j < count ; j++) {
+ idx[j]=p;
+ p+=(*((int *)p)+1)*4;
+ }
+ qsort(idx, count, sizeof(void *), item_bin_sort_compare);
+ f=fopen(out_file,"wb");
+ for (j = 0 ; j < count ; j++) {
+ ib=(struct item_bin *)(idx[j]);
+ c=(struct coord *)(ib+1);
+ fwrite(ib, (ib->len+1)*4, 1, f);
+ if (r) {
+ if (j)
+ bbox_extend(c, r);
+ else {
+ r->l=*c;
+ r->h=*c;
+ }
+ }
+ }
+ fclose(f);
+ return 1;
+ }
+ return 0;
+}
diff --git a/navit/maptool/maptool.h b/navit/maptool/maptool.h
index d64b9f0b..dbc79708 100644
--- a/navit/maptool/maptool.h
+++ b/navit/maptool/maptool.h
@@ -145,6 +145,7 @@ void item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data
void item_bin_add_attr(struct item_bin *ib, struct attr *attr);
void item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val);
void *item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last);
+struct attr_bin * item_bin_get_attr_bin_last(struct item_bin *ib);
void item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val);
void item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str);
void item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max);
@@ -154,6 +155,8 @@ void item_bin_dump(struct item_bin *ib, FILE *out);
void dump_itembin(struct item_bin *ib);
void item_bin_set_type_by_population(struct item_bin *ib, int population);
void item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
+int item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size);
+
/* maptool.c */
diff --git a/navit/maptool/osm.c b/navit/maptool/osm.c
index 3c038f0f..453ccb79 100644
--- a/navit/maptool/osm.c
+++ b/navit/maptool/osm.c
@@ -1445,8 +1445,8 @@ end_node(FILE *out)
if (result->file) {
item_bin_init(item_bin, item_bin->type);
item_bin_add_coord(item_bin, &ni->c, 1);
- item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]);
item_bin_add_attr_string(item_bin, attr_town_postal, postal);
+ item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]);
item_bin_write_match(item_bin, attr_town_name, attr_town_name_match, result->file);
}
@@ -1456,79 +1456,23 @@ end_node(FILE *out)
processed_nodes_out++;
}
-static int
-sort_countries_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;
- 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);
- 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);
- s1=(char *)(attr1+1);
- s2=(char *)(attr2+1);
- return strcmp(s1, s2);
-#if 0
- fprintf(stderr,"sort_countries_compare p1=%p p2=%p %s %s\n",p1,p2,s1,s2);
-#endif
- return 0;
-}
-
void
sort_countries(int keep_tmpfiles)
{
- int i,j,count;
+ int i;
struct country_table *co;
- struct coord *c;
- struct item_bin *ib;
- FILE *f;
- char *name;
- unsigned char *p,**idx,*buffer;
+ char *name_in,*name_out;
for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
co=&country_table[i];
if (co->file) {
fclose(co->file);
co->file=NULL;
}
- name=g_strdup_printf("country_%d.bin.unsorted", co->countryid);
- if (file_get_contents(name, &buffer, &co->size)) {
- if(!keep_tmpfiles)
- unlink(name);
- g_free(name);
- ib=(struct item_bin *)buffer;
- p=buffer;
- count=0;
- while (p < buffer+co->size) {
- count++;
- p+=(*((int *)p)+1)*4;
- }
- idx=malloc(count*sizeof(void *));
- dbg_assert(idx != NULL);
- p=buffer;
- for (j = 0 ; j < count ; j++) {
- idx[j]=p;
- p+=(*((int *)p)+1)*4;
- }
- qsort(idx, count, sizeof(void *), sort_countries_compare);
- name=g_strdup_printf("country_%d.bin", co->countryid);
- f=fopen(name,"wb");
- for (j = 0 ; j < count ; j++) {
- ib=(struct item_bin *)(idx[j]);
- c=(struct coord *)(ib+1);
- fwrite(ib, (ib->len+1)*4, 1, f);
- if (j)
- bbox_extend(c, &co->r);
- else {
- co->r.l=*c;
- co->r.h=*c;
- }
- }
- fclose(f);
- }
- g_free(name);
+ name_in=g_strdup_printf("country_%d.bin.unsorted", co->countryid);
+ name_out=g_strdup_printf("country_%d.bin", co->countryid);
+ item_bin_sort_file(name_in, name_out, &co->r, &co->size);
+ g_free(name_in);
+ g_free(name_out);
}
}