summaryrefslogtreecommitdiff
path: root/navit/maptool
diff options
context:
space:
mode:
authorJoseph Herlant <herlantj@gmail.com>2018-05-25 22:06:51 -0700
committerJoseph Herlant <aerostitch@users.noreply.github.com>2018-05-25 22:17:50 -0700
commit8a76acb966f7059caf9d72c853175bd923b1e9d7 (patch)
tree1735178f7a0718831b88d2c36ea18a9955de3224 /navit/maptool
parent032f15287b472f1a4b5349533f3e5b468684b281 (diff)
downloadnavit-8a76acb966f7059caf9d72c853175bd923b1e9d7.tar.gz
cleanup:global:Use astyle to reformat everything
Diffstat (limited to 'navit/maptool')
-rw-r--r--navit/maptool/boundaries.c558
-rw-r--r--navit/maptool/buffer.c95
-rw-r--r--navit/maptool/ch.c802
-rw-r--r--navit/maptool/coastline.c885
-rw-r--r--navit/maptool/generated-code/fileformat.pb-c.c394
-rw-r--r--navit/maptool/generated-code/osmformat.pb-c.c2611
-rw-r--r--navit/maptool/google/protobuf-c/protobuf-c.c3063
-rw-r--r--navit/maptool/itembin.c1072
-rw-r--r--navit/maptool/itembin_buffer.c62
-rw-r--r--navit/maptool/maptool.c1765
-rw-r--r--navit/maptool/misc.c682
-rw-r--r--navit/maptool/osm.c5925
-rw-r--r--navit/maptool/osm_o5m.c581
-rw-r--r--navit/maptool/osm_protobuf.c398
-rw-r--r--navit/maptool/osm_protobufdb.c1199
-rw-r--r--navit/maptool/osm_psql.c478
-rw-r--r--navit/maptool/osm_relations.c211
-rw-r--r--navit/maptool/osm_xml.c353
-rw-r--r--navit/maptool/sourcesink.c191
-rw-r--r--navit/maptool/tempfile.c60
-rw-r--r--navit/maptool/tile.c1083
-rw-r--r--navit/maptool/zip.c528
22 files changed, 11152 insertions, 11844 deletions
diff --git a/navit/maptool/boundaries.c b/navit/maptool/boundaries.c
index 75e1d2479..c6472adda 100644
--- a/navit/maptool/boundaries.c
+++ b/navit/maptool/boundaries.c
@@ -24,332 +24,322 @@
#endif
char *
-osm_tag_value(struct item_bin *ib, char *key)
-{
- char *tag=NULL;
- int len=strlen(key);
- while ((tag=item_bin_get_attr(ib, attr_osm_tag, tag))) {
- if (!strncmp(tag,key,len) && tag[len] == '=')
- return tag+len+1;
- }
- return NULL;
+osm_tag_value(struct item_bin *ib, char *key) {
+ char *tag=NULL;
+ int len=strlen(key);
+ while ((tag=item_bin_get_attr(ib, attr_osm_tag, tag))) {
+ if (!strncmp(tag,key,len) && tag[len] == '=')
+ return tag+len+1;
+ }
+ return NULL;
}
#if 0
static char *
-osm_tag_name(struct item_bin *ib)
-{
- return osm_tag_value(ib, "name");
+osm_tag_name(struct item_bin *ib) {
+ return osm_tag_value(ib, "name");
}
#endif
osmid
-boundary_relid(struct boundary *b)
-{
- long long *id;
- if (!b)
- return 0;
- if (!b->ib)
- return 0;
- id=item_bin_get_attr(b->ib, attr_osm_relationid, NULL);
- if (id)
- return *id;
- return 0;
+boundary_relid(struct boundary *b) {
+ long long *id;
+ if (!b)
+ return 0;
+ if (!b->ib)
+ return 0;
+ id=item_bin_get_attr(b->ib, attr_osm_relationid, NULL);
+ if (id)
+ return *id;
+ return 0;
}
static void
-process_boundaries_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv)
-{
- struct boundary *b=relation_priv;
- enum geom_poly_segment_type role=(long)member_priv;
- int *dup;
- dup=item_bin_get_attr(member,attr_duplicate,NULL);
- if(!dup || *dup==0)
- b->segments=g_list_prepend(b->segments,item_bin_to_poly_segment(member, role));
+process_boundaries_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) {
+ struct boundary *b=relation_priv;
+ enum geom_poly_segment_type role=(long)member_priv;
+ int *dup;
+ dup=item_bin_get_attr(member,attr_duplicate,NULL);
+ if(!dup || *dup==0)
+ b->segments=g_list_prepend(b->segments,item_bin_to_poly_segment(member, role));
}
static GList *
-process_boundaries_setup(FILE *boundaries, struct relations *relations)
-{
- struct item_bin *ib;
- GList *boundaries_list=NULL;
- struct relations_func *relations_func;
+process_boundaries_setup(FILE *boundaries, struct relations *relations) {
+ struct item_bin *ib;
+ GList *boundaries_list=NULL;
+ struct relations_func *relations_func;
- relations_func=relations_func_new(process_boundaries_member, NULL);
- while ((ib=read_item(boundaries))) {
- char *member=NULL;
- struct boundary *boundary=g_new0(struct boundary, 1);
- char *admin_level=osm_tag_value(ib, "admin_level");
- char *iso=osm_tag_value(ib, "ISO3166-1");
- int has_subrelations=0;
- int has_outer_ways=0;
-
- processed_relations++;
-
- if(!iso)
- iso=osm_tag_value(ib, "iso3166-1:alpha2");
-
- if (admin_level && !strcmp(admin_level, "2")) {
- if(!iso) {
- char *int_name=osm_tag_value(ib,"int_name");
- if(int_name && !strcmp(int_name,"France"))
- iso="FR";
- }
- if (iso) {
- struct country_table *country=country_from_iso2(iso);
- if (!country)
- osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary contains unknown ISO3166-1 value '%s'\n",iso);
- else {
- boundary->iso2=g_strdup(iso);
- osm_info("relation",item_bin_get_relationid(ib),0,"Country Boundary for '%s'\n",iso);
- }
- boundary->country=country;
- } else
- osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary doesn't contain an ISO3166-1 tag\n");
- }
- while ((member=item_bin_get_attr(ib, attr_osm_member, member))) {
- long long osm_id;
- int read=0;
- enum relation_member_type member_type;
- int member_type_numeric;
- char *rolestr;
+ relations_func=relations_func_new(process_boundaries_member, NULL);
+ while ((ib=read_item(boundaries))) {
+ char *member=NULL;
+ struct boundary *boundary=g_new0(struct boundary, 1);
+ char *admin_level=osm_tag_value(ib, "admin_level");
+ char *iso=osm_tag_value(ib, "ISO3166-1");
+ int has_subrelations=0;
+ int has_outer_ways=0;
- if (sscanf(member,RELATION_MEMBER_PARSE_FORMAT,&member_type_numeric,&osm_id,&read) < 2)
- continue;
-
- member_type=(enum relation_member_type)member_type_numeric;
- rolestr=member+read;
-
- if(member_type==rel_member_node) {
- if(!strcmp(rolestr,"admin_centre") || !strcmp(rolestr,"admin_center"))
- boundary->admin_centre=osm_id;
- }
- if(member_type==rel_member_way) {
- enum geom_poly_segment_type role;
- if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave")) {
- has_outer_ways=1;
- role=geom_poly_segment_type_way_outer;
- }
- else if (!strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave"))
- role=geom_poly_segment_type_way_inner;
- else if (!strcmp(rolestr,""))
- role=geom_poly_segment_type_way_unknown;
- else {
- osm_warning("relation",item_bin_get_relationid(ib),0,"Unknown role %s in member ",rolestr);
- osm_warning("way",osm_id,1,"\n");
- role=geom_poly_segment_type_none;
- }
- relations_add_relation_member_entry(relations, relations_func, boundary, (gpointer)role, rel_member_way, osm_id);
- }
- if(member_type==rel_member_relation) {
- if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave") || !strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave"))
- has_subrelations++;
- }
- }
- if(boundary->iso2 && has_subrelations)
- osm_warning("relation",item_bin_get_relationid(ib),0,"Country boundary '%s' has %d relations as boundary segments. These are not supported yet.\n", boundary->iso2, has_subrelations);
- if(boundary->iso2 && !has_outer_ways) {
- osm_warning("relation",item_bin_get_relationid(ib),0,"Skipping country boundary for '%s' because it has no outer ways.\n", boundary->iso2);
- g_free(boundary->iso2);
- boundary->iso2=NULL;
- }
+ processed_relations++;
- boundary->ib=item_bin_dup(ib);
- boundaries_list=g_list_append(boundaries_list, boundary);
- }
- return boundaries_list;
+ if(!iso)
+ iso=osm_tag_value(ib, "iso3166-1:alpha2");
+
+ if (admin_level && !strcmp(admin_level, "2")) {
+ if(!iso) {
+ char *int_name=osm_tag_value(ib,"int_name");
+ if(int_name && !strcmp(int_name,"France"))
+ iso="FR";
+ }
+ if (iso) {
+ struct country_table *country=country_from_iso2(iso);
+ if (!country)
+ osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary contains unknown ISO3166-1 value '%s'\n",iso);
+ else {
+ boundary->iso2=g_strdup(iso);
+ osm_info("relation",item_bin_get_relationid(ib),0,"Country Boundary for '%s'\n",iso);
+ }
+ boundary->country=country;
+ } else
+ osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary doesn't contain an ISO3166-1 tag\n");
+ }
+ while ((member=item_bin_get_attr(ib, attr_osm_member, member))) {
+ long long osm_id;
+ int read=0;
+ enum relation_member_type member_type;
+ int member_type_numeric;
+ char *rolestr;
+
+ if (sscanf(member,RELATION_MEMBER_PARSE_FORMAT,&member_type_numeric,&osm_id,&read) < 2)
+ continue;
+
+ member_type=(enum relation_member_type)member_type_numeric;
+ rolestr=member+read;
+
+ if(member_type==rel_member_node) {
+ if(!strcmp(rolestr,"admin_centre") || !strcmp(rolestr,"admin_center"))
+ boundary->admin_centre=osm_id;
+ }
+ if(member_type==rel_member_way) {
+ enum geom_poly_segment_type role;
+ if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave")) {
+ has_outer_ways=1;
+ role=geom_poly_segment_type_way_outer;
+ } else if (!strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave"))
+ role=geom_poly_segment_type_way_inner;
+ else if (!strcmp(rolestr,""))
+ role=geom_poly_segment_type_way_unknown;
+ else {
+ osm_warning("relation",item_bin_get_relationid(ib),0,"Unknown role %s in member ",rolestr);
+ osm_warning("way",osm_id,1,"\n");
+ role=geom_poly_segment_type_none;
+ }
+ relations_add_relation_member_entry(relations, relations_func, boundary, (gpointer)role, rel_member_way, osm_id);
+ }
+ if(member_type==rel_member_relation) {
+ if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave") || !strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave"))
+ has_subrelations++;
+ }
+ }
+ if(boundary->iso2 && has_subrelations)
+ osm_warning("relation",item_bin_get_relationid(ib),0,
+ "Country boundary '%s' has %d relations as boundary segments. These are not supported yet.\n", boundary->iso2,
+ has_subrelations);
+ if(boundary->iso2 && !has_outer_ways) {
+ osm_warning("relation",item_bin_get_relationid(ib),0,
+ "Skipping country boundary for '%s' because it has no outer ways.\n", boundary->iso2);
+ g_free(boundary->iso2);
+ boundary->iso2=NULL;
+ }
+
+ boundary->ib=item_bin_dup(ib);
+ boundaries_list=g_list_append(boundaries_list, boundary);
+ }
+ return boundaries_list;
}
GList *
-boundary_find_matches(GList *l, struct coord *c)
-{
- GList *ret=NULL;
- while (l) {
- struct boundary *boundary=l->data;
- if (bbox_contains_coord(&boundary->r, c)) {
- if (geom_poly_segments_point_inside(boundary->sorted_segments,c) > 0)
- ret=g_list_prepend(ret, boundary);
- ret=g_list_concat(ret,boundary_find_matches(boundary->children, c));
- }
- l=g_list_next(l);
- }
- return ret;
+boundary_find_matches(GList *l, struct coord *c) {
+ GList *ret=NULL;
+ while (l) {
+ struct boundary *boundary=l->data;
+ if (bbox_contains_coord(&boundary->r, c)) {
+ if (geom_poly_segments_point_inside(boundary->sorted_segments,c) > 0)
+ ret=g_list_prepend(ret, boundary);
+ ret=g_list_concat(ret,boundary_find_matches(boundary->children, c));
+ }
+ l=g_list_next(l);
+ }
+ return ret;
}
#if 0
static void
-test(GList *boundaries_list)
-{
- struct item_bin *ib;
- FILE *f=fopen("country_276.bin.unsorted","r");
- printf("start\n");
- while ((ib=read_item(f))) {
- struct coord *c=(struct coord *)(ib+1);
- char *name=item_bin_get_attr(ib, attr_town_name, NULL);
- printf("%s:",name);
- boundary_find_matches(boundaries_list, c);
- printf("\n");
- }
- fclose(f);
- printf("end\n");
+test(GList *boundaries_list) {
+ struct item_bin *ib;
+ FILE *f=fopen("country_276.bin.unsorted","r");
+ printf("start\n");
+ while ((ib=read_item(f))) {
+ struct coord *c=(struct coord *)(ib+1);
+ char *name=item_bin_get_attr(ib, attr_town_name, NULL);
+ printf("%s:",name);
+ boundary_find_matches(boundaries_list, c);
+ printf("\n");
+ }
+ fclose(f);
+ printf("end\n");
}
static void
-dump_hierarchy(GList *l, char *prefix)
-{
- char *newprefix=g_alloca(sizeof(char)*(strlen(prefix)+2));
- strcpy(newprefix, prefix);
- strcat(newprefix," ");
- while (l) {
- struct boundary *boundary=l->data;
- fprintf(stderr,"%s:%s (0x%x,0x%x)-(0x%x,0x%x)\n",prefix,osm_tag_name(boundary->ib),boundary->r.l.x,boundary->r.l.y,boundary->r.h.x,boundary->r.h.y);
- dump_hierarchy(boundary->children, newprefix);
- l=g_list_next(l);
- }
+dump_hierarchy(GList *l, char *prefix) {
+ char *newprefix=g_alloca(sizeof(char)*(strlen(prefix)+2));
+ strcpy(newprefix, prefix);
+ strcat(newprefix," ");
+ while (l) {
+ struct boundary *boundary=l->data;
+ fprintf(stderr,"%s:%s (0x%x,0x%x)-(0x%x,0x%x)\n",prefix,osm_tag_name(boundary->ib),boundary->r.l.x,boundary->r.l.y,
+ boundary->r.h.x,boundary->r.h.y);
+ dump_hierarchy(boundary->children, newprefix);
+ l=g_list_next(l);
+ }
}
static gint
-boundary_bbox_compare(gconstpointer a, gconstpointer b)
-{
- const struct boundary *boundarya=a;
- const struct boundary *boundaryb=b;
- long long areaa=bbox_area(&boundarya->r);
- long long areab=bbox_area(&boundaryb->r);
- if (areaa > areab)
- return 1;
- if (areaa < areab)
- return -1;
- return 0;
+boundary_bbox_compare(gconstpointer a, gconstpointer b) {
+ const struct boundary *boundarya=a;
+ const struct boundary *boundaryb=b;
+ long long areaa=bbox_area(&boundarya->r);
+ long long areab=bbox_area(&boundaryb->r);
+ if (areaa > areab)
+ return 1;
+ if (areaa < areab)
+ return -1;
+ return 0;
}
#endif
static GList *
-process_boundaries_insert(GList *list, struct boundary *boundary)
-{
- GList *l=list;
- while (l) {
- struct boundary *b=l->data;
- if (bbox_contains_bbox(&boundary->r, &b->r)) {
- list=g_list_remove(list, b);
- boundary->children=g_list_prepend(boundary->children, b);
- l=list;
- } else if (bbox_contains_bbox(&b->r, &boundary->r)) {
- b->children=process_boundaries_insert(b->children, boundary);
- return list;
- } else
- l=g_list_next(l);
- }
- return g_list_prepend(list, boundary);
+process_boundaries_insert(GList *list, struct boundary *boundary) {
+ GList *l=list;
+ while (l) {
+ struct boundary *b=l->data;
+ if (bbox_contains_bbox(&boundary->r, &b->r)) {
+ list=g_list_remove(list, b);
+ boundary->children=g_list_prepend(boundary->children, b);
+ l=list;
+ } else if (bbox_contains_bbox(&b->r, &boundary->r)) {
+ b->children=process_boundaries_insert(b->children, boundary);
+ return list;
+ } else
+ l=g_list_next(l);
+ }
+ return g_list_prepend(list, boundary);
}
static GList *
-process_boundaries_finish(GList *boundaries_list)
-{
- GList *l,*sl;
- GList *ret=NULL;
- l=boundaries_list;
- while (l) {
- struct boundary *boundary=l->data;
- int first=1;
- FILE *f=NULL,*fu=NULL;
- if (boundary->country) {
- char *name=g_strdup_printf("country_%s_poly",boundary->iso2);
- f=tempfile("",name,1);
- g_free(name);
- }
- boundary->sorted_segments=geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side);
- sl=boundary->sorted_segments;
- while (sl) {
- struct geom_poly_segment *gs=sl->data;
- struct coord *c=gs->first;
- while (c <= gs->last) {
- if (first) {
- boundary->r.l=*c;
- boundary->r.h=*c;
- first=0;
- } else
- bbox_extend(c, &boundary->r);
- c++;
- }
- if (f) {
- struct item_bin *ib=tmp_item_bin;
- item_bin_init(ib, type_selected_line);
- /* FIXME check for overflow */
- item_bin_add_coord(ib, gs->first, gs->last-gs->first+1);
- item_bin_write(ib, f);
- }
- if (boundary->country) {
- if (!coord_is_equal(*gs->first,*gs->last)) {
- struct item_bin *ib;
- if (!fu) {
- char *name=g_strdup_printf("country_%s_broken",boundary->iso2);
- fu=tempfile("",name,1);
- g_free(name);
- }
- ib=tmp_item_bin;
- item_bin_init(ib, type_selected_point);
- item_bin_add_coord(ib, gs->first, 1);
- item_bin_write(ib, fu);
- item_bin_init(ib, type_selected_point);
- item_bin_add_coord(ib, gs->last, 1);
- item_bin_write(ib, fu);
- }
- }
- sl=g_list_next(sl);
- }
- ret=process_boundaries_insert(ret, boundary);
- l=g_list_next(l);
- if (f)
- fclose(f);
- if (fu) {
- if (boundary->country)
- osm_warning("relation",item_bin_get_relationid(boundary->ib),0,"Broken country polygon '%s'\n",boundary->iso2);
- fclose(fu);
- }
-
- }
- return ret;
+process_boundaries_finish(GList *boundaries_list) {
+ GList *l,*sl;
+ GList *ret=NULL;
+ l=boundaries_list;
+ while (l) {
+ struct boundary *boundary=l->data;
+ int first=1;
+ FILE *f=NULL,*fu=NULL;
+ if (boundary->country) {
+ char *name=g_strdup_printf("country_%s_poly",boundary->iso2);
+ f=tempfile("",name,1);
+ g_free(name);
+ }
+ boundary->sorted_segments=geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side);
+ sl=boundary->sorted_segments;
+ while (sl) {
+ struct geom_poly_segment *gs=sl->data;
+ struct coord *c=gs->first;
+ while (c <= gs->last) {
+ if (first) {
+ boundary->r.l=*c;
+ boundary->r.h=*c;
+ first=0;
+ } else
+ bbox_extend(c, &boundary->r);
+ c++;
+ }
+ if (f) {
+ struct item_bin *ib=tmp_item_bin;
+ item_bin_init(ib, type_selected_line);
+ /* FIXME check for overflow */
+ item_bin_add_coord(ib, gs->first, gs->last-gs->first+1);
+ item_bin_write(ib, f);
+ }
+ if (boundary->country) {
+ if (!coord_is_equal(*gs->first,*gs->last)) {
+ struct item_bin *ib;
+ if (!fu) {
+ char *name=g_strdup_printf("country_%s_broken",boundary->iso2);
+ fu=tempfile("",name,1);
+ g_free(name);
+ }
+ ib=tmp_item_bin;
+ item_bin_init(ib, type_selected_point);
+ item_bin_add_coord(ib, gs->first, 1);
+ item_bin_write(ib, fu);
+ item_bin_init(ib, type_selected_point);
+ item_bin_add_coord(ib, gs->last, 1);
+ item_bin_write(ib, fu);
+ }
+ }
+ sl=g_list_next(sl);
+ }
+ ret=process_boundaries_insert(ret, boundary);
+ l=g_list_next(l);
+ if (f)
+ fclose(f);
+ if (fu) {
+ if (boundary->country)
+ osm_warning("relation",item_bin_get_relationid(boundary->ib),0,"Broken country polygon '%s'\n",boundary->iso2);
+ fclose(fu);
+ }
+
+ }
+ return ret;
}
GList *
-process_boundaries(FILE *boundaries, FILE *ways)
-{
- GList *boundaries_list;
- struct relations *relations=relations_new();
+process_boundaries(FILE *boundaries, FILE *ways) {
+ GList *boundaries_list;
+ struct relations *relations=relations_new();
- boundaries_list=process_boundaries_setup(boundaries, relations);
- relations_process(relations, NULL, ways);
- relations_destroy(relations);
- return process_boundaries_finish(boundaries_list);
+ boundaries_list=process_boundaries_setup(boundaries, relations);
+ relations_process(relations, NULL, ways);
+ relations_destroy(relations);
+ return process_boundaries_finish(boundaries_list);
}
void
-free_boundaries(GList *bl)
-{
- GList *l=bl;
- while (l) {
- struct boundary *boundary=l->data;
- GList *s=boundary->segments;
- while (s) {
- struct geom_poly_segment *seg=s->data;
- g_free(seg->first);
- g_free(seg);
- s=g_list_next(s);
- };
- s=boundary->sorted_segments;
- while (s) {
- struct geom_poly_segment *seg=s->data;
- g_free(seg->first);
- g_free(seg);
- s=g_list_next(s);
- };
- g_list_free(boundary->segments);
- g_list_free(boundary->sorted_segments);
- g_free(boundary->ib);
- g_free(boundary->iso2);
- free_boundaries(boundary->children);
- g_free(boundary);
- l=g_list_next(l);
- }
- g_list_free(bl);
+free_boundaries(GList *bl) {
+ GList *l=bl;
+ while (l) {
+ struct boundary *boundary=l->data;
+ GList *s=boundary->segments;
+ while (s) {
+ struct geom_poly_segment *seg=s->data;
+ g_free(seg->first);
+ g_free(seg);
+ s=g_list_next(s);
+ };
+ s=boundary->sorted_segments;
+ while (s) {
+ struct geom_poly_segment *seg=s->data;
+ g_free(seg->first);
+ g_free(seg);
+ s=g_list_next(s);
+ };
+ g_list_free(boundary->segments);
+ g_list_free(boundary->sorted_segments);
+ g_free(boundary->ib);
+ g_free(boundary->iso2);
+ free_boundaries(boundary->children);
+ g_free(boundary);
+ l=g_list_next(l);
+ }
+ g_list_free(bl);
}
diff --git a/navit/maptool/buffer.c b/navit/maptool/buffer.c
index 35f804b5e..43f643461 100644
--- a/navit/maptool/buffer.c
+++ b/navit/maptool/buffer.c
@@ -24,29 +24,28 @@
/**
* @brief Saves a buffer to a file
*
- * This function saves a buffer to a file.
+ * This function saves a buffer to a file.
*
* @param filename The name of the while to where the buffer is saved to.
* @param b Buffer which is saved to file.
* @param offset
*/
void
-save_buffer(char *filename, struct buffer *b, long long offset)
-{
- FILE *f;
- f=fopen(filename,"rb+");
- if (! f)
- f=fopen(filename,"wb+");
-
- dbg_assert(f != NULL);
- dbg_assert(fseeko(f, offset, SEEK_SET)==0);
- dbg_assert(fwrite(b->base, b->size, 1, f)==1);
- fclose(f);
+save_buffer(char *filename, struct buffer *b, long long offset) {
+ FILE *f;
+ f=fopen(filename,"rb+");
+ if (! f)
+ f=fopen(filename,"wb+");
+
+ dbg_assert(f != NULL);
+ dbg_assert(fseeko(f, offset, SEEK_SET)==0);
+ dbg_assert(fwrite(b->base, b->size, 1, f)==1);
+ fclose(f);
}
/**
* @brief Loads a buffer from a file
*
- * This function loads a buffer from a file.
+ * This function loads a buffer from a file.
*
* @param filename The name of the while to where the buffer is loaded from.
* @param b Buffer in which file is loaded.
@@ -54,49 +53,47 @@ save_buffer(char *filename, struct buffer *b, long long offset)
* @return indicator if operation suceeded
*/
int
-load_buffer(char *filename, struct buffer *b, long long offset, long long size)
-{
- FILE *f;
- long long len;
- dbg_assert(size>=0);
- dbg_assert(offset>=0);
- g_free(b->base);
- b->malloced=0;
- f=fopen(filename,"rb");
- fseeko(f, 0, SEEK_END);
- len=ftello(f);
- dbg_assert(len>=0);
- if (offset+size > len) {
- size=len-offset;
- }
- b->size=b->malloced=size;
- dbg_assert(b->size>0);
+load_buffer(char *filename, struct buffer *b, long long offset, long long size) {
+ FILE *f;
+ long long len;
+ dbg_assert(size>=0);
+ dbg_assert(offset>=0);
+ g_free(b->base);
+ b->malloced=0;
+ f=fopen(filename,"rb");
+ fseeko(f, 0, SEEK_END);
+ len=ftello(f);
+ dbg_assert(len>=0);
+ if (offset+size > len) {
+ size=len-offset;
+ }
+ b->size=b->malloced=size;
+ dbg_assert(b->size>0);
- fseeko(f, offset, SEEK_SET);
- b->base=g_malloc(b->size);
- if (fread(b->base, b->size, 1, f) == 0){
- dbg(lvl_warning, "fread failed");
- fclose(f);
- return 0;
- }
- fclose(f);
- return 1;
+ fseeko(f, offset, SEEK_SET);
+ b->base=g_malloc(b->size);
+ if (fread(b->base, b->size, 1, f) == 0) {
+ dbg(lvl_warning, "fread failed");
+ fclose(f);
+ return 0;
+ }
+ fclose(f);
+ return 1;
}
/**
- * @brief Determines size of buffer for file
+ * @brief Determines size of buffer for file
*
- * This function determines the size of the buffer required to read a file.
+ * This function determines the size of the buffer required to read a file.
*
* @param filename Name of file for which the required size of the buffer is determined
* @return required size of buffer
*/
long long
-sizeof_buffer(char *filename)
-{
- long long ret;
- FILE *f=fopen(filename,"rb");
- fseeko(f, 0, SEEK_END);
- ret=ftello(f);
- fclose(f);
- return ret;
+sizeof_buffer(char *filename) {
+ long long ret;
+ FILE *f=fopen(filename,"rb");
+ fseeko(f, 0, SEEK_END);
+ ret=ftello(f);
+ fclose(f);
+ return ret;
}
diff --git a/navit/maptool/ch.c b/navit/maptool/ch.c
index 59a4b7db2..f7fafafac 100644
--- a/navit/maptool/ch.c
+++ b/navit/maptool/ch.c
@@ -33,32 +33,32 @@
#endif
struct ch_edge {
- int flags;
- int weight;
- struct item_id target,middle;
+ int flags;
+ int weight;
+ struct item_id target,middle;
};
struct node {
- int first_edge;
- int dummy;
+ int first_edge;
+ int dummy;
} *nodes;
int node_count;
struct edge {
- unsigned target:26;
- unsigned scedge1:6;
- unsigned weight:28;
- unsigned type:2;
- unsigned flags:2;
- unsigned int edge_count;
- unsigned scedge2:6;
- unsigned scmiddle:26;
+ unsigned target:26;
+ unsigned scedge1:6;
+ unsigned weight:28;
+ unsigned type:2;
+ unsigned flags:2;
+ unsigned int edge_count;
+ unsigned scedge2:6;
+ unsigned scmiddle:26;
} *edges;
int edge_count;
struct newnode {
- int newnode;
+ int newnode;
} *newnodes;
int newnode_count;
@@ -66,7 +66,7 @@ int newnode_count;
GHashTable *newnode_hash;
struct edge_hash_item {
- int first,last;
+ int first,last;
};
@@ -81,466 +81,450 @@ GHashTable *sgr_nodes_hash;
static int ch_levels=14;
static int
-road_speed(enum item_type type)
-{
- switch (type) {
- case type_street_0:
- case type_street_1_city:
- case type_living_street:
- case type_street_service:
- case type_track_gravelled:
- case type_track_unpaved:
- return 10;
- case type_street_2_city:
- case type_track_paved:
- return 30;
- case type_street_3_city:
- return 40;
- case type_street_4_city:
- return 50;
- case type_highway_city:
- return 80;
- case type_street_1_land:
- return 60;
- case type_street_2_land:
- return 65;
- case type_street_3_land:
- return 70;
- case type_street_4_land:
- return 80;
- case type_street_n_lanes:
- return 120;
- case type_highway_land:
- return 120;
- case type_ramp:
- return 40;
- case type_roundabout:
- return 10;
- case type_ferry:
- return 40;
- default:
- return 0;
- }
+road_speed(enum item_type type) {
+ switch (type) {
+ case type_street_0:
+ case type_street_1_city:
+ case type_living_street:
+ case type_street_service:
+ case type_track_gravelled:
+ case type_track_unpaved:
+ return 10;
+ case type_street_2_city:
+ case type_track_paved:
+ return 30;
+ case type_street_3_city:
+ return 40;
+ case type_street_4_city:
+ return 50;
+ case type_highway_city:
+ return 80;
+ case type_street_1_land:
+ return 60;
+ case type_street_2_land:
+ return 65;
+ case type_street_3_land:
+ return 70;
+ case type_street_4_land:
+ return 80;
+ case type_street_n_lanes:
+ return 120;
+ case type_highway_land:
+ return 120;
+ case type_ramp:
+ return 40;
+ case type_roundabout:
+ return 10;
+ case type_ferry:
+ return 40;
+ default:
+ return 0;
+ }
}
static void
-coord_slice_free(void *data)
-{
- g_slice_free(struct coord, data);
+coord_slice_free(void *data) {
+ g_slice_free(struct coord, data);
}
static GHashTable *
-coord_hash_new(void)
-{
- return g_hash_table_new_full(coord_hash, coord_equal, coord_slice_free, NULL);
+coord_hash_new(void) {
+ return g_hash_table_new_full(coord_hash, coord_equal, coord_slice_free, NULL);
}
static void
-item_id_slice_free(void *data)
-{
- g_slice_free(struct item_id, data);
+item_id_slice_free(void *data) {
+ g_slice_free(struct item_id, data);
}
static void
-add_node_to_hash(FILE *idx, GHashTable *hash, struct coord *c, int *nodes)
-{
- if (! g_hash_table_lookup(hash, c)) {
- struct coord *ct=g_slice_new(struct coord);
- *ct=*c;
- fwrite(c, sizeof(*c), 1, idx);
- (*nodes)++;
- g_hash_table_insert(hash, ct, GINT_TO_POINTER(*nodes));
- }
+add_node_to_hash(FILE *idx, GHashTable *hash, struct coord *c, int *nodes) {
+ if (! g_hash_table_lookup(hash, c)) {
+ struct coord *ct=g_slice_new(struct coord);
+ *ct=*c;
+ fwrite(c, sizeof(*c), 1, idx);
+ (*nodes)++;
+ g_hash_table_insert(hash, ct, GINT_TO_POINTER(*nodes));
+ }
}
static void
-edge_hash_slice_free(void *data)
-{
- g_slice_free(struct edge_hash_item, data);
+edge_hash_slice_free(void *data) {
+ g_slice_free(struct edge_hash_item, data);
}
static guint
-edge_hash_hash(gconstpointer key)
-{
- const struct edge_hash_item *itm=key;
- return itm->first*2654435761UL+itm->last;
+edge_hash_hash(gconstpointer key) {
+ const struct edge_hash_item *itm=key;
+ return itm->first*2654435761UL+itm->last;
}
static gboolean
-edge_hash_equal(gconstpointer a, gconstpointer b)
-{
- const struct edge_hash_item *itm_a=a;
- const struct edge_hash_item *itm_b=b;
- return (itm_a->first == itm_b->first && itm_a->last == itm_b->last);
+edge_hash_equal(gconstpointer a, gconstpointer b) {
+ const struct edge_hash_item *itm_a=a;
+ const struct edge_hash_item *itm_b=b;
+ return (itm_a->first == itm_b->first && itm_a->last == itm_b->last);
}
static void
-ch_generate_ddsg(FILE *in, FILE *ref, FILE *idx, FILE *ddsg)
-{
- GHashTable *hash=coord_hash_new();
- struct item_bin *ib;
- int nodes=0,edges=0;
-
- while ((ib=read_item(in))) {
- int ccount=ib->clen/2;
- struct coord *c=(struct coord *)(ib+1);
- if (road_speed(ib->type)) {
- add_node_to_hash(idx, hash, &c[0], &nodes);
- add_node_to_hash(idx, hash, &c[ccount-1], &nodes);
- edges++;
- }
- }
- edge_hash=g_hash_table_new_full(edge_hash_hash, edge_hash_equal, edge_hash_slice_free, item_id_slice_free);
- fseek(in, 0, SEEK_SET);
- fprintf(ddsg,"d\n");
- fprintf(ddsg,"%d %d\n", nodes, edges);
- while ((ib=read_item(in))) {
- int i,ccount=ib->clen/2;
- struct coord *c=(struct coord *)(ib+1);
- int n1,n2,speed=road_speed(ib->type);
- struct item_id road_id;
- double l;
-
- if (fread(&road_id, sizeof(road_id), 1, ref) == 0){
- dbg(lvl_warning, "fread failed");
- continue;
- }
- if (speed) {
- struct edge_hash_item *hi=g_slice_new(struct edge_hash_item);
- struct item_id *id=g_slice_new(struct item_id);
- *id=road_id;
- dbg_assert((n1=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[0]))) != 0);
- dbg_assert((n2=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[ccount-1]))) != 0);
- l=0;
- for (i = 0 ; i < ccount-1 ; i++) {
- l+=sqrt(sq(c[i+1].x-c[i].x)+sq(c[i+1].y-c[i].y));
- }
- fprintf(ddsg,"%d %d %d 0\n", n1-1, n2-1, (int)(l*36/speed));
- hi->first=n1-1;
- hi->last=n2-1;
- g_hash_table_insert(edge_hash, hi, id);
- }
- }
- g_hash_table_destroy(hash);
+ch_generate_ddsg(FILE *in, FILE *ref, FILE *idx, FILE *ddsg) {
+ GHashTable *hash=coord_hash_new();
+ struct item_bin *ib;
+ int nodes=0,edges=0;
+
+ while ((ib=read_item(in))) {
+ int ccount=ib->clen/2;
+ struct coord *c=(struct coord *)(ib+1);
+ if (road_speed(ib->type)) {
+ add_node_to_hash(idx, hash, &c[0], &nodes);
+ add_node_to_hash(idx, hash, &c[ccount-1], &nodes);
+ edges++;
+ }
+ }
+ edge_hash=g_hash_table_new_full(edge_hash_hash, edge_hash_equal, edge_hash_slice_free, item_id_slice_free);
+ fseek(in, 0, SEEK_SET);
+ fprintf(ddsg,"d\n");
+ fprintf(ddsg,"%d %d\n", nodes, edges);
+ while ((ib=read_item(in))) {
+ int i,ccount=ib->clen/2;
+ struct coord *c=(struct coord *)(ib+1);
+ int n1,n2,speed=road_speed(ib->type);
+ struct item_id road_id;
+ double l;
+
+ if (fread(&road_id, sizeof(road_id), 1, ref) == 0) {
+ dbg(lvl_warning, "fread failed");
+ continue;
+ }
+ if (speed) {
+ struct edge_hash_item *hi=g_slice_new(struct edge_hash_item);
+ struct item_id *id=g_slice_new(struct item_id);
+ *id=road_id;
+ dbg_assert((n1=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[0]))) != 0);
+ dbg_assert((n2=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[ccount-1]))) != 0);
+ l=0;
+ for (i = 0 ; i < ccount-1 ; i++) {
+ l+=sqrt(sq(c[i+1].x-c[i].x)+sq(c[i+1].y-c[i].y));
+ }
+ fprintf(ddsg,"%d %d %d 0\n", n1-1, n2-1, (int)(l*36/speed));
+ hi->first=n1-1;
+ hi->last=n2-1;
+ g_hash_table_insert(edge_hash, hi, id);
+ }
+ }
+ g_hash_table_destroy(hash);
}
static void
-ch_generate_sgr(char *suffix)
-{
+ch_generate_sgr(char *suffix) {
#ifndef HAVE_API_WIN32_CE
- char command[1024];
- int system_result;
- sprintf(command,"./contraction-hierarchies-20080621/main -s -p -f ddsg_%s.tmp -o hcn_%s.tmp -l hcn_log_%s.tmp -x 190 -y 1 -e 600 -p 1000 -k 1,3.3,2,10,3,10,5",suffix,suffix,suffix);
- printf("%s\n",command);
- system_result = system(command);
- if (system_result == -1){
- dbg(lvl_warning, "Running main failed");
- }
- sprintf(command,"./contraction-hierarchies-20080621/main -c -f ddsg_%s.tmp -h hcn_%s.tmp -k 1,3.3,2,10,3,10,5 -C ch_%s.tmp -O 1 -z sgr_%s.tmp",suffix,suffix,suffix,suffix);
- printf("%s\n",command);
- system_result = system(command);
- if (system_result == -1){
- dbg(lvl_warning, "Running main failed");
- }
+ char command[1024];
+ int system_result;
+ sprintf(command,
+ "./contraction-hierarchies-20080621/main -s -p -f ddsg_%s.tmp -o hcn_%s.tmp -l hcn_log_%s.tmp -x 190 -y 1 -e 600 -p 1000 -k 1,3.3,2,10,3,10,5",
+ suffix,suffix,suffix);
+ printf("%s\n",command);
+ system_result = system(command);
+ if (system_result == -1) {
+ dbg(lvl_warning, "Running main failed");
+ }
+ sprintf(command,
+ "./contraction-hierarchies-20080621/main -c -f ddsg_%s.tmp -h hcn_%s.tmp -k 1,3.3,2,10,3,10,5 -C ch_%s.tmp -O 1 -z sgr_%s.tmp",
+ suffix,suffix,suffix,suffix);
+ printf("%s\n",command);
+ system_result = system(command);
+ if (system_result == -1) {
+ dbg(lvl_warning, "Running main failed");
+ }
#endif
}
static void
-ch_process_node(FILE *out, int node, int resolve)
-{
- int first_edge_id=nodes[node].first_edge;
- int last_edge_id=nodes[node+1].first_edge;
- int edge_id;
- struct ch_edge ch_edge;
- struct item_bin *item_bin;
- struct edge_hash_item fwd,rev;
- int oldnode;
- memset(&ch_edge, 0, sizeof(ch_edge));
- item_bin=init_item(type_ch_node);
- oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER(node)));
- item_bin_add_coord(item_bin, &node_index[oldnode], 1);
- fwd.first=oldnode;
- rev.last=oldnode;
- for (edge_id = first_edge_id ; edge_id < last_edge_id ; edge_id++) {
- if (resolve) {
- struct edge *edge=&edges[edge_id];
- int oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER((int)edge->target)));
- struct item_id *id;
- ch_edge.weight=edge->weight;
- fwd.last=oldnode;
- rev.first=oldnode;
- ch_edge.flags=edge->flags & 3;
- if (edge->scmiddle == 67108863) {
- id=g_hash_table_lookup(edge_hash, &fwd);
- if (!id) {
- ch_edge.flags|=8;
- id=g_hash_table_lookup(edge_hash, &rev);
- }
- if (id == NULL) {
- fprintf(stderr,"Shortcut %d Weight %d\n",edge->scmiddle,edge->weight);
- fprintf(stderr,"Neither %d-%d nor %d-%d exists\n",fwd.first,fwd.last,rev.first,rev.last);
- exit(1);
- } else {
- ch_edge.middle=*id;
- }
- } else {
- ch_edge.flags|=4;
- id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->scmiddle));
- dbg_assert(id != NULL);
- ch_edge.middle=*id;
- }
- id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->target));
- if (id == NULL) {
- fprintf(stderr,"Failed to look up target %d\n",edge->target);
- } else {
- ch_edge.target=*id;
- }
- }
- item_bin_add_attr_data(item_bin,attr_ch_edge,&ch_edge,sizeof(ch_edge));
- }
- item_bin_write(item_bin, out);
+ch_process_node(FILE *out, int node, int resolve) {
+ int first_edge_id=nodes[node].first_edge;
+ int last_edge_id=nodes[node+1].first_edge;
+ int edge_id;
+ struct ch_edge ch_edge;
+ struct item_bin *item_bin;
+ struct edge_hash_item fwd,rev;
+ int oldnode;
+ memset(&ch_edge, 0, sizeof(ch_edge));
+ item_bin=init_item(type_ch_node);
+ oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER(node)));
+ item_bin_add_coord(item_bin, &node_index[oldnode], 1);
+ fwd.first=oldnode;
+ rev.last=oldnode;
+ for (edge_id = first_edge_id ; edge_id < last_edge_id ; edge_id++) {
+ if (resolve) {
+ struct edge *edge=&edges[edge_id];
+ int oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER((int)edge->target)));
+ struct item_id *id;
+ ch_edge.weight=edge->weight;
+ fwd.last=oldnode;
+ rev.first=oldnode;
+ ch_edge.flags=edge->flags & 3;
+ if (edge->scmiddle == 67108863) {
+ id=g_hash_table_lookup(edge_hash, &fwd);
+ if (!id) {
+ ch_edge.flags|=8;
+ id=g_hash_table_lookup(edge_hash, &rev);
+ }
+ if (id == NULL) {
+ fprintf(stderr,"Shortcut %d Weight %d\n",edge->scmiddle,edge->weight);
+ fprintf(stderr,"Neither %d-%d nor %d-%d exists\n",fwd.first,fwd.last,rev.first,rev.last);
+ exit(1);
+ } else {
+ ch_edge.middle=*id;
+ }
+ } else {
+ ch_edge.flags|=4;
+ id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->scmiddle));
+ dbg_assert(id != NULL);
+ ch_edge.middle=*id;
+ }
+ id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->target));
+ if (id == NULL) {
+ fprintf(stderr,"Failed to look up target %d\n",edge->target);
+ } else {
+ ch_edge.target=*id;
+ }
+ }
+ item_bin_add_attr_data(item_bin,attr_ch_edge,&ch_edge,sizeof(ch_edge));
+ }
+ item_bin_write(item_bin, out);
}
static void
-ch_process_nodes(FILE *out, int pos, int count, int resolve)
-{
- int i;
- printf("count %d sum=%d newnode_count=%d\n",count,pos,newnode_count);
- for (i = 0 ; i < count ; i++)
- ch_process_node(out, pos+i, resolve);
+ch_process_nodes(FILE *out, int pos, int count, int resolve) {
+ int i;
+ printf("count %d sum=%d newnode_count=%d\n",count,pos,newnode_count);
+ for (i = 0 ; i < count ; i++)
+ ch_process_node(out, pos+i, resolve);
}
static void
-ch_process(FILE **files, int depth, int resolve)
-{
- int count=newnode_count;
- int pos=0;
-
- while (depth > 0 && pos < newnode_count) {
- count=(count+1)/2;
- ch_process_nodes(files[depth], pos, count, resolve);
- pos+=count;
- depth--;
- }
- ch_process_nodes(files[depth], pos, newnode_count-pos, resolve);
+ch_process(FILE **files, int depth, int resolve) {
+ int count=newnode_count;
+ int pos=0;
+
+ while (depth > 0 && pos < newnode_count) {
+ count=(count+1)/2;
+ ch_process_nodes(files[depth], pos, count, resolve);
+ pos+=count;
+ depth--;
+ }
+ ch_process_nodes(files[depth], pos, newnode_count-pos, resolve);
}
static void
-ch_setup(char *suffix)
-{
- int i;
- if (!sgr) {
- int *data,size,offset=0;
- char *filename=tempfile_name(suffix,"sgr");
- printf("filename=%s\n",filename);
- sgr=file_create(filename,0);
- g_free(filename);
- dbg_assert(sgr != NULL);
- file_mmap(sgr);
-
- size=sizeof(int);
- data=(int *)file_data_read(sgr, offset, size);
- node_count=*data;
- offset+=size;
-
- size=node_count*sizeof(struct node);
- nodes=(struct node *)file_data_read(sgr, offset, size);
- offset+=size;
-
- size=sizeof(int);
- data=(int *)file_data_read(sgr, offset, size);
- edge_count=*data;
- offset+=size;
-
- size=edge_count*sizeof(struct edge);
- edges=(struct edge *)file_data_read(sgr, offset, size);
- offset+=size;
-
- size=sizeof(int);
- data=(int *)file_data_read(sgr, offset, size);
- newnode_count=*data;
- offset+=size;
-
- size=edge_count*sizeof(struct newnode);
- newnodes=(struct newnode *)file_data_read(sgr, offset, size);
- offset+=size;
-
- newnode_hash=g_hash_table_new(NULL, NULL);
-
- for (i = 0 ; i < newnode_count ; i++) {
- g_hash_table_insert(newnode_hash, GINT_TO_POINTER(newnodes[i].newnode), GINT_TO_POINTER(i));
- }
- }
- if (!ddsg_node_index) {
- char *filename=tempfile_name(suffix,"ddsg_coords");
- ddsg_node_index=file_create(filename,0);
- g_free(filename);
- dbg_assert(ddsg_node_index != NULL);
- file_mmap(ddsg_node_index);
- node_index=(struct coord *)file_data_read(ddsg_node_index, 0, file_size(ddsg_node_index));
- }
+ch_setup(char *suffix) {
+ int i;
+ if (!sgr) {
+ int *data,size,offset=0;
+ char *filename=tempfile_name(suffix,"sgr");
+ printf("filename=%s\n",filename);
+ sgr=file_create(filename,0);
+ g_free(filename);
+ dbg_assert(sgr != NULL);
+ file_mmap(sgr);
+
+ size=sizeof(int);
+ data=(int *)file_data_read(sgr, offset, size);
+ node_count=*data;
+ offset+=size;
+
+ size=node_count*sizeof(struct node);
+ nodes=(struct node *)file_data_read(sgr, offset, size);
+ offset+=size;
+
+ size=sizeof(int);
+ data=(int *)file_data_read(sgr, offset, size);
+ edge_count=*data;
+ offset+=size;
+
+ size=edge_count*sizeof(struct edge);
+ edges=(struct edge *)file_data_read(sgr, offset, size);
+ offset+=size;
+
+ size=sizeof(int);
+ data=(int *)file_data_read(sgr, offset, size);
+ newnode_count=*data;
+ offset+=size;
+
+ size=edge_count*sizeof(struct newnode);
+ newnodes=(struct newnode *)file_data_read(sgr, offset, size);
+ offset+=size;
+
+ newnode_hash=g_hash_table_new(NULL, NULL);
+
+ for (i = 0 ; i < newnode_count ; i++) {
+ g_hash_table_insert(newnode_hash, GINT_TO_POINTER(newnodes[i].newnode), GINT_TO_POINTER(i));
+ }
+ }
+ if (!ddsg_node_index) {
+ char *filename=tempfile_name(suffix,"ddsg_coords");
+ ddsg_node_index=file_create(filename,0);
+ g_free(filename);
+ dbg_assert(ddsg_node_index != NULL);
+ file_mmap(ddsg_node_index);
+ node_index=(struct coord *)file_data_read(ddsg_node_index, 0, file_size(ddsg_node_index));
+ }
}
static void
-ch_create_tempfiles(char *suffix, FILE **files, int count, int mode)
-{
- char name[256];
- int i;
-
- for (i = 0 ; i <= count ; i++) {
- sprintf(name,"graph_%d",i);
- files[i]=tempfile(suffix, name, mode);
- }
+ch_create_tempfiles(char *suffix, FILE **files, int count, int mode) {
+ char name[256];
+ int i;
+
+ for (i = 0 ; i <= count ; i++) {
+ sprintf(name,"graph_%d",i);
+ files[i]=tempfile(suffix, name, mode);
+ }
}
static void
-ch_close_tempfiles(FILE **files, int count)
-{
- int i;
+ch_close_tempfiles(FILE **files, int count) {
+ int i;
- for (i = 0 ; i <= count ; i++) {
- fclose(files[i]);
- }
+ for (i = 0 ; i <= count ; i++) {
+ fclose(files[i]);
+ }
}
#if 0
static void
-ch_remove_tempfiles(char *suffix, int count)
-{
- char name[256];
- int i;
-
- for (i = 0 ; i <= count ; i++) {
- sprintf(name,"graph_%d",i);
- tempfile_unlink(suffix, name);
- }
+ch_remove_tempfiles(char *suffix, int count) {
+ char name[256];
+ int i;
+
+ for (i = 0 ; i <= count ; i++) {
+ sprintf(name,"graph_%d",i);
+ tempfile_unlink(suffix, name);
+ }
}
#endif
static void
-ch_copy_to_tiles(char *suffix, int count, struct tile_info *info, FILE *ref)
-{
- char name[256];
- int i;
- FILE *f;
- struct item_bin *item_bin;
-
- for (i = count ; i >= 0 ; i--) {
- sprintf(name,"graph_%d",i);
- f=tempfile(suffix, name, 0);
- while ((item_bin = read_item(f))) {
- tile_write_item_minmax(info, item_bin, ref, i, i);
- }
- fclose(f);
- }
+ch_copy_to_tiles(char *suffix, int count, struct tile_info *info, FILE *ref) {
+ char name[256];
+ int i;
+ FILE *f;
+ struct item_bin *item_bin;
+
+ for (i = count ; i >= 0 ; i--) {
+ sprintf(name,"graph_%d",i);
+ f=tempfile(suffix, name, 0);
+ while ((item_bin = read_item(f))) {
+ tile_write_item_minmax(info, item_bin, ref, i, i);
+ }
+ fclose(f);
+ }
}
void
-ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info)
-{
- struct tile_info info;
- FILE *in,*ref,*ddsg_coords,*ddsg;
- FILE **graphfiles;
- info.write=0;
- info.maxlen=0;
- info.suffix=suffix;
- info.tiles_list=NULL;
- info.tilesdir_out=tilesdir_out;
- graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
-
- ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
- in=tempfile(map_suffix,"ways_split",0);
- ref=tempfile(map_suffix,"ways_split_ref",0);
- ddsg_coords=tempfile(suffix,"ddsg_coords",1);
- ddsg=tempfile(suffix,"ddsg",1);
- ch_generate_ddsg(in, ref, ddsg_coords, ddsg);
- fclose(in);
- fclose(ref);
- fclose(ddsg_coords);
- fclose(ddsg);
- ch_generate_sgr(suffix);
- ch_setup(suffix);
- ch_process(graphfiles, ch_levels, 0);
- ch_close_tempfiles(graphfiles, ch_levels);
-
- tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
- ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
- merge_tiles(&info);
-
- write_tilesdir(&info, zip_info, tilesdir_out);
+ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info) {
+ struct tile_info info;
+ FILE *in,*ref,*ddsg_coords,*ddsg;
+ FILE **graphfiles;
+ info.write=0;
+ info.maxlen=0;
+ info.suffix=suffix;
+ info.tiles_list=NULL;
+ info.tilesdir_out=tilesdir_out;
+ graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
+
+ ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
+ in=tempfile(map_suffix,"ways_split",0);
+ ref=tempfile(map_suffix,"ways_split_ref",0);
+ ddsg_coords=tempfile(suffix,"ddsg_coords",1);
+ ddsg=tempfile(suffix,"ddsg",1);
+ ch_generate_ddsg(in, ref, ddsg_coords, ddsg);
+ fclose(in);
+ fclose(ref);
+ fclose(ddsg_coords);
+ fclose(ddsg);
+ ch_generate_sgr(suffix);
+ ch_setup(suffix);
+ ch_process(graphfiles, ch_levels, 0);
+ ch_close_tempfiles(graphfiles, ch_levels);
+
+ tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
+ merge_tiles(&info);
+
+ write_tilesdir(&info, zip_info, tilesdir_out);
}
void
-ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info)
-{
- struct tile_info info;
- struct tile_head *th;
- FILE **graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
- FILE *ref;
- struct item_id id;
- int nodeid=0;
-
- info.write=1;
- info.maxlen=zip_get_maxnamelen(zip_info);
- info.suffix=suffix;
- info.tiles_list=NULL;
- info.tilesdir_out=NULL;
- ref=tempfile(suffix,"sgr_ref",1);
-
- create_tile_hash();
-
- th=tile_head_root;
- while (th) {
- th->zip_data=NULL;
- th->process=1;
- th=th->next;
- }
-
- ch_setup(suffix);
- ch_copy_to_tiles(suffix, ch_levels, &info, ref);
- fclose(ref);
- ref=tempfile(suffix,"sgr_ref",0);
- sgr_nodes_hash=g_hash_table_new_full(NULL, NULL, NULL, item_id_slice_free);
- while (fread(&id, sizeof(id), 1, ref)) {
- struct item_id *id2=g_slice_new(struct item_id);
- *id2=id;
- g_hash_table_insert(sgr_nodes_hash, GINT_TO_POINTER(nodeid), id2);
- nodeid++;
- }
- th=tile_head_root;
- while (th) {
- th->zip_data=g_malloc(th->total_size);
- th->total_size_used=0;
- th=th->next;
- }
- ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
- ch_process(graphfiles, ch_levels, 1);
- ch_close_tempfiles(graphfiles, ch_levels);
-
- g_hash_table_destroy(newnode_hash);
- g_hash_table_destroy(edge_hash);
- g_hash_table_destroy(sgr_nodes_hash);
-
- ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
- write_tilesdir(&info, zip_info, NULL);
-
- th=tile_head_root;
- while (th) {
- if (th->name[0]) {
- if (th->total_size != th->total_size_used) {
- fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
- exit(1);
- }
- write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
- } else {
- fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info));
- }
- g_free(th->zip_data);
- th=th->next;
+ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info) {
+ struct tile_info info;
+ struct tile_head *th;
+ FILE **graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
+ FILE *ref;
+ struct item_id id;
+ int nodeid=0;
+
+ info.write=1;
+ info.maxlen=zip_get_maxnamelen(zip_info);
+ info.suffix=suffix;
+ info.tiles_list=NULL;
+ info.tilesdir_out=NULL;
+ ref=tempfile(suffix,"sgr_ref",1);
+
+ create_tile_hash();
+
+ th=tile_head_root;
+ while (th) {
+ th->zip_data=NULL;
+ th->process=1;
+ th=th->next;
+ }
+
+ ch_setup(suffix);
+ ch_copy_to_tiles(suffix, ch_levels, &info, ref);
+ fclose(ref);
+ ref=tempfile(suffix,"sgr_ref",0);
+ sgr_nodes_hash=g_hash_table_new_full(NULL, NULL, NULL, item_id_slice_free);
+ while (fread(&id, sizeof(id), 1, ref)) {
+ struct item_id *id2=g_slice_new(struct item_id);
+ *id2=id;
+ g_hash_table_insert(sgr_nodes_hash, GINT_TO_POINTER(nodeid), id2);
+ nodeid++;
+ }
+ th=tile_head_root;
+ while (th) {
+ th->zip_data=g_malloc(th->total_size);
+ th->total_size_used=0;
+ th=th->next;
+ }
+ ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
+ ch_process(graphfiles, ch_levels, 1);
+ ch_close_tempfiles(graphfiles, ch_levels);
+
+ g_hash_table_destroy(newnode_hash);
+ g_hash_table_destroy(edge_hash);
+ g_hash_table_destroy(sgr_nodes_hash);
+
+ ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
+ write_tilesdir(&info, zip_info, NULL);
+
+ th=tile_head_root;
+ while (th) {
+ if (th->name[0]) {
+ if (th->total_size != th->total_size_used) {
+ fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
+ exit(1);
+ }
+ write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
+ } else {
+ fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info));
}
+ g_free(th->zip_data);
+ th=th->next;
+ }
}
diff --git a/navit/maptool/coastline.c b/navit/maptool/coastline.c
index 5de56f5b2..68e73cca4 100644
--- a/navit/maptool/coastline.c
+++ b/navit/maptool/coastline.c
@@ -19,528 +19,511 @@
#include "maptool.h"
#include "debug.h"
-struct coastline_tile
-{
- osmid wayid;
- int edges;
+struct coastline_tile {
+ osmid wayid;
+ int edges;
};
-static int distance_from_ll(struct coord *c, struct rect *bbox)
-{
- int dist=0;
- if (c->x == bbox->l.x)
- return dist+c->y-bbox->l.y;
- dist+=bbox->h.y-bbox->l.y;
- if (c->y == bbox->h.y)
- return dist+c->x-bbox->l.x;
- dist+=bbox->h.x-bbox->l.x;
- if (c->x == bbox->h.x)
- return dist+bbox->h.y-c->y;
- dist+=bbox->h.y-bbox->l.y;
- if (c->y == bbox->l.y)
- return dist+bbox->h.x-c->x;
- return -1;
+static int distance_from_ll(struct coord *c, struct rect *bbox) {
+ int dist=0;
+ if (c->x == bbox->l.x)
+ return dist+c->y-bbox->l.y;
+ dist+=bbox->h.y-bbox->l.y;
+ if (c->y == bbox->h.y)
+ return dist+c->x-bbox->l.x;
+ dist+=bbox->h.x-bbox->l.x;
+ if (c->x == bbox->h.x)
+ return dist+bbox->h.y-c->y;
+ dist+=bbox->h.y-bbox->l.y;
+ if (c->y == bbox->l.y)
+ return dist+bbox->h.x-c->x;
+ return -1;
}
static struct geom_poly_segment *
-find_next(struct rect *bbox, GList *segments, struct coord *c, int exclude, struct coord *ci)
-{
- int min=INT_MAX,search=distance_from_ll(c, bbox)+(exclude?1:0);
- GList *curr;
- int i;
- struct geom_poly_segment *ret=NULL;
+find_next(struct rect *bbox, GList *segments, struct coord *c, int exclude, struct coord *ci) {
+ int min=INT_MAX,search=distance_from_ll(c, bbox)+(exclude?1:0);
+ GList *curr;
+ int i;
+ struct geom_poly_segment *ret=NULL;
- for (i = 0 ; i < 2 ; i++) {
- curr=segments;
- dbg(lvl_debug,"search distance %d",search);
- while (curr) {
- struct geom_poly_segment *seg=curr->data;
- int dist=distance_from_ll(seg->first, bbox);
- dbg(lvl_debug,"0x%x 0x%x dist %d",seg->first->x,seg->first->y,dist);
- if (dist != -1 && seg->first != seg->last && dist < min && (dist >= search)) {
- min=dist;
- ci[0]=*seg->first;
- ci[1]=*seg->last;
- ret=seg;
- }
- curr=g_list_next(curr);
- }
- if (ret || !search)
- break;
- search=0;
- }
- return ret;
+ for (i = 0 ; i < 2 ; i++) {
+ curr=segments;
+ dbg(lvl_debug,"search distance %d",search);
+ while (curr) {
+ struct geom_poly_segment *seg=curr->data;
+ int dist=distance_from_ll(seg->first, bbox);
+ dbg(lvl_debug,"0x%x 0x%x dist %d",seg->first->x,seg->first->y,dist);
+ if (dist != -1 && seg->first != seg->last && dist < min && (dist >= search)) {
+ min=dist;
+ ci[0]=*seg->first;
+ ci[1]=*seg->last;
+ ret=seg;
+ }
+ curr=g_list_next(curr);
+ }
+ if (ret || !search)
+ break;
+ search=0;
+ }
+ return ret;
}
static void
-close_polygon(struct item_bin *ib, struct coord *from, struct coord *to, int dir, struct rect *bbox, int *edges)
-{
- int i,e,dist,fromdist,todist;
- int full=(bbox->h.x-bbox->l.x+bbox->h.y-bbox->l.y)*2;
- int corners=0,first_corner=0;
- struct coord c;
- if (dir > 0) {
- fromdist=distance_from_ll(from, bbox);
- todist=distance_from_ll(to, bbox);
- } else {
- fromdist=distance_from_ll(to, bbox);
- todist=distance_from_ll(from, bbox);
- }
- if (fromdist > todist)
- todist+=full;
- for (i = 0 ; i < 8 ; i++) {
- if (dir > 0)
- e=i;
- else
- e=7-i;
- switch (e%4) {
- case 0:
- c=bbox->l;
- break;
- case 1:
- c.x=bbox->l.x;
- c.y=bbox->h.y;
- break;
- case 2:
- c=bbox->h;
- break;
- case 3:
- c.x=bbox->h.x;
- c.y=bbox->l.y;
- break;
- }
- dist=distance_from_ll(&c, bbox);
- if (e & 4)
- dist+=full;
- if (dist > fromdist && dist < todist) {
- item_bin_add_coord(ib, &c, 1);
- }
- if (dist >= fromdist && dist <= todist) {
- if (!corners)
- first_corner=e;
- corners++;
- }
- }
- while (corners >= 2) {
- *edges |= 1<<(first_corner%4);
- first_corner++;
- corners--;
- }
+close_polygon(struct item_bin *ib, struct coord *from, struct coord *to, int dir, struct rect *bbox, int *edges) {
+ int i,e,dist,fromdist,todist;
+ int full=(bbox->h.x-bbox->l.x+bbox->h.y-bbox->l.y)*2;
+ int corners=0,first_corner=0;
+ struct coord c;
+ if (dir > 0) {
+ fromdist=distance_from_ll(from, bbox);
+ todist=distance_from_ll(to, bbox);
+ } else {
+ fromdist=distance_from_ll(to, bbox);
+ todist=distance_from_ll(from, bbox);
+ }
+ if (fromdist > todist)
+ todist+=full;
+ for (i = 0 ; i < 8 ; i++) {
+ if (dir > 0)
+ e=i;
+ else
+ e=7-i;
+ switch (e%4) {
+ case 0:
+ c=bbox->l;
+ break;
+ case 1:
+ c.x=bbox->l.x;
+ c.y=bbox->h.y;
+ break;
+ case 2:
+ c=bbox->h;
+ break;
+ case 3:
+ c.x=bbox->h.x;
+ c.y=bbox->l.y;
+ break;
+ }
+ dist=distance_from_ll(&c, bbox);
+ if (e & 4)
+ dist+=full;
+ if (dist > fromdist && dist < todist) {
+ item_bin_add_coord(ib, &c, 1);
+ }
+ if (dist >= fromdist && dist <= todist) {
+ if (!corners)
+ first_corner=e;
+ corners++;
+ }
+ }
+ while (corners >= 2) {
+ *edges |= 1<<(first_corner%4);
+ first_corner++;
+ corners--;
+ }
}
struct coastline_tile_data {
- struct item_bin_sink_func *sink;
- GHashTable *tile_edges;
- int level;
- GList *k,*v;
+ struct item_bin_sink_func *sink;
+ GHashTable *tile_edges;
+ int level;
+ GList *k,*v;
};
static GList *
-tile_data_to_segments(int *tile_data)
-{
- int *end=tile_data+tile_data[0];
- int *curr=tile_data+1;
- GList *segments=NULL;
- int count=0;
+tile_data_to_segments(int *tile_data) {
+ int *end=tile_data+tile_data[0];
+ int *curr=tile_data+1;
+ GList *segments=NULL;
+ int count=0;
- while (curr < end) {
- struct item_bin *ib=(struct item_bin *)curr;
- segments=g_list_prepend(segments,item_bin_to_poly_segment(ib, geom_poly_segment_type_way_right_side));
- curr+=ib->len+1;
- count++;
- }
- return segments;
+ while (curr < end) {
+ struct item_bin *ib=(struct item_bin *)curr;
+ segments=g_list_prepend(segments,item_bin_to_poly_segment(ib, geom_poly_segment_type_way_right_side));
+ curr+=ib->len+1;
+ count++;
+ }
+ return segments;
}
static void
-tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_data *data)
-{
- int poly_start_valid,tile_start_valid,exclude,search=0;
- struct rect bbox;
- struct coord cn[2],end,poly_start,tile_start;
- struct geom_poly_segment *first;
- struct item_bin *ib=NULL;
- struct item_bin_sink *out=data->sink->priv_data[1];
- int edges=0,flags;
- GList *sorted_segments,*curr;
- struct item_bin *ibt=(struct item_bin *)(tile_data+1);
- struct coastline_tile *ct=g_new0(struct coastline_tile, 1);
- ct->wayid=item_bin_get_wayid(ibt);
- tile_bbox(tile, &bbox, 0);
- curr=tile_data_to_segments(tile_data);
- sorted_segments=geom_poly_segments_sort(curr, geom_poly_segment_type_way_right_side);
- g_list_foreach(curr,(GFunc)geom_poly_segment_destroy,NULL);
- g_list_free(curr);
-
- flags=0;
- curr=sorted_segments;
- while (curr) {
- struct geom_poly_segment *seg=curr->data;
- switch (seg->type) {
- case geom_poly_segment_type_way_inner:
- flags|=1;
- break;
- case geom_poly_segment_type_way_outer:
- flags|=2;
- break;
- default:
- flags|=4;
- break;
- }
- curr=g_list_next(curr);
- }
- if (flags == 1) {
- ct->edges=15;
- ib=init_item(type_poly_water_tiled);
- item_bin_bbox(ib, &bbox);
- item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid);
- item_bin_write_to_sink(ib, out, NULL);
- g_hash_table_insert(data->tile_edges, g_strdup(tile), ct);
- return;
- }
- end=bbox.l;
- tile_start_valid=0;
- poly_start_valid=0;
- exclude=0;
- poly_start.x=0;
- poly_start.y=0;
- tile_start.x=0;
- tile_start.y=0;
- for (;;) {
- search++;
- // item_bin_write_debug_point_to_sink(out, &end, "Search %d",search);
- dbg(lvl_debug,"searching next polygon from 0x%x 0x%x",end.x,end.y);
- first=find_next(&bbox, sorted_segments, &end, exclude, cn);
- exclude=1;
- if (!first)
- break;
- if (!tile_start_valid) {
- tile_start=cn[0];
- tile_start_valid=1;
- } else {
- if (cn[0].x == tile_start.x && cn[0].y == tile_start.y) {
- dbg(lvl_debug,"end of tile reached");
- break;
- }
- }
- if (first->type == geom_poly_segment_type_none) {
- end=cn[0];
- continue;
- }
- poly_start_valid=0;
- dbg(lvl_debug,"start of polygon 0x%x 0x%x",cn[0].x,cn[0].y);
- for (;;) {
- if (!poly_start_valid) {
- poly_start=cn[0];
- poly_start_valid=1;
- ib=init_item(type_poly_water_tiled);
- } else {
- close_polygon(ib, &end, &cn[0], 1, &bbox, &edges);
- if (cn[0].x == poly_start.x && cn[0].y == poly_start.y) {
- dbg(lvl_debug,"poly end reached");
- item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid);
- item_bin_write_to_sink(ib, out, NULL);
- end=cn[0];
- break;
- }
- }
- if (first->type == geom_poly_segment_type_none)
- break;
- item_bin_add_coord(ib, first->first, first->last-first->first+1);
- first->type=geom_poly_segment_type_none;
- end=cn[1];
- if (distance_from_ll(&end, &bbox) == -1) {
- dbg(lvl_debug,"incomplete");
- break;
- }
- first=find_next(&bbox, sorted_segments, &end, 1, cn);
- dbg(lvl_debug,"next segment of polygon 0x%x 0x%x",cn[0].x,cn[0].y);
- }
- if (search > 55)
- break;
- }
- g_list_foreach(sorted_segments,(GFunc)geom_poly_segment_destroy,NULL);
- g_list_free(sorted_segments);
+tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_data *data) {
+ int poly_start_valid,tile_start_valid,exclude,search=0;
+ struct rect bbox;
+ struct coord cn[2],end,poly_start,tile_start;
+ struct geom_poly_segment *first;
+ struct item_bin *ib=NULL;
+ struct item_bin_sink *out=data->sink->priv_data[1];
+ int edges=0,flags;
+ GList *sorted_segments,*curr;
+ struct item_bin *ibt=(struct item_bin *)(tile_data+1);
+ struct coastline_tile *ct=g_new0(struct coastline_tile, 1);
+ ct->wayid=item_bin_get_wayid(ibt);
+ tile_bbox(tile, &bbox, 0);
+ curr=tile_data_to_segments(tile_data);
+ sorted_segments=geom_poly_segments_sort(curr, geom_poly_segment_type_way_right_side);
+ g_list_foreach(curr,(GFunc)geom_poly_segment_destroy,NULL);
+ g_list_free(curr);
- ct->edges=edges;
- g_hash_table_insert(data->tile_edges, g_strdup(tile), ct);
+ flags=0;
+ curr=sorted_segments;
+ while (curr) {
+ struct geom_poly_segment *seg=curr->data;
+ switch (seg->type) {
+ case geom_poly_segment_type_way_inner:
+ flags|=1;
+ break;
+ case geom_poly_segment_type_way_outer:
+ flags|=2;
+ break;
+ default:
+ flags|=4;
+ break;
+ }
+ curr=g_list_next(curr);
+ }
+ if (flags == 1) {
+ ct->edges=15;
+ ib=init_item(type_poly_water_tiled);
+ item_bin_bbox(ib, &bbox);
+ item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid);
+ item_bin_write_to_sink(ib, out, NULL);
+ g_hash_table_insert(data->tile_edges, g_strdup(tile), ct);
+ return;
+ }
+ end=bbox.l;
+ tile_start_valid=0;
+ poly_start_valid=0;
+ exclude=0;
+ poly_start.x=0;
+ poly_start.y=0;
+ tile_start.x=0;
+ tile_start.y=0;
+ for (;;) {
+ search++;
+ // item_bin_write_debug_point_to_sink(out, &end, "Search %d",search);
+ dbg(lvl_debug,"searching next polygon from 0x%x 0x%x",end.x,end.y);
+ first=find_next(&bbox, sorted_segments, &end, exclude, cn);
+ exclude=1;
+ if (!first)
+ break;
+ if (!tile_start_valid) {
+ tile_start=cn[0];
+ tile_start_valid=1;
+ } else {
+ if (cn[0].x == tile_start.x && cn[0].y == tile_start.y) {
+ dbg(lvl_debug,"end of tile reached");
+ break;
+ }
+ }
+ if (first->type == geom_poly_segment_type_none) {
+ end=cn[0];
+ continue;
+ }
+ poly_start_valid=0;
+ dbg(lvl_debug,"start of polygon 0x%x 0x%x",cn[0].x,cn[0].y);
+ for (;;) {
+ if (!poly_start_valid) {
+ poly_start=cn[0];
+ poly_start_valid=1;
+ ib=init_item(type_poly_water_tiled);
+ } else {
+ close_polygon(ib, &end, &cn[0], 1, &bbox, &edges);
+ if (cn[0].x == poly_start.x && cn[0].y == poly_start.y) {
+ dbg(lvl_debug,"poly end reached");
+ item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid);
+ item_bin_write_to_sink(ib, out, NULL);
+ end=cn[0];
+ break;
+ }
+ }
+ if (first->type == geom_poly_segment_type_none)
+ break;
+ item_bin_add_coord(ib, first->first, first->last-first->first+1);
+ first->type=geom_poly_segment_type_none;
+ end=cn[1];
+ if (distance_from_ll(&end, &bbox) == -1) {
+ dbg(lvl_debug,"incomplete");
+ break;
+ }
+ first=find_next(&bbox, sorted_segments, &end, 1, cn);
+ dbg(lvl_debug,"next segment of polygon 0x%x 0x%x",cn[0].x,cn[0].y);
+ }
+ if (search > 55)
+ break;
+ }
+ g_list_foreach(sorted_segments,(GFunc)geom_poly_segment_destroy,NULL);
+ g_list_free(sorted_segments);
+
+ ct->edges=edges;
+ g_hash_table_insert(data->tile_edges, g_strdup(tile), ct);
}
static void
-ocean_tile(GHashTable *hash, char *tile, char c, osmid wayid, struct item_bin_sink *out)
-{
- int len=strlen(tile);
- char *tile2=g_alloca(sizeof(char)*(len+1));
- struct rect bbox;
- struct item_bin *ib;
- struct coastline_tile *ct;
+ocean_tile(GHashTable *hash, char *tile, char c, osmid wayid, struct item_bin_sink *out) {
+ int len=strlen(tile);
+ char *tile2=g_alloca(sizeof(char)*(len+1));
+ struct rect bbox;
+ struct item_bin *ib;
+ struct coastline_tile *ct;
- strcpy(tile2, tile);
- tile2[len-1]=c;
- //fprintf(stderr,"Testing %s\n",tile2);
- ct=g_hash_table_lookup(hash, tile2);
- if (ct)
- return;
- //fprintf(stderr,"%s ok\n",tile2);
- tile_bbox(tile2, &bbox, 0);
- ib=init_item(type_poly_water_tiled);
- item_bin_bbox(ib, &bbox);
- item_bin_add_attr_longlong(ib, attr_osm_wayid, wayid);
- item_bin_write_to_sink(ib, out, NULL);
- ct=g_new0(struct coastline_tile, 1);
- ct->edges=15;
- ct->wayid=wayid;
- g_hash_table_insert(hash, g_strdup(tile2), ct);
+ strcpy(tile2, tile);
+ tile2[len-1]=c;
+ //fprintf(stderr,"Testing %s\n",tile2);
+ ct=g_hash_table_lookup(hash, tile2);
+ if (ct)
+ return;
+ //fprintf(stderr,"%s ok\n",tile2);
+ tile_bbox(tile2, &bbox, 0);
+ ib=init_item(type_poly_water_tiled);
+ item_bin_bbox(ib, &bbox);
+ item_bin_add_attr_longlong(ib, attr_osm_wayid, wayid);
+ item_bin_write_to_sink(ib, out, NULL);
+ ct=g_new0(struct coastline_tile, 1);
+ ct->edges=15;
+ ct->wayid=wayid;
+ g_hash_table_insert(hash, g_strdup(tile2), ct);
}
/* ba */
/* dc */
static void
-tile_collector_add_siblings(char *tile, struct coastline_tile *ct, struct coastline_tile_data *data)
-{
- int len=strlen(tile);
- char t=tile[len-1];
- struct item_bin_sink *out=data->sink->priv_data[1];
- int edges=ct->edges;
- int debug=0;
- if (debug)
- fprintf(stderr,"%s (%c) has %d edges active\n",tile,t,edges);
- if (t == 'a' && (edges & 1))
- ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out);
- if (t == 'a' && (edges & 8))
- ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out);
- if (t == 'b' && (edges & 4))
- ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out);
- if (t == 'b' && (edges & 8))
- ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out);
- if (t == 'c' && (edges & 1))
- ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out);
- if (t == 'c' && (edges & 2))
- ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out);
- if (t == 'd' && (edges & 4))
- ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out);
- if (t == 'd' && (edges & 2))
- ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out);
+tile_collector_add_siblings(char *tile, struct coastline_tile *ct, struct coastline_tile_data *data) {
+ int len=strlen(tile);
+ char t=tile[len-1];
+ struct item_bin_sink *out=data->sink->priv_data[1];
+ int edges=ct->edges;
+ int debug=0;
+ if (debug)
+ fprintf(stderr,"%s (%c) has %d edges active\n",tile,t,edges);
+ if (t == 'a' && (edges & 1))
+ ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out);
+ if (t == 'a' && (edges & 8))
+ ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out);
+ if (t == 'b' && (edges & 4))
+ ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out);
+ if (t == 'b' && (edges & 8))
+ ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out);
+ if (t == 'c' && (edges & 1))
+ ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out);
+ if (t == 'c' && (edges & 2))
+ ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out);
+ if (t == 'd' && (edges & 4))
+ ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out);
+ if (t == 'd' && (edges & 2))
+ ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out);
}
static int
-tile_sibling_edges(GHashTable *hash, char *tile, char c)
-{
- int len=strlen(tile);
- char *tile2=g_alloca(sizeof(char)*(len+1));
- struct coastline_tile *ct;
- strcpy(tile2, tile);
- tile2[len-1]=c;
- ct=g_hash_table_lookup(hash, tile2);
- if (ct)
- return ct->edges;
- return 15;
+tile_sibling_edges(GHashTable *hash, char *tile, char c) {
+ int len=strlen(tile);
+ char *tile2=g_alloca(sizeof(char)*(len+1));
+ struct coastline_tile *ct;
+ strcpy(tile2, tile);
+ tile2[len-1]=c;
+ ct=g_hash_table_lookup(hash, tile2);
+ if (ct)
+ return ct->edges;
+ return 15;
}
#if 0
static void
-ocean_tile2(struct rect *r, int dx, int dy, int wf, int hf, struct item_bin_sink *out)
-{
- struct item_bin *ib;
- int w=r->h.x-r->l.x;
- int h=r->h.y-r->l.y;
- char tile2[32];
- struct rect bbox;
- bbox.l.x=r->l.x+dx*w;
- bbox.l.y=r->l.y+dy*h;
- bbox.h.x=bbox.l.x+w*wf;
- bbox.h.y=bbox.l.y+h*hf;
- //fprintf(stderr,"0x%x,0x%x-0x%x,0x%x -> 0x%x,0x%x-0x%x,0x%x\n",r->l.x,r->l.y,r->h.x,r->h.y,bbox.l.x,bbox.l.y,bbox.h.x,bbox.h.y);
- ib=init_item(type_poly_water_tiled);
- item_bin_bbox(ib, &bbox);
- item_bin_write_to_sink(ib, out, NULL);
+ocean_tile2(struct rect *r, int dx, int dy, int wf, int hf, struct item_bin_sink *out) {
+ struct item_bin *ib;
+ int w=r->h.x-r->l.x;
+ int h=r->h.y-r->l.y;
+ char tile2[32];
+ struct rect bbox;
+ bbox.l.x=r->l.x+dx*w;
+ bbox.l.y=r->l.y+dy*h;
+ bbox.h.x=bbox.l.x+w*wf;
+ bbox.h.y=bbox.l.y+h*hf;
+ //fprintf(stderr,"0x%x,0x%x-0x%x,0x%x -> 0x%x,0x%x-0x%x,0x%x\n",r->l.x,r->l.y,r->h.x,r->h.y,bbox.l.x,bbox.l.y,bbox.h.x,bbox.h.y);
+ ib=init_item(type_poly_water_tiled);
+ item_bin_bbox(ib, &bbox);
+ item_bin_write_to_sink(ib, out, NULL);
#if 0
- item_bin_init(ib, type_border_country);
- item_bin_bbox(ib, &bbox);
- item_bin_add_attr_string(ib, attr_debug, tile2);
- item_bin_write_to_sink(ib, out, NULL);
+ item_bin_init(ib, type_border_country);
+ item_bin_bbox(ib, &bbox);
+ item_bin_add_attr_string(ib, attr_debug, tile2);
+ item_bin_write_to_sink(ib, out, NULL);
#endif
- tile(&bbox, NULL, tile2, 32, 0, NULL);
+ tile(&bbox, NULL, tile2, 32, 0, NULL);
#if 0
- {
- struct coord co;
- co.x=(bbox.l.x+bbox.h.x)/2;
- co.y=(bbox.l.y+bbox.h.y)/2;
- item_bin_write_debug_point_to_sink(out, &co, "%s 15",tile2);
- }
+ {
+ struct coord co;
+ co.x=(bbox.l.x+bbox.h.x)/2;
+ co.y=(bbox.l.y+bbox.h.y)/2;
+ item_bin_write_debug_point_to_sink(out, &co, "%s 15",tile2);
+ }
#endif
}
#endif
static void
-tile_collector_add_siblings2(char *tile, struct coastline_tile *ct, struct coastline_tile_data *data)
-{
- int edges=ct->edges;
- int pedges=0;
- int debug=0;
- int len=strlen(tile);
- struct coastline_tile *cn, *co;
- char *tile2=g_alloca(sizeof(char)*(len+1));
- char t=tile[len-1];
- strcpy(tile2, tile);
- tile2[len-1]='\0';
- if (debug)
- fprintf(stderr,"len of %s %d vs %d\n",tile,len,data->level);
+tile_collector_add_siblings2(char *tile, struct coastline_tile *ct, struct coastline_tile_data *data) {
+ int edges=ct->edges;
+ int pedges=0;
+ int debug=0;
+ int len=strlen(tile);
+ struct coastline_tile *cn, *co;
+ char *tile2=g_alloca(sizeof(char)*(len+1));
+ char t=tile[len-1];
+ strcpy(tile2, tile);
+ tile2[len-1]='\0';
+ if (debug)
+ fprintf(stderr,"len of %s %d vs %d\n",tile,len,data->level);
- if (debug)
- fprintf(stderr,"checking siblings of '%s' with %d edges active\n",tile,edges);
- if (t == 'b' && (edges & 1) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 1))
- pedges|=1;
- if (t == 'd' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 1))
- pedges|=1;
- if (t == 'a' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 2))
- pedges|=2;
- if (t == 'b' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 2))
- pedges|=2;
- if (t == 'a' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 4))
- pedges|=4;
- if (t == 'c' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 4))
- pedges|=4;
- if (t == 'd' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 8))
- pedges|=8;
- if (t == 'c' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 8))
- pedges|=8;
- co=g_hash_table_lookup(data->tile_edges, tile2);
- if (debug)
- fprintf(stderr,"result '%s' %d old %d\n",tile2,pedges,co?co->edges:0);
- cn=g_new0(struct coastline_tile, 1);
- cn->edges=pedges;
- if (co) {
- cn->edges|=co->edges;
- cn->wayid=co->wayid;
- } else
- cn->wayid=ct->wayid;
- g_hash_table_insert(data->tile_edges, g_strdup(tile2), cn);
+ if (debug)
+ fprintf(stderr,"checking siblings of '%s' with %d edges active\n",tile,edges);
+ if (t == 'b' && (edges & 1) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 1))
+ pedges|=1;
+ if (t == 'd' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 1))
+ pedges|=1;
+ if (t == 'a' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'b') & 2))
+ pedges|=2;
+ if (t == 'b' && (edges & 2) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 2))
+ pedges|=2;
+ if (t == 'a' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 4))
+ pedges|=4;
+ if (t == 'c' && (edges & 4) && (tile_sibling_edges(data->tile_edges, tile, 'a') & 4))
+ pedges|=4;
+ if (t == 'd' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'c') & 8))
+ pedges|=8;
+ if (t == 'c' && (edges & 8) && (tile_sibling_edges(data->tile_edges, tile, 'd') & 8))
+ pedges|=8;
+ co=g_hash_table_lookup(data->tile_edges, tile2);
+ if (debug)
+ fprintf(stderr,"result '%s' %d old %d\n",tile2,pedges,co?co->edges:0);
+ cn=g_new0(struct coastline_tile, 1);
+ cn->edges=pedges;
+ if (co) {
+ cn->edges|=co->edges;
+ cn->wayid=co->wayid;
+ } else
+ cn->wayid=ct->wayid;
+ g_hash_table_insert(data->tile_edges, g_strdup(tile2), cn);
}
static void
-foreach_tile_func(gpointer key, gpointer value, gpointer user_data)
-{
- struct coastline_tile_data *data=user_data;
- if (strlen((char *)key) == data->level) {
- data->k=g_list_prepend(data->k, key);
- data->v=g_list_prepend(data->v, value);
- }
+foreach_tile_func(gpointer key, gpointer value, gpointer user_data) {
+ struct coastline_tile_data *data=user_data;
+ if (strlen((char *)key) == data->level) {
+ data->k=g_list_prepend(data->k, key);
+ data->v=g_list_prepend(data->v, value);
+ }
}
static void
-foreach_tile(struct coastline_tile_data *data, void(*func)(char *, struct coastline_tile *, struct coastline_tile_data *))
-{
- GList *k,*v;
- data->k=NULL;
- data->v=NULL;
-
- g_hash_table_foreach(data->tile_edges, foreach_tile_func, data);
- k=data->k;
- v=data->v;
- while (k) {
- func(k->data,v->data,data);
- k=g_list_next(k);
- v=g_list_next(v);
- }
- g_list_free(data->k);
- g_list_free(data->v);
+foreach_tile(struct coastline_tile_data *data, void(*func)(char *, struct coastline_tile *,
+ struct coastline_tile_data *)) {
+ GList *k,*v;
+ data->k=NULL;
+ data->v=NULL;
+
+ g_hash_table_foreach(data->tile_edges, foreach_tile_func, data);
+ k=data->k;
+ v=data->v;
+ while (k) {
+ func(k->data,v->data,data);
+ k=g_list_next(k);
+ v=g_list_next(v);
+ }
+ g_list_free(data->k);
+ g_list_free(data->v);
}
static int
-tile_collector_finish(struct item_bin_sink_func *tile_collector)
-{
- struct coastline_tile_data data;
- int i;
- GHashTable *hash;
- data.sink=tile_collector;
- data.tile_edges=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
- hash=tile_collector->priv_data[0];
- fprintf(stderr,"tile_collector_finish\n");
+tile_collector_finish(struct item_bin_sink_func *tile_collector) {
+ struct coastline_tile_data data;
+ int i;
+ GHashTable *hash;
+ data.sink=tile_collector;
+ data.tile_edges=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ hash=tile_collector->priv_data[0];
+ fprintf(stderr,"tile_collector_finish\n");
#if 1
- g_hash_table_foreach(hash, (GHFunc) tile_collector_process_tile, &data);
+ g_hash_table_foreach(hash, (GHFunc) tile_collector_process_tile, &data);
#endif
- fprintf(stderr,"tile_collector_finish foreach done\n");
- g_hash_table_destroy(hash);
- fprintf(stderr,"tile_collector_finish destroy done\n");
- for (i = 14 ; i > 0 ; i--) {
- fprintf(stderr,"Level=%d\n",i);
- data.level=i;
- foreach_tile(&data, tile_collector_add_siblings);
- fprintf(stderr,"*");
- foreach_tile(&data, tile_collector_add_siblings);
- fprintf(stderr,"*");
- foreach_tile(&data, tile_collector_add_siblings);
- fprintf(stderr,"*");
- foreach_tile(&data, tile_collector_add_siblings);
- fprintf(stderr,"*");
- foreach_tile(&data, tile_collector_add_siblings2);
- fprintf(stderr,"*\n");
- foreach_tile(&data, tile_collector_add_siblings2);
- fprintf(stderr,"*\n");
- foreach_tile(&data, tile_collector_add_siblings2);
- fprintf(stderr,"*\n");
- foreach_tile(&data, tile_collector_add_siblings2);
- fprintf(stderr,"*\n");
- }
- item_bin_sink_func_destroy(tile_collector);
- fprintf(stderr,"tile_collector_finish done\n");
- return 0;
+ fprintf(stderr,"tile_collector_finish foreach done\n");
+ g_hash_table_destroy(hash);
+ fprintf(stderr,"tile_collector_finish destroy done\n");
+ for (i = 14 ; i > 0 ; i--) {
+ fprintf(stderr,"Level=%d\n",i);
+ data.level=i;
+ foreach_tile(&data, tile_collector_add_siblings);
+ fprintf(stderr,"*");
+ foreach_tile(&data, tile_collector_add_siblings);
+ fprintf(stderr,"*");
+ foreach_tile(&data, tile_collector_add_siblings);
+ fprintf(stderr,"*");
+ foreach_tile(&data, tile_collector_add_siblings);
+ fprintf(stderr,"*");
+ foreach_tile(&data, tile_collector_add_siblings2);
+ fprintf(stderr,"*\n");
+ foreach_tile(&data, tile_collector_add_siblings2);
+ fprintf(stderr,"*\n");
+ foreach_tile(&data, tile_collector_add_siblings2);
+ fprintf(stderr,"*\n");
+ foreach_tile(&data, tile_collector_add_siblings2);
+ fprintf(stderr,"*\n");
+ }
+ item_bin_sink_func_destroy(tile_collector);
+ fprintf(stderr,"tile_collector_finish done\n");
+ return 0;
}
static int
-coastline_processor_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data)
-{
- item_bin_write_clipped(ib, func->priv_data[0], func->priv_data[1]);
- return 0;
+coastline_processor_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data) {
+ item_bin_write_clipped(ib, func->priv_data[0], func->priv_data[1]);
+ return 0;
}
static struct item_bin_sink_func *
-coastline_processor_new(struct item_bin_sink *out)
-{
- struct item_bin_sink_func *coastline_processor=item_bin_sink_func_new(coastline_processor_process);
- struct item_bin_sink *tiles=item_bin_sink_new();
- struct item_bin_sink_func *tile_collector=tile_collector_new(out);
- struct tile_parameter *param=g_new0(struct tile_parameter, 1);
+coastline_processor_new(struct item_bin_sink *out) {
+ struct item_bin_sink_func *coastline_processor=item_bin_sink_func_new(coastline_processor_process);
+ struct item_bin_sink *tiles=item_bin_sink_new();
+ struct item_bin_sink_func *tile_collector=tile_collector_new(out);
+ struct tile_parameter *param=g_new0(struct tile_parameter, 1);
- param->min=14;
- param->max=14;
- param->overlap=0;
- param->attr_to_copy=attr_osm_wayid;
+ param->min=14;
+ param->max=14;
+ param->overlap=0;
+ param->attr_to_copy=attr_osm_wayid;
- item_bin_sink_add_func(tiles, tile_collector);
- coastline_processor->priv_data[0]=param;
- coastline_processor->priv_data[1]=tiles;
- coastline_processor->priv_data[2]=tile_collector;
- return coastline_processor;
+ item_bin_sink_add_func(tiles, tile_collector);
+ coastline_processor->priv_data[0]=param;
+ coastline_processor->priv_data[1]=tiles;
+ coastline_processor->priv_data[2]=tile_collector;
+ return coastline_processor;
}
static void
-coastline_processor_finish(struct item_bin_sink_func *coastline_processor)
-{
- struct tile_parameter *param=coastline_processor->priv_data[0];
- struct item_bin_sink *tiles=coastline_processor->priv_data[1];
- struct item_bin_sink_func *tile_collector=coastline_processor->priv_data[2];
- g_free(param);
- tile_collector_finish(tile_collector);
- item_bin_sink_destroy(tiles);
- item_bin_sink_func_destroy(coastline_processor);
+coastline_processor_finish(struct item_bin_sink_func *coastline_processor) {
+ struct tile_parameter *param=coastline_processor->priv_data[0];
+ struct item_bin_sink *tiles=coastline_processor->priv_data[1];
+ struct item_bin_sink_func *tile_collector=coastline_processor->priv_data[2];
+ g_free(param);
+ tile_collector_finish(tile_collector);
+ item_bin_sink_destroy(tiles);
+ item_bin_sink_func_destroy(coastline_processor);
}
void
-process_coastlines(FILE *in, FILE *out)
-{
- struct item_bin_sink *reader=file_reader_new(in,-1,0);
- struct item_bin_sink_func *file_writer=file_writer_new(out);
- struct item_bin_sink *result=item_bin_sink_new();
- struct item_bin_sink_func *coastline_processor=coastline_processor_new(result);
- item_bin_sink_add_func(reader, coastline_processor);
- item_bin_sink_add_func(result, file_writer);
- file_reader_finish(reader);
- coastline_processor_finish(coastline_processor);
- file_writer_finish(file_writer);
- item_bin_sink_destroy(result);
+process_coastlines(FILE *in, FILE *out) {
+ struct item_bin_sink *reader=file_reader_new(in,-1,0);
+ struct item_bin_sink_func *file_writer=file_writer_new(out);
+ struct item_bin_sink *result=item_bin_sink_new();
+ struct item_bin_sink_func *coastline_processor=coastline_processor_new(result);
+ item_bin_sink_add_func(reader, coastline_processor);
+ item_bin_sink_add_func(result, file_writer);
+ file_reader_finish(reader);
+ coastline_processor_finish(coastline_processor);
+ file_writer_finish(file_writer);
+ item_bin_sink_destroy(result);
}
diff --git a/navit/maptool/generated-code/fileformat.pb-c.c b/navit/maptool/generated-code/fileformat.pb-c.c
index f67ba94d5..7189091ad 100644
--- a/navit/maptool/generated-code/fileformat.pb-c.c
+++ b/navit/maptool/generated-code/fileformat.pb-c.c
@@ -7,242 +7,224 @@
#include "fileformat.pb-c.h"
void osmpbf__blob__init
- (OSMPBF__Blob *message)
-{
- static OSMPBF__Blob init_value = OSMPBF__BLOB__INIT;
- *message = init_value;
+(OSMPBF__Blob *message) {
+ static OSMPBF__Blob init_value = OSMPBF__BLOB__INIT;
+ *message = init_value;
}
size_t osmpbf__blob__get_packed_size
- (const OSMPBF__Blob *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Blob *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__blob__pack
- (const OSMPBF__Blob *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Blob *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__blob__pack_to_buffer
- (const OSMPBF__Blob *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Blob *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Blob *
- osmpbf__blob__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Blob *)
- protobuf_c_message_unpack (&osmpbf__blob__descriptor,
- allocator, len, data);
+osmpbf__blob__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Blob *)
+ protobuf_c_message_unpack (&osmpbf__blob__descriptor,
+ allocator, len, data);
}
void osmpbf__blob__free_unpacked
- (OSMPBF__Blob *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__Blob *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__blob_header__init
- (OSMPBF__BlobHeader *message)
-{
- static OSMPBF__BlobHeader init_value = OSMPBF__BLOB_HEADER__INIT;
- *message = init_value;
+(OSMPBF__BlobHeader *message) {
+ static OSMPBF__BlobHeader init_value = OSMPBF__BLOB_HEADER__INIT;
+ *message = init_value;
}
size_t osmpbf__blob_header__get_packed_size
- (const OSMPBF__BlobHeader *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__BlobHeader *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__blob_header__pack
- (const OSMPBF__BlobHeader *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__BlobHeader *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__blob_header__pack_to_buffer
- (const OSMPBF__BlobHeader *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__BlobHeader *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__BlobHeader *
- osmpbf__blob_header__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__BlobHeader *)
- protobuf_c_message_unpack (&osmpbf__blob_header__descriptor,
- allocator, len, data);
+osmpbf__blob_header__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__BlobHeader *)
+ protobuf_c_message_unpack (&osmpbf__blob_header__descriptor,
+ allocator, len, data);
}
void osmpbf__blob_header__free_unpacked
- (OSMPBF__BlobHeader *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__BlobHeader *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
-static const ProtobufCFieldDescriptor osmpbf__blob__field_descriptors[5] =
-{
- {
- "raw",
- 1,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "raw_size",
- 2,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw_size),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw_size),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "zlib_data",
- 3,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_zlib_data),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, zlib_data),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lzma_data",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_lzma_data),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, lzma_data),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "OBSOLETE_bzip2_data",
- 5,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_obsolete_bzip2_data),
- PROTOBUF_C_OFFSETOF(OSMPBF__Blob, obsolete_bzip2_data),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__blob__field_descriptors[5] = {
+ {
+ "raw",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "raw_size",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw_size),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw_size),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "zlib_data",
+ 3,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_zlib_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, zlib_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lzma_data",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_lzma_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, lzma_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "OBSOLETE_bzip2_data",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_obsolete_bzip2_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, obsolete_bzip2_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__blob__field_indices_by_name[] = {
- 4, /* field[4] = OBSOLETE_bzip2_data */
- 3, /* field[3] = lzma_data */
- 0, /* field[0] = raw */
- 1, /* field[1] = raw_size */
- 2, /* field[2] = zlib_data */
+ 4, /* field[4] = OBSOLETE_bzip2_data */
+ 3, /* field[3] = lzma_data */
+ 0, /* field[0] = raw */
+ 1, /* field[1] = raw_size */
+ 2, /* field[2] = zlib_data */
};
-static const ProtobufCIntRange osmpbf__blob__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__blob__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__blob__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Blob",
- "Blob",
- "OSMPBF__Blob",
- "OSMPBF",
- sizeof(OSMPBF__Blob),
- 5,
- osmpbf__blob__field_descriptors,
- osmpbf__blob__field_indices_by_name,
- 1, osmpbf__blob__number_ranges,
- (ProtobufCMessageInit) osmpbf__blob__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__blob__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Blob",
+ "Blob",
+ "OSMPBF__Blob",
+ "OSMPBF",
+ sizeof(OSMPBF__Blob),
+ 5,
+ osmpbf__blob__field_descriptors,
+ osmpbf__blob__field_indices_by_name,
+ 1, osmpbf__blob__number_ranges,
+ (ProtobufCMessageInit) osmpbf__blob__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__blob_header__field_descriptors[3] =
-{
- {
- "type",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_STRING,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, type),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "indexdata",
- 2,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, has_indexdata),
- PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, indexdata),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "datasize",
- 3,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_INT32,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, datasize),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__blob_header__field_descriptors[3] = {
+ {
+ "type",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, type),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "indexdata",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, has_indexdata),
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, indexdata),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "datasize",
+ 3,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT32,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, datasize),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__blob_header__field_indices_by_name[] = {
- 2, /* field[2] = datasize */
- 1, /* field[1] = indexdata */
- 0, /* field[0] = type */
+ 2, /* field[2] = datasize */
+ 1, /* field[1] = indexdata */
+ 0, /* field[0] = type */
};
-static const ProtobufCIntRange osmpbf__blob_header__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 3 }
+static const ProtobufCIntRange osmpbf__blob_header__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 3 }
};
-const ProtobufCMessageDescriptor osmpbf__blob_header__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.BlobHeader",
- "BlobHeader",
- "OSMPBF__BlobHeader",
- "OSMPBF",
- sizeof(OSMPBF__BlobHeader),
- 3,
- osmpbf__blob_header__field_descriptors,
- osmpbf__blob_header__field_indices_by_name,
- 1, osmpbf__blob_header__number_ranges,
- (ProtobufCMessageInit) osmpbf__blob_header__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__blob_header__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.BlobHeader",
+ "BlobHeader",
+ "OSMPBF__BlobHeader",
+ "OSMPBF",
+ sizeof(OSMPBF__BlobHeader),
+ 3,
+ osmpbf__blob_header__field_descriptors,
+ osmpbf__blob_header__field_indices_by_name,
+ 1, osmpbf__blob_header__number_ranges,
+ (ProtobufCMessageInit) osmpbf__blob_header__init,
+ NULL,NULL,NULL /* reserved[123] */
};
diff --git a/navit/maptool/generated-code/osmformat.pb-c.c b/navit/maptool/generated-code/osmformat.pb-c.c
index f31a72c4e..118b2ee5d 100644
--- a/navit/maptool/generated-code/osmformat.pb-c.c
+++ b/navit/maptool/generated-code/osmformat.pb-c.c
@@ -7,1576 +7,1465 @@
#include "osmformat.pb-c.h"
void osmpbf__header_block__init
- (OSMPBF__HeaderBlock *message)
-{
- static OSMPBF__HeaderBlock init_value = OSMPBF__HEADER_BLOCK__INIT;
- *message = init_value;
+(OSMPBF__HeaderBlock *message) {
+ static OSMPBF__HeaderBlock init_value = OSMPBF__HEADER_BLOCK__INIT;
+ *message = init_value;
}
size_t osmpbf__header_block__get_packed_size
- (const OSMPBF__HeaderBlock *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__HeaderBlock *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__header_block__pack
- (const OSMPBF__HeaderBlock *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__HeaderBlock *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__header_block__pack_to_buffer
- (const OSMPBF__HeaderBlock *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__HeaderBlock *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__HeaderBlock *
- osmpbf__header_block__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__HeaderBlock *)
- protobuf_c_message_unpack (&osmpbf__header_block__descriptor,
- allocator, len, data);
+osmpbf__header_block__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__HeaderBlock *)
+ protobuf_c_message_unpack (&osmpbf__header_block__descriptor,
+ allocator, len, data);
}
void osmpbf__header_block__free_unpacked
- (OSMPBF__HeaderBlock *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__HeaderBlock *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__header_bbox__init
- (OSMPBF__HeaderBBox *message)
-{
- static OSMPBF__HeaderBBox init_value = OSMPBF__HEADER_BBOX__INIT;
- *message = init_value;
+(OSMPBF__HeaderBBox *message) {
+ static OSMPBF__HeaderBBox init_value = OSMPBF__HEADER_BBOX__INIT;
+ *message = init_value;
}
size_t osmpbf__header_bbox__get_packed_size
- (const OSMPBF__HeaderBBox *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__HeaderBBox *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__header_bbox__pack
- (const OSMPBF__HeaderBBox *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__HeaderBBox *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__header_bbox__pack_to_buffer
- (const OSMPBF__HeaderBBox *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__HeaderBBox *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__HeaderBBox *
- osmpbf__header_bbox__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__HeaderBBox *)
- protobuf_c_message_unpack (&osmpbf__header_bbox__descriptor,
- allocator, len, data);
+osmpbf__header_bbox__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__HeaderBBox *)
+ protobuf_c_message_unpack (&osmpbf__header_bbox__descriptor,
+ allocator, len, data);
}
void osmpbf__header_bbox__free_unpacked
- (OSMPBF__HeaderBBox *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__HeaderBBox *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__primitive_block__init
- (OSMPBF__PrimitiveBlock *message)
-{
- static OSMPBF__PrimitiveBlock init_value = OSMPBF__PRIMITIVE_BLOCK__INIT;
- *message = init_value;
+(OSMPBF__PrimitiveBlock *message) {
+ static OSMPBF__PrimitiveBlock init_value = OSMPBF__PRIMITIVE_BLOCK__INIT;
+ *message = init_value;
}
size_t osmpbf__primitive_block__get_packed_size
- (const OSMPBF__PrimitiveBlock *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__PrimitiveBlock *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__primitive_block__pack
- (const OSMPBF__PrimitiveBlock *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__PrimitiveBlock *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__primitive_block__pack_to_buffer
- (const OSMPBF__PrimitiveBlock *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__PrimitiveBlock *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__PrimitiveBlock *
- osmpbf__primitive_block__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__PrimitiveBlock *)
- protobuf_c_message_unpack (&osmpbf__primitive_block__descriptor,
- allocator, len, data);
+osmpbf__primitive_block__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__PrimitiveBlock *)
+ protobuf_c_message_unpack (&osmpbf__primitive_block__descriptor,
+ allocator, len, data);
}
void osmpbf__primitive_block__free_unpacked
- (OSMPBF__PrimitiveBlock *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__PrimitiveBlock *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__primitive_group__init
- (OSMPBF__PrimitiveGroup *message)
-{
- static OSMPBF__PrimitiveGroup init_value = OSMPBF__PRIMITIVE_GROUP__INIT;
- *message = init_value;
+(OSMPBF__PrimitiveGroup *message) {
+ static OSMPBF__PrimitiveGroup init_value = OSMPBF__PRIMITIVE_GROUP__INIT;
+ *message = init_value;
}
size_t osmpbf__primitive_group__get_packed_size
- (const OSMPBF__PrimitiveGroup *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__PrimitiveGroup *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__primitive_group__pack
- (const OSMPBF__PrimitiveGroup *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__PrimitiveGroup *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__primitive_group__pack_to_buffer
- (const OSMPBF__PrimitiveGroup *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__PrimitiveGroup *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__PrimitiveGroup *
- osmpbf__primitive_group__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__PrimitiveGroup *)
- protobuf_c_message_unpack (&osmpbf__primitive_group__descriptor,
- allocator, len, data);
+osmpbf__primitive_group__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__PrimitiveGroup *)
+ protobuf_c_message_unpack (&osmpbf__primitive_group__descriptor,
+ allocator, len, data);
}
void osmpbf__primitive_group__free_unpacked
- (OSMPBF__PrimitiveGroup *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__PrimitiveGroup *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__string_table__init
- (OSMPBF__StringTable *message)
-{
- static OSMPBF__StringTable init_value = OSMPBF__STRING_TABLE__INIT;
- *message = init_value;
+(OSMPBF__StringTable *message) {
+ static OSMPBF__StringTable init_value = OSMPBF__STRING_TABLE__INIT;
+ *message = init_value;
}
size_t osmpbf__string_table__get_packed_size
- (const OSMPBF__StringTable *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__StringTable *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__string_table__pack
- (const OSMPBF__StringTable *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__StringTable *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__string_table__pack_to_buffer
- (const OSMPBF__StringTable *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__StringTable *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__StringTable *
- osmpbf__string_table__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__StringTable *)
- protobuf_c_message_unpack (&osmpbf__string_table__descriptor,
- allocator, len, data);
+osmpbf__string_table__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__StringTable *)
+ protobuf_c_message_unpack (&osmpbf__string_table__descriptor,
+ allocator, len, data);
}
void osmpbf__string_table__free_unpacked
- (OSMPBF__StringTable *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__StringTable *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__info__init
- (OSMPBF__Info *message)
-{
- static OSMPBF__Info init_value = OSMPBF__INFO__INIT;
- *message = init_value;
+(OSMPBF__Info *message) {
+ static OSMPBF__Info init_value = OSMPBF__INFO__INIT;
+ *message = init_value;
}
size_t osmpbf__info__get_packed_size
- (const OSMPBF__Info *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Info *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__info__pack
- (const OSMPBF__Info *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Info *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__info__pack_to_buffer
- (const OSMPBF__Info *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Info *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Info *
- osmpbf__info__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Info *)
- protobuf_c_message_unpack (&osmpbf__info__descriptor,
- allocator, len, data);
+osmpbf__info__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Info *)
+ protobuf_c_message_unpack (&osmpbf__info__descriptor,
+ allocator, len, data);
}
void osmpbf__info__free_unpacked
- (OSMPBF__Info *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__Info *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__dense_info__init
- (OSMPBF__DenseInfo *message)
-{
- static OSMPBF__DenseInfo init_value = OSMPBF__DENSE_INFO__INIT;
- *message = init_value;
+(OSMPBF__DenseInfo *message) {
+ static OSMPBF__DenseInfo init_value = OSMPBF__DENSE_INFO__INIT;
+ *message = init_value;
}
size_t osmpbf__dense_info__get_packed_size
- (const OSMPBF__DenseInfo *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__DenseInfo *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__dense_info__pack
- (const OSMPBF__DenseInfo *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__DenseInfo *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__dense_info__pack_to_buffer
- (const OSMPBF__DenseInfo *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__DenseInfo *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__DenseInfo *
- osmpbf__dense_info__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__DenseInfo *)
- protobuf_c_message_unpack (&osmpbf__dense_info__descriptor,
- allocator, len, data);
+osmpbf__dense_info__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__DenseInfo *)
+ protobuf_c_message_unpack (&osmpbf__dense_info__descriptor,
+ allocator, len, data);
}
void osmpbf__dense_info__free_unpacked
- (OSMPBF__DenseInfo *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__DenseInfo *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__change_set__init
- (OSMPBF__ChangeSet *message)
-{
- static OSMPBF__ChangeSet init_value = OSMPBF__CHANGE_SET__INIT;
- *message = init_value;
+(OSMPBF__ChangeSet *message) {
+ static OSMPBF__ChangeSet init_value = OSMPBF__CHANGE_SET__INIT;
+ *message = init_value;
}
size_t osmpbf__change_set__get_packed_size
- (const OSMPBF__ChangeSet *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__ChangeSet *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__change_set__pack
- (const OSMPBF__ChangeSet *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__ChangeSet *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__change_set__pack_to_buffer
- (const OSMPBF__ChangeSet *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__ChangeSet *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__ChangeSet *
- osmpbf__change_set__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__ChangeSet *)
- protobuf_c_message_unpack (&osmpbf__change_set__descriptor,
- allocator, len, data);
+osmpbf__change_set__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__ChangeSet *)
+ protobuf_c_message_unpack (&osmpbf__change_set__descriptor,
+ allocator, len, data);
}
void osmpbf__change_set__free_unpacked
- (OSMPBF__ChangeSet *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__ChangeSet *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__node__init
- (OSMPBF__Node *message)
-{
- static OSMPBF__Node init_value = OSMPBF__NODE__INIT;
- *message = init_value;
+(OSMPBF__Node *message) {
+ static OSMPBF__Node init_value = OSMPBF__NODE__INIT;
+ *message = init_value;
}
size_t osmpbf__node__get_packed_size
- (const OSMPBF__Node *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Node *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__node__pack
- (const OSMPBF__Node *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Node *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__node__pack_to_buffer
- (const OSMPBF__Node *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Node *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Node *
- osmpbf__node__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Node *)
- protobuf_c_message_unpack (&osmpbf__node__descriptor,
- allocator, len, data);
+osmpbf__node__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Node *)
+ protobuf_c_message_unpack (&osmpbf__node__descriptor,
+ allocator, len, data);
}
void osmpbf__node__free_unpacked
- (OSMPBF__Node *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__Node *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__dense_nodes__init
- (OSMPBF__DenseNodes *message)
-{
- static OSMPBF__DenseNodes init_value = OSMPBF__DENSE_NODES__INIT;
- *message = init_value;
+(OSMPBF__DenseNodes *message) {
+ static OSMPBF__DenseNodes init_value = OSMPBF__DENSE_NODES__INIT;
+ *message = init_value;
}
size_t osmpbf__dense_nodes__get_packed_size
- (const OSMPBF__DenseNodes *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__DenseNodes *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__dense_nodes__pack
- (const OSMPBF__DenseNodes *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__DenseNodes *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__dense_nodes__pack_to_buffer
- (const OSMPBF__DenseNodes *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__DenseNodes *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__DenseNodes *
- osmpbf__dense_nodes__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__DenseNodes *)
- protobuf_c_message_unpack (&osmpbf__dense_nodes__descriptor,
- allocator, len, data);
+osmpbf__dense_nodes__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__DenseNodes *)
+ protobuf_c_message_unpack (&osmpbf__dense_nodes__descriptor,
+ allocator, len, data);
}
void osmpbf__dense_nodes__free_unpacked
- (OSMPBF__DenseNodes *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__DenseNodes *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__way__init
- (OSMPBF__Way *message)
-{
- static OSMPBF__Way init_value = OSMPBF__WAY__INIT;
- *message = init_value;
+(OSMPBF__Way *message) {
+ static OSMPBF__Way init_value = OSMPBF__WAY__INIT;
+ *message = init_value;
}
size_t osmpbf__way__get_packed_size
- (const OSMPBF__Way *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Way *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__way__pack
- (const OSMPBF__Way *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Way *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__way__pack_to_buffer
- (const OSMPBF__Way *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Way *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Way *
- osmpbf__way__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Way *)
- protobuf_c_message_unpack (&osmpbf__way__descriptor,
- allocator, len, data);
+osmpbf__way__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Way *)
+ protobuf_c_message_unpack (&osmpbf__way__descriptor,
+ allocator, len, data);
}
void osmpbf__way__free_unpacked
- (OSMPBF__Way *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+(OSMPBF__Way *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void osmpbf__relation__init
- (OSMPBF__Relation *message)
-{
- static OSMPBF__Relation init_value = OSMPBF__RELATION__INIT;
- *message = init_value;
+(OSMPBF__Relation *message) {
+ static OSMPBF__Relation init_value = OSMPBF__RELATION__INIT;
+ *message = init_value;
}
size_t osmpbf__relation__get_packed_size
- (const OSMPBF__Relation *message)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
- return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+(const OSMPBF__Relation *message) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t osmpbf__relation__pack
- (const OSMPBF__Relation *message,
- uint8_t *out)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
- return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+(const OSMPBF__Relation *message,
+ uint8_t *out) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t osmpbf__relation__pack_to_buffer
- (const OSMPBF__Relation *message,
- ProtobufCBuffer *buffer)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
- return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+(const OSMPBF__Relation *message,
+ ProtobufCBuffer *buffer) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
OSMPBF__Relation *
- osmpbf__relation__unpack
- (ProtobufCAllocator *allocator,
- size_t len,
- const uint8_t *data)
-{
- return (OSMPBF__Relation *)
- protobuf_c_message_unpack (&osmpbf__relation__descriptor,
- allocator, len, data);
+osmpbf__relation__unpack
+(ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data) {
+ return (OSMPBF__Relation *)
+ protobuf_c_message_unpack (&osmpbf__relation__descriptor,
+ allocator, len, data);
}
void osmpbf__relation__free_unpacked
- (OSMPBF__Relation *message,
- ProtobufCAllocator *allocator)
-{
- PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
- protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-static const ProtobufCFieldDescriptor osmpbf__header_block__field_descriptors[5] =
-{
- {
- "bbox",
- 1,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, bbox),
- &osmpbf__header_bbox__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "required_features",
- 4,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_STRING,
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_required_features),
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, required_features),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "optional_features",
- 5,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_STRING,
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_optional_features),
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, optional_features),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "writingprogram",
- 16,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_STRING,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, writingprogram),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "source",
- 17,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_STRING,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, source),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+(OSMPBF__Relation *message,
+ ProtobufCAllocator *allocator) {
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+static const ProtobufCFieldDescriptor osmpbf__header_block__field_descriptors[5] = {
+ {
+ "bbox",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, bbox),
+ &osmpbf__header_bbox__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "required_features",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_STRING,
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_required_features),
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, required_features),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "optional_features",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_STRING,
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_optional_features),
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, optional_features),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "writingprogram",
+ 16,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, writingprogram),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "source",
+ 17,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, source),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__header_block__field_indices_by_name[] = {
- 0, /* field[0] = bbox */
- 2, /* field[2] = optional_features */
- 1, /* field[1] = required_features */
- 4, /* field[4] = source */
- 3, /* field[3] = writingprogram */
+ 0, /* field[0] = bbox */
+ 2, /* field[2] = optional_features */
+ 1, /* field[1] = required_features */
+ 4, /* field[4] = source */
+ 3, /* field[3] = writingprogram */
};
-static const ProtobufCIntRange osmpbf__header_block__number_ranges[3 + 1] =
-{
- { 1, 0 },
- { 4, 1 },
- { 16, 3 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__header_block__number_ranges[3 + 1] = {
+ { 1, 0 },
+ { 4, 1 },
+ { 16, 3 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__header_block__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.HeaderBlock",
- "HeaderBlock",
- "OSMPBF__HeaderBlock",
- "OSMPBF",
- sizeof(OSMPBF__HeaderBlock),
- 5,
- osmpbf__header_block__field_descriptors,
- osmpbf__header_block__field_indices_by_name,
- 3, osmpbf__header_block__number_ranges,
- (ProtobufCMessageInit) osmpbf__header_block__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__header_block__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.HeaderBlock",
+ "HeaderBlock",
+ "OSMPBF__HeaderBlock",
+ "OSMPBF",
+ sizeof(OSMPBF__HeaderBlock),
+ 5,
+ osmpbf__header_block__field_descriptors,
+ osmpbf__header_block__field_indices_by_name,
+ 3, osmpbf__header_block__number_ranges,
+ (ProtobufCMessageInit) osmpbf__header_block__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__header_bbox__field_descriptors[4] =
-{
- {
- "left",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, left),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "right",
- 2,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, right),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "top",
- 3,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, top),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "bottom",
- 4,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, bottom),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__header_bbox__field_descriptors[4] = {
+ {
+ "left",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, left),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "right",
+ 2,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, right),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "top",
+ 3,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, top),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "bottom",
+ 4,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, bottom),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__header_bbox__field_indices_by_name[] = {
- 3, /* field[3] = bottom */
- 0, /* field[0] = left */
- 1, /* field[1] = right */
- 2, /* field[2] = top */
+ 3, /* field[3] = bottom */
+ 0, /* field[0] = left */
+ 1, /* field[1] = right */
+ 2, /* field[2] = top */
};
-static const ProtobufCIntRange osmpbf__header_bbox__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 4 }
+static const ProtobufCIntRange osmpbf__header_bbox__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 4 }
};
-const ProtobufCMessageDescriptor osmpbf__header_bbox__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.HeaderBBox",
- "HeaderBBox",
- "OSMPBF__HeaderBBox",
- "OSMPBF",
- sizeof(OSMPBF__HeaderBBox),
- 4,
- osmpbf__header_bbox__field_descriptors,
- osmpbf__header_bbox__field_indices_by_name,
- 1, osmpbf__header_bbox__number_ranges,
- (ProtobufCMessageInit) osmpbf__header_bbox__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__header_bbox__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.HeaderBBox",
+ "HeaderBBox",
+ "OSMPBF__HeaderBBox",
+ "OSMPBF",
+ sizeof(OSMPBF__HeaderBBox),
+ 4,
+ osmpbf__header_bbox__field_descriptors,
+ osmpbf__header_bbox__field_indices_by_name,
+ 1, osmpbf__header_bbox__number_ranges,
+ (ProtobufCMessageInit) osmpbf__header_bbox__init,
+ NULL,NULL,NULL /* reserved[123] */
};
static const int32_t osmpbf__primitive_block__granularity__default_value = 100;
static const int64_t osmpbf__primitive_block__lat_offset__default_value = 0;
static const int64_t osmpbf__primitive_block__lon_offset__default_value = 0;
static const int32_t osmpbf__primitive_block__date_granularity__default_value = 1000;
-static const ProtobufCFieldDescriptor osmpbf__primitive_block__field_descriptors[6] =
-{
- {
- "stringtable",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, stringtable),
- &osmpbf__string_table__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "primitivegroup",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, n_primitivegroup),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, primitivegroup),
- &osmpbf__primitive_group__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "granularity",
- 17,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_granularity),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, granularity),
- NULL,
- &osmpbf__primitive_block__granularity__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "date_granularity",
- 18,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_date_granularity),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, date_granularity),
- NULL,
- &osmpbf__primitive_block__date_granularity__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lat_offset",
- 19,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lat_offset),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lat_offset),
- NULL,
- &osmpbf__primitive_block__lat_offset__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lon_offset",
- 20,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lon_offset),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lon_offset),
- NULL,
- &osmpbf__primitive_block__lon_offset__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__primitive_block__field_descriptors[6] = {
+ {
+ "stringtable",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, stringtable),
+ &osmpbf__string_table__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "primitivegroup",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, n_primitivegroup),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, primitivegroup),
+ &osmpbf__primitive_group__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "granularity",
+ 17,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_granularity),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, granularity),
+ NULL,
+ &osmpbf__primitive_block__granularity__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "date_granularity",
+ 18,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_date_granularity),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, date_granularity),
+ NULL,
+ &osmpbf__primitive_block__date_granularity__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat_offset",
+ 19,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lat_offset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lat_offset),
+ NULL,
+ &osmpbf__primitive_block__lat_offset__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon_offset",
+ 20,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lon_offset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lon_offset),
+ NULL,
+ &osmpbf__primitive_block__lon_offset__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__primitive_block__field_indices_by_name[] = {
- 3, /* field[3] = date_granularity */
- 2, /* field[2] = granularity */
- 4, /* field[4] = lat_offset */
- 5, /* field[5] = lon_offset */
- 1, /* field[1] = primitivegroup */
- 0, /* field[0] = stringtable */
+ 3, /* field[3] = date_granularity */
+ 2, /* field[2] = granularity */
+ 4, /* field[4] = lat_offset */
+ 5, /* field[5] = lon_offset */
+ 1, /* field[1] = primitivegroup */
+ 0, /* field[0] = stringtable */
};
-static const ProtobufCIntRange osmpbf__primitive_block__number_ranges[2 + 1] =
-{
- { 1, 0 },
- { 17, 2 },
- { 0, 6 }
+static const ProtobufCIntRange osmpbf__primitive_block__number_ranges[2 + 1] = {
+ { 1, 0 },
+ { 17, 2 },
+ { 0, 6 }
};
-const ProtobufCMessageDescriptor osmpbf__primitive_block__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.PrimitiveBlock",
- "PrimitiveBlock",
- "OSMPBF__PrimitiveBlock",
- "OSMPBF",
- sizeof(OSMPBF__PrimitiveBlock),
- 6,
- osmpbf__primitive_block__field_descriptors,
- osmpbf__primitive_block__field_indices_by_name,
- 2, osmpbf__primitive_block__number_ranges,
- (ProtobufCMessageInit) osmpbf__primitive_block__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__primitive_block__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.PrimitiveBlock",
+ "PrimitiveBlock",
+ "OSMPBF__PrimitiveBlock",
+ "OSMPBF",
+ sizeof(OSMPBF__PrimitiveBlock),
+ 6,
+ osmpbf__primitive_block__field_descriptors,
+ osmpbf__primitive_block__field_indices_by_name,
+ 2, osmpbf__primitive_block__number_ranges,
+ (ProtobufCMessageInit) osmpbf__primitive_block__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__primitive_group__field_descriptors[5] =
-{
- {
- "nodes",
- 1,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_nodes),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, nodes),
- &osmpbf__node__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "dense",
- 2,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, dense),
- &osmpbf__dense_nodes__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "ways",
- 3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_ways),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, ways),
- &osmpbf__way__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "relations",
- 4,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_relations),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, relations),
- &osmpbf__relation__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "changesets",
- 5,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_MESSAGE,
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_changesets),
- PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, changesets),
- &osmpbf__change_set__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__primitive_group__field_descriptors[5] = {
+ {
+ "nodes",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_nodes),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, nodes),
+ &osmpbf__node__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "dense",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, dense),
+ &osmpbf__dense_nodes__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "ways",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_ways),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, ways),
+ &osmpbf__way__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "relations",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_relations),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, relations),
+ &osmpbf__relation__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changesets",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_changesets),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, changesets),
+ &osmpbf__change_set__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__primitive_group__field_indices_by_name[] = {
- 4, /* field[4] = changesets */
- 1, /* field[1] = dense */
- 0, /* field[0] = nodes */
- 3, /* field[3] = relations */
- 2, /* field[2] = ways */
+ 4, /* field[4] = changesets */
+ 1, /* field[1] = dense */
+ 0, /* field[0] = nodes */
+ 3, /* field[3] = relations */
+ 2, /* field[2] = ways */
};
-static const ProtobufCIntRange osmpbf__primitive_group__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__primitive_group__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__primitive_group__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.PrimitiveGroup",
- "PrimitiveGroup",
- "OSMPBF__PrimitiveGroup",
- "OSMPBF",
- sizeof(OSMPBF__PrimitiveGroup),
- 5,
- osmpbf__primitive_group__field_descriptors,
- osmpbf__primitive_group__field_indices_by_name,
- 1, osmpbf__primitive_group__number_ranges,
- (ProtobufCMessageInit) osmpbf__primitive_group__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__primitive_group__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.PrimitiveGroup",
+ "PrimitiveGroup",
+ "OSMPBF__PrimitiveGroup",
+ "OSMPBF",
+ sizeof(OSMPBF__PrimitiveGroup),
+ 5,
+ osmpbf__primitive_group__field_descriptors,
+ osmpbf__primitive_group__field_indices_by_name,
+ 1, osmpbf__primitive_group__number_ranges,
+ (ProtobufCMessageInit) osmpbf__primitive_group__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__string_table__field_descriptors[1] =
-{
- {
- "s",
- 1,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_BYTES,
- PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, n_s),
- PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, s),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__string_table__field_descriptors[1] = {
+ {
+ "s",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, n_s),
+ PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, s),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__string_table__field_indices_by_name[] = {
- 0, /* field[0] = s */
+ 0, /* field[0] = s */
};
-static const ProtobufCIntRange osmpbf__string_table__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 1 }
+static const ProtobufCIntRange osmpbf__string_table__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 1 }
};
-const ProtobufCMessageDescriptor osmpbf__string_table__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.StringTable",
- "StringTable",
- "OSMPBF__StringTable",
- "OSMPBF",
- sizeof(OSMPBF__StringTable),
- 1,
- osmpbf__string_table__field_descriptors,
- osmpbf__string_table__field_indices_by_name,
- 1, osmpbf__string_table__number_ranges,
- (ProtobufCMessageInit) osmpbf__string_table__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__string_table__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.StringTable",
+ "StringTable",
+ "OSMPBF__StringTable",
+ "OSMPBF",
+ sizeof(OSMPBF__StringTable),
+ 1,
+ osmpbf__string_table__field_descriptors,
+ osmpbf__string_table__field_indices_by_name,
+ 1, osmpbf__string_table__number_ranges,
+ (ProtobufCMessageInit) osmpbf__string_table__init,
+ NULL,NULL,NULL /* reserved[123] */
};
static const int32_t osmpbf__info__version__default_value = -1;
-static const ProtobufCFieldDescriptor osmpbf__info__field_descriptors[5] =
-{
- {
- "version",
- 1,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_version),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, version),
- NULL,
- &osmpbf__info__version__default_value,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "timestamp",
- 2,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_timestamp),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, timestamp),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "changeset",
- 3,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_changeset),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, changeset),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "uid",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_uid),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, uid),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "user_sid",
- 5,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_user_sid),
- PROTOBUF_C_OFFSETOF(OSMPBF__Info, user_sid),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__info__field_descriptors[5] = {
+ {
+ "version",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_version),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, version),
+ NULL,
+ &osmpbf__info__version__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "timestamp",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_timestamp),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, timestamp),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changeset",
+ 3,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_changeset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, changeset),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "uid",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_uid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, uid),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "user_sid",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_user_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, user_sid),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__info__field_indices_by_name[] = {
- 2, /* field[2] = changeset */
- 1, /* field[1] = timestamp */
- 3, /* field[3] = uid */
- 4, /* field[4] = user_sid */
- 0, /* field[0] = version */
+ 2, /* field[2] = changeset */
+ 1, /* field[1] = timestamp */
+ 3, /* field[3] = uid */
+ 4, /* field[4] = user_sid */
+ 0, /* field[0] = version */
};
-static const ProtobufCIntRange osmpbf__info__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__info__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__info__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Info",
- "Info",
- "OSMPBF__Info",
- "OSMPBF",
- sizeof(OSMPBF__Info),
- 5,
- osmpbf__info__field_descriptors,
- osmpbf__info__field_indices_by_name,
- 1, osmpbf__info__number_ranges,
- (ProtobufCMessageInit) osmpbf__info__init,
- NULL,NULL,NULL /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor osmpbf__dense_info__field_descriptors[5] =
-{
- {
- "version",
- 1,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_version),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, version),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "timestamp",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_timestamp),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, timestamp),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "changeset",
- 3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_changeset),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, changeset),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "uid",
- 4,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_uid),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, uid),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "user_sid",
+const ProtobufCMessageDescriptor osmpbf__info__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Info",
+ "Info",
+ "OSMPBF__Info",
+ "OSMPBF",
+ sizeof(OSMPBF__Info),
5,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_user_sid),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, user_sid),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+ osmpbf__info__field_descriptors,
+ osmpbf__info__field_indices_by_name,
+ 1, osmpbf__info__number_ranges,
+ (ProtobufCMessageInit) osmpbf__info__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__dense_info__field_descriptors[5] = {
+ {
+ "version",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_version),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, version),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "timestamp",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_timestamp),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, timestamp),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changeset",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_changeset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, changeset),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "uid",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_uid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, uid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "user_sid",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_user_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, user_sid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__dense_info__field_indices_by_name[] = {
- 2, /* field[2] = changeset */
- 1, /* field[1] = timestamp */
- 3, /* field[3] = uid */
- 4, /* field[4] = user_sid */
- 0, /* field[0] = version */
+ 2, /* field[2] = changeset */
+ 1, /* field[1] = timestamp */
+ 3, /* field[3] = uid */
+ 4, /* field[4] = user_sid */
+ 0, /* field[0] = version */
};
-static const ProtobufCIntRange osmpbf__dense_info__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__dense_info__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__dense_info__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.DenseInfo",
- "DenseInfo",
- "OSMPBF__DenseInfo",
- "OSMPBF",
- sizeof(OSMPBF__DenseInfo),
- 5,
- osmpbf__dense_info__field_descriptors,
- osmpbf__dense_info__field_indices_by_name,
- 1, osmpbf__dense_info__number_ranges,
- (ProtobufCMessageInit) osmpbf__dense_info__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__dense_info__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.DenseInfo",
+ "DenseInfo",
+ "OSMPBF__DenseInfo",
+ "OSMPBF",
+ sizeof(OSMPBF__DenseInfo),
+ 5,
+ osmpbf__dense_info__field_descriptors,
+ osmpbf__dense_info__field_indices_by_name,
+ 1, osmpbf__dense_info__number_ranges,
+ (ProtobufCMessageInit) osmpbf__dense_info__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__change_set__field_descriptors[1] =
-{
- {
- "id",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_INT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__ChangeSet, id),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__change_set__field_descriptors[1] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__ChangeSet, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__change_set__field_indices_by_name[] = {
- 0, /* field[0] = id */
-};
-static const ProtobufCIntRange osmpbf__change_set__number_ranges[1 + 1] =
-{
- { 1, 0 },
- { 0, 1 }
+ 0, /* field[0] = id */
};
-const ProtobufCMessageDescriptor osmpbf__change_set__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.ChangeSet",
- "ChangeSet",
- "OSMPBF__ChangeSet",
- "OSMPBF",
- sizeof(OSMPBF__ChangeSet),
- 1,
- osmpbf__change_set__field_descriptors,
- osmpbf__change_set__field_indices_by_name,
- 1, osmpbf__change_set__number_ranges,
- (ProtobufCMessageInit) osmpbf__change_set__init,
- NULL,NULL,NULL /* reserved[123] */
+static const ProtobufCIntRange osmpbf__change_set__number_ranges[1 + 1] = {
+ { 1, 0 },
+ { 0, 1 }
};
-static const ProtobufCFieldDescriptor osmpbf__node__field_descriptors[6] =
-{
- {
- "id",
+const ProtobufCMessageDescriptor osmpbf__change_set__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.ChangeSet",
+ "ChangeSet",
+ "OSMPBF__ChangeSet",
+ "OSMPBF",
+ sizeof(OSMPBF__ChangeSet),
1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, id),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "keys",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_keys),
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, keys),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "vals",
- 3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_vals),
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, vals),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "info",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, info),
- &osmpbf__info__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lat",
- 8,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, lat),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lon",
- 9,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_SINT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Node, lon),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+ osmpbf__change_set__field_descriptors,
+ osmpbf__change_set__field_indices_by_name,
+ 1, osmpbf__change_set__number_ranges,
+ (ProtobufCMessageInit) osmpbf__change_set__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__node__field_descriptors[6] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat",
+ 8,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, lat),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon",
+ 9,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, lon),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__node__field_indices_by_name[] = {
- 0, /* field[0] = id */
- 3, /* field[3] = info */
- 1, /* field[1] = keys */
- 4, /* field[4] = lat */
- 5, /* field[5] = lon */
- 2, /* field[2] = vals */
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 4, /* field[4] = lat */
+ 5, /* field[5] = lon */
+ 2, /* field[2] = vals */
};
-static const ProtobufCIntRange osmpbf__node__number_ranges[2 + 1] =
-{
- { 1, 0 },
- { 8, 4 },
- { 0, 6 }
+static const ProtobufCIntRange osmpbf__node__number_ranges[2 + 1] = {
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 6 }
};
-const ProtobufCMessageDescriptor osmpbf__node__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Node",
- "Node",
- "OSMPBF__Node",
- "OSMPBF",
- sizeof(OSMPBF__Node),
- 6,
- osmpbf__node__field_descriptors,
- osmpbf__node__field_indices_by_name,
- 2, osmpbf__node__number_ranges,
- (ProtobufCMessageInit) osmpbf__node__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__node__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Node",
+ "Node",
+ "OSMPBF__Node",
+ "OSMPBF",
+ sizeof(OSMPBF__Node),
+ 6,
+ osmpbf__node__field_descriptors,
+ osmpbf__node__field_indices_by_name,
+ 2, osmpbf__node__number_ranges,
+ (ProtobufCMessageInit) osmpbf__node__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__dense_nodes__field_descriptors[5] =
-{
- {
- "id",
- 1,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_id),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, id),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "denseinfo",
- 5,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, denseinfo),
- &osmpbf__dense_info__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lat",
- 8,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lat),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lat),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "lon",
- 9,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lon),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lon),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "keys_vals",
- 10,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_keys_vals),
- PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, keys_vals),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__dense_nodes__field_descriptors[5] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_id),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, id),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "denseinfo",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, denseinfo),
+ &osmpbf__dense_info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lat),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lat),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon",
+ 9,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lon),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lon),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys_vals",
+ 10,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_keys_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, keys_vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__dense_nodes__field_indices_by_name[] = {
- 1, /* field[1] = denseinfo */
- 0, /* field[0] = id */
- 4, /* field[4] = keys_vals */
- 2, /* field[2] = lat */
- 3, /* field[3] = lon */
+ 1, /* field[1] = denseinfo */
+ 0, /* field[0] = id */
+ 4, /* field[4] = keys_vals */
+ 2, /* field[2] = lat */
+ 3, /* field[3] = lon */
};
-static const ProtobufCIntRange osmpbf__dense_nodes__number_ranges[3 + 1] =
-{
- { 1, 0 },
- { 5, 1 },
- { 8, 2 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__dense_nodes__number_ranges[3 + 1] = {
+ { 1, 0 },
+ { 5, 1 },
+ { 8, 2 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__dense_nodes__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.DenseNodes",
- "DenseNodes",
- "OSMPBF__DenseNodes",
- "OSMPBF",
- sizeof(OSMPBF__DenseNodes),
- 5,
- osmpbf__dense_nodes__field_descriptors,
- osmpbf__dense_nodes__field_indices_by_name,
- 3, osmpbf__dense_nodes__number_ranges,
- (ProtobufCMessageInit) osmpbf__dense_nodes__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__dense_nodes__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.DenseNodes",
+ "DenseNodes",
+ "OSMPBF__DenseNodes",
+ "OSMPBF",
+ sizeof(OSMPBF__DenseNodes),
+ 5,
+ osmpbf__dense_nodes__field_descriptors,
+ osmpbf__dense_nodes__field_indices_by_name,
+ 3, osmpbf__dense_nodes__number_ranges,
+ (ProtobufCMessageInit) osmpbf__dense_nodes__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-static const ProtobufCFieldDescriptor osmpbf__way__field_descriptors[5] =
-{
- {
- "id",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_INT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, id),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "keys",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_keys),
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, keys),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "vals",
- 3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_vals),
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, vals),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "info",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, info),
- &osmpbf__info__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "refs",
- 8,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_refs),
- PROTOBUF_C_OFFSETOF(OSMPBF__Way, refs),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+static const ProtobufCFieldDescriptor osmpbf__way__field_descriptors[5] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "refs",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_refs),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, refs),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__way__field_indices_by_name[] = {
- 0, /* field[0] = id */
- 3, /* field[3] = info */
- 1, /* field[1] = keys */
- 4, /* field[4] = refs */
- 2, /* field[2] = vals */
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 4, /* field[4] = refs */
+ 2, /* field[2] = vals */
};
-static const ProtobufCIntRange osmpbf__way__number_ranges[2 + 1] =
-{
- { 1, 0 },
- { 8, 4 },
- { 0, 5 }
+static const ProtobufCIntRange osmpbf__way__number_ranges[2 + 1] = {
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 5 }
};
-const ProtobufCMessageDescriptor osmpbf__way__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Way",
- "Way",
- "OSMPBF__Way",
- "OSMPBF",
- sizeof(OSMPBF__Way),
- 5,
- osmpbf__way__field_descriptors,
- osmpbf__way__field_indices_by_name,
- 2, osmpbf__way__number_ranges,
- (ProtobufCMessageInit) osmpbf__way__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__way__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Way",
+ "Way",
+ "OSMPBF__Way",
+ "OSMPBF",
+ sizeof(OSMPBF__Way),
+ 5,
+ osmpbf__way__field_descriptors,
+ osmpbf__way__field_indices_by_name,
+ 2, osmpbf__way__number_ranges,
+ (ProtobufCMessageInit) osmpbf__way__init,
+ NULL,NULL,NULL /* reserved[123] */
};
-const ProtobufCEnumValue osmpbf__relation__member_type__enum_values_by_number[3] =
-{
- { "NODE", "OSMPBF__RELATION__MEMBER_TYPE__NODE", 0 },
- { "WAY", "OSMPBF__RELATION__MEMBER_TYPE__WAY", 1 },
- { "RELATION", "OSMPBF__RELATION__MEMBER_TYPE__RELATION", 2 },
+const ProtobufCEnumValue osmpbf__relation__member_type__enum_values_by_number[3] = {
+ { "NODE", "OSMPBF__RELATION__MEMBER_TYPE__NODE", 0 },
+ { "WAY", "OSMPBF__RELATION__MEMBER_TYPE__WAY", 1 },
+ { "RELATION", "OSMPBF__RELATION__MEMBER_TYPE__RELATION", 2 },
};
static const ProtobufCIntRange osmpbf__relation__member_type__value_ranges[] = {
-{0, 0},{0, 3}
-};
-const ProtobufCEnumValueIndex osmpbf__relation__member_type__enum_values_by_name[3] =
-{
- { "NODE", 0 },
- { "RELATION", 2 },
- { "WAY", 1 },
+ {0, 0},{0, 3}
};
-const ProtobufCEnumDescriptor osmpbf__relation__member_type__descriptor =
-{
- PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC,
- "OSMPBF.Relation.MemberType",
- "MemberType",
- "OSMPBF__Relation__MemberType",
- "OSMPBF",
- 3,
- osmpbf__relation__member_type__enum_values_by_number,
- 3,
- osmpbf__relation__member_type__enum_values_by_name,
- 1,
- osmpbf__relation__member_type__value_ranges,
- NULL,NULL,NULL,NULL /* reserved[1234] */
+const ProtobufCEnumValueIndex osmpbf__relation__member_type__enum_values_by_name[3] = {
+ { "NODE", 0 },
+ { "RELATION", 2 },
+ { "WAY", 1 },
};
-static const ProtobufCFieldDescriptor osmpbf__relation__field_descriptors[7] =
-{
- {
- "id",
- 1,
- PROTOBUF_C_LABEL_REQUIRED,
- PROTOBUF_C_TYPE_INT64,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, id),
- NULL,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "keys",
- 2,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_keys),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, keys),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "vals",
+const ProtobufCEnumDescriptor osmpbf__relation__member_type__descriptor = {
+ PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC,
+ "OSMPBF.Relation.MemberType",
+ "MemberType",
+ "OSMPBF__Relation__MemberType",
+ "OSMPBF",
3,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_UINT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_vals),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, vals),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "info",
- 4,
- PROTOBUF_C_LABEL_OPTIONAL,
- PROTOBUF_C_TYPE_MESSAGE,
- 0, /* quantifier_offset */
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, info),
- &osmpbf__info__descriptor,
- NULL,
- 0, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "roles_sid",
- 8,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_INT32,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_roles_sid),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, roles_sid),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "memids",
- 9,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_SINT64,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_memids),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, memids),
- NULL,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
- {
- "types",
- 10,
- PROTOBUF_C_LABEL_REPEATED,
- PROTOBUF_C_TYPE_ENUM,
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_types),
- PROTOBUF_C_OFFSETOF(OSMPBF__Relation, types),
- &osmpbf__relation__member_type__descriptor,
- NULL,
- 1, /* packed */
- 0,NULL,NULL /* reserved1,reserved2, etc */
- },
+ osmpbf__relation__member_type__enum_values_by_number,
+ 3,
+ osmpbf__relation__member_type__enum_values_by_name,
+ 1,
+ osmpbf__relation__member_type__value_ranges,
+ NULL,NULL,NULL,NULL /* reserved[1234] */
+};
+static const ProtobufCFieldDescriptor osmpbf__relation__field_descriptors[7] = {
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "roles_sid",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_roles_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, roles_sid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "memids",
+ 9,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_memids),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, memids),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "types",
+ 10,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_ENUM,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_types),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, types),
+ &osmpbf__relation__member_type__descriptor,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
};
static const unsigned osmpbf__relation__field_indices_by_name[] = {
- 0, /* field[0] = id */
- 3, /* field[3] = info */
- 1, /* field[1] = keys */
- 5, /* field[5] = memids */
- 4, /* field[4] = roles_sid */
- 6, /* field[6] = types */
- 2, /* field[2] = vals */
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 5, /* field[5] = memids */
+ 4, /* field[4] = roles_sid */
+ 6, /* field[6] = types */
+ 2, /* field[2] = vals */
};
-static const ProtobufCIntRange osmpbf__relation__number_ranges[2 + 1] =
-{
- { 1, 0 },
- { 8, 4 },
- { 0, 7 }
+static const ProtobufCIntRange osmpbf__relation__number_ranges[2 + 1] = {
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 7 }
};
-const ProtobufCMessageDescriptor osmpbf__relation__descriptor =
-{
- PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
- "OSMPBF.Relation",
- "Relation",
- "OSMPBF__Relation",
- "OSMPBF",
- sizeof(OSMPBF__Relation),
- 7,
- osmpbf__relation__field_descriptors,
- osmpbf__relation__field_indices_by_name,
- 2, osmpbf__relation__number_ranges,
- (ProtobufCMessageInit) osmpbf__relation__init,
- NULL,NULL,NULL /* reserved[123] */
+const ProtobufCMessageDescriptor osmpbf__relation__descriptor = {
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Relation",
+ "Relation",
+ "OSMPBF__Relation",
+ "OSMPBF",
+ sizeof(OSMPBF__Relation),
+ 7,
+ osmpbf__relation__field_descriptors,
+ osmpbf__relation__field_indices_by_name,
+ 2, osmpbf__relation__number_ranges,
+ (ProtobufCMessageInit) osmpbf__relation__init,
+ NULL,NULL,NULL /* reserved[123] */
};
diff --git a/navit/maptool/google/protobuf-c/protobuf-c.c b/navit/maptool/google/protobuf-c/protobuf-c.c
index 17a6f5a42..63cfef85b 100644
--- a/navit/maptool/google/protobuf-c/protobuf-c.c
+++ b/navit/maptool/google/protobuf-c/protobuf-c.c
@@ -2,7 +2,7 @@
/*
* Copyright 2008, Dave Benson.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License
@@ -59,11 +59,10 @@
#define FALSE 0
static void
-alloc_failed_warning (unsigned size, const char *filename, unsigned line)
-{
- fprintf (stderr,
- "WARNING: out-of-memory allocating a block of size %u (%s:%u)\n",
- size, filename, line);
+alloc_failed_warning (unsigned size, const char *filename, unsigned line) {
+ fprintf (stderr,
+ "WARNING: out-of-memory allocating a block of size %u (%s:%u)\n",
+ size, filename, line);
}
/* Try to allocate memory, running some special code if it fails. */
@@ -93,81 +92,74 @@ alloc_failed_warning (unsigned size, const char *filename, unsigned line)
/* --- allocator --- */
-static void protobuf_c_out_of_memory_default (void)
-{
- fprintf (stderr, "Out Of Memory!!!\n");
- abort ();
+static void protobuf_c_out_of_memory_default (void) {
+ fprintf (stderr, "Out Of Memory!!!\n");
+ abort ();
}
void (*protobuf_c_out_of_memory) (void) = protobuf_c_out_of_memory_default;
-static void *system_alloc(void *allocator_data, size_t size)
-{
- void *rv;
- (void) allocator_data;
- if (size == 0)
- return NULL;
- rv = g_malloc (size);
- if (rv == NULL)
- protobuf_c_out_of_memory ();
- return rv;
+static void *system_alloc(void *allocator_data, size_t size) {
+ void *rv;
+ (void) allocator_data;
+ if (size == 0)
+ return NULL;
+ rv = g_malloc (size);
+ if (rv == NULL)
+ protobuf_c_out_of_memory ();
+ return rv;
}
-static void system_free (void *allocator_data, void *data)
-{
- (void) allocator_data;
- g_free (data);
+static void system_free (void *allocator_data, void *data) {
+ (void) allocator_data;
+ g_free (data);
}
/* Some users may configure the default allocator;
providing your own allocator to unpack() is prefered.
this allocator is still used for packing nested messages. */
-ProtobufCAllocator protobuf_c_default_allocator =
-{
- system_alloc,
- system_free,
- NULL,
- 8192,
- NULL
+ProtobufCAllocator protobuf_c_default_allocator = {
+ system_alloc,
+ system_free,
+ NULL,
+ 8192,
+ NULL
};
/* Users should NOT modify this structure,
but it's difficult to prevent.
please modify protobuf_c_default_allocator instead. */
-ProtobufCAllocator protobuf_c_system_allocator =
-{
- system_alloc,
- system_free,
- NULL,
- 8192,
- NULL
+ProtobufCAllocator protobuf_c_system_allocator = {
+ system_alloc,
+ system_free,
+ NULL,
+ 8192,
+ NULL
};
/* === buffer-simple === */
void
protobuf_c_buffer_simple_append (ProtobufCBuffer *buffer,
size_t len,
- const uint8_t *data)
-{
- ProtobufCBufferSimple *simp = (ProtobufCBufferSimple *) buffer;
- size_t new_len = simp->len + len;
- if (new_len > simp->alloced)
- {
- size_t new_alloced = simp->alloced * 2;
- uint8_t *new_data;
- while (new_alloced < new_len)
- new_alloced += new_alloced;
- DO_ALLOC (new_data, &protobuf_c_default_allocator, new_alloced, return);
- memcpy (new_data, simp->data, simp->len);
- if (simp->must_free_data)
- FREE (&protobuf_c_default_allocator, simp->data);
- else
- simp->must_free_data = 1;
- simp->data = new_data;
- simp->alloced = new_alloced;
+ const uint8_t *data) {
+ ProtobufCBufferSimple *simp = (ProtobufCBufferSimple *) buffer;
+ size_t new_len = simp->len + len;
+ if (new_len > simp->alloced) {
+ size_t new_alloced = simp->alloced * 2;
+ uint8_t *new_data;
+ while (new_alloced < new_len)
+ new_alloced += new_alloced;
+ DO_ALLOC (new_data, &protobuf_c_default_allocator, new_alloced, return);
+ memcpy (new_data, simp->data, simp->len);
+ if (simp->must_free_data)
+ FREE (&protobuf_c_default_allocator, simp->data);
+ else
+ simp->must_free_data = 1;
+ simp->data = new_data;
+ simp->alloced = new_alloced;
}
- memcpy (simp->data + simp->len, data, len);
- simp->len = new_len;
+ memcpy (simp->data + simp->len, data, len);
+ simp->len = new_len;
}
/* === get_packed_size() === */
@@ -176,106 +168,99 @@ protobuf_c_buffer_simple_append (ProtobufCBuffer *buffer,
tag for the field (which includes 3 bits for
the wire-type, and a single bit that denotes the end-of-tag. */
static inline size_t
-get_tag_size (unsigned number)
-{
- if (number < (1<<4))
- return 1;
- else if (number < (1<<11))
- return 2;
- else if (number < (1<<18))
- return 3;
- else if (number < (1<<25))
- return 4;
- else
- return 5;
+get_tag_size (unsigned number) {
+ if (number < (1<<4))
+ return 1;
+ else if (number < (1<<11))
+ return 2;
+ else if (number < (1<<18))
+ return 3;
+ else if (number < (1<<25))
+ return 4;
+ else
+ return 5;
}
/* Return the number of bytes required to store
a variable-length unsigned integer that fits in 32-bit uint
in base-128 encoding. */
static inline size_t
-uint32_size (uint32_t v)
-{
- if (v < (1<<7))
- return 1;
- else if (v < (1<<14))
- return 2;
- else if (v < (1<<21))
- return 3;
- else if (v < (1<<28))
- return 4;
- else
- return 5;
+uint32_size (uint32_t v) {
+ if (v < (1<<7))
+ return 1;
+ else if (v < (1<<14))
+ return 2;
+ else if (v < (1<<21))
+ return 3;
+ else if (v < (1<<28))
+ return 4;
+ else
+ return 5;
}
/* Return the number of bytes required to store
a variable-length signed integer that fits in 32-bit int
in base-128 encoding. */
static inline size_t
-int32_size (int32_t v)
-{
- if (v < 0)
- return 10;
- else if (v < (1<<7))
- return 1;
- else if (v < (1<<14))
- return 2;
- else if (v < (1<<21))
- return 3;
- else if (v < (1<<28))
- return 4;
- else
- return 5;
+int32_size (int32_t v) {
+ if (v < 0)
+ return 10;
+ else if (v < (1<<7))
+ return 1;
+ else if (v < (1<<14))
+ return 2;
+ else if (v < (1<<21))
+ return 3;
+ else if (v < (1<<28))
+ return 4;
+ else
+ return 5;
}
/* return the zigzag-encoded 32-bit unsigned int from a 32-bit signed int */
static inline uint32_t
-zigzag32 (int32_t v)
-{
- if (v < 0)
- return ((uint32_t)(-v)) * 2 - 1;
- else
- return v * 2;
+zigzag32 (int32_t v) {
+ if (v < 0)
+ return ((uint32_t)(-v)) * 2 - 1;
+ else
+ return v * 2;
}
/* Return the number of bytes required to store
a variable-length signed integer that fits in 32-bit int,
converted to unsigned via the zig-zag algorithm,
then packed using base-128 encoding. */
static inline size_t
-sint32_size (int32_t v)
-{
- return uint32_size(zigzag32(v));
+sint32_size (int32_t v) {
+ return uint32_size(zigzag32(v));
}
/* Return the number of bytes required to store
a variable-length unsigned integer that fits in 64-bit uint
in base-128 encoding. */
static inline size_t
-uint64_size (uint64_t v)
-{
- uint32_t upper_v = (v>>32);
- if (upper_v == 0)
- return uint32_size ((uint32_t)v);
- else if (upper_v < (1<<3))
- return 5;
- else if (upper_v < (1<<10))
- return 6;
- else if (upper_v < (1<<17))
- return 7;
- else if (upper_v < (1<<24))
- return 8;
- else if (upper_v < (1U<<31))
- return 9;
- else
- return 10;
+uint64_size (uint64_t v) {
+ uint32_t upper_v = (v>>32);
+ if (upper_v == 0)
+ return uint32_size ((uint32_t)v);
+ else if (upper_v < (1<<3))
+ return 5;
+ else if (upper_v < (1<<10))
+ return 6;
+ else if (upper_v < (1<<17))
+ return 7;
+ else if (upper_v < (1<<24))
+ return 8;
+ else if (upper_v < (1U<<31))
+ return 9;
+ else
+ return 10;
}
/* return the zigzag-encoded 64-bit unsigned int from a 64-bit signed int */
static inline uint64_t
-zigzag64 (int64_t v)
-{
- if (v < 0)
- return ((uint64_t)(-v)) * 2 - 1;
- else
- return v * 2;
+zigzag64 (int64_t v) {
+ if (v < 0)
+ return ((uint64_t)(-v)) * 2 - 1;
+ else
+ return v * 2;
}
/* Return the number of bytes required to store
@@ -283,67 +268,61 @@ zigzag64 (int64_t v)
converted to unsigned via the zig-zag algorithm,
then packed using base-128 encoding. */
static inline size_t
-sint64_size (int64_t v)
-{
- return uint64_size(zigzag64(v));
+sint64_size (int64_t v) {
+ return uint64_size(zigzag64(v));
}
/* Get serialized size of a single field in the message,
including the space needed by the identifying tag. */
static size_t
required_field_get_packed_size (const ProtobufCFieldDescriptor *field,
- const void *member)
-{
- size_t rv = get_tag_size (field->id);
- switch (field->type)
- {
+ const void *member) {
+ size_t rv = get_tag_size (field->id);
+ switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
- return rv + sint32_size (*(const int32_t *) member);
+ return rv + sint32_size (*(const int32_t *) member);
case PROTOBUF_C_TYPE_INT32:
- return rv + int32_size (*(const uint32_t *) member);
+ return rv + int32_size (*(const uint32_t *) member);
case PROTOBUF_C_TYPE_UINT32:
- return rv + uint32_size (*(const uint32_t *) member);
+ return rv + uint32_size (*(const uint32_t *) member);
case PROTOBUF_C_TYPE_SINT64:
- return rv + sint64_size (*(const int64_t *) member);
+ return rv + sint64_size (*(const int64_t *) member);
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- return rv + uint64_size (*(const uint64_t *) member);
+ return rv + uint64_size (*(const uint64_t *) member);
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
- return rv + 4;
+ return rv + 4;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
- return rv + 8;
+ return rv + 8;
case PROTOBUF_C_TYPE_BOOL:
- return rv + 1;
+ return rv + 1;
case PROTOBUF_C_TYPE_FLOAT:
- return rv + 4;
+ return rv + 4;
case PROTOBUF_C_TYPE_DOUBLE:
- return rv + 8;
+ return rv + 8;
case PROTOBUF_C_TYPE_ENUM:
- // TODO: is this correct for negative-valued enums?
- return rv + uint32_size (*(const uint32_t *) member);
- case PROTOBUF_C_TYPE_STRING:
- {
+ // TODO: is this correct for negative-valued enums?
+ return rv + uint32_size (*(const uint32_t *) member);
+ case PROTOBUF_C_TYPE_STRING: {
const char *str = *(char * const *) member;
size_t len = str ? strlen (str) : 0;
return rv + uint32_size (len) + len;
- }
- case PROTOBUF_C_TYPE_BYTES:
- {
+ }
+ case PROTOBUF_C_TYPE_BYTES: {
size_t len = ((const ProtobufCBinaryData*) member)->len;
return rv + uint32_size (len) + len;
- }
+ }
//case PROTOBUF_C_TYPE_GROUP:
- case PROTOBUF_C_TYPE_MESSAGE:
- {
+ case PROTOBUF_C_TYPE_MESSAGE: {
const ProtobufCMessage *msg = * (ProtobufCMessage * const *) member;
size_t subrv = msg ? protobuf_c_message_get_packed_size (msg) : 0;
return rv + uint32_size (subrv) + subrv;
- }
}
- PROTOBUF_C_ASSERT_NOT_REACHED ();
- return 0;
+ }
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
}
/* Get serialized size of a single optional field in the message,
@@ -352,22 +331,18 @@ required_field_get_packed_size (const ProtobufCFieldDescriptor *field,
static size_t
optional_field_get_packed_size (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has,
- const void *member)
-{
- if (field->type == PROTOBUF_C_TYPE_MESSAGE
- || field->type == PROTOBUF_C_TYPE_STRING)
- {
- const void *ptr = * (const void * const *) member;
- if (ptr == NULL
- || ptr == field->default_value)
- return 0;
- }
- else
- {
- if (!*has)
- return 0;
+ const void *member) {
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING) {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ } else {
+ if (!*has)
+ return 0;
}
- return required_field_get_packed_size (field, member);
+ return required_field_get_packed_size (field, member);
}
/* Get serialized size of a repeated field in the message,
@@ -376,232 +351,208 @@ optional_field_get_packed_size (const ProtobufCFieldDescriptor *field,
static size_t
repeated_field_get_packed_size (const ProtobufCFieldDescriptor *field,
size_t count,
- const void *member)
-{
- size_t header_size;
- size_t rv = 0;
- unsigned i;
- void *array = * (void * const *) member;
- if (count == 0)
- return 0;
- header_size = get_tag_size (field->id);
- if (!field->packed)
- header_size *= count;
- switch (field->type)
- {
+ const void *member) {
+ size_t header_size;
+ size_t rv = 0;
+ unsigned i;
+ void *array = * (void * const *) member;
+ if (count == 0)
+ return 0;
+ header_size = get_tag_size (field->id);
+ if (!field->packed)
+ header_size *= count;
+ switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
- for (i = 0; i < count; i++)
- rv += sint32_size (((int32_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += sint32_size (((int32_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_INT32:
- for (i = 0; i < count; i++)
- rv += int32_size (((uint32_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += int32_size (((uint32_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM:
- for (i = 0; i < count; i++)
- rv += uint32_size (((uint32_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += uint32_size (((uint32_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_SINT64:
- for (i = 0; i < count; i++)
- rv += sint64_size (((int64_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += sint64_size (((int64_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- for (i = 0; i < count; i++)
- rv += uint64_size (((uint64_t*)array)[i]);
- break;
+ for (i = 0; i < count; i++)
+ rv += uint64_size (((uint64_t*)array)[i]);
+ break;
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- rv += 4 * count;
- break;
+ rv += 4 * count;
+ break;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- rv += 8 * count;
- break;
+ rv += 8 * count;
+ break;
case PROTOBUF_C_TYPE_BOOL:
- rv += count;
- break;
+ rv += count;
+ break;
case PROTOBUF_C_TYPE_STRING:
- for (i = 0; i < count; i++)
- {
- size_t len = strlen (((char**) array)[i]);
- rv += uint32_size (len) + len;
+ for (i = 0; i < count; i++) {
+ size_t len = strlen (((char**) array)[i]);
+ rv += uint32_size (len) + len;
}
- break;
-
+ break;
+
case PROTOBUF_C_TYPE_BYTES:
- for (i = 0; i < count; i++)
- {
- size_t len = ((ProtobufCBinaryData*) array)[i].len;
- rv += uint32_size (len) + len;
+ for (i = 0; i < count; i++) {
+ size_t len = ((ProtobufCBinaryData*) array)[i].len;
+ rv += uint32_size (len) + len;
}
- break;
+ break;
case PROTOBUF_C_TYPE_MESSAGE:
- for (i = 0; i < count; i++)
- {
- size_t len = protobuf_c_message_get_packed_size (((ProtobufCMessage **) array)[i]);
- rv += uint32_size (len) + len;
+ for (i = 0; i < count; i++) {
+ size_t len = protobuf_c_message_get_packed_size (((ProtobufCMessage **) array)[i]);
+ rv += uint32_size (len) + len;
}
- break;
- //case PROTOBUF_C_TYPE_GROUP: // NOT SUPPORTED
+ break;
+ //case PROTOBUF_C_TYPE_GROUP: // NOT SUPPORTED
}
- if (field->packed)
- header_size += uint32_size (rv);
- return header_size + rv;
+ if (field->packed)
+ header_size += uint32_size (rv);
+ return header_size + rv;
}
/* Get the packed size of a unknown field (meaning one that
is passed through mostly uninterpreted... this is done
for forward compatibilty with the addition of new fields). */
static inline size_t
-unknown_field_get_packed_size (const ProtobufCMessageUnknownField *field)
-{
- return get_tag_size (field->tag) + field->len;
+unknown_field_get_packed_size (const ProtobufCMessageUnknownField *field) {
+ return get_tag_size (field->tag) + field->len;
}
/* Get the number of bytes that the message will occupy once serialized. */
size_t
-protobuf_c_message_get_packed_size(const ProtobufCMessage *message)
-{
- unsigned i;
- size_t rv = 0;
- ASSERT_IS_MESSAGE (message);
- for (i = 0; i < message->descriptor->n_fields; i++)
- {
- const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
- const void *member = ((const char *) message) + field->offset;
- const void *qmember = ((const char *) message) + field->quantifier_offset;
-
- if (field->label == PROTOBUF_C_LABEL_REQUIRED)
- rv += required_field_get_packed_size (field, member);
- else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
- rv += optional_field_get_packed_size (field, qmember, member);
- else
- rv += repeated_field_get_packed_size (field, * (const size_t *) qmember, member);
+protobuf_c_message_get_packed_size(const ProtobufCMessage *message) {
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++) {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_get_packed_size (field, member);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ rv += optional_field_get_packed_size (field, qmember, member);
+ else
+ rv += repeated_field_get_packed_size (field, * (const size_t *) qmember, member);
}
- for (i = 0; i < message->n_unknown_fields; i++)
- rv += unknown_field_get_packed_size (&message->unknown_fields[i]);
- return rv;
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_get_packed_size (&message->unknown_fields[i]);
+ return rv;
}
/* === pack() === */
/* Pack an unsigned 32-bit integer in base-128 encoding, and return the number of bytes needed:
this will be 5 or less. */
static inline size_t
-uint32_pack (uint32_t value, uint8_t *out)
-{
- unsigned rv = 0;
- if (value >= 0x80)
- {
- out[rv++] = value | 0x80;
- value >>= 7;
- if (value >= 0x80)
- {
- out[rv++] = value | 0x80;
- value >>= 7;
- if (value >= 0x80)
- {
- out[rv++] = value | 0x80;
- value >>= 7;
- if (value >= 0x80)
- {
- out[rv++] = value | 0x80;
- value >>= 7;
+uint32_pack (uint32_t value, uint8_t *out) {
+ unsigned rv = 0;
+ if (value >= 0x80) {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80) {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80) {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80) {
+ out[rv++] = value | 0x80;
+ value >>= 7;
}
}
}
}
- /* assert: value<128 */
- out[rv++] = value;
- return rv;
+ /* assert: value<128 */
+ out[rv++] = value;
+ return rv;
}
/* Pack a 32-bit signed integer, returning the number of bytes needed.
Negative numbers are packed as twos-complement 64-bit integers. */
static inline size_t
-int32_pack (int32_t value, uint8_t *out)
-{
- if (value < 0)
- {
- out[0] = value | 0x80;
- out[1] = (value>>7) | 0x80;
- out[2] = (value>>14) | 0x80;
- out[3] = (value>>21) | 0x80;
- out[4] = (value>>28) | 0x80;
- out[5] = out[6] = out[7] = out[8] = 0xff;
- out[9] = 0x01;
- return 10;
- }
- else
- return uint32_pack (value, out);
+int32_pack (int32_t value, uint8_t *out) {
+ if (value < 0) {
+ out[0] = value | 0x80;
+ out[1] = (value>>7) | 0x80;
+ out[2] = (value>>14) | 0x80;
+ out[3] = (value>>21) | 0x80;
+ out[4] = (value>>28) | 0x80;
+ out[5] = out[6] = out[7] = out[8] = 0xff;
+ out[9] = 0x01;
+ return 10;
+ } else
+ return uint32_pack (value, out);
}
/* Pack a 32-bit integer in zigwag encoding. */
static inline size_t
-sint32_pack (int32_t value, uint8_t *out)
-{
- return uint32_pack (zigzag32 (value), out);
+sint32_pack (int32_t value, uint8_t *out) {
+ return uint32_pack (zigzag32 (value), out);
}
/* Pack a 64-bit unsigned integer that fits in a 64-bit uint,
using base-128 encoding. */
static size_t
-uint64_pack (uint64_t value, uint8_t *out)
-{
- uint32_t hi = value>>32;
- uint32_t lo = value;
- unsigned rv;
- if (hi == 0)
- return uint32_pack ((uint32_t)lo, out);
- out[0] = (lo) | 0x80;
- out[1] = (lo>>7) | 0x80;
- out[2] = (lo>>14) | 0x80;
- out[3] = (lo>>21) | 0x80;
- if (hi < 8)
- {
- out[4] = (hi<<4) | (lo>>28);
- return 5;
+uint64_pack (uint64_t value, uint8_t *out) {
+ uint32_t hi = value>>32;
+ uint32_t lo = value;
+ unsigned rv;
+ if (hi == 0)
+ return uint32_pack ((uint32_t)lo, out);
+ out[0] = (lo) | 0x80;
+ out[1] = (lo>>7) | 0x80;
+ out[2] = (lo>>14) | 0x80;
+ out[3] = (lo>>21) | 0x80;
+ if (hi < 8) {
+ out[4] = (hi<<4) | (lo>>28);
+ return 5;
+ } else {
+ out[4] = ((hi&7)<<4) | (lo>>28) | 0x80;
+ hi >>= 3;
}
- else
- {
- out[4] = ((hi&7)<<4) | (lo>>28) | 0x80;
- hi >>= 3;
+ rv = 5;
+ while (hi >= 128) {
+ out[rv++] = hi | 0x80;
+ hi >>= 7;
}
- rv = 5;
- while (hi >= 128)
- {
- out[rv++] = hi | 0x80;
- hi >>= 7;
- }
- out[rv++] = hi;
- return rv;
+ out[rv++] = hi;
+ return rv;
}
/* Pack a 64-bit signed integer in zigzan encoding,
return the size of the packed output.
(Max returned value is 10) */
static inline size_t
-sint64_pack (int64_t value, uint8_t *out)
-{
- return uint64_pack (zigzag64 (value), out);
+sint64_pack (int64_t value, uint8_t *out) {
+ return uint64_pack (zigzag64 (value), out);
}
/* Pack a 32-bit value, little-endian.
Used for fixed32, sfixed32, float) */
static inline size_t
-fixed32_pack (uint32_t value, uint8_t *out)
-{
+fixed32_pack (uint32_t value, uint8_t *out) {
#ifdef IS_LITTLE_ENDIAN
- memcpy (out, &value, 4);
+ memcpy (out, &value, 4);
#else
- out[0] = value;
- out[1] = value>>8;
- out[2] = value>>16;
- out[3] = value>>24;
+ out[0] = value;
+ out[1] = value>>8;
+ out[2] = value>>16;
+ out[3] = value>>24;
#endif
- return 4;
+ return 4;
}
/* Pack a 64-bit fixed-length value.
@@ -610,15 +561,14 @@ fixed32_pack (uint32_t value, uint8_t *out)
a 64-bit version would be appreciated, plus a way
to decide to use 64-bit math where convenient. */
static inline size_t
-fixed64_pack (uint64_t value, uint8_t *out)
-{
+fixed64_pack (uint64_t value, uint8_t *out) {
#ifdef IS_LITTLE_ENDIAN
- memcpy (out, &value, 8);
+ memcpy (out, &value, 8);
#else
- fixed32_pack (value, out);
- fixed32_pack (value>>32, out+4);
+ fixed32_pack (value, out);
+ fixed32_pack (value>>32, out+4);
#endif
- return 8;
+ return 8;
}
@@ -627,10 +577,9 @@ fixed64_pack (uint64_t value, uint8_t *out)
/* XXX: perhaps on some platforms "*out = !!value" would be
a better impl, b/c that is idiotmatic c++ in some stl impls. */
static inline size_t
-boolean_pack (protobuf_c_boolean value, uint8_t *out)
-{
- *out = value ? 1 : 0;
- return 1;
+boolean_pack (protobuf_c_boolean value, uint8_t *out) {
+ *out = value ? 1 : 0;
+ return 1;
}
/* Pack a length-prefixed string.
@@ -639,153 +588,132 @@ boolean_pack (protobuf_c_boolean value, uint8_t *out)
The NULL pointer is treated as an empty string.
This isn't really necessary, but it allows people
to leave required strings blank.
- (See Issue 13 in the bug tracker for a
+ (See Issue 13 in the bug tracker for a
little more explanation).
*/
static inline size_t
-string_pack (const char * str, uint8_t *out)
-{
- if (str == NULL)
- {
- out[0] = 0;
- return 1;
- }
- else
- {
- size_t len = strlen (str);
- size_t rv = uint32_pack (len, out);
- memcpy (out + rv, str, len);
- return rv + len;
+string_pack (const char * str, uint8_t *out) {
+ if (str == NULL) {
+ out[0] = 0;
+ return 1;
+ } else {
+ size_t len = strlen (str);
+ size_t rv = uint32_pack (len, out);
+ memcpy (out + rv, str, len);
+ return rv + len;
}
}
static inline size_t
-binary_data_pack (const ProtobufCBinaryData *bd, uint8_t *out)
-{
- size_t len = bd->len;
- size_t rv = uint32_pack (len, out);
- memcpy (out + rv, bd->data, len);
- return rv + len;
+binary_data_pack (const ProtobufCBinaryData *bd, uint8_t *out) {
+ size_t len = bd->len;
+ size_t rv = uint32_pack (len, out);
+ memcpy (out + rv, bd->data, len);
+ return rv + len;
}
static inline size_t
-prefixed_message_pack (const ProtobufCMessage *message, uint8_t *out)
-{
- if (message == NULL)
- {
- out[0] = 0;
- return 1;
- }
- else
- {
- size_t rv = protobuf_c_message_pack (message, out + 1);
- uint32_t rv_packed_size = uint32_size (rv);
- if (rv_packed_size != 1)
- memmove (out + rv_packed_size, out + 1, rv);
- return uint32_pack (rv, out) + rv;
+prefixed_message_pack (const ProtobufCMessage *message, uint8_t *out) {
+ if (message == NULL) {
+ out[0] = 0;
+ return 1;
+ } else {
+ size_t rv = protobuf_c_message_pack (message, out + 1);
+ uint32_t rv_packed_size = uint32_size (rv);
+ if (rv_packed_size != 1)
+ memmove (out + rv_packed_size, out + 1, rv);
+ return uint32_pack (rv, out) + rv;
}
}
/* wire-type will be added in required_field_pack() */
/* XXX: just call uint64_pack on 64-bit platforms. */
static size_t
-tag_pack (uint32_t id, uint8_t *out)
-{
- if (id < (1<<(32-3)))
- return uint32_pack (id<<3, out);
- else
- return uint64_pack (((uint64_t)id) << 3, out);
+tag_pack (uint32_t id, uint8_t *out) {
+ if (id < (1<<(32-3)))
+ return uint32_pack (id<<3, out);
+ else
+ return uint64_pack (((uint64_t)id) << 3, out);
}
static size_t
required_field_pack (const ProtobufCFieldDescriptor *field,
const void *member,
- uint8_t *out)
-{
- size_t rv = tag_pack (field->id, out);
- switch (field->type)
- {
+ uint8_t *out) {
+ size_t rv = tag_pack (field->id, out);
+ switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + sint32_pack (*(const int32_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + sint32_pack (*(const int32_t *) member, out + rv);
case PROTOBUF_C_TYPE_INT32:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + int32_pack (*(const uint32_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + int32_pack (*(const uint32_t *) member, out + rv);
case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + uint32_pack (*(const uint32_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + uint32_pack (*(const uint32_t *) member, out + rv);
case PROTOBUF_C_TYPE_SINT64:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + sint64_pack (*(const int64_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + sint64_pack (*(const int64_t *) member, out + rv);
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + uint64_pack (*(const uint64_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + uint64_pack (*(const uint64_t *) member, out + rv);
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
- return rv + fixed32_pack (*(const uint32_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
+ return rv + fixed32_pack (*(const uint32_t *) member, out + rv);
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
- return rv + fixed64_pack (*(const uint64_t *) member, out + rv);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
+ return rv + fixed64_pack (*(const uint64_t *) member, out + rv);
case PROTOBUF_C_TYPE_BOOL:
- out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- return rv + boolean_pack (*(const protobuf_c_boolean *) member, out + rv);
- case PROTOBUF_C_TYPE_STRING:
- {
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + boolean_pack (*(const protobuf_c_boolean *) member, out + rv);
+ case PROTOBUF_C_TYPE_STRING: {
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + string_pack (*(char * const *) member, out + rv);
- }
-
- case PROTOBUF_C_TYPE_BYTES:
- {
+ }
+
+ case PROTOBUF_C_TYPE_BYTES: {
const ProtobufCBinaryData * bd = ((const ProtobufCBinaryData*) member);
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + binary_data_pack (bd, out + rv);
- }
+ }
//case PROTOBUF_C_TYPE_GROUP: // NOT SUPPORTED
- case PROTOBUF_C_TYPE_MESSAGE:
- {
+ case PROTOBUF_C_TYPE_MESSAGE: {
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + prefixed_message_pack (*(ProtobufCMessage * const *) member,
out + rv);
- }
}
- PROTOBUF_C_ASSERT_NOT_REACHED ();
- return 0;
+ }
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
}
static size_t
optional_field_pack (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has,
const void *member,
- uint8_t *out)
-{
- if (field->type == PROTOBUF_C_TYPE_MESSAGE
- || field->type == PROTOBUF_C_TYPE_STRING)
- {
- const void *ptr = * (const void * const *) member;
- if (ptr == NULL
- || ptr == field->default_value)
- return 0;
- }
- else
- {
- if (!*has)
- return 0;
+ uint8_t *out) {
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING) {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ } else {
+ if (!*has)
+ return 0;
}
- return required_field_pack (field, member, out);
+ return required_field_pack (field, member, out);
}
/* TODO: implement as a table lookup */
static inline size_t
-sizeof_elt_in_repeated_array (ProtobufCType type)
-{
- switch (type)
- {
+sizeof_elt_in_repeated_array (ProtobufCType type) {
+ switch (type) {
case PROTOBUF_C_TYPE_SINT32:
case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_UINT32:
@@ -793,284 +721,262 @@ sizeof_elt_in_repeated_array (ProtobufCType type)
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_ENUM:
- return 4;
+ return 4;
case PROTOBUF_C_TYPE_SINT64:
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- return 8;
+ return 8;
case PROTOBUF_C_TYPE_BOOL:
- return sizeof (protobuf_c_boolean);
+ return sizeof (protobuf_c_boolean);
case PROTOBUF_C_TYPE_STRING:
case PROTOBUF_C_TYPE_MESSAGE:
- return sizeof (void *);
+ return sizeof (void *);
case PROTOBUF_C_TYPE_BYTES:
- return sizeof (ProtobufCBinaryData);
+ return sizeof (ProtobufCBinaryData);
}
- PROTOBUF_C_ASSERT_NOT_REACHED ();
- return 0;
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
}
static void
-copy_to_little_endian_32 (void *out, const void *in, unsigned N)
-{
+copy_to_little_endian_32 (void *out, const void *in, unsigned N) {
#ifdef IS_LITTLE_ENDIAN
- memcpy (out, in, N * 4);
+ memcpy (out, in, N * 4);
#else
- unsigned i;
- const uint32_t *ini = in;
- for (i = 0; i < N; i++)
- fixed32_pack (ini[i], (uint8_t*)out + 4*i);
+ unsigned i;
+ const uint32_t *ini = in;
+ for (i = 0; i < N; i++)
+ fixed32_pack (ini[i], (uint8_t*)out + 4*i);
#endif
}
static void
-copy_to_little_endian_64 (void *out, const void *in, unsigned N)
-{
+copy_to_little_endian_64 (void *out, const void *in, unsigned N) {
#ifdef IS_LITTLE_ENDIAN
- memcpy (out, in, N * 8);
+ memcpy (out, in, N * 8);
#else
- unsigned i;
- const uint64_t *ini = in;
- for (i = 0; i < N; i++)
- fixed64_pack (ini[i], (uint8_t*)out + 8*i);
+ unsigned i;
+ const uint64_t *ini = in;
+ for (i = 0; i < N; i++)
+ fixed64_pack (ini[i], (uint8_t*)out + 8*i);
#endif
}
static unsigned
-get_type_min_size (ProtobufCType type)
-{
- if (type == PROTOBUF_C_TYPE_SFIXED32
- || type == PROTOBUF_C_TYPE_FIXED32
- || type == PROTOBUF_C_TYPE_FLOAT)
- return 4;
- if (type == PROTOBUF_C_TYPE_SFIXED64
- || type == PROTOBUF_C_TYPE_FIXED64
- || type == PROTOBUF_C_TYPE_DOUBLE)
- return 8;
- return 1;
+get_type_min_size (ProtobufCType type) {
+ if (type == PROTOBUF_C_TYPE_SFIXED32
+ || type == PROTOBUF_C_TYPE_FIXED32
+ || type == PROTOBUF_C_TYPE_FLOAT)
+ return 4;
+ if (type == PROTOBUF_C_TYPE_SFIXED64
+ || type == PROTOBUF_C_TYPE_FIXED64
+ || type == PROTOBUF_C_TYPE_DOUBLE)
+ return 8;
+ return 1;
}
static size_t
repeated_field_pack (const ProtobufCFieldDescriptor *field,
size_t count,
const void *member,
- uint8_t *out)
-{
- char *array = * (char * const *) member;
- unsigned i;
- if (field->packed)
- {
- unsigned header_len;
- unsigned len_start;
- unsigned min_length;
- unsigned payload_len;
- unsigned length_size_min;
- unsigned actual_length_size;
- uint8_t *payload_at;
- if (count == 0)
- return 0;
- header_len = tag_pack (field->id, out);
- out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
- len_start = header_len;
- min_length = get_type_min_size (field->type) * count;
- length_size_min = uint32_size (min_length);
- header_len += length_size_min;
- payload_at = out + header_len;
- switch (field->type)
- {
+ uint8_t *out) {
+ char *array = * (char * const *) member;
+ unsigned i;
+ if (field->packed) {
+ unsigned header_len;
+ unsigned len_start;
+ unsigned min_length;
+ unsigned payload_len;
+ unsigned length_size_min;
+ unsigned actual_length_size;
+ uint8_t *payload_at;
+ if (count == 0)
+ return 0;
+ header_len = tag_pack (field->id, out);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ len_start = header_len;
+ min_length = get_type_min_size (field->type) * count;
+ length_size_min = uint32_size (min_length);
+ header_len += length_size_min;
+ payload_at = out + header_len;
+ switch (field->type) {
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- copy_to_little_endian_32 (payload_at, array, count);
- payload_at += count * 4;
- break;
+ copy_to_little_endian_32 (payload_at, array, count);
+ payload_at += count * 4;
+ break;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- copy_to_little_endian_64 (payload_at, array, count);
- payload_at += count * 8;
- break;
+ copy_to_little_endian_64 (payload_at, array, count);
+ payload_at += count * 8;
+ break;
- case PROTOBUF_C_TYPE_INT32:
- {
+ case PROTOBUF_C_TYPE_INT32: {
const int32_t *arr = (const int32_t *) array;
for (i = 0; i < count; i++)
- payload_at += int32_pack (arr[i], payload_at);
- }
- break;
+ payload_at += int32_pack (arr[i], payload_at);
+ }
+ break;
- case PROTOBUF_C_TYPE_SINT32:
- {
+ case PROTOBUF_C_TYPE_SINT32: {
const int32_t *arr = (const int32_t *) array;
for (i = 0; i < count; i++)
- payload_at += sint32_pack (arr[i], payload_at);
- }
- break;
+ payload_at += sint32_pack (arr[i], payload_at);
+ }
+ break;
- case PROTOBUF_C_TYPE_SINT64:
- {
+ case PROTOBUF_C_TYPE_SINT64: {
const int64_t *arr = (const int64_t *) array;
for (i = 0; i < count; i++)
- payload_at += sint64_pack (arr[i], payload_at);
- }
- break;
+ payload_at += sint64_pack (arr[i], payload_at);
+ }
+ break;
case PROTOBUF_C_TYPE_ENUM:
- case PROTOBUF_C_TYPE_UINT32:
- {
+ case PROTOBUF_C_TYPE_UINT32: {
const uint32_t *arr = (const uint32_t *) array;
for (i = 0; i < count; i++)
- payload_at += uint32_pack (arr[i], payload_at);
- }
- break;
+ payload_at += uint32_pack (arr[i], payload_at);
+ }
+ break;
case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_UINT64:
- {
+ case PROTOBUF_C_TYPE_UINT64: {
const uint64_t *arr = (const uint64_t *) array;
for (i = 0; i < count; i++)
- payload_at += uint64_pack (arr[i], payload_at);
- }
- break;
- case PROTOBUF_C_TYPE_BOOL:
- {
+ payload_at += uint64_pack (arr[i], payload_at);
+ }
+ break;
+ case PROTOBUF_C_TYPE_BOOL: {
const protobuf_c_boolean *arr = (const protobuf_c_boolean *) array;
for (i = 0; i < count; i++)
- payload_at += boolean_pack (arr[i], payload_at);
- }
- break;
-
+ payload_at += boolean_pack (arr[i], payload_at);
+ }
+ break;
+
default:
- assert (0);
+ assert (0);
}
- payload_len = payload_at - (out + header_len);
- actual_length_size = uint32_size (payload_len);
- if (length_size_min != actual_length_size)
- {
- assert (actual_length_size == length_size_min + 1);
- memmove (out + header_len + 1, out + header_len, payload_len);
- header_len++;
+ payload_len = payload_at - (out + header_len);
+ actual_length_size = uint32_size (payload_len);
+ if (length_size_min != actual_length_size) {
+ assert (actual_length_size == length_size_min + 1);
+ memmove (out + header_len + 1, out + header_len, payload_len);
+ header_len++;
}
- uint32_pack (payload_len, out + len_start);
- return header_len + payload_len;
- }
- else
- {
- /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
- size_t rv = 0;
- unsigned siz = sizeof_elt_in_repeated_array (field->type);
- for (i = 0; i < count; i++)
- {
- rv += required_field_pack (field, array, out + rv);
- array += siz;
+ uint32_pack (payload_len, out + len_start);
+ return header_len + payload_len;
+ } else {
+ /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
+ size_t rv = 0;
+ unsigned siz = sizeof_elt_in_repeated_array (field->type);
+ for (i = 0; i < count; i++) {
+ rv += required_field_pack (field, array, out + rv);
+ array += siz;
}
- return rv;
+ return rv;
}
}
static size_t
unknown_field_pack (const ProtobufCMessageUnknownField *field,
- uint8_t *out)
-{
- size_t rv = tag_pack (field->tag, out);
- out[0] |= field->wire_type;
- memcpy (out + rv, field->data, field->len);
- return rv + field->len;
+ uint8_t *out) {
+ size_t rv = tag_pack (field->tag, out);
+ out[0] |= field->wire_type;
+ memcpy (out + rv, field->data, field->len);
+ return rv + field->len;
}
size_t
protobuf_c_message_pack (const ProtobufCMessage *message,
- uint8_t *out)
-{
- unsigned i;
- size_t rv = 0;
- ASSERT_IS_MESSAGE (message);
- for (i = 0; i < message->descriptor->n_fields; i++)
- {
- const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
- const void *member = ((const char *) message) + field->offset;
-
- /* it doesn't hurt to compute qmember (a pointer to the quantifier
- field of the structure), but the pointer is only valid if
- the field is one of:
- - a repeated field
- - an optional field that isn't a pointer type
- (meaning: not a message or a string) */
- const void *qmember = ((const char *) message) + field->quantifier_offset;
-
- if (field->label == PROTOBUF_C_LABEL_REQUIRED)
- rv += required_field_pack (field, member, out + rv);
- else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
- /* note that qmember is bogus for strings and messages,
- but it isn't used */
- rv += optional_field_pack (field, qmember, member, out + rv);
- else
- rv += repeated_field_pack (field, * (const size_t *) qmember, member, out + rv);
+ uint8_t *out) {
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++) {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+
+ /* it doesn't hurt to compute qmember (a pointer to the quantifier
+ field of the structure), but the pointer is only valid if
+ the field is one of:
+ - a repeated field
+ - an optional field that isn't a pointer type
+ (meaning: not a message or a string) */
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_pack (field, member, out + rv);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ /* note that qmember is bogus for strings and messages,
+ but it isn't used */
+ rv += optional_field_pack (field, qmember, member, out + rv);
+ else
+ rv += repeated_field_pack (field, * (const size_t *) qmember, member, out + rv);
}
- for (i = 0; i < message->n_unknown_fields; i++)
- rv += unknown_field_pack (&message->unknown_fields[i], out + rv);
- return rv;
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_pack (&message->unknown_fields[i], out + rv);
+ return rv;
}
/* === pack_to_buffer() === */
static size_t
required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
const void *member,
- ProtobufCBuffer *buffer)
-{
- size_t rv;
- uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
- rv = tag_pack (field->id, scratch);
- switch (field->type)
- {
+ ProtobufCBuffer *buffer) {
+ size_t rv;
+ uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
+ rv = tag_pack (field->id, scratch);
+ switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += sint32_pack (*(const int32_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += sint32_pack (*(const int32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_INT32:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += int32_pack (*(const uint32_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += int32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += uint32_pack (*(const uint32_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += uint32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_SINT64:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += sint64_pack (*(const int64_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += sint64_pack (*(const int64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += uint64_pack (*(const uint64_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += uint64_pack (*(const uint64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
- rv += fixed32_pack (*(const uint32_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
+ rv += fixed32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
- rv += fixed64_pack (*(const uint64_t *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
+ rv += fixed64_pack (*(const uint64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
case PROTOBUF_C_TYPE_BOOL:
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
- rv += boolean_pack (*(const protobuf_c_boolean *) member, scratch + rv);
- buffer->append (buffer, rv, scratch);
- break;
- case PROTOBUF_C_TYPE_STRING:
- {
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += boolean_pack (*(const protobuf_c_boolean *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_STRING: {
const char *str = *(char * const *) member;
size_t sublen = str ? strlen (str) : 0;
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
@@ -1079,10 +985,9 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
buffer->append (buffer, sublen, (const uint8_t *) str);
rv += sublen;
break;
- }
-
- case PROTOBUF_C_TYPE_BYTES:
- {
+ }
+
+ case PROTOBUF_C_TYPE_BYTES: {
const ProtobufCBinaryData * bd = ((const ProtobufCBinaryData*) member);
size_t sublen = bd->len;
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
@@ -1091,221 +996,199 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
buffer->append (buffer, sublen, bd->data);
rv += sublen;
break;
- }
+ }
//PROTOBUF_C_TYPE_GROUP, // NOT SUPPORTED
- case PROTOBUF_C_TYPE_MESSAGE:
- {
+ case PROTOBUF_C_TYPE_MESSAGE: {
uint8_t simple_buffer_scratch[256];
size_t sublen;
ProtobufCBufferSimple simple_buffer
- = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_buffer_scratch);
+ = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_buffer_scratch);
const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member;
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
if (msg == NULL)
- sublen = 0;
+ sublen = 0;
else
- sublen = protobuf_c_message_pack_to_buffer (msg, &simple_buffer.base);
+ sublen = protobuf_c_message_pack_to_buffer (msg, &simple_buffer.base);
rv += uint32_pack (sublen, scratch + rv);
buffer->append (buffer, rv, scratch);
buffer->append (buffer, sublen, simple_buffer.data);
rv += sublen;
PROTOBUF_C_BUFFER_SIMPLE_CLEAR (&simple_buffer);
break;
- }
+ }
default:
- PROTOBUF_C_ASSERT_NOT_REACHED ();
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
}
- return rv;
+ return rv;
}
static size_t
optional_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has,
const void *member,
- ProtobufCBuffer *buffer)
-{
- if (field->type == PROTOBUF_C_TYPE_MESSAGE
- || field->type == PROTOBUF_C_TYPE_STRING)
- {
- const void *ptr = * (const void * const *) member;
- if (ptr == NULL
- || ptr == field->default_value)
- return 0;
+ ProtobufCBuffer *buffer) {
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING) {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ } else {
+ if (!*has)
+ return 0;
}
- else
- {
- if (!*has)
- return 0;
- }
- return required_field_pack_to_buffer (field, member, buffer);
+ return required_field_pack_to_buffer (field, member, buffer);
}
static size_t
get_packed_payload_length (const ProtobufCFieldDescriptor *field,
unsigned count,
- const void *array)
-{
- unsigned rv = 0;
- unsigned i;
- switch (field->type)
- {
+ const void *array) {
+ unsigned rv = 0;
+ unsigned i;
+ switch (field->type) {
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- return count * 4;
+ return count * 4;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- return count * 8;
+ return count * 8;
- case PROTOBUF_C_TYPE_INT32:
- {
+ case PROTOBUF_C_TYPE_INT32: {
const int32_t *arr = (const int32_t *) array;
for (i = 0; i < count; i++)
- rv += int32_size (arr[i]);
- }
- break;
+ rv += int32_size (arr[i]);
+ }
+ break;
- case PROTOBUF_C_TYPE_SINT32:
- {
+ case PROTOBUF_C_TYPE_SINT32: {
const int32_t *arr = (const int32_t *) array;
for (i = 0; i < count; i++)
- rv += sint32_size (arr[i]);
- }
- break;
+ rv += sint32_size (arr[i]);
+ }
+ break;
case PROTOBUF_C_TYPE_ENUM:
- case PROTOBUF_C_TYPE_UINT32:
- {
+ case PROTOBUF_C_TYPE_UINT32: {
const uint32_t *arr = (const uint32_t *) array;
for (i = 0; i < count; i++)
- rv += uint32_size (arr[i]);
- }
- break;
+ rv += uint32_size (arr[i]);
+ }
+ break;
- case PROTOBUF_C_TYPE_SINT64:
- {
+ case PROTOBUF_C_TYPE_SINT64: {
const int64_t *arr = (const int64_t *) array;
for (i = 0; i < count; i++)
- rv += sint64_size (arr[i]);
- }
- break;
+ rv += sint64_size (arr[i]);
+ }
+ break;
case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_UINT64:
- {
+ case PROTOBUF_C_TYPE_UINT64: {
const uint64_t *arr = (const uint64_t *) array;
for (i = 0; i < count; i++)
- rv += uint64_size (arr[i]);
- }
- break;
+ rv += uint64_size (arr[i]);
+ }
+ break;
case PROTOBUF_C_TYPE_BOOL:
- return count;
+ return count;
default:
- assert (0);
+ assert (0);
}
- return rv;
+ return rv;
}
static size_t
pack_buffer_packed_payload (const ProtobufCFieldDescriptor *field,
unsigned count,
const void *array,
- ProtobufCBuffer *buffer)
-{
- uint8_t scratch[16];
- size_t rv = 0;
- unsigned i;
- switch (field->type)
- {
- case PROTOBUF_C_TYPE_SFIXED32:
- case PROTOBUF_C_TYPE_FIXED32:
- case PROTOBUF_C_TYPE_FLOAT:
+ ProtobufCBuffer *buffer) {
+ uint8_t scratch[16];
+ size_t rv = 0;
+ unsigned i;
+ switch (field->type) {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
#ifdef IS_LITTLE_ENDIAN
rv = count * 4;
goto no_packing_needed;
#else
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
unsigned len = fixed32_pack (((uint32_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
#endif
break;
- case PROTOBUF_C_TYPE_SFIXED64:
- case PROTOBUF_C_TYPE_FIXED64:
- case PROTOBUF_C_TYPE_DOUBLE:
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
#ifdef IS_LITTLE_ENDIAN
rv = count * 8;
goto no_packing_needed;
#else
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
unsigned len = fixed64_pack (((uint64_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
#endif
- case PROTOBUF_C_TYPE_INT32:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_INT32:
+ for (i = 0; i < count; i++) {
unsigned len = int32_pack (((int32_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_SINT32:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_SINT32:
+ for (i = 0; i < count; i++) {
unsigned len = sint32_pack (((int32_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_ENUM:
- case PROTOBUF_C_TYPE_UINT32:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ for (i = 0; i < count; i++) {
unsigned len = uint32_pack (((uint32_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_SINT64:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_SINT64:
+ for (i = 0; i < count; i++) {
unsigned len = sint64_pack (((int64_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_UINT64:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ for (i = 0; i < count; i++) {
unsigned len = uint64_pack (((uint64_t*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
break;
- case PROTOBUF_C_TYPE_BOOL:
- for (i = 0; i < count; i++)
- {
+ case PROTOBUF_C_TYPE_BOOL:
+ for (i = 0; i < count; i++) {
unsigned len = boolean_pack (((protobuf_c_boolean*)array)[i], scratch);
buffer->append (buffer, len, scratch);
rv += len;
- }
+ }
return count;
- default:
+ default:
assert(0);
}
- return rv;
+ return rv;
#ifdef IS_LITTLE_ENDIAN
no_packing_needed:
- buffer->append (buffer, rv, array);
- return rv;
+ buffer->append (buffer, rv, array);
+ return rv;
#endif
}
@@ -1313,79 +1196,71 @@ static size_t
repeated_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
unsigned count,
const void *member,
- ProtobufCBuffer *buffer)
-{
- char *array = * (char * const *) member;
- if (count == 0)
- return 0;
- if (field->packed)
- {
- uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
- size_t rv = tag_pack (field->id, scratch);
- size_t payload_len = get_packed_payload_length (field, count, array);
- size_t tmp;
- scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
- rv += uint32_pack (payload_len, scratch + rv);
- buffer->append (buffer, rv, scratch);
- tmp = pack_buffer_packed_payload (field, count, array, buffer);
- if (tmp != payload_len){
- fprintf (stderr, "Unexpected payload length: %zu (expected: %zu). Aborting.\n", tmp, payload_len);
- abort ();
- }
- return rv + payload_len;
- }
- else
- {
- size_t siz;
- unsigned i;
- /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
- unsigned rv = 0;
- siz = sizeof_elt_in_repeated_array (field->type);
- for (i = 0; i < count; i++)
- {
- rv += required_field_pack_to_buffer (field, array, buffer);
- array += siz;
+ ProtobufCBuffer *buffer) {
+ char *array = * (char * const *) member;
+ if (count == 0)
+ return 0;
+ if (field->packed) {
+ uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
+ size_t rv = tag_pack (field->id, scratch);
+ size_t payload_len = get_packed_payload_length (field, count, array);
+ size_t tmp;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ rv += uint32_pack (payload_len, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ tmp = pack_buffer_packed_payload (field, count, array, buffer);
+ if (tmp != payload_len) {
+ fprintf (stderr, "Unexpected payload length: %zu (expected: %zu). Aborting.\n", tmp, payload_len);
+ abort ();
+ }
+ return rv + payload_len;
+ } else {
+ size_t siz;
+ unsigned i;
+ /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
+ unsigned rv = 0;
+ siz = sizeof_elt_in_repeated_array (field->type);
+ for (i = 0; i < count; i++) {
+ rv += required_field_pack_to_buffer (field, array, buffer);
+ array += siz;
}
- return rv;
+ return rv;
}
}
static size_t
unknown_field_pack_to_buffer (const ProtobufCMessageUnknownField *field,
- ProtobufCBuffer *buffer)
-{
- uint8_t header[MAX_UINT64_ENCODED_SIZE];
- size_t rv = tag_pack (field->tag, header);
- header[0] |= field->wire_type;
- buffer->append (buffer, rv, header);
- buffer->append (buffer, field->len, field->data);
- return rv + field->len;
+ ProtobufCBuffer *buffer) {
+ uint8_t header[MAX_UINT64_ENCODED_SIZE];
+ size_t rv = tag_pack (field->tag, header);
+ header[0] |= field->wire_type;
+ buffer->append (buffer, rv, header);
+ buffer->append (buffer, field->len, field->data);
+ return rv + field->len;
}
size_t
protobuf_c_message_pack_to_buffer (const ProtobufCMessage *message,
- ProtobufCBuffer *buffer)
-{
- unsigned i;
- size_t rv = 0;
- ASSERT_IS_MESSAGE (message);
- for (i = 0; i < message->descriptor->n_fields; i++)
- {
- const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
- const void *member = ((const char *) message) + field->offset;
- const void *qmember = ((const char *) message) + field->quantifier_offset;
-
- if (field->label == PROTOBUF_C_LABEL_REQUIRED)
- rv += required_field_pack_to_buffer (field, member, buffer);
- else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
- rv += optional_field_pack_to_buffer (field, qmember, member, buffer);
- else
- rv += repeated_field_pack_to_buffer (field, * (const size_t *) qmember, member, buffer);
+ ProtobufCBuffer *buffer) {
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++) {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_pack_to_buffer (field, member, buffer);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ rv += optional_field_pack_to_buffer (field, qmember, member, buffer);
+ else
+ rv += repeated_field_pack_to_buffer (field, * (const size_t *) qmember, member, buffer);
}
- for (i = 0; i < message->n_unknown_fields; i++)
- rv += unknown_field_pack_to_buffer (&message->unknown_fields[i], buffer);
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_pack_to_buffer (&message->unknown_fields[i], buffer);
- return rv;
+ return rv;
}
/* === unpacking === */
@@ -1398,124 +1273,106 @@ protobuf_c_message_pack_to_buffer (const ProtobufCMessage *message,
static inline int
int_range_lookup (unsigned n_ranges,
const ProtobufCIntRange *ranges,
- int value)
-{
- unsigned start, n;
- if (n_ranges == 0)
- return -1;
- start = 0;
- n = n_ranges;
- while (n > 1)
- {
- unsigned mid = start + n / 2;
- if (value < ranges[mid].start_value)
- {
- n = mid - start;
- }
- else if (value >= ranges[mid].start_value + (int)(ranges[mid+1].orig_index-ranges[mid].orig_index))
- {
- unsigned new_start = mid + 1;
- n = start + n - new_start;
- start = new_start;
- }
- else
- return (value - ranges[mid].start_value) + ranges[mid].orig_index;
+ int value) {
+ unsigned start, n;
+ if (n_ranges == 0)
+ return -1;
+ start = 0;
+ n = n_ranges;
+ while (n > 1) {
+ unsigned mid = start + n / 2;
+ if (value < ranges[mid].start_value) {
+ n = mid - start;
+ } else if (value >= ranges[mid].start_value + (int)(ranges[mid+1].orig_index-ranges[mid].orig_index)) {
+ unsigned new_start = mid + 1;
+ n = start + n - new_start;
+ start = new_start;
+ } else
+ return (value - ranges[mid].start_value) + ranges[mid].orig_index;
}
- if (n > 0)
- {
- unsigned start_orig_index = ranges[start].orig_index;
- unsigned range_size = ranges[start+1].orig_index - start_orig_index;
-
- if (ranges[start].start_value <= value
- && value < (int)(ranges[start].start_value + range_size))
- return (value - ranges[start].start_value) + start_orig_index;
+ if (n > 0) {
+ unsigned start_orig_index = ranges[start].orig_index;
+ unsigned range_size = ranges[start+1].orig_index - start_orig_index;
+
+ if (ranges[start].start_value <= value
+ && value < (int)(ranges[start].start_value + range_size))
+ return (value - ranges[start].start_value) + start_orig_index;
}
- return -1;
+ return -1;
}
static size_t
parse_tag_and_wiretype (size_t len,
const uint8_t *data,
uint32_t *tag_out,
- ProtobufCWireType *wiretype_out)
-{
- unsigned max_rv = len > 5 ? 5 : len;
- uint32_t tag = (data[0]&0x7f) >> 3;
- unsigned shift = 4;
- unsigned rv;
- *wiretype_out = data[0] & 7;
- if ((data[0] & 0x80) == 0)
- {
- *tag_out = tag;
- return 1;
- }
- for (rv = 1; rv < max_rv; rv++)
- if (data[rv] & 0x80)
- {
- tag |= (data[rv] & 0x7f) << shift;
- shift += 7;
- }
- else
- {
- tag |= data[rv] << shift;
+ ProtobufCWireType *wiretype_out) {
+ unsigned max_rv = len > 5 ? 5 : len;
+ uint32_t tag = (data[0]&0x7f) >> 3;
+ unsigned shift = 4;
+ unsigned rv;
+ *wiretype_out = data[0] & 7;
+ if ((data[0] & 0x80) == 0) {
*tag_out = tag;
- return rv + 1;
- }
- return 0; /* error: bad header */
+ return 1;
+ }
+ for (rv = 1; rv < max_rv; rv++)
+ if (data[rv] & 0x80) {
+ tag |= (data[rv] & 0x7f) << shift;
+ shift += 7;
+ } else {
+ tag |= data[rv] << shift;
+ *tag_out = tag;
+ return rv + 1;
+ }
+ return 0; /* error: bad header */
}
/* sizeof(ScannedMember) must be <= (1<<BOUND_SIZEOF_SCANNED_MEMBER_LOG2) */
#define BOUND_SIZEOF_SCANNED_MEMBER_LOG2 5
typedef struct _ScannedMember ScannedMember;
-struct _ScannedMember
-{
- uint32_t tag;
- uint8_t wire_type;
- uint8_t length_prefix_len;
- const ProtobufCFieldDescriptor *field;
- size_t len;
- const uint8_t *data;
+struct _ScannedMember {
+ uint32_t tag;
+ uint8_t wire_type;
+ uint8_t length_prefix_len;
+ const ProtobufCFieldDescriptor *field;
+ size_t len;
+ const uint8_t *data;
};
static inline uint32_t
-scan_length_prefixed_data (size_t len, const uint8_t *data, size_t *prefix_len_out)
-{
- unsigned hdr_max = len < 5 ? len : 5;
- unsigned hdr_len;
- uint32_t val = 0;
- unsigned i;
- unsigned shift = 0;
- for (i = 0; i < hdr_max; i++)
- {
- val |= (data[i] & 0x7f) << shift;
- shift += 7;
- if ((data[i] & 0x80) == 0)
- break;
+scan_length_prefixed_data (size_t len, const uint8_t *data, size_t *prefix_len_out) {
+ unsigned hdr_max = len < 5 ? len : 5;
+ unsigned hdr_len;
+ uint32_t val = 0;
+ unsigned i;
+ unsigned shift = 0;
+ for (i = 0; i < hdr_max; i++) {
+ val |= (data[i] & 0x7f) << shift;
+ shift += 7;
+ if ((data[i] & 0x80) == 0)
+ break;
}
- if (i == hdr_max)
- {
- UNPACK_ERROR (("error parsing length for length-prefixed data"));
- return 0;
+ if (i == hdr_max) {
+ UNPACK_ERROR (("error parsing length for length-prefixed data"));
+ return 0;
}
- hdr_len = i + 1;
- *prefix_len_out = hdr_len;
- if (hdr_len + val > len)
- {
- UNPACK_ERROR (("data too short after length-prefix of %u",
- val));
- return 0;
+ hdr_len = i + 1;
+ *prefix_len_out = hdr_len;
+ if (hdr_len + val > len) {
+ UNPACK_ERROR (("data too short after length-prefix of %u",
+ val));
+ return 0;
}
- return hdr_len + val;
+ return hdr_len + val;
}
-static size_t
-max_b128_numbers (size_t len, const uint8_t *data)
-{
- size_t rv = 0;
- while (len--)
- if ((*data++ & 0x80) == 0)
- ++rv;
- return rv;
+static size_t
+max_b128_numbers (size_t len, const uint8_t *data) {
+ size_t rv = 0;
+ while (len--)
+ if ((*data++ & 0x80) == 0)
+ ++rv;
+ return rv;
}
@@ -1528,31 +1385,27 @@ static protobuf_c_boolean
count_packed_elements (ProtobufCType type,
size_t len,
const uint8_t *data,
- size_t *count_out)
-{
- switch (type)
- {
+ size_t *count_out) {
+ switch (type) {
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- if (len % 4 != 0)
- {
- UNPACK_ERROR (("length must be a multiple of 4 for fixed-length 32-bit types"));
- return FALSE;
+ if (len % 4 != 0) {
+ UNPACK_ERROR (("length must be a multiple of 4 for fixed-length 32-bit types"));
+ return FALSE;
}
- *count_out = len / 4;
- return TRUE;
+ *count_out = len / 4;
+ return TRUE;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- if (len % 8 != 0)
- {
- UNPACK_ERROR (("length must be a multiple of 8 for fixed-length 64-bit types"));
- return FALSE;
+ if (len % 8 != 0) {
+ UNPACK_ERROR (("length must be a multiple of 8 for fixed-length 64-bit types"));
+ return FALSE;
}
- *count_out = len / 8;
- return TRUE;
+ *count_out = len / 8;
+ return TRUE;
case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_SINT32:
@@ -1561,510 +1414,470 @@ count_packed_elements (ProtobufCType type,
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_SINT64:
case PROTOBUF_C_TYPE_UINT64:
- *count_out = max_b128_numbers (len, data);
- return TRUE;
+ *count_out = max_b128_numbers (len, data);
+ return TRUE;
case PROTOBUF_C_TYPE_BOOL:
- *count_out = len;
- return TRUE;
+ *count_out = len;
+ return TRUE;
case PROTOBUF_C_TYPE_STRING:
case PROTOBUF_C_TYPE_BYTES:
case PROTOBUF_C_TYPE_MESSAGE:
default:
- UNPACK_ERROR (("bad protobuf-c type %u for packed-repeated", type));
- return FALSE;
+ UNPACK_ERROR (("bad protobuf-c type %u for packed-repeated", type));
+ return FALSE;
}
}
static inline uint32_t
-parse_uint32 (unsigned len, const uint8_t *data)
-{
- unsigned rv = data[0] & 0x7f;
- if (len > 1)
- {
- rv |= ((data[1] & 0x7f) << 7);
- if (len > 2)
- {
- rv |= ((data[2] & 0x7f) << 14);
- if (len > 3)
- {
- rv |= ((data[3] & 0x7f) << 21);
- if (len > 4)
- rv |= (data[4] << 28);
+parse_uint32 (unsigned len, const uint8_t *data) {
+ unsigned rv = data[0] & 0x7f;
+ if (len > 1) {
+ rv |= ((data[1] & 0x7f) << 7);
+ if (len > 2) {
+ rv |= ((data[2] & 0x7f) << 14);
+ if (len > 3) {
+ rv |= ((data[3] & 0x7f) << 21);
+ if (len > 4)
+ rv |= (data[4] << 28);
}
}
}
- return rv;
+ return rv;
}
static inline uint32_t
-parse_int32 (unsigned len, const uint8_t *data)
-{
- return parse_uint32 (len, data);
+parse_int32 (unsigned len, const uint8_t *data) {
+ return parse_uint32 (len, data);
}
static inline int32_t
-unzigzag32 (uint32_t v)
-{
- if (v&1)
- return -(v>>1) - 1;
- else
- return v>>1;
+unzigzag32 (uint32_t v) {
+ if (v&1)
+ return -(v>>1) - 1;
+ else
+ return v>>1;
}
static inline uint32_t
-parse_fixed_uint32 (const uint8_t *data)
-{
+parse_fixed_uint32 (const uint8_t *data) {
#ifdef IS_LITTLE_ENDIAN
- uint32_t t;
- memcpy (&t, data, 4);
- return t;
+ uint32_t t;
+ memcpy (&t, data, 4);
+ return t;
#else
- return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+ return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
#endif
}
static uint64_t
-parse_uint64 (unsigned len, const uint8_t *data)
-{
- unsigned shift, i;
- if (len < 5)
- return parse_uint32 (len, data);
- uint64_t rv = ((data[0] & 0x7f))
- | ((data[1] & 0x7f)<<7)
- | ((data[2] & 0x7f)<<14)
- | ((data[3] & 0x7f)<<21);
- shift = 28;
- for (i = 4; i < len; i++)
- {
- rv |= (((uint64_t)(data[i]&0x7f)) << shift);
- shift += 7;
+parse_uint64 (unsigned len, const uint8_t *data) {
+ unsigned shift, i;
+ if (len < 5)
+ return parse_uint32 (len, data);
+ uint64_t rv = ((data[0] & 0x7f))
+ | ((data[1] & 0x7f)<<7)
+ | ((data[2] & 0x7f)<<14)
+ | ((data[3] & 0x7f)<<21);
+ shift = 28;
+ for (i = 4; i < len; i++) {
+ rv |= (((uint64_t)(data[i]&0x7f)) << shift);
+ shift += 7;
}
- return rv;
+ return rv;
}
static inline int64_t
-unzigzag64 (uint64_t v)
-{
- if (v&1)
- return -(v>>1) - 1;
- else
- return v>>1;
+unzigzag64 (uint64_t v) {
+ if (v&1)
+ return -(v>>1) - 1;
+ else
+ return v>>1;
}
static inline uint64_t
-parse_fixed_uint64 (const uint8_t *data)
-{
+parse_fixed_uint64 (const uint8_t *data) {
#ifdef IS_LITTLE_ENDIAN
- uint64_t t;
- memcpy (&t, data, 8);
- return t;
+ uint64_t t;
+ memcpy (&t, data, 8);
+ return t;
#else
- return (uint64_t)parse_fixed_uint32 (data)
- | (((uint64_t)parse_fixed_uint32(data+4)) << 32);
+ return (uint64_t)parse_fixed_uint32 (data)
+ | (((uint64_t)parse_fixed_uint32(data+4)) << 32);
#endif
}
static protobuf_c_boolean
-parse_boolean (unsigned len, const uint8_t *data)
-{
- unsigned i;
- for (i = 0; i < len; i++)
- if (data[i] & 0x7f)
- return 1;
- return 0;
+parse_boolean (unsigned len, const uint8_t *data) {
+ unsigned i;
+ for (i = 0; i < len; i++)
+ if (data[i] & 0x7f)
+ return 1;
+ return 0;
}
static protobuf_c_boolean
parse_required_member (ScannedMember *scanned_member,
void *member,
ProtobufCAllocator *allocator,
- protobuf_c_boolean maybe_clear)
-{
- unsigned len = scanned_member->len;
- const uint8_t *data = scanned_member->data;
- ProtobufCWireType wire_type = scanned_member->wire_type;
- switch (scanned_member->field->type)
- {
+ protobuf_c_boolean maybe_clear) {
+ unsigned len = scanned_member->len;
+ const uint8_t *data = scanned_member->data;
+ ProtobufCWireType wire_type = scanned_member->wire_type;
+ switch (scanned_member->field->type) {
case PROTOBUF_C_TYPE_INT32:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(uint32_t*)member = parse_int32 (len, data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_int32 (len, data);
+ return 1;
case PROTOBUF_C_TYPE_UINT32:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(uint32_t*)member = parse_uint32 (len, data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_uint32 (len, data);
+ return 1;
case PROTOBUF_C_TYPE_SINT32:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(int32_t*)member = unzigzag32 (parse_uint32 (len, data));
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(int32_t*)member = unzigzag32 (parse_uint32 (len, data));
+ return 1;
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_32BIT)
- return 0;
- *(uint32_t*)member = parse_fixed_uint32 (data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_32BIT)
+ return 0;
+ *(uint32_t*)member = parse_fixed_uint32 (data);
+ return 1;
case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(uint64_t*)member = parse_uint64 (len, data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint64_t*)member = parse_uint64 (len, data);
+ return 1;
case PROTOBUF_C_TYPE_SINT64:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(int64_t*)member = unzigzag64 (parse_uint64 (len, data));
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(int64_t*)member = unzigzag64 (parse_uint64 (len, data));
+ return 1;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_64BIT)
- return 0;
- *(uint64_t*)member = parse_fixed_uint64 (data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_64BIT)
+ return 0;
+ *(uint64_t*)member = parse_fixed_uint64 (data);
+ return 1;
case PROTOBUF_C_TYPE_BOOL:
- *(protobuf_c_boolean*)member = parse_boolean (len, data);
- return 1;
+ *(protobuf_c_boolean*)member = parse_boolean (len, data);
+ return 1;
case PROTOBUF_C_TYPE_ENUM:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
- return 0;
- *(uint32_t*)member = parse_uint32 (len, data);
- return 1;
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_uint32 (len, data);
+ return 1;
case PROTOBUF_C_TYPE_STRING:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- return 0;
- {
- char **pstr = member;
- unsigned pref_len = scanned_member->length_prefix_len;
- if (maybe_clear && *pstr != NULL)
- {
- const char *def = scanned_member->field->default_value;
- if (*pstr != NULL && *pstr != def)
- FREE (allocator, *pstr);
- }
- DO_ALLOC (*pstr, allocator, len - pref_len + 1, return 0);
- memcpy (*pstr, data + pref_len, len - pref_len);
- (*pstr)[len-pref_len] = 0;
- return 1;
- }
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ char **pstr = member;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ if (maybe_clear && *pstr != NULL) {
+ const char *def = scanned_member->field->default_value;
+ if (*pstr != NULL && *pstr != def)
+ FREE (allocator, *pstr);
+ }
+ DO_ALLOC (*pstr, allocator, len - pref_len + 1, return 0);
+ memcpy (*pstr, data + pref_len, len - pref_len);
+ (*pstr)[len-pref_len] = 0;
+ return 1;
+ }
case PROTOBUF_C_TYPE_BYTES:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- return 0;
- {
- ProtobufCBinaryData *bd = member;
- const ProtobufCBinaryData *def_bd;
- unsigned pref_len = scanned_member->length_prefix_len;
- def_bd = scanned_member->field->default_value;
- if (maybe_clear && bd->data != NULL && bd->data != def_bd->data)
- FREE (allocator, bd->data);
- DO_ALLOC (bd->data, allocator, len - pref_len, return 0);
- memcpy (bd->data, data + pref_len, len - pref_len);
- bd->len = len - pref_len;
- return 1;
- }
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ ProtobufCBinaryData *bd = member;
+ const ProtobufCBinaryData *def_bd;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ def_bd = scanned_member->field->default_value;
+ if (maybe_clear && bd->data != NULL && bd->data != def_bd->data)
+ FREE (allocator, bd->data);
+ DO_ALLOC (bd->data, allocator, len - pref_len, return 0);
+ memcpy (bd->data, data + pref_len, len - pref_len);
+ bd->len = len - pref_len;
+ return 1;
+ }
//case PROTOBUF_C_TYPE_GROUP, // NOT SUPPORTED
case PROTOBUF_C_TYPE_MESSAGE:
- if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- return 0;
- {
- ProtobufCMessage **pmessage = member;
- ProtobufCMessage *subm;
- const ProtobufCMessage *def_mess;
- unsigned pref_len = scanned_member->length_prefix_len;
- def_mess = scanned_member->field->default_value;
- if (maybe_clear && *pmessage != NULL && *pmessage != def_mess)
- protobuf_c_message_free_unpacked (*pmessage, allocator);
- subm = protobuf_c_message_unpack (scanned_member->field->descriptor,
- allocator,
- len - pref_len, data + pref_len);
- *pmessage = subm; /* since we freed the message we must clear the field, even if NULL */
- if (subm == NULL)
- return 0;
- return 1;
- }
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ ProtobufCMessage **pmessage = member;
+ ProtobufCMessage *subm;
+ const ProtobufCMessage *def_mess;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ def_mess = scanned_member->field->default_value;
+ if (maybe_clear && *pmessage != NULL && *pmessage != def_mess)
+ protobuf_c_message_free_unpacked (*pmessage, allocator);
+ subm = protobuf_c_message_unpack (scanned_member->field->descriptor,
+ allocator,
+ len - pref_len, data + pref_len);
+ *pmessage = subm; /* since we freed the message we must clear the field, even if NULL */
+ if (subm == NULL)
+ return 0;
+ return 1;
+ }
}
- return 0;
+ return 0;
}
static protobuf_c_boolean
parse_optional_member (ScannedMember *scanned_member,
void *member,
ProtobufCMessage *message,
- ProtobufCAllocator *allocator)
-{
- if (!parse_required_member (scanned_member, member, allocator, TRUE))
- return 0;
- if (scanned_member->field->quantifier_offset != 0)
- STRUCT_MEMBER (protobuf_c_boolean,
- message,
- scanned_member->field->quantifier_offset) = 1;
- return 1;
+ ProtobufCAllocator *allocator) {
+ if (!parse_required_member (scanned_member, member, allocator, TRUE))
+ return 0;
+ if (scanned_member->field->quantifier_offset != 0)
+ STRUCT_MEMBER (protobuf_c_boolean,
+ message,
+ scanned_member->field->quantifier_offset) = 1;
+ return 1;
}
static protobuf_c_boolean
parse_repeated_member (ScannedMember *scanned_member,
void *member,
ProtobufCMessage *message,
- ProtobufCAllocator *allocator)
-{
- const ProtobufCFieldDescriptor *field = scanned_member->field;
- size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
- size_t siz = sizeof_elt_in_repeated_array (field->type);
- char *array = *(char**)member;
- if (!parse_required_member (scanned_member,
- array + siz * (*p_n),
- allocator,
- FALSE))
- return 0;
- *p_n += 1;
- return 1;
-}
-
-static unsigned scan_varint (unsigned len, const uint8_t *data)
-{
- unsigned i;
- if (len > 10)
- len = 10;
- for (i = 0; i < len; i++)
- if ((data[i] & 0x80) == 0)
- break;
- if (i == len)
- return 0;
- return i + 1;
+ ProtobufCAllocator *allocator) {
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ char *array = *(char**)member;
+ if (!parse_required_member (scanned_member,
+ array + siz * (*p_n),
+ allocator,
+ FALSE))
+ return 0;
+ *p_n += 1;
+ return 1;
+}
+
+static unsigned scan_varint (unsigned len, const uint8_t *data) {
+ unsigned i;
+ if (len > 10)
+ len = 10;
+ for (i = 0; i < len; i++)
+ if ((data[i] & 0x80) == 0)
+ break;
+ if (i == len)
+ return 0;
+ return i + 1;
}
static protobuf_c_boolean
parse_packed_repeated_member (ScannedMember *scanned_member,
void *member,
- ProtobufCMessage *message)
-{
- const ProtobufCFieldDescriptor *field = scanned_member->field;
- size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
- size_t siz = sizeof_elt_in_repeated_array (field->type);
- char *array = *(char**)member + siz * (*p_n);
- const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
- size_t rem = scanned_member->len - scanned_member->length_prefix_len;
- size_t count = 0;
- unsigned i;
- switch (field->type)
- {
- case PROTOBUF_C_TYPE_SFIXED32:
- case PROTOBUF_C_TYPE_FIXED32:
- case PROTOBUF_C_TYPE_FLOAT:
+ ProtobufCMessage *message) {
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ char *array = *(char**)member + siz * (*p_n);
+ const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
+ size_t rem = scanned_member->len - scanned_member->length_prefix_len;
+ size_t count = 0;
+ unsigned i;
+ switch (field->type) {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
count = (scanned_member->len - scanned_member->length_prefix_len) / 4;
#ifdef IS_LITTLE_ENDIAN
goto no_unpacking_needed;
#else
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
((uint32_t*)array)[i] = parse_fixed_uint32 (at);
at += 4;
- }
+ }
#endif
break;
- case PROTOBUF_C_TYPE_SFIXED64:
- case PROTOBUF_C_TYPE_FIXED64:
- case PROTOBUF_C_TYPE_DOUBLE:
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
count = (scanned_member->len - scanned_member->length_prefix_len) / 8;
#ifdef IS_LITTLE_ENDIAN
goto no_unpacking_needed;
#else
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
((uint64_t*)array)[i] = parse_fixed_uint64 (at);
at += 8;
- }
+ }
break;
#endif
- case PROTOBUF_C_TYPE_INT32:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_INT32:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated int32 value"));
return FALSE;
- }
+ }
((int32_t*)array)[count++] = parse_int32 (s, at);
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_SINT32:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_SINT32:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated sint32 value"));
return FALSE;
- }
+ }
((int32_t*)array)[count++] = unzigzag32 (parse_uint32 (s, at));
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_ENUM:
- case PROTOBUF_C_TYPE_UINT32:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated enum or uint32 value"));
return FALSE;
- }
+ }
((uint32_t*)array)[count++] = parse_uint32 (s, at);
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_SINT64:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_SINT64:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated sint64 value"));
return FALSE;
- }
+ }
((int64_t*)array)[count++] = unzigzag64 (parse_uint64 (s, at));
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_UINT64:
- while (rem > 0)
- {
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ while (rem > 0) {
unsigned s = scan_varint (rem, at);
- if (s == 0)
- {
+ if (s == 0) {
UNPACK_ERROR (("bad packed-repeated int64/uint64 value"));
return FALSE;
- }
+ }
((int64_t*)array)[count++] = parse_uint64 (s, at);
at += s;
rem -= s;
- }
+ }
break;
- case PROTOBUF_C_TYPE_BOOL:
+ case PROTOBUF_C_TYPE_BOOL:
count = rem;
- for (i = 0; i < count; i++)
- {
- if (at[i] > 1)
- {
+ for (i = 0; i < count; i++) {
+ if (at[i] > 1) {
UNPACK_ERROR (("bad packed-repeated boolean value"));
return FALSE;
- }
+ }
((protobuf_c_boolean*)array)[i] = at[i];
- }
+ }
break;
- default:
+ default:
assert(0);
}
- *p_n += count;
- return TRUE;
+ *p_n += count;
+ return TRUE;
#ifdef IS_LITTLE_ENDIAN
no_unpacking_needed:
- memcpy (array, at, count * siz);
- *p_n += count;
- return TRUE;
+ memcpy (array, at, count * siz);
+ *p_n += count;
+ return TRUE;
#endif
}
static protobuf_c_boolean
parse_member (ScannedMember *scanned_member,
ProtobufCMessage *message,
- ProtobufCAllocator *allocator)
-{
- const ProtobufCFieldDescriptor *field = scanned_member->field;
- void *member;
- if (field == NULL)
- {
- ProtobufCMessageUnknownField *ufield = message->unknown_fields + (message->n_unknown_fields++);
- ufield->tag = scanned_member->tag;
- ufield->wire_type = scanned_member->wire_type;
- ufield->len = scanned_member->len;
- DO_UNALIGNED_ALLOC (ufield->data, allocator, scanned_member->len, return 0);
- memcpy (ufield->data, scanned_member->data, ufield->len);
- return 1;
+ ProtobufCAllocator *allocator) {
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ void *member;
+ if (field == NULL) {
+ ProtobufCMessageUnknownField *ufield = message->unknown_fields + (message->n_unknown_fields++);
+ ufield->tag = scanned_member->tag;
+ ufield->wire_type = scanned_member->wire_type;
+ ufield->len = scanned_member->len;
+ DO_UNALIGNED_ALLOC (ufield->data, allocator, scanned_member->len, return 0);
+ memcpy (ufield->data, scanned_member->data, ufield->len);
+ return 1;
}
- member = (char*)message + field->offset;
- switch (field->label)
- {
+ member = (char*)message + field->offset;
+ switch (field->label) {
case PROTOBUF_C_LABEL_REQUIRED:
- return parse_required_member (scanned_member, member, allocator, TRUE);
+ return parse_required_member (scanned_member, member, allocator, TRUE);
case PROTOBUF_C_LABEL_OPTIONAL:
- return parse_optional_member (scanned_member, member, message, allocator);
+ return parse_optional_member (scanned_member, member, message, allocator);
case PROTOBUF_C_LABEL_REPEATED:
- if (field->packed
- && scanned_member->wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- return parse_packed_repeated_member (scanned_member, member, message);
- else
- return parse_repeated_member (scanned_member, member, message, allocator);
+ if (field->packed
+ && scanned_member->wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return parse_packed_repeated_member (scanned_member, member, message);
+ else
+ return parse_repeated_member (scanned_member, member, message, allocator);
}
- PROTOBUF_C_ASSERT_NOT_REACHED ();
- return 0;
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
}
-/* TODO: expose/use this function if desc->message_init==NULL
+/* TODO: expose/use this function if desc->message_init==NULL
(which occurs for old code, and may be useful for certain
programatic techniques for generating descriptors). */
static void
protobuf_c_message_init_generic (const ProtobufCMessageDescriptor *desc,
- ProtobufCMessage *message)
-{
- unsigned i;
- memset (message, 0, desc->sizeof_message);
- message->descriptor = desc;
- for (i = 0; i < desc->n_fields; i++)
- if (desc->fields[i].default_value != NULL
- && desc->fields[i].label != PROTOBUF_C_LABEL_REPEATED)
- {
- void *field = STRUCT_MEMBER_P (message, desc->fields[i].offset);
- const void *dv = desc->fields[i].default_value;
- switch (desc->fields[i].type)
- {
- case PROTOBUF_C_TYPE_INT32:
- case PROTOBUF_C_TYPE_SINT32:
- case PROTOBUF_C_TYPE_SFIXED32:
- case PROTOBUF_C_TYPE_UINT32:
- case PROTOBUF_C_TYPE_FIXED32:
- case PROTOBUF_C_TYPE_FLOAT:
- case PROTOBUF_C_TYPE_ENUM:
- memcpy (field, dv, 4);
- break;
+ ProtobufCMessage *message) {
+ unsigned i;
+ memset (message, 0, desc->sizeof_message);
+ message->descriptor = desc;
+ for (i = 0; i < desc->n_fields; i++)
+ if (desc->fields[i].default_value != NULL
+ && desc->fields[i].label != PROTOBUF_C_LABEL_REPEATED) {
+ void *field = STRUCT_MEMBER_P (message, desc->fields[i].offset);
+ const void *dv = desc->fields[i].default_value;
+ switch (desc->fields[i].type) {
+ case PROTOBUF_C_TYPE_INT32:
+ case PROTOBUF_C_TYPE_SINT32:
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_UINT32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ case PROTOBUF_C_TYPE_ENUM:
+ memcpy (field, dv, 4);
+ break;
- case PROTOBUF_C_TYPE_INT64:
- case PROTOBUF_C_TYPE_SINT64:
- case PROTOBUF_C_TYPE_SFIXED64:
- case PROTOBUF_C_TYPE_UINT64:
- case PROTOBUF_C_TYPE_FIXED64:
- case PROTOBUF_C_TYPE_DOUBLE:
- memcpy (field, dv, 8);
- break;
-
- case PROTOBUF_C_TYPE_BOOL:
- memcpy (field, dv, sizeof (protobuf_c_boolean));
- break;
-
- case PROTOBUF_C_TYPE_BYTES:
- memcpy (field, dv, sizeof (ProtobufCBinaryData));
- break;
-
- case PROTOBUF_C_TYPE_STRING:
- case PROTOBUF_C_TYPE_MESSAGE:
- /* the next line essentially implements a cast from const,
- which is totally unavoidable. */
- *(const void**)field = dv;
- break;
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_SINT64:
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_UINT64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ memcpy (field, dv, 8);
+ break;
+
+ case PROTOBUF_C_TYPE_BOOL:
+ memcpy (field, dv, sizeof (protobuf_c_boolean));
+ break;
+
+ case PROTOBUF_C_TYPE_BYTES:
+ memcpy (field, dv, sizeof (ProtobufCBinaryData));
+ break;
+
+ case PROTOBUF_C_TYPE_STRING:
+ case PROTOBUF_C_TYPE_MESSAGE:
+ /* the next line essentially implements a cast from const,
+ which is totally unavoidable. */
+ *(const void**)field = dv;
+ break;
+ }
}
- }
}
/* ScannedMember slabs (an unpacking implementation detail).
@@ -2091,205 +1904,181 @@ ProtobufCMessage *
protobuf_c_message_unpack (const ProtobufCMessageDescriptor *desc,
ProtobufCAllocator *allocator,
size_t len,
- const uint8_t *data)
-{
- ProtobufCMessage *rv;
- size_t rem = len;
- const uint8_t *at = data;
- const ProtobufCFieldDescriptor *last_field = desc->fields + 0;
- ScannedMember first_member_slab[1<<FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2];
-
- /* scanned_member_slabs[i] is an array of arrays of ScannedMember.
- The first slab (scanned_member_slabs[0] is just a pointer to
- first_member_slab), above. All subsequent slabs will be allocated
- using the allocator. */
- ScannedMember *scanned_member_slabs[MAX_SCANNED_MEMBER_SLAB+1];
- unsigned which_slab = 0; /* the slab we are currently populating */
- unsigned in_slab_index = 0; /* number of members in the slab */
- size_t n_unknown = 0;
- unsigned f;
- unsigned i_slab;
- unsigned last_field_index = 0;
- unsigned long *required_fields_bitmap;
- unsigned required_fields_bitmap_len;
- static const unsigned word_bits = sizeof(long) * 8;
-
- ASSERT_IS_MESSAGE_DESCRIPTOR (desc);
-
- if (allocator == NULL)
- allocator = &protobuf_c_default_allocator;
-
- required_fields_bitmap_len = (desc->n_fields + word_bits - 1) / word_bits;
- required_fields_bitmap = alloca(required_fields_bitmap_len * sizeof(long));
- memset(required_fields_bitmap, 0, required_fields_bitmap_len * sizeof(long));
-
- DO_ALLOC (rv, allocator, desc->sizeof_message, return NULL);
- scanned_member_slabs[0] = first_member_slab;
-
- /* Generated code always defines "message_init".
- However, we provide a fallback for (1) users of old protobuf-c
- generated-code that do not provide the function,
- and (2) descriptors constructed from some other source
- (most likely, direct construction from the .proto file) */
- if (desc->message_init != NULL)
- protobuf_c_message_init (desc, rv);
- else
- protobuf_c_message_init_generic (desc, rv);
-
- while (rem > 0)
- {
- uint32_t tag;
- ProtobufCWireType wire_type;
- size_t used = parse_tag_and_wiretype (rem, at, &tag, &wire_type);
- const ProtobufCFieldDescriptor *field;
- ScannedMember tmp;
- if (used == 0)
- {
- UNPACK_ERROR (("error parsing tag/wiretype at offset %u",
- (unsigned)(at-data)));
- goto error_cleanup_during_scan;
+ const uint8_t *data) {
+ ProtobufCMessage *rv;
+ size_t rem = len;
+ const uint8_t *at = data;
+ const ProtobufCFieldDescriptor *last_field = desc->fields + 0;
+ ScannedMember first_member_slab[1<<FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2];
+
+ /* scanned_member_slabs[i] is an array of arrays of ScannedMember.
+ The first slab (scanned_member_slabs[0] is just a pointer to
+ first_member_slab), above. All subsequent slabs will be allocated
+ using the allocator. */
+ ScannedMember *scanned_member_slabs[MAX_SCANNED_MEMBER_SLAB+1];
+ unsigned which_slab = 0; /* the slab we are currently populating */
+ unsigned in_slab_index = 0; /* number of members in the slab */
+ size_t n_unknown = 0;
+ unsigned f;
+ unsigned i_slab;
+ unsigned last_field_index = 0;
+ unsigned long *required_fields_bitmap;
+ unsigned required_fields_bitmap_len;
+ static const unsigned word_bits = sizeof(long) * 8;
+
+ ASSERT_IS_MESSAGE_DESCRIPTOR (desc);
+
+ if (allocator == NULL)
+ allocator = &protobuf_c_default_allocator;
+
+ required_fields_bitmap_len = (desc->n_fields + word_bits - 1) / word_bits;
+ required_fields_bitmap = alloca(required_fields_bitmap_len * sizeof(long));
+ memset(required_fields_bitmap, 0, required_fields_bitmap_len * sizeof(long));
+
+ DO_ALLOC (rv, allocator, desc->sizeof_message, return NULL);
+ scanned_member_slabs[0] = first_member_slab;
+
+ /* Generated code always defines "message_init".
+ However, we provide a fallback for (1) users of old protobuf-c
+ generated-code that do not provide the function,
+ and (2) descriptors constructed from some other source
+ (most likely, direct construction from the .proto file) */
+ if (desc->message_init != NULL)
+ protobuf_c_message_init (desc, rv);
+ else
+ protobuf_c_message_init_generic (desc, rv);
+
+ while (rem > 0) {
+ uint32_t tag;
+ ProtobufCWireType wire_type;
+ size_t used = parse_tag_and_wiretype (rem, at, &tag, &wire_type);
+ const ProtobufCFieldDescriptor *field;
+ ScannedMember tmp;
+ if (used == 0) {
+ UNPACK_ERROR (("error parsing tag/wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
}
- /* XXX: consider optimizing for field[1].id == tag, if field[1] exists! */
- if (last_field->id != tag)
- {
- /* lookup field */
- int field_index = int_range_lookup (desc->n_field_ranges,
- desc->field_ranges,
- tag);
- if (field_index < 0)
- {
- field = NULL;
- n_unknown++;
- }
- else
- {
- field = desc->fields + field_index;
- last_field = field;
- last_field_index = field_index;
+ /* XXX: consider optimizing for field[1].id == tag, if field[1] exists! */
+ if (last_field->id != tag) {
+ /* lookup field */
+ int field_index = int_range_lookup (desc->n_field_ranges,
+ desc->field_ranges,
+ tag);
+ if (field_index < 0) {
+ field = NULL;
+ n_unknown++;
+ } else {
+ field = desc->fields + field_index;
+ last_field = field;
+ last_field_index = field_index;
}
- }
- else
- field = last_field;
-
- if (field != NULL && field->label == PROTOBUF_C_LABEL_REQUIRED)
- required_fields_bitmap[last_field_index / word_bits] |= (1UL << (last_field_index % word_bits));
-
- at += used;
- rem -= used;
- tmp.tag = tag;
- tmp.wire_type = wire_type;
- tmp.field = field;
- tmp.data = at;
- switch (wire_type)
- {
- case PROTOBUF_C_WIRE_TYPE_VARINT:
- {
+ } else
+ field = last_field;
+
+ if (field != NULL && field->label == PROTOBUF_C_LABEL_REQUIRED)
+ required_fields_bitmap[last_field_index / word_bits] |= (1UL << (last_field_index % word_bits));
+
+ at += used;
+ rem -= used;
+ tmp.tag = tag;
+ tmp.wire_type = wire_type;
+ tmp.field = field;
+ tmp.data = at;
+ switch (wire_type) {
+ case PROTOBUF_C_WIRE_TYPE_VARINT: {
unsigned max_len = rem < 10 ? rem : 10;
unsigned i;
for (i = 0; i < max_len; i++)
- if ((at[i] & 0x80) == 0)
- break;
- if (i == max_len)
- {
+ if ((at[i] & 0x80) == 0)
+ break;
+ if (i == max_len) {
UNPACK_ERROR (("unterminated varint at offset %u",
(unsigned)(at-data)));
goto error_cleanup_during_scan;
- }
+ }
tmp.len = i + 1;
- }
- break;
+ }
+ break;
case PROTOBUF_C_WIRE_TYPE_64BIT:
- if (rem < 8)
- {
- UNPACK_ERROR (("too short after 64bit wiretype at offset %u",
- (unsigned)(at-data)));
- goto error_cleanup_during_scan;
+ if (rem < 8) {
+ UNPACK_ERROR (("too short after 64bit wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
}
- tmp.len = 8;
- break;
- case PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED:
- {
+ tmp.len = 8;
+ break;
+ case PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED: {
size_t pref_len;
tmp.len = scan_length_prefixed_data (rem, at, &pref_len);
- if (tmp.len == 0)
- {
+ if (tmp.len == 0) {
/* NOTE: scan_length_prefixed_data calls UNPACK_ERROR */
goto error_cleanup_during_scan;
- }
+ }
tmp.length_prefix_len = pref_len;
break;
- }
+ }
case PROTOBUF_C_WIRE_TYPE_32BIT:
- if (rem < 4)
- {
- UNPACK_ERROR (("too short after 32bit wiretype at offset %u",
- (unsigned)(at-data)));
- goto error_cleanup_during_scan;
+ if (rem < 4) {
+ UNPACK_ERROR (("too short after 32bit wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
}
- tmp.len = 4;
- break;
+ tmp.len = 4;
+ break;
default:
- UNPACK_ERROR (("unsupported tag %u at offset %u",
- wire_type, (unsigned)(at-data)));
- goto error_cleanup_during_scan;
+ UNPACK_ERROR (("unsupported tag %u at offset %u",
+ wire_type, (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
}
- if (in_slab_index == (1U<<(which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2)))
- {
- size_t size;
- in_slab_index = 0;
- if (which_slab == MAX_SCANNED_MEMBER_SLAB)
- {
- UNPACK_ERROR (("too many fields"));
- goto error_cleanup_during_scan;
+ if (in_slab_index == (1U<<(which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2))) {
+ size_t size;
+ in_slab_index = 0;
+ if (which_slab == MAX_SCANNED_MEMBER_SLAB) {
+ UNPACK_ERROR (("too many fields"));
+ goto error_cleanup_during_scan;
}
- which_slab++;
- size = sizeof(ScannedMember) << (which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2);
- /* TODO: consider using alloca() ! */
- if (allocator->tmp_alloc != NULL)
- scanned_member_slabs[which_slab] = TMPALLOC(allocator, size);
- else
- DO_ALLOC (scanned_member_slabs[which_slab], allocator, size, goto error_cleanup_during_scan);
+ which_slab++;
+ size = sizeof(ScannedMember) << (which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2);
+ /* TODO: consider using alloca() ! */
+ if (allocator->tmp_alloc != NULL)
+ scanned_member_slabs[which_slab] = TMPALLOC(allocator, size);
+ else
+ DO_ALLOC (scanned_member_slabs[which_slab], allocator, size, goto error_cleanup_during_scan);
}
- scanned_member_slabs[which_slab][in_slab_index++] = tmp;
-
- if (field != NULL && field->label == PROTOBUF_C_LABEL_REPEATED)
- {
- size_t *n = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
- if (field->packed
- && wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
- {
- size_t count;
- if (!count_packed_elements (field->type,
- tmp.len - tmp.length_prefix_len,
- tmp.data + tmp.length_prefix_len,
- &count))
- {
- UNPACK_ERROR (("counting packed elements"));
- goto error_cleanup_during_scan;
+ scanned_member_slabs[which_slab][in_slab_index++] = tmp;
+
+ if (field != NULL && field->label == PROTOBUF_C_LABEL_REPEATED) {
+ size_t *n = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
+ if (field->packed
+ && wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) {
+ size_t count;
+ if (!count_packed_elements (field->type,
+ tmp.len - tmp.length_prefix_len,
+ tmp.data + tmp.length_prefix_len,
+ &count)) {
+ UNPACK_ERROR (("counting packed elements"));
+ goto error_cleanup_during_scan;
}
- *n += count;
- }
- else
- *n += 1;
+ *n += count;
+ } else
+ *n += 1;
}
- at += tmp.len;
- rem -= tmp.len;
+ at += tmp.len;
+ rem -= tmp.len;
}
- /* allocate space for repeated fields, also check that all required fields have been set */
- for (f = 0; f < desc->n_fields; f++)
- {
- const ProtobufCFieldDescriptor *field = desc->fields + f;
- if (field->label == PROTOBUF_C_LABEL_REPEATED)
- {
- size_t siz = sizeof_elt_in_repeated_array (field->type);
- size_t *n_ptr = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
- if (*n_ptr != 0)
- {
- unsigned n = *n_ptr;
- *n_ptr = 0;
- assert(rv->descriptor != NULL);
+ /* allocate space for repeated fields, also check that all required fields have been set */
+ for (f = 0; f < desc->n_fields; f++) {
+ const ProtobufCFieldDescriptor *field = desc->fields + f;
+ if (field->label == PROTOBUF_C_LABEL_REPEATED) {
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ size_t *n_ptr = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
+ if (*n_ptr != 0) {
+ unsigned n = *n_ptr;
+ *n_ptr = 0;
+ assert(rv->descriptor != NULL);
#define CLEAR_REMAINING_N_PTRS() \
for(f++;f < desc->n_fields; f++) \
{ \
@@ -2297,146 +2086,122 @@ protobuf_c_message_unpack (const ProtobufCMessageDescriptor *desc,
if (field->label == PROTOBUF_C_LABEL_REPEATED) \
STRUCT_MEMBER (size_t, rv, field->quantifier_offset) = 0; \
}
- DO_ALLOC (STRUCT_MEMBER (void *, rv, field->offset),
- allocator, siz * n,
- CLEAR_REMAINING_N_PTRS (); goto error_cleanup);
+ DO_ALLOC (STRUCT_MEMBER (void *, rv, field->offset),
+ allocator, siz * n,
+ CLEAR_REMAINING_N_PTRS (); goto error_cleanup);
#undef CLEAR_REMAINING_N_PTRS
- }
- }
- else if (field->label == PROTOBUF_C_LABEL_REQUIRED)
- {
- if (field->default_value == NULL && 0 == (required_fields_bitmap[f / word_bits] & (1UL << (f % word_bits))))
- {
- UNPACK_ERROR (("message '%s': missing required field '%s'", desc->name, field->name));
- goto error_cleanup;
- }
+ }
+ } else if (field->label == PROTOBUF_C_LABEL_REQUIRED) {
+ if (field->default_value == NULL && 0 == (required_fields_bitmap[f / word_bits] & (1UL << (f % word_bits)))) {
+ UNPACK_ERROR (("message '%s': missing required field '%s'", desc->name, field->name));
+ goto error_cleanup;
+ }
+ }
}
- }
-
- /* allocate space for unknown fields */
- if (n_unknown)
- {
- DO_ALLOC (rv->unknown_fields,
- allocator, n_unknown * sizeof (ProtobufCMessageUnknownField),
- goto error_cleanup);
+
+ /* allocate space for unknown fields */
+ if (n_unknown) {
+ DO_ALLOC (rv->unknown_fields,
+ allocator, n_unknown * sizeof (ProtobufCMessageUnknownField),
+ goto error_cleanup);
}
- /* do real parsing */
- for (i_slab = 0; i_slab <= which_slab; i_slab++)
- {
- unsigned max = (i_slab == which_slab) ? in_slab_index : (1U<<(i_slab+4));
- ScannedMember *slab = scanned_member_slabs[i_slab];
- unsigned j;
- for (j = 0; j < max; j++)
- {
- if (!parse_member (slab + j, rv, allocator))
- {
- UNPACK_ERROR (("error parsing member %s of %s",
- slab->field ? slab->field->name : "*unknown-field*", desc->name));
- goto error_cleanup;
+ /* do real parsing */
+ for (i_slab = 0; i_slab <= which_slab; i_slab++) {
+ unsigned max = (i_slab == which_slab) ? in_slab_index : (1U<<(i_slab+4));
+ ScannedMember *slab = scanned_member_slabs[i_slab];
+ unsigned j;
+ for (j = 0; j < max; j++) {
+ if (!parse_member (slab + j, rv, allocator)) {
+ UNPACK_ERROR (("error parsing member %s of %s",
+ slab->field ? slab->field->name : "*unknown-field*", desc->name));
+ goto error_cleanup;
}
}
}
- /* cleanup */
- if (allocator->tmp_alloc == NULL)
- {
- unsigned j;
- for (j = 1; j <= which_slab; j++)
- FREE (allocator, scanned_member_slabs[j]);
+ /* cleanup */
+ if (allocator->tmp_alloc == NULL) {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
}
- return rv;
+ return rv;
error_cleanup:
- protobuf_c_message_free_unpacked (rv, allocator);
- if (allocator->tmp_alloc == NULL)
- {
- unsigned j;
- for (j = 1; j <= which_slab; j++)
- FREE (allocator, scanned_member_slabs[j]);
+ protobuf_c_message_free_unpacked (rv, allocator);
+ if (allocator->tmp_alloc == NULL) {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
}
- return NULL;
+ return NULL;
error_cleanup_during_scan:
- FREE (allocator, rv);
- if (allocator->tmp_alloc == NULL)
- {
- unsigned j;
- for (j = 1; j <= which_slab; j++)
- FREE (allocator, scanned_member_slabs[j]);
+ FREE (allocator, rv);
+ if (allocator->tmp_alloc == NULL) {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
}
- return NULL;
+ return NULL;
}
/* === free_unpacked === */
-void
+void
protobuf_c_message_free_unpacked (ProtobufCMessage *message,
- ProtobufCAllocator *allocator)
-{
- const ProtobufCMessageDescriptor *desc = message->descriptor;
- unsigned f;
- ASSERT_IS_MESSAGE (message);
- if (allocator == NULL)
- allocator = &protobuf_c_default_allocator;
- message->descriptor = NULL;
- for (f = 0; f < desc->n_fields; f++)
- {
- if (desc->fields[f].label == PROTOBUF_C_LABEL_REPEATED)
- {
- size_t n = STRUCT_MEMBER (size_t, message, desc->fields[f].quantifier_offset);
- void * arr = STRUCT_MEMBER (void *, message, desc->fields[f].offset);
- if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING)
- {
- unsigned i;
- for (i = 0; i < n; i++)
- FREE (allocator, ((char**)arr)[i]);
- }
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES)
- {
- unsigned i;
- for (i = 0; i < n; i++)
- FREE (allocator, ((ProtobufCBinaryData*)arr)[i].data);
+ ProtobufCAllocator *allocator) {
+ const ProtobufCMessageDescriptor *desc = message->descriptor;
+ unsigned f;
+ ASSERT_IS_MESSAGE (message);
+ if (allocator == NULL)
+ allocator = &protobuf_c_default_allocator;
+ message->descriptor = NULL;
+ for (f = 0; f < desc->n_fields; f++) {
+ if (desc->fields[f].label == PROTOBUF_C_LABEL_REPEATED) {
+ size_t n = STRUCT_MEMBER (size_t, message, desc->fields[f].quantifier_offset);
+ void * arr = STRUCT_MEMBER (void *, message, desc->fields[f].offset);
+ if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ FREE (allocator, ((char**)arr)[i]);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ FREE (allocator, ((ProtobufCBinaryData*)arr)[i].data);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ protobuf_c_message_free_unpacked (((ProtobufCMessage**)arr)[i], allocator);
}
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE)
- {
- unsigned i;
- for (i = 0; i < n; i++)
- protobuf_c_message_free_unpacked (((ProtobufCMessage**)arr)[i], allocator);
- }
- if (arr != NULL)
- FREE (allocator, arr);
- }
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING)
- {
- char *str = STRUCT_MEMBER (char *, message, desc->fields[f].offset);
- if (str && str != desc->fields[f].default_value)
- FREE (allocator, str);
- }
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES)
- {
- void *data = STRUCT_MEMBER (ProtobufCBinaryData, message, desc->fields[f].offset).data;
- const ProtobufCBinaryData *default_bd;
- default_bd = desc->fields[f].default_value;
- if (data != NULL
- && (default_bd == NULL || default_bd->data != data))
- FREE (allocator, data);
- }
- else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE)
- {
- ProtobufCMessage *sm;
- sm = STRUCT_MEMBER (ProtobufCMessage *, message,desc->fields[f].offset);
- if (sm && sm != desc->fields[f].default_value)
- protobuf_c_message_free_unpacked (sm, allocator);
+ if (arr != NULL)
+ FREE (allocator, arr);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) {
+ char *str = STRUCT_MEMBER (char *, message, desc->fields[f].offset);
+ if (str && str != desc->fields[f].default_value)
+ FREE (allocator, str);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) {
+ void *data = STRUCT_MEMBER (ProtobufCBinaryData, message, desc->fields[f].offset).data;
+ const ProtobufCBinaryData *default_bd;
+ default_bd = desc->fields[f].default_value;
+ if (data != NULL
+ && (default_bd == NULL || default_bd->data != data))
+ FREE (allocator, data);
+ } else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) {
+ ProtobufCMessage *sm;
+ sm = STRUCT_MEMBER (ProtobufCMessage *, message,desc->fields[f].offset);
+ if (sm && sm != desc->fields[f].default_value)
+ protobuf_c_message_free_unpacked (sm, allocator);
}
}
- for (f = 0; f < message->n_unknown_fields; f++)
- FREE (allocator, message->unknown_fields[f].data);
- if (message->unknown_fields != NULL)
- FREE (allocator, message->unknown_fields);
+ for (f = 0; f < message->n_unknown_fields; f++)
+ FREE (allocator, message->unknown_fields[f].data);
+ if (message->unknown_fields != NULL)
+ FREE (allocator, message->unknown_fields);
- FREE (allocator, message);
+ FREE (allocator, message);
}
/* === services === */
@@ -2444,159 +2209,141 @@ typedef void (*GenericHandler)(void *service,
const ProtobufCMessage *input,
ProtobufCClosure closure,
void *closure_data);
-void
+void
protobuf_c_service_invoke_internal(ProtobufCService *service,
- unsigned method_index,
- const ProtobufCMessage *input,
- ProtobufCClosure closure,
- void *closure_data)
-{
- GenericHandler *handlers;
- GenericHandler handler;
-
- /* Verify that method_index is within range.
- If this fails, you are likely invoking a newly added
- method on an old service. (Although other memory corruption
- bugs can cause this assertion too) */
- PROTOBUF_C_ASSERT (method_index < service->descriptor->n_methods);
-
- /* Get the array of virtual methods (which are enumerated by
- the generated code) */
- handlers = (GenericHandler *) (service + 1);
-
- /* get our method and invoke it */
- /* TODO: seems like handler==NULL is a situation that
- needs handling */
- handler = handlers[method_index];
- (*handler) (service, input, closure, closure_data);
+ unsigned method_index,
+ const ProtobufCMessage *input,
+ ProtobufCClosure closure,
+ void *closure_data) {
+ GenericHandler *handlers;
+ GenericHandler handler;
+
+ /* Verify that method_index is within range.
+ If this fails, you are likely invoking a newly added
+ method on an old service. (Although other memory corruption
+ bugs can cause this assertion too) */
+ PROTOBUF_C_ASSERT (method_index < service->descriptor->n_methods);
+
+ /* Get the array of virtual methods (which are enumerated by
+ the generated code) */
+ handlers = (GenericHandler *) (service + 1);
+
+ /* get our method and invoke it */
+ /* TODO: seems like handler==NULL is a situation that
+ needs handling */
+ handler = handlers[method_index];
+ (*handler) (service, input, closure, closure_data);
}
void
protobuf_c_service_generated_init (ProtobufCService *service,
const ProtobufCServiceDescriptor *descriptor,
- ProtobufCServiceDestroy destroy)
-{
- ASSERT_IS_SERVICE_DESCRIPTOR(descriptor);
- service->descriptor = descriptor;
- service->destroy = destroy;
- service->invoke = protobuf_c_service_invoke_internal;
- memset (service + 1, 0, descriptor->n_methods * sizeof (GenericHandler));
+ ProtobufCServiceDestroy destroy) {
+ ASSERT_IS_SERVICE_DESCRIPTOR(descriptor);
+ service->descriptor = descriptor;
+ service->destroy = destroy;
+ service->invoke = protobuf_c_service_invoke_internal;
+ memset (service + 1, 0, descriptor->n_methods * sizeof (GenericHandler));
}
-void protobuf_c_service_destroy (ProtobufCService *service)
-{
- service->destroy (service);
+void protobuf_c_service_destroy (ProtobufCService *service) {
+ service->destroy (service);
}
/* --- querying the descriptors --- */
const ProtobufCEnumValue *
-protobuf_c_enum_descriptor_get_value_by_name
- (const ProtobufCEnumDescriptor *desc,
- const char *name)
-{
- unsigned start = 0, count = desc->n_value_names;
- while (count > 1)
- {
- unsigned mid = start + count / 2;
- int rv = strcmp (desc->values_by_name[mid].name, name);
- if (rv == 0)
- return desc->values + desc->values_by_name[mid].index;
- else if (rv < 0)
- {
- count = start + count - (mid + 1);
- start = mid + 1;
- }
- else
- count = mid - start;
+protobuf_c_enum_descriptor_get_value_by_name
+(const ProtobufCEnumDescriptor *desc,
+ const char *name) {
+ unsigned start = 0, count = desc->n_value_names;
+ while (count > 1) {
+ unsigned mid = start + count / 2;
+ int rv = strcmp (desc->values_by_name[mid].name, name);
+ if (rv == 0)
+ return desc->values + desc->values_by_name[mid].index;
+ else if (rv < 0) {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ } else
+ count = mid - start;
}
- if (count == 0)
+ if (count == 0)
+ return NULL;
+ if (strcmp (desc->values_by_name[start].name, name) == 0)
+ return desc->values + desc->values_by_name[start].index;
return NULL;
- if (strcmp (desc->values_by_name[start].name, name) == 0)
- return desc->values + desc->values_by_name[start].index;
- return NULL;
}
const ProtobufCEnumValue *
-protobuf_c_enum_descriptor_get_value
- (const ProtobufCEnumDescriptor *desc,
- int value)
-{
- int rv = int_range_lookup (desc->n_value_ranges, desc->value_ranges, value);
- if (rv < 0)
- return NULL;
- return desc->values + rv;
+protobuf_c_enum_descriptor_get_value
+(const ProtobufCEnumDescriptor *desc,
+ int value) {
+ int rv = int_range_lookup (desc->n_value_ranges, desc->value_ranges, value);
+ if (rv < 0)
+ return NULL;
+ return desc->values + rv;
}
const ProtobufCFieldDescriptor *
protobuf_c_message_descriptor_get_field_by_name
- (const ProtobufCMessageDescriptor *desc,
- const char *name)
-{
- unsigned start = 0, count = desc->n_fields;
- const ProtobufCFieldDescriptor *field;
- while (count > 1)
- {
- unsigned mid = start + count / 2;
- int rv;
- field = desc->fields + desc->fields_sorted_by_name[mid];
- rv = strcmp (field->name, name);
- if (rv == 0)
- return field;
- else if (rv < 0)
- {
- count = start + count - (mid + 1);
- start = mid + 1;
- }
- else
- count = mid - start;
+(const ProtobufCMessageDescriptor *desc,
+ const char *name) {
+ unsigned start = 0, count = desc->n_fields;
+ const ProtobufCFieldDescriptor *field;
+ while (count > 1) {
+ unsigned mid = start + count / 2;
+ int rv;
+ field = desc->fields + desc->fields_sorted_by_name[mid];
+ rv = strcmp (field->name, name);
+ if (rv == 0)
+ return field;
+ else if (rv < 0) {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ } else
+ count = mid - start;
}
- if (count == 0)
+ if (count == 0)
+ return NULL;
+ field = desc->fields + desc->fields_sorted_by_name[start];
+ if (strcmp (field->name, name) == 0)
+ return field;
return NULL;
- field = desc->fields + desc->fields_sorted_by_name[start];
- if (strcmp (field->name, name) == 0)
- return field;
- return NULL;
}
const ProtobufCFieldDescriptor *
-protobuf_c_message_descriptor_get_field
- (const ProtobufCMessageDescriptor *desc,
- unsigned value)
-{
- int rv = int_range_lookup (desc->n_field_ranges,
- desc->field_ranges,
- value);
- if (rv < 0)
- return NULL;
- return desc->fields + rv;
+protobuf_c_message_descriptor_get_field
+(const ProtobufCMessageDescriptor *desc,
+ unsigned value) {
+ int rv = int_range_lookup (desc->n_field_ranges,
+ desc->field_ranges,
+ value);
+ if (rv < 0)
+ return NULL;
+ return desc->fields + rv;
}
const ProtobufCMethodDescriptor *
protobuf_c_service_descriptor_get_method_by_name
- (const ProtobufCServiceDescriptor *desc,
- const char *name)
-{
- unsigned start = 0, count = desc->n_methods;
- while (count > 1)
- {
- unsigned mid = start + count / 2;
- unsigned mid_index = desc->method_indices_by_name[mid];
- const char *mid_name = desc->methods[mid_index].name;
- int rv = strcmp (mid_name, name);
- if (rv == 0)
- return desc->methods + desc->method_indices_by_name[mid];
- if (rv < 0)
- {
- count = start + count - (mid + 1);
- start = mid + 1;
- }
- else
- {
- count = mid - start;
+(const ProtobufCServiceDescriptor *desc,
+ const char *name) {
+ unsigned start = 0, count = desc->n_methods;
+ while (count > 1) {
+ unsigned mid = start + count / 2;
+ unsigned mid_index = desc->method_indices_by_name[mid];
+ const char *mid_name = desc->methods[mid_index].name;
+ int rv = strcmp (mid_name, name);
+ if (rv == 0)
+ return desc->methods + desc->method_indices_by_name[mid];
+ if (rv < 0) {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ } else {
+ count = mid - start;
}
}
- if (count == 0)
+ if (count == 0)
+ return NULL;
+ if (strcmp (desc->methods[desc->method_indices_by_name[start]].name, name) == 0)
+ return desc->methods + desc->method_indices_by_name[start];
return NULL;
- if (strcmp (desc->methods[desc->method_indices_by_name[start]].name, name) == 0)
- return desc->methods + desc->method_indices_by_name[start];
- return NULL;
}
diff --git a/navit/maptool/itembin.c b/navit/maptool/itembin.c
index 0c62eb205..a27aa18c4 100644
--- a/navit/maptool/itembin.c
+++ b/navit/maptool/itembin.c
@@ -28,677 +28,643 @@
int
-item_bin_read(struct item_bin *ib, FILE *in)
-{
- if (fread(ib, 4, 1, in) == 0)
- return 0;
- if (!ib->len)
- return 1;
- if (fread((unsigned char *)ib+4, ib->len*4, 1, in))
- return 2;
- return 0;
+item_bin_read(struct item_bin *ib, FILE *in) {
+ if (fread(ib, 4, 1, in) == 0)
+ return 0;
+ if (!ib->len)
+ return 1;
+ if (fread((unsigned char *)ib+4, ib->len*4, 1, in))
+ return 2;
+ return 0;
}
void
-item_bin_set_type(struct item_bin *ib, enum item_type type)
-{
- ib->type=type;
+item_bin_set_type(struct item_bin *ib, enum item_type type) {
+ ib->type=type;
}
void
-item_bin_init(struct item_bin *ib, enum item_type type)
-{
- ib->clen=0;
- ib->len=2;
- item_bin_set_type(ib, type);
+item_bin_init(struct item_bin *ib, enum item_type type) {
+ ib->clen=0;
+ ib->len=2;
+ item_bin_set_type(ib, type);
}
void
-item_bin_add_coord(struct item_bin *ib, struct coord *coords_to_add, int count)
-{
- struct coord *coord_list=(struct coord *)(ib+1);
- coord_list+=ib->clen/2;
- memcpy(coord_list, coords_to_add, count*sizeof(struct coord));
- ib->clen+=count*2;
- ib->len+=count*2;
+item_bin_add_coord(struct item_bin *ib, struct coord *coords_to_add, int count) {
+ struct coord *coord_list=(struct coord *)(ib+1);
+ coord_list+=ib->clen/2;
+ memcpy(coord_list, coords_to_add, count*sizeof(struct coord));
+ ib->clen+=count*2;
+ ib->len+=count*2;
}
void
-item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count)
-{
- int i;
- for (i = count-1 ; i >= 0 ; i--)
- item_bin_add_coord(ib, &c[i], 1);
+item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count) {
+ int i;
+ for (i = count-1 ; i >= 0 ; i--)
+ item_bin_add_coord(ib, &c[i], 1);
}
void
-item_bin_bbox(struct item_bin *ib, struct rect *r)
-{
- struct coord c;
- item_bin_add_coord(ib, &r->l, 1);
- c.x=r->h.x;
- c.y=r->l.y;
- item_bin_add_coord(ib, &c, 1);
- item_bin_add_coord(ib, &r->h, 1);
- c.x=r->l.x;
- c.y=r->h.y;
- item_bin_add_coord(ib, &c, 1);
- item_bin_add_coord(ib, &r->l, 1);
+item_bin_bbox(struct item_bin *ib, struct rect *r) {
+ struct coord c;
+ item_bin_add_coord(ib, &r->l, 1);
+ c.x=r->h.x;
+ c.y=r->l.y;
+ item_bin_add_coord(ib, &c, 1);
+ item_bin_add_coord(ib, &r->h, 1);
+ c.x=r->l.x;
+ c.y=r->h.y;
+ item_bin_add_coord(ib, &c, 1);
+ item_bin_add_coord(ib, &r->l, 1);
}
void
-item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir)
-{
- struct coord *c=(struct coord *)(from+1);
- int i,count=from->clen/2;
- if (dir >= 0) {
- item_bin_add_coord(ib, c, count);
- return;
- }
- for (i = 1 ; i <= count ; i++)
- item_bin_add_coord(ib, &c[count-i], 1);
+item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir) {
+ struct coord *c=(struct coord *)(from+1);
+ int i,count=from->clen/2;
+ if (dir >= 0) {
+ item_bin_add_coord(ib, c, count);
+ return;
+ }
+ for (i = 1 ; i <= count ; i++)
+ item_bin_add_coord(ib, &c[count-i], 1);
}
void
-item_bin_copy_attr(struct item_bin *ib, struct item_bin *from, enum attr_type attr)
-{
- struct attr_bin *ab=item_bin_get_attr_bin(from, attr, NULL);
- if (ab)
- item_bin_add_attr_data(ib, ab->type, (void *)(ab+1), (ab->len-1)*4);
- assert(attr == attr_osm_wayid);
- assert(item_bin_get_wayid(ib) == item_bin_get_wayid(from));
+item_bin_copy_attr(struct item_bin *ib, struct item_bin *from, enum attr_type attr) {
+ struct attr_bin *ab=item_bin_get_attr_bin(from, attr, NULL);
+ if (ab)
+ item_bin_add_attr_data(ib, ab->type, (void *)(ab+1), (ab->len-1)*4);
+ assert(attr == attr_osm_wayid);
+ assert(item_bin_get_wayid(ib) == item_bin_get_wayid(from));
}
void
-item_bin_add_coord_rect(struct item_bin *ib, struct rect *r)
-{
- item_bin_add_coord(ib, &r->l, 1);
- item_bin_add_coord(ib, &r->h, 1);
+item_bin_add_coord_rect(struct item_bin *ib, struct rect *r) {
+ item_bin_add_coord(ib, &r->l, 1);
+ item_bin_add_coord(ib, &r->h, 1);
}
int
-attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size)
-{
- int pad=(4-(size%4))%4;
- ab->type=type;
- memcpy(ab+1, data, size);
- memset((unsigned char *)(ab+1)+size, 0, pad);
- ab->len=(size+pad)/4+1;
- return ab->len+1;
+attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size) {
+ int pad=(4-(size%4))%4;
+ ab->type=type;
+ memcpy(ab+1, data, size);
+ memset((unsigned char *)(ab+1)+size, 0, pad);
+ ab->len=(size+pad)/4+1;
+ return ab->len+1;
}
int
-attr_bin_write_attr(struct attr_bin *ab, struct attr *attr)
-{
- return attr_bin_write_data(ab, attr->type, attr_data_get(attr), attr_data_size(attr));
+attr_bin_write_attr(struct attr_bin *ab, struct attr *attr) {
+ return attr_bin_write_data(ab, attr->type, attr_data_get(attr), attr_data_size(attr));
}
void
-item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size)
-{
- struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
- ib->len+=attr_bin_write_data(ab, type, data, size);
+item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size) {
+ struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
+ ib->len+=attr_bin_write_data(ab, type, data, size);
}
void
-item_bin_add_attr(struct item_bin *ib, struct attr *attr)
-{
- struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
- if (ATTR_IS_GROUP(attr->type)) {
- int i=0;
- int *abptr;
- ab->type=attr->type;
- ab->len=1;
- abptr=(int *)(ab+1);
- while (attr->u.attrs[i].type) {
- int size=attr_bin_write_attr((struct attr_bin *)abptr, &attr->u.attrs[i]);
- ab->len+=size;
- abptr+=size;
- i++;
- }
- ib->len+=ab->len+1;
+item_bin_add_attr(struct item_bin *ib, struct attr *attr) {
+ struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
+ if (ATTR_IS_GROUP(attr->type)) {
+ int i=0;
+ int *abptr;
+ ab->type=attr->type;
+ ab->len=1;
+ abptr=(int *)(ab+1);
+ while (attr->u.attrs[i].type) {
+ int size=attr_bin_write_attr((struct attr_bin *)abptr, &attr->u.attrs[i]);
+ ab->len+=size;
+ abptr+=size;
+ i++;
+ }
+ ib->len+=ab->len+1;
+
+ } else
+ ib->len+=attr_bin_write_attr(ab, attr);
- } else
- ib->len+=attr_bin_write_attr(ab, attr);
-
}
void
-item_bin_remove_attr(struct item_bin *ib, void *ptr)
-{
- 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) {
- struct attr_bin *ab=(struct attr_bin *)s;
- s+=(ab->len+1)*4;
- if ((void *)(ab+1) == ptr) {
- ib->len-=ab->len+1;
- memmove(ab,s,e-s);
- return;
- }
- }
+item_bin_remove_attr(struct item_bin *ib, void *ptr) {
+ 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) {
+ struct attr_bin *ab=(struct attr_bin *)s;
+ s+=(ab->len+1)*4;
+ if ((void *)(ab+1) == ptr) {
+ ib->len-=ab->len+1;
+ memmove(ab,s,e-s);
+ return;
+ }
+ }
}
void
-item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val)
-{
- struct attr attr;
- attr.type=type;
- attr.u.num=val;
- item_bin_add_attr(ib, &attr);
+item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val) {
+ struct attr attr;
+ attr.type=type;
+ attr.u.num=val;
+ item_bin_add_attr(ib, &attr);
}
void *
-item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last)
-{
- 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) {
- struct attr_bin *ab=(struct attr_bin *)s;
- s+=(ab->len+1)*4;
- if (ab->type == type && (void *)(ab+1) > last) {
- return (ab+1);
- }
- }
- return NULL;
+item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last) {
+ 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) {
+ struct attr_bin *ab=(struct attr_bin *)s;
+ s+=(ab->len+1)*4;
+ if (ab->type == type && (void *)(ab+1) > last) {
+ return (ab+1);
+ }
+ }
+ return NULL;
}
struct attr_bin *
-item_bin_get_attr_bin(struct item_bin *ib, enum attr_type type, void *last)
-{
- 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) {
- struct attr_bin *ab=(struct attr_bin *)s;
- s+=(ab->len+1)*4;
- if (ab->type == type && (void *)(ab+1) > last) {
- return ab;
- }
- }
- return NULL;
+item_bin_get_attr_bin(struct item_bin *ib, enum attr_type type, void *last) {
+ 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) {
+ struct attr_bin *ab=(struct attr_bin *)s;
+ s+=(ab->len+1)*4;
+ if (ab->type == type && (void *)(ab+1) > last) {
+ return ab;
+ }
+ }
+ 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;
+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)
-{
- struct attr attr;
- attr.type=type;
- attr.u.num64=&val;
- item_bin_add_attr(ib, &attr);
+item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val) {
+ struct attr attr;
+ attr.type=type;
+ attr.u.num64=&val;
+ item_bin_add_attr(ib, &attr);
}
void
-item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str)
-{
- struct attr attr;
- if (! str)
- return;
- attr.type=type;
- attr.u.str=str;
- item_bin_add_attr(ib, &attr);
+item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str) {
+ struct attr attr;
+ if (! str)
+ return;
+ attr.type=type;
+ attr.u.str=str;
+ item_bin_add_attr(ib, &attr);
}
void
-item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max)
-{
- struct attr attr;
- attr.type=type;
- attr.u.range.min=min;
- attr.u.range.max=max;
- item_bin_add_attr(ib, &attr);
+item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max) {
+ struct attr attr;
+ attr.type=type;
+ attr.u.range.min=min;
+ attr.u.range.max=max;
+ item_bin_add_attr(ib, &attr);
}
void
-item_bin_write(struct item_bin *ib, FILE *out)
-{
- dbg_assert(fwrite(ib, (ib->len+1)*4, 1, out)==1);
+item_bin_write(struct item_bin *ib, FILE *out) {
+ dbg_assert(fwrite(ib, (ib->len+1)*4, 1, out)==1);
}
struct item_bin *
-item_bin_dup(struct item_bin *ib)
-{
- int len=(ib->len+1)*4;
- struct item_bin *ret=g_malloc(len);
- memcpy(ret, ib, len);
+item_bin_dup(struct item_bin *ib) {
+ int len=(ib->len+1)*4;
+ struct item_bin *ret=g_malloc(len);
+ memcpy(ret, ib, len);
- return ret;
+ return ret;
}
void
-item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out)
-{
- struct tile_data tile_data;
- int i;
- bbox((struct coord *)(ib+1), ib->clen/2, &tile_data.item_bbox);
- tile_data.buffer[0]='\0';
- tile_data.tile_depth=tile(&tile_data.item_bbox, NULL, tile_data.buffer, param->max, param->overlap, &tile_data.tile_bbox);
- if (tile_data.tile_depth == param->max || tile_data.tile_depth >= param->min) {
- item_bin_write_to_sink(ib, out, &tile_data);
- return;
- }
- for (i = 0 ; i < 4 ; i++) {
- struct rect clip_rect;
- tile_data.buffer[tile_data.tile_depth]='a'+i;
- tile_data.buffer[tile_data.tile_depth+1]='\0';
- tile_bbox(tile_data.buffer, &clip_rect, param->overlap);
- if (ib->type < type_area)
- clip_line(ib, &clip_rect, param, out);
- else
- clip_polygon(ib, &clip_rect, param, out);
- }
+item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out) {
+ struct tile_data tile_data;
+ int i;
+ bbox((struct coord *)(ib+1), ib->clen/2, &tile_data.item_bbox);
+ tile_data.buffer[0]='\0';
+ tile_data.tile_depth=tile(&tile_data.item_bbox, NULL, tile_data.buffer, param->max, param->overlap,
+ &tile_data.tile_bbox);
+ if (tile_data.tile_depth == param->max || tile_data.tile_depth >= param->min) {
+ item_bin_write_to_sink(ib, out, &tile_data);
+ return;
+ }
+ for (i = 0 ; i < 4 ; i++) {
+ struct rect clip_rect;
+ tile_data.buffer[tile_data.tile_depth]='a'+i;
+ tile_data.buffer[tile_data.tile_depth+1]='\0';
+ tile_bbox(tile_data.buffer, &clip_rect, param->overlap);
+ if (ib->type < type_area)
+ clip_line(ib, &clip_rect, param, out);
+ else
+ clip_polygon(ib, &clip_rect, param, out);
+ }
}
static char *
-coord_to_str(struct coord *c)
-{
- int x=c->x;
- int y=c->y;
- char *sx="";
- char *sy="";
- if (x < 0) {
- sx="-";
- x=-x;
- }
- if (y < 0) {
- sy="-";
- y=-y;
- }
- return g_strdup_printf("%s0x%x %s0x%x",sx,x,sy,y);
+coord_to_str(struct coord *c) {
+ int x=c->x;
+ int y=c->y;
+ char *sx="";
+ char *sy="";
+ if (x < 0) {
+ sx="-";
+ x=-x;
+ }
+ if (y < 0) {
+ sy="-";
+ y=-y;
+ }
+ return g_strdup_printf("%s0x%x %s0x%x",sx,x,sy,y);
}
static void
-dump_coord(struct coord *c, FILE *out)
-{
- char *str=coord_to_str(c);
- fprintf(out,"%s",str);
- g_free(str);
+dump_coord(struct coord *c, FILE *out) {
+ char *str=coord_to_str(c);
+ fprintf(out,"%s",str);
+ g_free(str);
}
void
-item_bin_dump(struct item_bin *ib, FILE *out)
-{
- struct coord *c;
- struct attr_bin *a;
- struct attr attr;
- int *attr_start;
- int *attr_end;
- int i;
- char *str;
-
- c=(struct coord *)(ib+1);
- if (ib->type < type_line) {
- dump_coord(c,out);
- fprintf(out, " ");
- }
- attr_start=(int *)(ib+1)+ib->clen;
- attr_end=(int *)ib+ib->len+1;
- fprintf(out,"type=%s", item_to_name(ib->type));
- while (attr_start < attr_end) {
- a=(struct attr_bin *)(attr_start);
- attr_start+=a->len+1;
- attr.type=a->type;
- attr_data_set(&attr, (a+1));
- str=attr_to_text(&attr, NULL, 1);
- fprintf(out," %s=\"%s\"", attr_to_name(a->type), str);
- g_free(str);
- }
- fprintf(out," debug=\"length=%d\"", ib->len);
- fprintf(out,"\n");
- if (ib->type >= type_line) {
- for (i = 0 ; i < ib->clen/2 ; i++) {
- dump_coord(c+i,out);
- fprintf(out,"\n");
- }
- }
+item_bin_dump(struct item_bin *ib, FILE *out) {
+ struct coord *c;
+ struct attr_bin *a;
+ struct attr attr;
+ int *attr_start;
+ int *attr_end;
+ int i;
+ char *str;
+
+ c=(struct coord *)(ib+1);
+ if (ib->type < type_line) {
+ dump_coord(c,out);
+ fprintf(out, " ");
+ }
+ attr_start=(int *)(ib+1)+ib->clen;
+ attr_end=(int *)ib+ib->len+1;
+ fprintf(out,"type=%s", item_to_name(ib->type));
+ while (attr_start < attr_end) {
+ a=(struct attr_bin *)(attr_start);
+ attr_start+=a->len+1;
+ attr.type=a->type;
+ attr_data_set(&attr, (a+1));
+ str=attr_to_text(&attr, NULL, 1);
+ fprintf(out," %s=\"%s\"", attr_to_name(a->type), str);
+ g_free(str);
+ }
+ fprintf(out," debug=\"length=%d\"", ib->len);
+ fprintf(out,"\n");
+ if (ib->type >= type_line) {
+ for (i = 0 ; i < ib->clen/2 ; i++) {
+ dump_coord(c+i,out);
+ fprintf(out,"\n");
+ }
+ }
}
void
-dump_itembin(struct item_bin *ib)
-{
- item_bin_dump(ib, stdout);
+dump_itembin(struct item_bin *ib) {
+ item_bin_dump(ib, stdout);
}
struct population_table {
- enum item_type type;
- int population;
+ enum item_type type;
+ int population;
};
static struct population_table town_population[] = {
- {type_town_label_0e0,0},
- {type_town_label_1e0,1},
- {type_town_label_2e0,2},
- {type_town_label_5e0,5},
- {type_town_label_1e1,10},
- {type_town_label_2e1,20},
- {type_town_label_5e1,50},
- {type_town_label_1e2,100},
- {type_town_label_2e2,200},
- {type_town_label_5e2,500},
- {type_town_label_1e3,1000},
- {type_town_label_2e3,2000},
- {type_town_label_5e3,5000},
- {type_town_label_1e4,10000},
- {type_town_label_2e4,20000},
- {type_town_label_5e4,50000},
- {type_town_label_1e5,100000},
- {type_town_label_2e5,200000},
- {type_town_label_5e5,500000},
- {type_town_label_1e6,1000000},
- {type_town_label_2e6,2000000},
- {type_town_label_5e6,5000000},
- {type_town_label_1e7,10000000},
+ {type_town_label_0e0,0},
+ {type_town_label_1e0,1},
+ {type_town_label_2e0,2},
+ {type_town_label_5e0,5},
+ {type_town_label_1e1,10},
+ {type_town_label_2e1,20},
+ {type_town_label_5e1,50},
+ {type_town_label_1e2,100},
+ {type_town_label_2e2,200},
+ {type_town_label_5e2,500},
+ {type_town_label_1e3,1000},
+ {type_town_label_2e3,2000},
+ {type_town_label_5e3,5000},
+ {type_town_label_1e4,10000},
+ {type_town_label_2e4,20000},
+ {type_town_label_5e4,50000},
+ {type_town_label_1e5,100000},
+ {type_town_label_2e5,200000},
+ {type_town_label_5e5,500000},
+ {type_town_label_1e6,1000000},
+ {type_town_label_2e6,2000000},
+ {type_town_label_5e6,5000000},
+ {type_town_label_1e7,10000000},
};
static struct population_table district_population[] = {
- {type_district_label_0e0,0},
- {type_district_label_1e0,1},
- {type_district_label_2e0,2},
- {type_district_label_5e0,5},
- {type_district_label_1e1,10},
- {type_district_label_2e1,20},
- {type_district_label_5e1,50},
- {type_district_label_1e2,100},
- {type_district_label_2e2,200},
- {type_district_label_5e2,500},
- {type_district_label_1e3,1000},
- {type_district_label_2e3,2000},
- {type_district_label_5e3,5000},
- {type_district_label_1e4,10000},
- {type_district_label_2e4,20000},
- {type_district_label_5e4,50000},
- {type_district_label_1e5,100000},
- {type_district_label_2e5,200000},
- {type_district_label_5e5,500000},
- {type_district_label_1e6,1000000},
- {type_district_label_2e6,2000000},
- {type_district_label_5e6,5000000},
- {type_district_label_1e7,10000000},
+ {type_district_label_0e0,0},
+ {type_district_label_1e0,1},
+ {type_district_label_2e0,2},
+ {type_district_label_5e0,5},
+ {type_district_label_1e1,10},
+ {type_district_label_2e1,20},
+ {type_district_label_5e1,50},
+ {type_district_label_1e2,100},
+ {type_district_label_2e2,200},
+ {type_district_label_5e2,500},
+ {type_district_label_1e3,1000},
+ {type_district_label_2e3,2000},
+ {type_district_label_5e3,5000},
+ {type_district_label_1e4,10000},
+ {type_district_label_2e4,20000},
+ {type_district_label_5e4,50000},
+ {type_district_label_1e5,100000},
+ {type_district_label_2e5,200000},
+ {type_district_label_5e5,500000},
+ {type_district_label_1e6,1000000},
+ {type_district_label_2e6,2000000},
+ {type_district_label_5e6,5000000},
+ {type_district_label_1e7,10000000},
};
void
-item_bin_set_type_by_population(struct item_bin *ib, int population)
-{
- struct population_table *table;
- int i,count;
-
- if (population < 0)
- population=0;
- if (item_is_district(*ib)) {
- table=district_population;
- count=sizeof(district_population)/sizeof(district_population[0]);
- } else {
- table=town_population;
- count=sizeof(town_population)/sizeof(town_population[0]);
- }
- for (i = 0 ; i < count ; i++) {
- if (population < table[i].population)
- break;
- }
- item_bin_set_type(ib, table[i-1].type);
+item_bin_set_type_by_population(struct item_bin *ib, int population) {
+ struct population_table *table;
+ int i,count;
+
+ if (population < 0)
+ population=0;
+ if (item_is_district(*ib)) {
+ table=district_population;
+ count=sizeof(district_population)/sizeof(district_population[0]);
+ } else {
+ table=town_population;
+ count=sizeof(town_population)/sizeof(town_population[0]);
+ }
+ for (i = 0 ; i < count ; i++) {
+ if (population < table[i].population)
+ break;
+ }
+ item_bin_set_type(ib, table[i-1].type);
}
void
-item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, int maxdepth, FILE *out)
-{
- char *word=item_bin_get_attr(ib, type, NULL);
- int i,words=0,len;
- char tilename[32]="";
-
- if (!word)
- return;
-
- if(maxdepth && ib->clen>0) {
- struct rect r;
- struct coord *c=(struct coord *)(ib+1);
- r.l=c[0];
- r.h=c[0];
- for (i = 1 ; i < ib->clen/2 ; i++)
- bbox_extend(&c[i], &r);
- tile(&r,NULL,tilename,maxdepth,overlap,NULL);
- }
-
- /* insert attr_tile_name attribute before the attribute used as alphabetical key (of type type) */
- if(maxdepth) {
- item_bin_add_attr_string(ib, attr_tile_name, tilename);
- item_bin_add_attr_string(ib, type, word);
- item_bin_remove_attr(ib,word);
- word=item_bin_get_attr(ib, type, NULL);
- }
- len=ib->len;
- do {
- if (linguistics_search(word)) {
- for (i = 0 ; i < 3 ; i++) {
- char *str=linguistics_expand_special(word, i);
- if (str) {
- ib->len=len;
- if (i || words)
- item_bin_add_attr_string(ib, match, str);
- item_bin_write(ib, out);
- g_free(str);
- }
- }
- words++;
- }
- word=linguistics_next_word(word);
- } while (word);
+item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, int maxdepth, FILE *out) {
+ char *word=item_bin_get_attr(ib, type, NULL);
+ int i,words=0,len;
+ char tilename[32]="";
+
+ if (!word)
+ return;
+
+ if(maxdepth && ib->clen>0) {
+ struct rect r;
+ struct coord *c=(struct coord *)(ib+1);
+ r.l=c[0];
+ r.h=c[0];
+ for (i = 1 ; i < ib->clen/2 ; i++)
+ bbox_extend(&c[i], &r);
+ tile(&r,NULL,tilename,maxdepth,overlap,NULL);
+ }
+
+ /* insert attr_tile_name attribute before the attribute used as alphabetical key (of type type) */
+ if(maxdepth) {
+ item_bin_add_attr_string(ib, attr_tile_name, tilename);
+ item_bin_add_attr_string(ib, type, word);
+ item_bin_remove_attr(ib,word);
+ word=item_bin_get_attr(ib, type, NULL);
+ }
+ len=ib->len;
+ do {
+ if (linguistics_search(word)) {
+ for (i = 0 ; i < 3 ; i++) {
+ char *str=linguistics_expand_special(word, i);
+ if (str) {
+ ib->len=len;
+ if (i || words)
+ item_bin_add_attr_string(ib, match, str);
+ item_bin_write(ib, out);
+ g_free(str);
+ }
+ }
+ words++;
+ }
+ word=linguistics_next_word(word);
+ } 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;
-
- 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;
- }
- attr1=item_bin_get_attr_bin_last(ib1);
- attr2=item_bin_get_attr_bin_last(ib2);
- 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;
- }
- return ret;
+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;
+ }
+ attr1=item_bin_get_attr_bin_last(ib1);
+ attr2=item_bin_get_attr_bin_last(ib2);
+ 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;
+ }
+ return ret;
}
int
-item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size)
-{
- int j,k,count,rc=0;
- 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=g_malloc(count*sizeof(void *));
- 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);
- dbg_assert(fwrite(ib, (ib->len+1)*4, 1, f)==1);
- if (r) {
- for (k = 0 ; k < ib->clen/2 ; k++) {
- if (rc)
- bbox_extend(&c[k], r);
- else {
- r->l=c[k];
- r->h=c[k];
- }
- rc++;
- }
- }
- }
- fclose(f);
- g_free(idx);
- g_free(buffer);
- return 1;
- }
- return 0;
+item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size) {
+ int j,k,count,rc=0;
+ 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=g_malloc(count*sizeof(void *));
+ 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);
+ dbg_assert(fwrite(ib, (ib->len+1)*4, 1, f)==1);
+ if (r) {
+ for (k = 0 ; k < ib->clen/2 ; k++) {
+ if (rc)
+ bbox_extend(&c[k], r);
+ else {
+ r->l=c[k];
+ r->h=c[k];
+ }
+ rc++;
+ }
+ }
+ }
+ fclose(f);
+ g_free(idx);
+ g_free(buffer);
+ return 1;
+ }
+ return 0;
}
struct geom_poly_segment *
-item_bin_to_poly_segment(struct item_bin *ib, int type)
-{
- struct geom_poly_segment *ret=g_new(struct geom_poly_segment, 1);
- int count=ib->clen*sizeof(int)/sizeof(struct coord);
- ret->type=type;
- ret->first=g_new(struct coord, count);
- ret->last=ret->first+count-1;
- geom_coord_copy((struct coord *)(ib+1), ret->first, count, 0);
- return ret;
+item_bin_to_poly_segment(struct item_bin *ib, int type) {
+ struct geom_poly_segment *ret=g_new(struct geom_poly_segment, 1);
+ int count=ib->clen*sizeof(int)/sizeof(struct coord);
+ ret->type=type;
+ ret->first=g_new(struct coord, count);
+ ret->last=ret->first+count-1;
+ geom_coord_copy((struct coord *)(ib+1), ret->first, count, 0);
+ return ret;
}
void
-clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out)
-{
- char *buffer=g_alloca(sizeof(char)*(ib->len*4+32));
- struct item_bin *ib_new=(struct item_bin *)buffer;
- struct coord *pa=(struct coord *)(ib+1);
- int count=ib->clen/2;
- struct coord p1,p2;
- int i,code;
- item_bin_init(ib_new, ib->type);
- for (i = 0 ; i < count ; i++) {
- if (i) {
- p1.x=pa[i-1].x;
- p1.y=pa[i-1].y;
- p2.x=pa[i].x;
- p2.y=pa[i].y;
- /* 0 = invisible, 1 = completely visible, 3 = start point clipped, 5 = end point clipped, 7 both points clipped */
- code=geom_clip_line_code(&p1, &p2, r);
+clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out) {
+ char *buffer=g_alloca(sizeof(char)*(ib->len*4+32));
+ struct item_bin *ib_new=(struct item_bin *)buffer;
+ struct coord *pa=(struct coord *)(ib+1);
+ int count=ib->clen/2;
+ struct coord p1,p2;
+ int i,code;
+ item_bin_init(ib_new, ib->type);
+ for (i = 0 ; i < count ; i++) {
+ if (i) {
+ p1.x=pa[i-1].x;
+ p1.y=pa[i-1].y;
+ p2.x=pa[i].x;
+ p2.y=pa[i].y;
+ /* 0 = invisible, 1 = completely visible, 3 = start point clipped, 5 = end point clipped, 7 both points clipped */
+ code=geom_clip_line_code(&p1, &p2, r);
#if 1
- if (((code == 1 || code == 5) && ib_new->clen == 0) || (code & 2)) {
- item_bin_add_coord(ib_new, &p1, 1);
- }
- if (code) {
- item_bin_add_coord(ib_new, &p2, 1);
- }
- if (i == count-1 || (code & 4)) {
- if (param->attr_to_copy)
- item_bin_copy_attr(ib_new, ib, param->attr_to_copy);
- if (ib_new->clen)
- item_bin_write_clipped(ib_new, param, out);
- item_bin_init(ib_new, ib->type);
- }
+ if (((code == 1 || code == 5) && ib_new->clen == 0) || (code & 2)) {
+ item_bin_add_coord(ib_new, &p1, 1);
+ }
+ if (code) {
+ item_bin_add_coord(ib_new, &p2, 1);
+ }
+ if (i == count-1 || (code & 4)) {
+ if (param->attr_to_copy)
+ item_bin_copy_attr(ib_new, ib, param->attr_to_copy);
+ if (ib_new->clen)
+ item_bin_write_clipped(ib_new, param, out);
+ item_bin_init(ib_new, ib->type);
+ }
#else
- if (code) {
- item_bin_init(ib_new, ib->type);
- item_bin_add_coord(ib_new, &p1, 1);
- item_bin_add_coord(ib_new, &p2, 1);
- if (param->attr_to_copy)
- item_bin_copy_attr(ib_new, ib, param->attr_to_copy);
- item_bin_write_clipped(ib_new, param, out);
- }
+ if (code) {
+ item_bin_init(ib_new, ib->type);
+ item_bin_add_coord(ib_new, &p1, 1);
+ item_bin_add_coord(ib_new, &p2, 1);
+ if (param->attr_to_copy)
+ item_bin_copy_attr(ib_new, ib, param->attr_to_copy);
+ item_bin_write_clipped(ib_new, param, out);
+ }
#endif
- }
- }
+ }
+ }
}
void
-clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out)
-{
- int count_in=ib->clen/2;
- struct coord *pin,*p,*s,pi;
- char *buffer1=g_alloca(sizeof(char)*(ib->len*4+ib->clen*7+32));
- struct item_bin *ib1=(struct item_bin *)buffer1;
- char *buffer2=g_alloca(sizeof(char)*(ib->len*4+ib->clen*7+32));
- struct item_bin *ib2=(struct item_bin *)buffer2;
- struct item_bin *ib_in,*ib_out;
- int edge,i;
- ib_out=ib1;
- ib_in=ib;
- for (edge = 0 ; edge < 4 ; edge++) {
- count_in=ib_in->clen/2;
- pin=(struct coord *)(ib_in+1);
- p=pin;
- s=pin+count_in-1;
- item_bin_init(ib_out, ib_in->type);
- for (i = 0 ; i < count_in ; i++) {
- if (geom_is_inside(p, r, edge)) {
- if (! geom_is_inside(s, r, edge)) {
- geom_poly_intersection(s,p,r,edge,&pi);
- item_bin_add_coord(ib_out, &pi, 1);
- }
- item_bin_add_coord(ib_out, p, 1);
- } else {
- if (geom_is_inside(s, r, edge)) {
- geom_poly_intersection(p,s,r,edge,&pi);
- item_bin_add_coord(ib_out, &pi, 1);
- }
- }
- s=p;
- p++;
- }
- if (ib_in == ib1) {
- ib_in=ib2;
- ib_out=ib1;
- } else {
- ib_in=ib1;
- ib_out=ib2;
- }
- }
- if (ib_in->clen) {
- if (param->attr_to_copy)
- item_bin_copy_attr(ib_in, ib, param->attr_to_copy);
- item_bin_write_clipped(ib_in, param, out);
- }
+clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out) {
+ int count_in=ib->clen/2;
+ struct coord *pin,*p,*s,pi;
+ char *buffer1=g_alloca(sizeof(char)*(ib->len*4+ib->clen*7+32));
+ struct item_bin *ib1=(struct item_bin *)buffer1;
+ char *buffer2=g_alloca(sizeof(char)*(ib->len*4+ib->clen*7+32));
+ struct item_bin *ib2=(struct item_bin *)buffer2;
+ struct item_bin *ib_in,*ib_out;
+ int edge,i;
+ ib_out=ib1;
+ ib_in=ib;
+ for (edge = 0 ; edge < 4 ; edge++) {
+ count_in=ib_in->clen/2;
+ pin=(struct coord *)(ib_in+1);
+ p=pin;
+ s=pin+count_in-1;
+ item_bin_init(ib_out, ib_in->type);
+ for (i = 0 ; i < count_in ; i++) {
+ if (geom_is_inside(p, r, edge)) {
+ if (! geom_is_inside(s, r, edge)) {
+ geom_poly_intersection(s,p,r,edge,&pi);
+ item_bin_add_coord(ib_out, &pi, 1);
+ }
+ item_bin_add_coord(ib_out, p, 1);
+ } else {
+ if (geom_is_inside(s, r, edge)) {
+ geom_poly_intersection(p,s,r,edge,&pi);
+ item_bin_add_coord(ib_out, &pi, 1);
+ }
+ }
+ s=p;
+ p++;
+ }
+ if (ib_in == ib1) {
+ ib_in=ib2;
+ ib_out=ib1;
+ } else {
+ ib_in=ib1;
+ ib_out=ib2;
+ }
+ }
+ if (ib_in->clen) {
+ if (param->attr_to_copy)
+ item_bin_copy_attr(ib_in, ib, param->attr_to_copy);
+ item_bin_write_clipped(ib_in, param, out);
+ }
}
diff --git a/navit/maptool/itembin_buffer.c b/navit/maptool/itembin_buffer.c
index 980749539..a3d63cf17 100644
--- a/navit/maptool/itembin_buffer.c
+++ b/navit/maptool/itembin_buffer.c
@@ -30,48 +30,44 @@ struct item_bin *tmp_item_bin=(struct item_bin *)(void *)misc_item_buffer;
static struct node_item *tmp_node_item=(struct node_item *)(void *)misc_item_buffer;
struct node_item *
-read_node_item(FILE *in)
-{
- if (fread(tmp_node_item, sizeof(struct node_item), 1, in) != 1)
- return NULL;
- return tmp_node_item;
+read_node_item(FILE *in) {
+ if (fread(tmp_node_item, sizeof(struct node_item), 1, in) != 1)
+ return NULL;
+ return tmp_node_item;
}
struct item_bin *
-read_item(FILE *in)
-{
- struct item_bin *ib=(struct item_bin *) misc_item_buffer;
- for (;;) {
- switch (item_bin_read(ib, in)) {
- case 0:
- return NULL;
- case 2:
- dbg_assert((ib->len+1)*4 < sizeof(misc_item_buffer));
- bytes_read+=(ib->len+1)*sizeof(int);
- return ib;
- default:
- continue;
- }
- }
+read_item(FILE *in) {
+ struct item_bin *ib=(struct item_bin *) misc_item_buffer;
+ for (;;) {
+ switch (item_bin_read(ib, in)) {
+ case 0:
+ return NULL;
+ case 2:
+ dbg_assert((ib->len+1)*4 < sizeof(misc_item_buffer));
+ bytes_read+=(ib->len+1)*sizeof(int);
+ return ib;
+ default:
+ continue;
+ }
+ }
}
struct item_bin *
-read_item_range(FILE *in, int *min, int *max)
-{
- struct range r;
+read_item_range(FILE *in, int *min, int *max) {
+ struct range r;
- if (fread(&r, sizeof(r), 1, in) != 1)
- return NULL;
- *min=r.min;
- *max=r.max;
- return read_item(in);
+ if (fread(&r, sizeof(r), 1, in) != 1)
+ return NULL;
+ *min=r.min;
+ *max=r.max;
+ return read_item(in);
}
struct item_bin *
-init_item(enum item_type type)
-{
- struct item_bin *ib=(struct item_bin *) misc_item_buffer;
+init_item(enum item_type type) {
+ struct item_bin *ib=(struct item_bin *) misc_item_buffer;
- item_bin_init(ib, type);
- return ib;
+ item_bin_init(ib, type);
+ return ib;
}
diff --git a/navit/maptool/maptool.c b/navit/maptool/maptool.c
index f8946aa58..2d7e0d4a9 100644
--- a/navit/maptool/maptool.c
+++ b/navit/maptool/maptool.c
@@ -58,12 +58,13 @@ int slices;
int unknown_country;
char ch_suffix[] ="r"; /* Used to make compiler happy due to Bug 35903 in gcc */
/** Textual description of available experimental features, or NULL (=none available). */
-char* experimental_feature_description = "Move coastline data to order 6 tiles. Makes map look more smooth, but may affect drawing/searching performance."; /* add description here */
+char* experimental_feature_description =
+ "Move coastline data to order 6 tiles. Makes map look more smooth, but may affect drawing/searching performance."; /* add description here */
/** Indicates if experimental features (if available) were enabled. */
int experimental;
struct buffer node_buffer = {
- 64*1024*1024,
+ 64*1024*1024,
};
int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles;
@@ -81,1044 +82,1024 @@ static struct timespec start_ts;
/*
Asynchronous signal safe lltoa function (note: no trailing \0 char!)
*/
-static int assafe_lltoa(long long n, int maxlen, char *buf)
-{
- int i;
- int out_length;
+static int assafe_lltoa(long long n, int maxlen, char *buf) {
+ int i;
+ int out_length;
- if(maxlen<1)
- return 0;
+ if(maxlen<1)
+ return 0;
- if(n<0) {
- n=-n;
- buf[0]='-';
- maxlen--;
- buf++;
- } else if(n==0) {
- buf[0]='0';
- return 1;
- }
+ if(n<0) {
+ n=-n;
+ buf[0]='-';
+ maxlen--;
+ buf++;
+ } else if(n==0) {
+ buf[0]='0';
+ return 1;
+ }
- for(i=0; n>0 && i<maxlen; i++) {
- buf[i]='0'+(n%10);
- n/=10;
- }
- out_length=i;
- for(i=0;i<out_length/2;i++) {
- char c=buf[i];
- buf[i]=buf[out_length-i-1];
- buf[out_length-i-1]=c;
- }
- return out_length;
+ for(i=0; n>0 && i<maxlen; i++) {
+ buf[i]='0'+(n%10);
+ n/=10;
+ }
+ out_length=i;
+ for(i=0; i<out_length/2; i++) {
+ char c=buf[i];
+ buf[i]=buf[out_length-i-1];
+ buf[out_length-i-1]=c;
+ }
+ return out_length;
}
/*
Asynchronous signal safe string copy to buffer function (note: no trailing \0 char!)
*/
-static int assafe_strcp2buf(char *str, int maxlen, char *buf)
-{
- int i;
- for(i=0;str[i] && i<maxlen;i++)
- buf[i]=str[i];
- return i;
+static int assafe_strcp2buf(char *str, int maxlen, char *buf) {
+ int i;
+ for(i=0; str[i] && i<maxlen; i++)
+ buf[i]=str[i];
+ return i;
}
static void
-progress_time(void)
-{
- struct timespec ts;
- int seconds;
- const int buflen=20;
- char buf[buflen];
- int pos=1;
- buf[0]=' ';
+progress_time(void) {
+ struct timespec ts;
+ int seconds;
+ const int buflen=20;
+ char buf[buflen];
+ int pos=1;
+ buf[0]=' ';
#ifdef _WIN32
- gettimeofday(&ts, NULL);
+ gettimeofday(&ts, NULL);
#else
- clock_gettime(CLOCK_REALTIME, &ts);
+ clock_gettime(CLOCK_REALTIME, &ts);
#endif
- seconds=ts.tv_sec-start_ts.tv_sec;
- pos+=assafe_lltoa(seconds/60, buflen-pos, buf+pos);
- seconds%=60;
- pos+=assafe_strcp2buf(seconds>9?":":":0", buflen-pos, buf+pos);
- pos+=assafe_lltoa(seconds, buflen-pos, buf+pos);
- if (write(2,buf,pos) == -1){
- dbg(lvl_warning, "Writing progress time failed. Error-Code: %d" , errno);
- }
+ seconds=ts.tv_sec-start_ts.tv_sec;
+ pos+=assafe_lltoa(seconds/60, buflen-pos, buf+pos);
+ seconds%=60;
+ pos+=assafe_strcp2buf(seconds>9?":":":0", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(seconds, buflen-pos, buf+pos);
+ if (write(2,buf,pos) == -1) {
+ dbg(lvl_warning, "Writing progress time failed. Error-Code: %d", errno);
+ }
}
static void
-progress_memory(void)
-{
+progress_memory(void) {
#ifdef HAVE_SBRK
- long mem=(long)sbrk(0)-start_brk;
- const int buflen=20;
- char buf[buflen];
- int pos=1;
- int write_result;
- buf[0]=' ';
- pos+=assafe_lltoa(mem/1024/1024, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" MB", buflen-pos, buf+pos);
- write_result = write(2,buf,pos);
- if (write_result == -1){
- dbg(lvl_warning, "Writing progress memory failed. Error-Code: %d" , errno);
- }
+ long mem=(long)sbrk(0)-start_brk;
+ const int buflen=20;
+ char buf[buflen];
+ int pos=1;
+ int write_result;
+ buf[0]=' ';
+ pos+=assafe_lltoa(mem/1024/1024, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" MB", buflen-pos, buf+pos);
+ write_result = write(2,buf,pos);
+ if (write_result == -1) {
+ dbg(lvl_warning, "Writing progress memory failed. Error-Code: %d", errno);
+ }
#endif
}
static void
-sig_alrm_do(int sig)
-{
- const int buflen=1024;
- char buf[buflen];
- int pos=0;
- int write_result;
+sig_alrm_do(int sig) {
+ const int buflen=1024;
+ char buf[buflen];
+ int pos=0;
+ int write_result;
#ifndef _WIN32
- signal(SIGALRM, sig_alrm_do);
- alarm(30);
+ signal(SIGALRM, sig_alrm_do);
+ alarm(30);
#endif
- pos+=assafe_strcp2buf("PROGRESS", buflen-pos, buf+pos);
- pos+=assafe_lltoa(phase, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(": Processed ", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_nodes, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" nodes (", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_nodes_out, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" out) ", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_ways, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" ways ", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_relations, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" relations ", buflen-pos, buf+pos);
- pos+=assafe_lltoa(processed_tiles, buflen-pos, buf+pos);
- pos+=assafe_strcp2buf(" tiles", buflen-pos, buf+pos);
- write_result = write(2,buf,pos);
- if (write_result == -1){
- dbg(lvl_warning, "Writing sig alrm ailed. Error-Code: %d" , errno);
- }
- progress_time();
- progress_memory();
+ pos+=assafe_strcp2buf("PROGRESS", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(phase, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(": Processed ", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_nodes, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" nodes (", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_nodes_out, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" out) ", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_ways, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" ways ", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_relations, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" relations ", buflen-pos, buf+pos);
+ pos+=assafe_lltoa(processed_tiles, buflen-pos, buf+pos);
+ pos+=assafe_strcp2buf(" tiles", buflen-pos, buf+pos);
+ write_result = write(2,buf,pos);
+ if (write_result == -1) {
+ dbg(lvl_warning, "Writing sig alrm ailed. Error-Code: %d", errno);
+ }
+ progress_time();
+ progress_memory();
#ifndef _WIN32
- write_result = write(2,"\r\n",2);
- if (write_result == -1){
- dbg(lvl_warning, "Writing new line in sig alrm ailed. Error-Code: %d" , errno);
- }
+ write_result = write(2,"\r\n",2);
+ if (write_result == -1) {
+ dbg(lvl_warning, "Writing new line in sig alrm ailed. Error-Code: %d", errno);
+ }
#else
- write_result = write(2,"\n",1);
- if (write_result == -1){
- dbg(lvl_warning, "Writing new line in sig alrm ailed. Error-Code: %d" , errno);
- }
+ write_result = write(2,"\n",1);
+ if (write_result == -1) {
+ dbg(lvl_warning, "Writing new line in sig alrm ailed. Error-Code: %d", errno);
+ }
#endif
}
void
-sig_alrm(int sig)
-{
- fflush(stderr);
- sig_alrm_do(sig);
+sig_alrm(int sig) {
+ fflush(stderr);
+ sig_alrm_do(sig);
}
void
-sig_alrm_end(void)
-{
+sig_alrm_end(void) {
#ifndef _WIN32
- alarm(0);
+ alarm(0);
#endif
}
static struct files_relation_processing *
files_relation_processing_new(FILE *line2poi, char *suffix) {
- struct files_relation_processing *result = g_new(struct files_relation_processing, 1);
- result->ways_in=tempfile(suffix,"ways_split",0);
- result->ways_out=tempfile(suffix,"ways_split_relproc_tmp",1);
- result->nodes_in=tempfile(suffix,"nodes",0);
- result->nodes_out=tempfile(suffix,"nodes_relproc_tmp",1);
- result->nodes2_in=NULL;
- result->nodes2_out=NULL;
- if(line2poi) {
- result->nodes2_in=tempfile(suffix,"way2poi_result",0);
- result->nodes2_out=tempfile(suffix,"way2poi_result_relproc_tmp",1);
- }
- return result;
+ struct files_relation_processing *result = g_new(struct files_relation_processing, 1);
+ result->ways_in=tempfile(suffix,"ways_split",0);
+ result->ways_out=tempfile(suffix,"ways_split_relproc_tmp",1);
+ result->nodes_in=tempfile(suffix,"nodes",0);
+ result->nodes_out=tempfile(suffix,"nodes_relproc_tmp",1);
+ result->nodes2_in=NULL;
+ result->nodes2_out=NULL;
+ if(line2poi) {
+ result->nodes2_in=tempfile(suffix,"way2poi_result",0);
+ result->nodes2_out=tempfile(suffix,"way2poi_result_relproc_tmp",1);
+ }
+ return result;
}
static void
files_relation_processing_destroy(struct files_relation_processing *files_relproc, char *suffix) {
- fclose(files_relproc->ways_in);
- fclose(files_relproc->nodes_in);
- fclose(files_relproc->ways_out);
- fclose(files_relproc->nodes_out);
- tempfile_rename(suffix,"ways_split_relproc_tmp","ways_split");
- tempfile_rename(suffix,"nodes_relproc_tmp","nodes");
- if(files_relproc->nodes2_in) {
- fclose(files_relproc->nodes2_in);
- fclose(files_relproc->nodes2_out);
- tempfile_rename(suffix,"way2poi_result_relproc_tmp","way2poi_result");
- }
- g_free(files_relproc);
+ fclose(files_relproc->ways_in);
+ fclose(files_relproc->nodes_in);
+ fclose(files_relproc->ways_out);
+ fclose(files_relproc->nodes_out);
+ tempfile_rename(suffix,"ways_split_relproc_tmp","ways_split");
+ tempfile_rename(suffix,"nodes_relproc_tmp","nodes");
+ if(files_relproc->nodes2_in) {
+ fclose(files_relproc->nodes2_in);
+ fclose(files_relproc->nodes2_out);
+ tempfile_rename(suffix,"way2poi_result_relproc_tmp","way2poi_result");
+ }
+ g_free(files_relproc);
}
static struct plugins *plugins;
-static void add_plugin(char *path)
-{
- struct attr pa_attr={attr_path};
- struct attr pl_attr={attr_plugins};
- struct attr *attrs[2]={&pa_attr,NULL};
+static void add_plugin(char *path) {
+ struct attr pa_attr= {attr_path};
+ struct attr pl_attr= {attr_plugins};
+ struct attr *attrs[2]= {&pa_attr,NULL};
- if (! plugins) {
- file_init();
- plugins=plugins_new();
- }
- pa_attr.u.str=path;
- pl_attr.u.plugins=plugins;
- plugin_new(&pl_attr,attrs);
+ if (! plugins) {
+ file_init();
+ plugins=plugins_new();
+ }
+ pa_attr.u.str=path;
+ pl_attr.u.plugins=plugins;
+ plugin_new(&pl_attr,attrs);
}
static void
-maptool_init(FILE* rule_file)
-{
- if (plugins)
- plugins_init(plugins);
- osm_init(rule_file);
+maptool_init(FILE* rule_file) {
+ if (plugins)
+ plugins_init(plugins);
+ osm_init(rule_file);
}
static void
-usage(void)
-{
- FILE *f = stdout;
- /* DEVELOPERS : don't forget to update the manpage if you modify theses options */
- fprintf(f,"\n");
- fprintf(f,"maptool - parse osm textfile and convert to Navit binfile format\n\n");
- fprintf(f,"Usage (for OSM XML data):\n");
- fprintf(f,"bzcat planet.osm.bz2 | maptool mymap.bin\n");
- fprintf(f,"Usage (for OSM Protobuf/PBF data):\n");
- fprintf(f,"maptool --protobuf -i planet.osm.pbf planet.bin\n");
- fprintf(f,"Available switches:\n");
- fprintf(f,"-h (--help) : this screen\n");
- fprintf(f,"-6 (--64bit) : set zip 64 bit compression\n");
- fprintf(f,"-a (--attr-debug-level) <level> : control which data is included in the debug attribute\n");
- fprintf(f,"-c (--dump-coordinates) : dump coordinates after phase 1\n");
+usage(void) {
+ FILE *f = stdout;
+ /* DEVELOPERS : don't forget to update the manpage if you modify theses options */
+ fprintf(f,"\n");
+ fprintf(f,"maptool - parse osm textfile and convert to Navit binfile format\n\n");
+ fprintf(f,"Usage (for OSM XML data):\n");
+ fprintf(f,"bzcat planet.osm.bz2 | maptool mymap.bin\n");
+ fprintf(f,"Usage (for OSM Protobuf/PBF data):\n");
+ fprintf(f,"maptool --protobuf -i planet.osm.pbf planet.bin\n");
+ fprintf(f,"Available switches:\n");
+ fprintf(f,"-h (--help) : this screen\n");
+ fprintf(f,"-6 (--64bit) : set zip 64 bit compression\n");
+ fprintf(f,"-a (--attr-debug-level) <level> : control which data is included in the debug attribute\n");
+ fprintf(f,"-c (--dump-coordinates) : dump coordinates after phase 1\n");
#ifdef HAVE_POSTGRESQL
- fprintf(f,"-d (--db) <conn. string> : get osm data out of a postgresql database with osm simple scheme and given connect string\n");
+ fprintf(f,
+ "-d (--db) <conn. string> : get osm data out of a postgresql database with osm simple scheme and given connect string\n");
#endif
- fprintf(f,"-D (--dump) : dump map data to standard output in Navit textfile format\n");
- fprintf(f,"-e (--end) <phase> : end at specified phase\n");
- fprintf(f,"-E (--experimental) : Enable experimental features (%s)\n",
- experimental_feature_description ? experimental_feature_description : "-not available in this version-");
- fprintf(f,"-i (--input-file) <file> : specify the input file name (OSM), overrules default stdin\n");
- fprintf(f,"-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n");
- fprintf(f,"-M (--o5m) : input data is in o5m format\n");
- fprintf(f,"-n (--ignore-unknown) : do not output ways and nodes with unknown type\n");
- fprintf(f,"-N (--nodes-only) : process only nodes\n");
- fprintf(f,"-P (--protobuf) : input data is in pbf (Protocol Buffer) format\n");
- fprintf(f,"-r (--rule-file) <file> : read mapping rules from specified file\n");
- fprintf(f,"-s (--start) <phase> : start at specified phase\n");
- fprintf(f,"-S (--slice-size) <size> : limit memory to use for some large internal buffers, in bytes. Default is %dGB.\n", SLIZE_SIZE_DEFAULT_GB);
- fprintf(f,"-t (--timestamp) <y-m-dTh:m:s> : Set zip timestamp\n");
- fprintf(f,"-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n");
- fprintf(f,"-W (--ways-only) : process only ways\n");
- fprintf(f,"-U (--unknown-country) : add objects with unknown country to index\n");
- fprintf(f,"-x (--index-size) : set maximum country index size in bytes\n");
- fprintf(f,"-z (--compression-level) <level> : set the compression level\n");
- fprintf(f,"Internal options (undocumented):\n");
- fprintf(f,"-b (--binfile)\n");
- fprintf(f,"-B \n");
- fprintf(f,"-m (--map) \n");
- fprintf(f,"-O \n");
- fprintf(f,"-p (--plugin) \n");
- fprintf(f,"-u (--url) \n");
-
- exit(0);
+ fprintf(f,"-D (--dump) : dump map data to standard output in Navit textfile format\n");
+ fprintf(f,"-e (--end) <phase> : end at specified phase\n");
+ fprintf(f,"-E (--experimental) : Enable experimental features (%s)\n",
+ experimental_feature_description ? experimental_feature_description : "-not available in this version-");
+ fprintf(f,"-i (--input-file) <file> : specify the input file name (OSM), overrules default stdin\n");
+ fprintf(f,"-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n");
+ fprintf(f,"-M (--o5m) : input data is in o5m format\n");
+ fprintf(f,"-n (--ignore-unknown) : do not output ways and nodes with unknown type\n");
+ fprintf(f,"-N (--nodes-only) : process only nodes\n");
+ fprintf(f,"-P (--protobuf) : input data is in pbf (Protocol Buffer) format\n");
+ fprintf(f,"-r (--rule-file) <file> : read mapping rules from specified file\n");
+ fprintf(f,"-s (--start) <phase> : start at specified phase\n");
+ fprintf(f,
+ "-S (--slice-size) <size> : limit memory to use for some large internal buffers, in bytes. Default is %dGB.\n",
+ SLIZE_SIZE_DEFAULT_GB);
+ fprintf(f,"-t (--timestamp) <y-m-dTh:m:s> : Set zip timestamp\n");
+ fprintf(f,
+ "-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n");
+ fprintf(f,"-W (--ways-only) : process only ways\n");
+ fprintf(f,"-U (--unknown-country) : add objects with unknown country to index\n");
+ fprintf(f,"-x (--index-size) : set maximum country index size in bytes\n");
+ fprintf(f,"-z (--compression-level) <level> : set the compression level\n");
+ fprintf(f,"Internal options (undocumented):\n");
+ fprintf(f,"-b (--binfile)\n");
+ fprintf(f,"-B \n");
+ fprintf(f,"-m (--map) \n");
+ fprintf(f,"-O \n");
+ fprintf(f,"-p (--plugin) \n");
+ fprintf(f,"-u (--url) \n");
+
+ exit(0);
}
struct maptool_params {
- int zip64;
- int keep_tmpfiles;
- int process_nodes;
- int process_ways;
- int process_relations;
- char *protobufdb;
- char *protobufdb_operation;
- int start;
- int end;
- int dump;
- int o5m;
- int compression_level;
- int protobuf;
- int dump_coordinates;
- int input;
- GList *map_handles;
- FILE* input_file;
- FILE* rule_file;
- char *url;
- struct maptool_osm osm;
- FILE *ways_split;
- char *timestamp;
- char *result;
- char *dbstr;
- int node_table_loaded;
- int countries_loaded;
- int tilesdir_loaded;
- int max_index_size;
+ int zip64;
+ int keep_tmpfiles;
+ int process_nodes;
+ int process_ways;
+ int process_relations;
+ char *protobufdb;
+ char *protobufdb_operation;
+ int start;
+ int end;
+ int dump;
+ int o5m;
+ int compression_level;
+ int protobuf;
+ int dump_coordinates;
+ int input;
+ GList *map_handles;
+ FILE* input_file;
+ FILE* rule_file;
+ char *url;
+ struct maptool_osm osm;
+ FILE *ways_split;
+ char *timestamp;
+ char *result;
+ char *dbstr;
+ int node_table_loaded;
+ int countries_loaded;
+ int tilesdir_loaded;
+ int max_index_size;
};
static int
-parse_option(struct maptool_params *p, char **argv, int argc, int *option_index)
-{
- char *optarg_cp,*attr_name,*attr_value;
- struct map *handle;
- struct attr *attrs[10];
- int pos,c,i;
+parse_option(struct maptool_params *p, char **argv, int argc, int *option_index) {
+ char *optarg_cp,*attr_name,*attr_value;
+ struct map *handle;
+ struct attr *attrs[10];
+ int pos,c,i;
- static struct option long_options[] = {
- {"64bit", 0, 0, '6'},
- {"attr-debug-level", 1, 0, 'a'},
- {"binfile", 0, 0, 'b'},
- {"compression-level", 1, 0, 'z'},
+ static struct option long_options[] = {
+ {"64bit", 0, 0, '6'},
+ {"attr-debug-level", 1, 0, 'a'},
+ {"binfile", 0, 0, 'b'},
+ {"compression-level", 1, 0, 'z'},
#ifdef HAVE_POSTGRESQL
- {"db", 1, 0, 'd'},
+ {"db", 1, 0, 'd'},
#endif
- {"dedupe-ways", 0, 0, 'w'},
- {"dump", 0, 0, 'D'},
- {"dump-coordinates", 0, 0, 'c'},
- {"end", 1, 0, 'e'},
- {"experimental", 0, 0, 'E'},
- {"help", 0, 0, 'h'},
- {"keep-tmpfiles", 0, 0, 'k'},
- {"nodes-only", 0, 0, 'N'},
- {"map", 1, 0, 'm'},
- {"o5m", 0, 0, 'M'},
- {"plugin", 1, 0, 'p'},
- {"protobuf", 0, 0, 'P'},
- {"start", 1, 0, 's'},
- {"timestamp", 1, 0, 't'},
- {"input-file", 1, 0, 'i'},
- {"rule-file", 1, 0, 'r'},
- {"ignore-unknown", 0, 0, 'n'},
- {"url", 1, 0, 'u'},
- {"ways-only", 0, 0, 'W'},
- {"slice-size", 1, 0, 'S'},
- {"unknown-country", 0, 0, 'U'},
- {"index-size", 0, 0, 'x'},
- {0, 0, 0, 0}
- };
- c = getopt_long (argc, argv, "6B:DEMNO:PS:Wa:bc"
+ {"dedupe-ways", 0, 0, 'w'},
+ {"dump", 0, 0, 'D'},
+ {"dump-coordinates", 0, 0, 'c'},
+ {"end", 1, 0, 'e'},
+ {"experimental", 0, 0, 'E'},
+ {"help", 0, 0, 'h'},
+ {"keep-tmpfiles", 0, 0, 'k'},
+ {"nodes-only", 0, 0, 'N'},
+ {"map", 1, 0, 'm'},
+ {"o5m", 0, 0, 'M'},
+ {"plugin", 1, 0, 'p'},
+ {"protobuf", 0, 0, 'P'},
+ {"start", 1, 0, 's'},
+ {"timestamp", 1, 0, 't'},
+ {"input-file", 1, 0, 'i'},
+ {"rule-file", 1, 0, 'r'},
+ {"ignore-unknown", 0, 0, 'n'},
+ {"url", 1, 0, 'u'},
+ {"ways-only", 0, 0, 'W'},
+ {"slice-size", 1, 0, 'S'},
+ {"unknown-country", 0, 0, 'U'},
+ {"index-size", 0, 0, 'x'},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long (argc, argv, "6B:DEMNO:PS:Wa:bc"
#ifdef HAVE_POSTGRESQL
- "d:"
+ "d:"
#endif
- "e:hi:knm:p:r:s:t:wu:z:Ux:", long_options, option_index);
- if (c == -1)
- return 1;
- switch (c) {
- case '6':
- p->zip64=1;
- break;
- case 'B':
- p->protobufdb=optarg;
- break;
- case 'D':
- p->dump=1;
- break;
- case 'E':
- experimental=1;
- break;
- case 'M':
- p->o5m=1;
- break;
- case 'N':
- p->process_ways=0;
- break;
- case 'R':
- p->process_relations=0;
- break;
- case 'O':
- p->protobufdb_operation=optarg;
- p->dump=1;
- break;
- case 'P':
- p->protobuf=1;
- break;
- case 'S':
- slice_size=atoll(optarg);
- break;
- case 'W':
- p->process_nodes=0;
- break;
- case 'U':
- unknown_country=1;
- break;
- case 'a':
- attr_debug_level=atoi(optarg);
- break;
- case 'b':
- p->input=1;
- break;
- case 'c':
- p->dump_coordinates=1;
- break;
+ "e:hi:knm:p:r:s:t:wu:z:Ux:", long_options, option_index);
+ if (c == -1)
+ return 1;
+ switch (c) {
+ case '6':
+ p->zip64=1;
+ break;
+ case 'B':
+ p->protobufdb=optarg;
+ break;
+ case 'D':
+ p->dump=1;
+ break;
+ case 'E':
+ experimental=1;
+ break;
+ case 'M':
+ p->o5m=1;
+ break;
+ case 'N':
+ p->process_ways=0;
+ break;
+ case 'R':
+ p->process_relations=0;
+ break;
+ case 'O':
+ p->protobufdb_operation=optarg;
+ p->dump=1;
+ break;
+ case 'P':
+ p->protobuf=1;
+ break;
+ case 'S':
+ slice_size=atoll(optarg);
+ break;
+ case 'W':
+ p->process_nodes=0;
+ break;
+ case 'U':
+ unknown_country=1;
+ break;
+ case 'a':
+ attr_debug_level=atoi(optarg);
+ break;
+ case 'b':
+ p->input=1;
+ break;
+ case 'c':
+ p->dump_coordinates=1;
+ break;
#ifdef HAVE_POSTGRESQL
- case 'd':
- p->dbstr=optarg;
- break;
+ case 'd':
+ p->dbstr=optarg;
+ break;
#endif
- case 'e':
- p->end=atoi(optarg);
- break;
- case 'h':
- return 2;
- case 'm':
- optarg_cp=g_strdup(optarg);
- pos=0;
- i=0;
- attr_name=g_strdup(optarg);
- attr_value=g_strdup(optarg);
- while (i < 9 && attr_from_line(optarg_cp, NULL, &pos, attr_value, attr_name)) {
- attrs[i]=attr_new_from_text(attr_name,attr_value);
- if (attrs[i]) {
- i++;
- } else {
- fprintf(stderr,"Failed to convert %s=%s to attribute\n",attr_name,attr_value);
- }
- attr_value=g_strdup(optarg);
- }
- attrs[i++]=NULL;
- g_free(attr_value);
- g_free(optarg_cp);
- handle=map_new(NULL, attrs);
- if (! handle) {
- fprintf(stderr,"Failed to create map from attributes\n");
- exit(1);
- }
- p->map_handles=g_list_append(p->map_handles,handle);
- break;
- case 'n':
- fprintf(stderr,"I will IGNORE unknown types\n");
- ignore_unknown=1;
- break;
- case 'k':
- fprintf(stderr,"I will KEEP tmp files\n");
- p->keep_tmpfiles=1;
- break;
- case 'p':
- add_plugin(optarg);
- break;
- case 's':
- p->start=atoi(optarg);
- break;
- case 't':
- p->timestamp=optarg;
- break;
- case 'w':
- dedupe_ways_hash=g_hash_table_new(NULL, NULL);
- break;
- case 'i':
- p->input_file = fopen( optarg, "r" );
- if (p->input_file == NULL )
- {
- fprintf( stderr, "\nInput file (%s) not found\n", optarg );
- exit( 1 );
- }
- break;
- case 'r':
- p->rule_file = fopen( optarg, "r" );
- if (p->rule_file == NULL )
- {
- fprintf( stderr, "\nRule file (%s) not found\n", optarg );
- exit( 1 );
- }
- break;
- case 'u':
- p->url=optarg;
- break;
- case 'x':
- p->max_index_size=atoi(optarg);
- break;
+ case 'e':
+ p->end=atoi(optarg);
+ break;
+ case 'h':
+ return 2;
+ case 'm':
+ optarg_cp=g_strdup(optarg);
+ pos=0;
+ i=0;
+ attr_name=g_strdup(optarg);
+ attr_value=g_strdup(optarg);
+ while (i < 9 && attr_from_line(optarg_cp, NULL, &pos, attr_value, attr_name)) {
+ attrs[i]=attr_new_from_text(attr_name,attr_value);
+ if (attrs[i]) {
+ i++;
+ } else {
+ fprintf(stderr,"Failed to convert %s=%s to attribute\n",attr_name,attr_value);
+ }
+ attr_value=g_strdup(optarg);
+ }
+ attrs[i++]=NULL;
+ g_free(attr_value);
+ g_free(optarg_cp);
+ handle=map_new(NULL, attrs);
+ if (! handle) {
+ fprintf(stderr,"Failed to create map from attributes\n");
+ exit(1);
+ }
+ p->map_handles=g_list_append(p->map_handles,handle);
+ break;
+ case 'n':
+ fprintf(stderr,"I will IGNORE unknown types\n");
+ ignore_unknown=1;
+ break;
+ case 'k':
+ fprintf(stderr,"I will KEEP tmp files\n");
+ p->keep_tmpfiles=1;
+ break;
+ case 'p':
+ add_plugin(optarg);
+ break;
+ case 's':
+ p->start=atoi(optarg);
+ break;
+ case 't':
+ p->timestamp=optarg;
+ break;
+ case 'w':
+ dedupe_ways_hash=g_hash_table_new(NULL, NULL);
+ break;
+ case 'i':
+ p->input_file = fopen( optarg, "r" );
+ if (p->input_file == NULL ) {
+ fprintf( stderr, "\nInput file (%s) not found\n", optarg );
+ exit( 1 );
+ }
+ break;
+ case 'r':
+ p->rule_file = fopen( optarg, "r" );
+ if (p->rule_file == NULL ) {
+ fprintf( stderr, "\nRule file (%s) not found\n", optarg );
+ exit( 1 );
+ }
+ break;
+ case 'u':
+ p->url=optarg;
+ break;
+ case 'x':
+ p->max_index_size=atoi(optarg);
+ break;
#ifdef HAVE_ZLIB
- case 'z':
- p->compression_level=atoi(optarg);
- break;
+ case 'z':
+ p->compression_level=atoi(optarg);
+ break;
#endif
- case '?':
- default:
- return 0;
- }
- return 3;
+ case '?':
+ default:
+ return 0;
+ }
+ return 3;
}
static int
-start_phase(struct maptool_params *p, char *str)
-{
- phase++;
- if (p->start <= phase && p->end >= phase) {
- fprintf(stderr,"PROGRESS: Phase %d: %s",phase,str);
- fflush(stderr);
- progress_time();
- progress_memory();
- fprintf(stderr,"\n");
- return 1;
- } else
- return 0;
+start_phase(struct maptool_params *p, char *str) {
+ phase++;
+ if (p->start <= phase && p->end >= phase) {
+ fprintf(stderr,"PROGRESS: Phase %d: %s",phase,str);
+ fflush(stderr);
+ progress_time();
+ progress_memory();
+ fprintf(stderr,"\n");
+ return 1;
+ } else
+ return 0;
}
static void
exit_with_error(char* error_message) {
- fprintf(stderr, "%s", error_message);
- exit(1);
+ fprintf(stderr, "%s", error_message);
+ exit(1);
}
static void
-osm_read_input_data(struct maptool_params *p, char *suffix)
-{
- unlink("coords.tmp");
- if (p->process_ways)
- p->osm.ways=tempfile(suffix,"ways",1);
- if (p->process_nodes) {
- p->osm.nodes=tempfile(suffix,"nodes",1);
- p->osm.towns=tempfile(suffix,"towns",1);
- }
- if (p->process_ways && p->process_nodes) {
- p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",1);
- p->osm.line2poi=tempfile(suffix,"line2poi",1);
- p->osm.poly2poi=tempfile(suffix,"poly2poi",1);
- }
- if (p->process_relations) {
- p->osm.boundaries=tempfile(suffix,"boundaries",1);
- p->osm.associated_streets=tempfile(suffix,"associated_streets",1);
- p->osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",1);
- }
+osm_read_input_data(struct maptool_params *p, char *suffix) {
+ unlink("coords.tmp");
+ if (p->process_ways)
+ p->osm.ways=tempfile(suffix,"ways",1);
+ if (p->process_nodes) {
+ p->osm.nodes=tempfile(suffix,"nodes",1);
+ p->osm.towns=tempfile(suffix,"towns",1);
+ }
+ if (p->process_ways && p->process_nodes) {
+ p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",1);
+ p->osm.line2poi=tempfile(suffix,"line2poi",1);
+ p->osm.poly2poi=tempfile(suffix,"poly2poi",1);
+ }
+ if (p->process_relations) {
+ p->osm.boundaries=tempfile(suffix,"boundaries",1);
+ p->osm.associated_streets=tempfile(suffix,"associated_streets",1);
+ p->osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",1);
+ }
#ifdef HAVE_POSTGRESQL
- if (p->dbstr)
- map_collect_data_osm_db(p->dbstr,&p->osm);
- else
+ if (p->dbstr)
+ map_collect_data_osm_db(p->dbstr,&p->osm);
+ else
#endif
- if (p->map_handles) {
- GList *l;
- phase1_map(p->map_handles,p->osm.ways,p->osm.nodes);
- l=p->map_handles;
- while (l) {
- map_destroy(l->data);
- l=g_list_next(l);
- }
- }
- else if (p->protobuf) {
+ if (p->map_handles) {
+ GList *l;
+ phase1_map(p->map_handles,p->osm.ways,p->osm.nodes);
+ l=p->map_handles;
+ while (l) {
+ map_destroy(l->data);
+ l=g_list_next(l);
+ }
+ } else if (p->protobuf) {
#ifdef _MSC_VER
- exit_with_error("Option -P not yet supported on MSVC\n");
+ exit_with_error("Option -P not yet supported on MSVC\n");
#else
- map_collect_data_osm_protobuf(p->input_file,&p->osm);
+ map_collect_data_osm_protobuf(p->input_file,&p->osm);
#endif
- }
- else if (p->o5m)
- map_collect_data_osm_o5m(p->input_file,&p->osm);
- else
- map_collect_data_osm(p->input_file,&p->osm);
+ } else if (p->o5m)
+ map_collect_data_osm_o5m(p->input_file,&p->osm);
+ else
+ map_collect_data_osm(p->input_file,&p->osm);
- if (node_buffer.size==0 && !p->map_handles){
- fprintf(stderr,"No nodes found - looks like an invalid input file.\n");
- exit(1);
- }
- flush_nodes(1);
- if (p->osm.ways)
- fclose(p->osm.ways);
- if (p->osm.nodes)
- fclose(p->osm.nodes);
- if (p->osm.turn_restrictions)
- fclose(p->osm.turn_restrictions);
- if (p->osm.associated_streets)
- fclose(p->osm.associated_streets);
- if (p->osm.house_number_interpolations)
- fclose(p->osm.house_number_interpolations);
- if (p->osm.boundaries)
- fclose(p->osm.boundaries);
- if (p->osm.poly2poi)
- fclose(p->osm.poly2poi);
- if (p->osm.line2poi)
- fclose(p->osm.line2poi);
- if (p->osm.towns)
- fclose(p->osm.towns);
+ if (node_buffer.size==0 && !p->map_handles) {
+ fprintf(stderr,"No nodes found - looks like an invalid input file.\n");
+ exit(1);
+ }
+ flush_nodes(1);
+ if (p->osm.ways)
+ fclose(p->osm.ways);
+ if (p->osm.nodes)
+ fclose(p->osm.nodes);
+ if (p->osm.turn_restrictions)
+ fclose(p->osm.turn_restrictions);
+ if (p->osm.associated_streets)
+ fclose(p->osm.associated_streets);
+ if (p->osm.house_number_interpolations)
+ fclose(p->osm.house_number_interpolations);
+ if (p->osm.boundaries)
+ fclose(p->osm.boundaries);
+ if (p->osm.poly2poi)
+ fclose(p->osm.poly2poi);
+ if (p->osm.line2poi)
+ fclose(p->osm.line2poi);
+ if (p->osm.towns)
+ fclose(p->osm.towns);
}
int debug_ref=0;
static void
-osm_count_references(struct maptool_params *p, char *suffix, int clear)
-{
- int i,first=1;
- fprintf(stderr,"%d slices\n",slices);
- for (i = slices-1 ; i>=0 ; i--) {
- fprintf(stderr, "slice %d of %d\n",slices-i-1,slices-1);
- if (!first) {
- FILE *ways=tempfile(suffix,"ways",0);
- load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size);
- if (clear)
- clear_node_item_buffer();
- ref_ways(ways);
- save_buffer("coords.tmp",&node_buffer, i*slice_size);
- fclose(ways);
- }
- FILE *poly2poi=tempfile(suffix,first?"poly2poi":"poly2poi_resolved",0);
- FILE *poly2poinew=tempfile(suffix,"poly2poi_resolved_new",1);
- FILE *line2poi=tempfile(suffix,first?"line2poi":"line2poi_resolved",0);
- FILE *line2poinew=tempfile(suffix,"line2poi_resolved_new",1);
- resolve_ways(poly2poi, poly2poinew);
- resolve_ways(line2poi, line2poinew);
- fclose(poly2poi);
- fclose(poly2poinew);
- fclose(line2poi);
- fclose(line2poinew);
- tempfile_rename(suffix,"poly2poi_resolved_new","poly2poi_resolved");
- tempfile_rename(suffix,"line2poi_resolved_new","line2poi_resolved");
- if (first && !p->keep_tmpfiles) {
- tempfile_unlink(suffix,"poly2poi");
- tempfile_unlink(suffix,"line2poi");
- }
- first=0;
- }
+osm_count_references(struct maptool_params *p, char *suffix, int clear) {
+ int i,first=1;
+ fprintf(stderr,"%d slices\n",slices);
+ for (i = slices-1 ; i>=0 ; i--) {
+ fprintf(stderr, "slice %d of %d\n",slices-i-1,slices-1);
+ if (!first) {
+ FILE *ways=tempfile(suffix,"ways",0);
+ load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size);
+ if (clear)
+ clear_node_item_buffer();
+ ref_ways(ways);
+ save_buffer("coords.tmp",&node_buffer, i*slice_size);
+ fclose(ways);
+ }
+ FILE *poly2poi=tempfile(suffix,first?"poly2poi":"poly2poi_resolved",0);
+ FILE *poly2poinew=tempfile(suffix,"poly2poi_resolved_new",1);
+ FILE *line2poi=tempfile(suffix,first?"line2poi":"line2poi_resolved",0);
+ FILE *line2poinew=tempfile(suffix,"line2poi_resolved_new",1);
+ resolve_ways(poly2poi, poly2poinew);
+ resolve_ways(line2poi, line2poinew);
+ fclose(poly2poi);
+ fclose(poly2poinew);
+ fclose(line2poi);
+ fclose(line2poinew);
+ tempfile_rename(suffix,"poly2poi_resolved_new","poly2poi_resolved");
+ tempfile_rename(suffix,"line2poi_resolved_new","line2poi_resolved");
+ if (first && !p->keep_tmpfiles) {
+ tempfile_unlink(suffix,"poly2poi");
+ tempfile_unlink(suffix,"line2poi");
+ }
+ first=0;
+ }
}
static void
-osm_resolve_coords_and_split_at_intersections(struct maptool_params *p, char *suffix)
-{
- FILE *ways, *ways_split, *ways_split_index, *graph, *coastline;
- int i;
+osm_resolve_coords_and_split_at_intersections(struct maptool_params *p, char *suffix) {
+ FILE *ways, *ways_split, *ways_split_index, *graph, *coastline;
+ int i;
- ways=tempfile(suffix,"ways",0);
- for (i = 0 ; i < slices ; i++) {
- int final=(i >= slices-1);
- ways_split=tempfile(suffix,"ways_split",1);
- ways_split_index=final ? tempfile(suffix,"ways_split_index",1) : NULL;
- graph=tempfile(suffix,"graph",1);
- coastline=tempfile(suffix,"coastline",1);
- if (i)
- load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size);
- map_resolve_coords_and_split_at_intersections(ways,ways_split,ways_split_index,graph,coastline,final);
- fclose(ways_split);
- if (ways_split_index)
- fclose(ways_split_index);
- fclose(ways);
- fclose(graph);
- fclose(coastline);
- if (! final) {
- tempfile_rename(suffix,"ways_split","ways_to_resolve");
- ways=tempfile(suffix,"ways_to_resolve",0);
- }
- }
- if(!p->keep_tmpfiles)
- tempfile_unlink(suffix,"ways");
- tempfile_unlink(suffix,"ways_to_resolve");
+ ways=tempfile(suffix,"ways",0);
+ for (i = 0 ; i < slices ; i++) {
+ int final=(i >= slices-1);
+ ways_split=tempfile(suffix,"ways_split",1);
+ ways_split_index=final ? tempfile(suffix,"ways_split_index",1) : NULL;
+ graph=tempfile(suffix,"graph",1);
+ coastline=tempfile(suffix,"coastline",1);
+ if (i)
+ load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size);
+ map_resolve_coords_and_split_at_intersections(ways,ways_split,ways_split_index,graph,coastline,final);
+ fclose(ways_split);
+ if (ways_split_index)
+ fclose(ways_split_index);
+ fclose(ways);
+ fclose(graph);
+ fclose(coastline);
+ if (! final) {
+ tempfile_rename(suffix,"ways_split","ways_to_resolve");
+ ways=tempfile(suffix,"ways_to_resolve",0);
+ }
+ }
+ if(!p->keep_tmpfiles)
+ tempfile_unlink(suffix,"ways");
+ tempfile_unlink(suffix,"ways_to_resolve");
}
static void
-osm_process_way2poi(struct maptool_params *p, char *suffix)
-{
- FILE *poly2poi=tempfile(suffix,"poly2poi_resolved",0);
- FILE *line2poi=tempfile(suffix,"line2poi_resolved",0);
- FILE *way2poi_result=tempfile(suffix,"way2poi_result",1);
- if (poly2poi) {
- process_way2poi(poly2poi, way2poi_result, type_area);
- fclose(poly2poi);
- }
- if (line2poi) {
- process_way2poi(line2poi, way2poi_result, type_line);
- fclose(line2poi);
- }
- fclose(way2poi_result);
+osm_process_way2poi(struct maptool_params *p, char *suffix) {
+ FILE *poly2poi=tempfile(suffix,"poly2poi_resolved",0);
+ FILE *line2poi=tempfile(suffix,"line2poi_resolved",0);
+ FILE *way2poi_result=tempfile(suffix,"way2poi_result",1);
+ if (poly2poi) {
+ process_way2poi(poly2poi, way2poi_result, type_area);
+ fclose(poly2poi);
+ }
+ if (line2poi) {
+ process_way2poi(line2poi, way2poi_result, type_line);
+ fclose(line2poi);
+ }
+ fclose(way2poi_result);
}
static void
-osm_process_coastlines(struct maptool_params *p, char *suffix)
-{
- FILE *coastline=tempfile(suffix,"coastline",0);
- if (coastline) {
- FILE *coastline_result=tempfile(suffix,"coastline_result",1);
- process_coastlines(coastline, coastline_result);
- fclose(coastline_result);
- fclose(coastline);
- }
+osm_process_coastlines(struct maptool_params *p, char *suffix) {
+ FILE *coastline=tempfile(suffix,"coastline",0);
+ if (coastline) {
+ FILE *coastline_result=tempfile(suffix,"coastline_result",1);
+ process_coastlines(coastline, coastline_result);
+ fclose(coastline_result);
+ fclose(coastline);
+ }
}
static void
-osm_process_turn_restrictions(struct maptool_params *p, char *suffix)
-{
- FILE *ways_split, *ways_split_index, *relations, *coords;
- p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",0);
- if (!p->osm.turn_restrictions)
- return;
- relations=tempfile(suffix,"relations",1);
- coords=fopen("coords.tmp","rb");
- ways_split=tempfile(suffix,"ways_split",0);
- ways_split_index=tempfile(suffix,"ways_split_index",0);
- process_turn_restrictions(p->osm.turn_restrictions,coords,ways_split,ways_split_index,relations);
- fclose(ways_split_index);
- fclose(ways_split);
- fclose(coords);
- fclose(relations);
- fclose(p->osm.turn_restrictions);
- if(!p->keep_tmpfiles)
- tempfile_unlink(suffix,"turn_restrictions");
+osm_process_turn_restrictions(struct maptool_params *p, char *suffix) {
+ FILE *ways_split, *ways_split_index, *relations, *coords;
+ p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",0);
+ if (!p->osm.turn_restrictions)
+ return;
+ relations=tempfile(suffix,"relations",1);
+ coords=fopen("coords.tmp","rb");
+ ways_split=tempfile(suffix,"ways_split",0);
+ ways_split_index=tempfile(suffix,"ways_split_index",0);
+ process_turn_restrictions(p->osm.turn_restrictions,coords,ways_split,ways_split_index,relations);
+ fclose(ways_split_index);
+ fclose(ways_split);
+ fclose(coords);
+ fclose(relations);
+ fclose(p->osm.turn_restrictions);
+ if(!p->keep_tmpfiles)
+ tempfile_unlink(suffix,"turn_restrictions");
}
static void
-maptool_dump(struct maptool_params *p, char *suffix)
-{
- char *files[10];
- int i,files_count=0;
- if (p->process_nodes)
- files[files_count++]="nodes";
- if (p->process_ways)
- files[files_count++]="ways_split";
- if (p->process_relations)
- files[files_count++]="relations";
- for (i = 0 ; i < files_count ; i++) {
- FILE *f=tempfile(suffix,files[i],0);
- if (f) {
- dump(f);
- fclose(f);
- }
- }
+maptool_dump(struct maptool_params *p, char *suffix) {
+ char *files[10];
+ int i,files_count=0;
+ if (p->process_nodes)
+ files[files_count++]="nodes";
+ if (p->process_ways)
+ files[files_count++]="ways_split";
+ if (p->process_relations)
+ files[files_count++]="relations";
+ for (i = 0 ; i < files_count ; i++) {
+ FILE *f=tempfile(suffix,files[i],0);
+ if (f) {
+ dump(f);
+ fclose(f);
+ }
+ }
}
static void
-maptool_generate_tiles(struct maptool_params *p, char *suffix, char **filenames, int filename_count, int first, char *suffix0)
-{
- struct zip_info *zip_info;
- FILE *tilesdir;
- FILE *files[10];
- int zipnum, f;
- if (first) {
- zip_info=zip_new();
- zip_set_zip64(zip_info, p->zip64);
- zip_set_timestamp(zip_info, p->timestamp);
- }
- zipnum=zip_get_zipnum(zip_info);
- tilesdir=tempfile(suffix,"tilesdir",1);
- if (!strcmp(suffix,ch_suffix)) { /* Makes compiler happy due to bug 35903 in gcc */
- ch_generate_tiles(suffix0,suffix,tilesdir,zip_info);
- } else {
- for (f = 0 ; f < filename_count ; f++)
- files[f]=tempfile(suffix,filenames[f],0);
- phase4(files,filename_count,0,suffix,tilesdir,zip_info);
- for (f = 0 ; f < filename_count ; f++) {
- if (files[f])
- fclose(files[f]);
- }
- }
- fclose(tilesdir);
- zip_set_zipnum(zip_info,zipnum);
+maptool_generate_tiles(struct maptool_params *p, char *suffix, char **filenames, int filename_count, int first,
+ char *suffix0) {
+ struct zip_info *zip_info;
+ FILE *tilesdir;
+ FILE *files[10];
+ int zipnum, f;
+ if (first) {
+ zip_info=zip_new();
+ zip_set_zip64(zip_info, p->zip64);
+ zip_set_timestamp(zip_info, p->timestamp);
+ }
+ zipnum=zip_get_zipnum(zip_info);
+ tilesdir=tempfile(suffix,"tilesdir",1);
+ if (!strcmp(suffix,ch_suffix)) { /* Makes compiler happy due to bug 35903 in gcc */
+ ch_generate_tiles(suffix0,suffix,tilesdir,zip_info);
+ } else {
+ for (f = 0 ; f < filename_count ; f++)
+ files[f]=tempfile(suffix,filenames[f],0);
+ phase4(files,filename_count,0,suffix,tilesdir,zip_info);
+ for (f = 0 ; f < filename_count ; f++) {
+ if (files[f])
+ fclose(files[f]);
+ }
+ }
+ fclose(tilesdir);
+ zip_set_zipnum(zip_info,zipnum);
}
static void
-maptool_assemble_map(struct maptool_params *p, char *suffix, char **filenames, char **referencenames, int filename_count, int first, int last, char *suffix0)
-{
- FILE *files[10];
- FILE *references[10];
- struct zip_info *zip_info;
- int zipnum,f;
+maptool_assemble_map(struct maptool_params *p, char *suffix, char **filenames, char **referencenames,
+ int filename_count, int first, int last, char *suffix0) {
+ FILE *files[10];
+ FILE *references[10];
+ struct zip_info *zip_info;
+ int zipnum,f;
- if (first) {
- char *zipdir=tempfile_name("zipdir","");
- char *zipindex=tempfile_name("index","");
- zip_info=zip_new();
- zip_set_zip64(zip_info, p->zip64);
- zip_set_timestamp(zip_info, p->timestamp);
- zip_set_maxnamelen(zip_info, 14+strlen(suffix0));
- zip_set_compression_level(zip_info, p->compression_level);
- if(!zip_open(zip_info, p->result, zipdir, zipindex)) {
- fprintf(stderr,"Fatal: Could not write output file.\n");
- exit(1);
- }
- if (p->url) {
- map_information_attrs[1].type=attr_url;
- map_information_attrs[1].u.str=p->url;
- }
- index_init(zip_info, 1);
- }
- if (!strcmp(suffix,ch_suffix)) { /* Makes compiler happy due to bug 35903 in gcc */
- ch_assemble_map(suffix0,suffix,zip_info);
- } else {
- for (f = 0 ; f < filename_count ; f++) {
- files[f]=tempfile(suffix, filenames[f], 0);
- if (referencenames[f])
- references[f]=tempfile(suffix,referencenames[f],1);
- else
- references[f]=NULL;
- }
- phase5(files,references,filename_count,0,suffix,zip_info);
- for (f = 0 ; f < filename_count ; f++) {
- if (files[f])
- fclose(files[f]);
- if (references[f])
- fclose(references[f]);
- }
- }
- if(!p->keep_tmpfiles) {
- tempfile_unlink(suffix,"relations");
- tempfile_unlink(suffix,"nodes");
- tempfile_unlink(suffix,"ways_split");
- tempfile_unlink(suffix,"poly2poi_resolved");
- tempfile_unlink(suffix,"line2poi_resolved");
- tempfile_unlink(suffix,"ways_split_ref");
- tempfile_unlink(suffix,"coastline");
- tempfile_unlink(suffix,"turn_restrictions");
- tempfile_unlink(suffix,"graph");
- tempfile_unlink(suffix,"tilesdir");
- tempfile_unlink(suffix,"boundaries");
- tempfile_unlink(suffix,"way2poi_result");
- tempfile_unlink(suffix,"coastline_result");
- tempfile_unlink(suffix,"towns_poly");
- unlink("coords.tmp");
- }
- if (last) {
- zipnum=zip_get_zipnum(zip_info);
- add_aux_tiles("auxtiles.txt", zip_info);
- write_countrydir(zip_info,p->max_index_size);
- zip_set_zipnum(zip_info, zipnum);
- write_aux_tiles(zip_info);
- zip_write_index(zip_info);
- zip_write_directory(zip_info);
- zip_close(zip_info);
- if (!p->keep_tmpfiles) {
- remove_countryfiles();
- tempfile_unlink("index","");
- tempfile_unlink("zipdir","");
- }
- }
+ if (first) {
+ char *zipdir=tempfile_name("zipdir","");
+ char *zipindex=tempfile_name("index","");
+ zip_info=zip_new();
+ zip_set_zip64(zip_info, p->zip64);
+ zip_set_timestamp(zip_info, p->timestamp);
+ zip_set_maxnamelen(zip_info, 14+strlen(suffix0));
+ zip_set_compression_level(zip_info, p->compression_level);
+ if(!zip_open(zip_info, p->result, zipdir, zipindex)) {
+ fprintf(stderr,"Fatal: Could not write output file.\n");
+ exit(1);
+ }
+ if (p->url) {
+ map_information_attrs[1].type=attr_url;
+ map_information_attrs[1].u.str=p->url;
+ }
+ index_init(zip_info, 1);
+ }
+ if (!strcmp(suffix,ch_suffix)) { /* Makes compiler happy due to bug 35903 in gcc */
+ ch_assemble_map(suffix0,suffix,zip_info);
+ } else {
+ for (f = 0 ; f < filename_count ; f++) {
+ files[f]=tempfile(suffix, filenames[f], 0);
+ if (referencenames[f])
+ references[f]=tempfile(suffix,referencenames[f],1);
+ else
+ references[f]=NULL;
+ }
+ phase5(files,references,filename_count,0,suffix,zip_info);
+ for (f = 0 ; f < filename_count ; f++) {
+ if (files[f])
+ fclose(files[f]);
+ if (references[f])
+ fclose(references[f]);
+ }
+ }
+ if(!p->keep_tmpfiles) {
+ tempfile_unlink(suffix,"relations");
+ tempfile_unlink(suffix,"nodes");
+ tempfile_unlink(suffix,"ways_split");
+ tempfile_unlink(suffix,"poly2poi_resolved");
+ tempfile_unlink(suffix,"line2poi_resolved");
+ tempfile_unlink(suffix,"ways_split_ref");
+ tempfile_unlink(suffix,"coastline");
+ tempfile_unlink(suffix,"turn_restrictions");
+ tempfile_unlink(suffix,"graph");
+ tempfile_unlink(suffix,"tilesdir");
+ tempfile_unlink(suffix,"boundaries");
+ tempfile_unlink(suffix,"way2poi_result");
+ tempfile_unlink(suffix,"coastline_result");
+ tempfile_unlink(suffix,"towns_poly");
+ unlink("coords.tmp");
+ }
+ if (last) {
+ zipnum=zip_get_zipnum(zip_info);
+ add_aux_tiles("auxtiles.txt", zip_info);
+ write_countrydir(zip_info,p->max_index_size);
+ zip_set_zipnum(zip_info, zipnum);
+ write_aux_tiles(zip_info);
+ zip_write_index(zip_info);
+ zip_write_directory(zip_info);
+ zip_close(zip_info);
+ if (!p->keep_tmpfiles) {
+ remove_countryfiles();
+ tempfile_unlink("index","");
+ tempfile_unlink("zipdir","");
+ }
+ }
}
static void
-maptool_load_node_table(struct maptool_params *p, int last)
-{
- if (!p->node_table_loaded) {
- slices=(sizeof_buffer("coords.tmp")+(long long)slice_size-(long long)1)/(long long)slice_size;
- assert(slices>0);
- load_buffer("coords.tmp",&node_buffer,last?(slices-1)*slice_size:0, slice_size);
- p->node_table_loaded=1;
- }
+maptool_load_node_table(struct maptool_params *p, int last) {
+ if (!p->node_table_loaded) {
+ slices=(sizeof_buffer("coords.tmp")+(long long)slice_size-(long long)1)/(long long)slice_size;
+ assert(slices>0);
+ load_buffer("coords.tmp",&node_buffer,last?(slices-1)*slice_size:0, slice_size);
+ p->node_table_loaded=1;
+ }
}
static void
-maptool_load_countries(struct maptool_params *p)
-{
- if (!p->countries_loaded) {
- load_countries();
- p->countries_loaded=1;
- }
+maptool_load_countries(struct maptool_params *p) {
+ if (!p->countries_loaded) {
+ load_countries();
+ p->countries_loaded=1;
+ }
}
static void
-maptool_load_tilesdir(struct maptool_params *p, char *suffix)
-{
- if (!p->tilesdir_loaded) {
- FILE *tilesdir=tempfile(suffix,"tilesdir",0);
- load_tilesdir(tilesdir);
- p->tilesdir_loaded=1;
- }
+maptool_load_tilesdir(struct maptool_params *p, char *suffix) {
+ if (!p->tilesdir_loaded) {
+ FILE *tilesdir=tempfile(suffix,"tilesdir",0);
+ load_tilesdir(tilesdir);
+ p->tilesdir_loaded=1;
+ }
}
-int main(int argc, char **argv)
-{
- struct maptool_params p;
- char *suffixes[]={""};
- char *suffix=suffixes[0];
- char *filenames[20];
- char *referencenames[20];
- int filename_count=0;
+int main(int argc, char **argv) {
+ struct maptool_params p;
+ char *suffixes[]= {""};
+ char *suffix=suffixes[0];
+ char *filenames[20];
+ char *referencenames[20];
+ int filename_count=0;
- int suffix_count=sizeof(suffixes)/sizeof(char *);
- int i;
- int suffix_start=0;
- int option_index=0;
- main_init(argv[0]);
+ int suffix_count=sizeof(suffixes)/sizeof(char *);
+ int i;
+ int suffix_start=0;
+ int option_index=0;
+ main_init(argv[0]);
#ifndef HAVE_GLIB
- _g_slice_thread_init_nomessage();
+ _g_slice_thread_init_nomessage();
#endif
- linguistics_init();
+ linguistics_init();
- memset(&p, 0, sizeof(p));
+ memset(&p, 0, sizeof(p));
#ifdef HAVE_ZLIB
- p.compression_level=9;
+ p.compression_level=9;
#endif
- p.start=1;
- p.end=99;
- p.input_file=stdin;
- p.process_nodes=1;
- p.process_ways=1;
- p.process_relations=1;
- p.timestamp=current_to_iso8601();
- p.max_index_size=65536;
+ p.start=1;
+ p.end=99;
+ p.input_file=stdin;
+ p.process_nodes=1;
+ p.process_ways=1;
+ p.process_relations=1;
+ p.timestamp=current_to_iso8601();
+ p.max_index_size=65536;
#ifdef HAVE_SBRK
- start_brk=(long)sbrk(0);
+ start_brk=(long)sbrk(0);
#endif
#ifdef _WIN32
- gettimeofday(&start_ts,NULL);
+ gettimeofday(&start_ts,NULL);
#else
- clock_gettime(CLOCK_REALTIME, &start_ts);
+ clock_gettime(CLOCK_REALTIME, &start_ts);
#endif
- while (1) {
- int parse_result=parse_option(&p, argv, argc, &option_index);
- if (!parse_result) {
- exit(1);
- }
- if (parse_result == 1)
- break;
- if (parse_result == 2) {
- usage();
- exit(0);
- }
- }
- if (experimental && (!experimental_feature_description )) {
- exit_with_error("No experimental features available in this version, aborting. \n");
- }
- if (optind < argc -1) {
- exit_with_error("Only one non-option argument allowed.\n");
- }
- if (p.dump == 0 && optind != argc -1) {
- exit_with_error("Please specify an output file.\n");
- }
- if (p.dump == 1 && optind != argc) {
- exit_with_error("Please do not specify an output file in dump mode.\n");
- }
+ while (1) {
+ int parse_result=parse_option(&p, argv, argc, &option_index);
+ if (!parse_result) {
+ exit(1);
+ }
+ if (parse_result == 1)
+ break;
+ if (parse_result == 2) {
+ usage();
+ exit(0);
+ }
+ }
+ if (experimental && (!experimental_feature_description )) {
+ exit_with_error("No experimental features available in this version, aborting. \n");
+ }
+ if (optind < argc -1) {
+ exit_with_error("Only one non-option argument allowed.\n");
+ }
+ if (p.dump == 0 && optind != argc -1) {
+ exit_with_error("Please specify an output file.\n");
+ }
+ if (p.dump == 1 && optind != argc) {
+ exit_with_error("Please do not specify an output file in dump mode.\n");
+ }
- p.result=argv[optind];
+ p.result=argv[optind];
- // initialize plugins and OSM mappings
- maptool_init(p.rule_file);
- if (p.protobufdb_operation) {
+ // initialize plugins and OSM mappings
+ maptool_init(p.rule_file);
+ if (p.protobufdb_operation) {
#ifdef _MSC_VER
- exit_with_error("Option -O not yet supported on MSVC\n");
+ exit_with_error("Option -O not yet supported on MSVC\n");
#else
- osm_protobufdb_load(p.input_file, p.protobufdb);
- return 0;
+ osm_protobufdb_load(p.input_file, p.protobufdb);
+ return 0;
#endif
- }
- phase=0;
+ }
+ phase=0;
+
+ // input from an OSM file
+ if (p.input == 0) {
+ if (start_phase(&p, "reading input data")) {
+ osm_read_input_data(&p, suffix);
+ p.node_table_loaded=1;
+ }
+ if (start_phase(&p, "counting references and resolving ways")) {
+ maptool_load_node_table(&p,1);
+ osm_count_references(&p, suffix, p.start == phase);
+ }
+ if (start_phase(&p,"converting ways to pois")) {
+ osm_process_way2poi(&p, suffix);
+ }
+ if (start_phase(&p,"splitting at intersections")) {
+ if (p.process_ways) {
+ maptool_load_node_table(&p,0);
+ osm_resolve_coords_and_split_at_intersections(&p, suffix);
+ }
+ }
+ g_free(node_buffer.base);
+ node_buffer.base=NULL;
+ node_buffer.malloced=0;
+ node_buffer.size=0;
+ p.node_table_loaded=0;
+ } else {
+ if (start_phase(&p,"reading data")) {
+ FILE *ways_split=tempfile(suffix,"ways_split",1);
+ process_binfile(stdin, ways_split);
+ fclose(ways_split);
+ }
+ }
+ if (start_phase(&p,"generating coastlines")) {
+ osm_process_coastlines(&p, suffix);
+ }
+ if (start_phase(&p,"assigning towns to countries")) {
+ FILE *towns=tempfile(suffix,"towns",0),*boundaries=NULL,*ways=NULL;
+ if (towns) {
+ boundaries=tempfile(suffix,"boundaries",0);
+ ways=tempfile(suffix,"ways_split",0);
+ osm_process_towns(towns,boundaries,ways,suffix);
+ fclose(ways);
+ fclose(boundaries);
+ fclose(towns);
+ if(!p.keep_tmpfiles)
+ tempfile_unlink(suffix,"towns");
+ }
+ }
+ if (start_phase(&p,"sorting countries")) {
+ sort_countries(p.keep_tmpfiles);
+ p.countries_loaded=1;
+ }
+ if (start_phase(&p,"generating turn restrictions")) {
+ if (p.process_relations) {
+ osm_process_turn_restrictions(&p, suffix);
+ }
+ if(!p.keep_tmpfiles)
+ tempfile_unlink(suffix,"ways_split_index");
+ }
+ if (p.process_relations && p.process_ways && p.process_nodes
+ && start_phase(&p,"processing associated street relations")) {
+ struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix);
+ p.osm.associated_streets=tempfile(suffix,"associated_streets",0);
+ if (p.osm.associated_streets) {
- // input from an OSM file
- if (p.input == 0) {
- if (start_phase(&p, "reading input data")) {
- osm_read_input_data(&p, suffix);
- p.node_table_loaded=1;
- }
- if (start_phase(&p, "counting references and resolving ways")) {
- maptool_load_node_table(&p,1);
- osm_count_references(&p, suffix, p.start == phase);
- }
- if (start_phase(&p,"converting ways to pois")) {
- osm_process_way2poi(&p, suffix);
- }
- if (start_phase(&p,"splitting at intersections")) {
- if (p.process_ways) {
- maptool_load_node_table(&p,0);
- osm_resolve_coords_and_split_at_intersections(&p, suffix);
- }
- }
- g_free(node_buffer.base);
- node_buffer.base=NULL;
- node_buffer.malloced=0;
- node_buffer.size=0;
- p.node_table_loaded=0;
- } else {
- if (start_phase(&p,"reading data")) {
- FILE *ways_split=tempfile(suffix,"ways_split",1);
- process_binfile(stdin, ways_split);
- fclose(ways_split);
- }
- }
- if (start_phase(&p,"generating coastlines")) {
- osm_process_coastlines(&p, suffix);
- }
- if (start_phase(&p,"assigning towns to countries")) {
- FILE *towns=tempfile(suffix,"towns",0),*boundaries=NULL,*ways=NULL;
- if (towns) {
- boundaries=tempfile(suffix,"boundaries",0);
- ways=tempfile(suffix,"ways_split",0);
- osm_process_towns(towns,boundaries,ways,suffix);
- fclose(ways);
- fclose(boundaries);
- fclose(towns);
- if(!p.keep_tmpfiles)
- tempfile_unlink(suffix,"towns");
- }
- }
- if (start_phase(&p,"sorting countries")) {
- sort_countries(p.keep_tmpfiles);
- p.countries_loaded=1;
- }
- if (start_phase(&p,"generating turn restrictions")) {
- if (p.process_relations) {
- osm_process_turn_restrictions(&p, suffix);
- }
- if(!p.keep_tmpfiles)
- tempfile_unlink(suffix,"ways_split_index");
- }
- if (p.process_relations && p.process_ways && p.process_nodes && start_phase(&p,"processing associated street relations")) {
- struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix);
- p.osm.associated_streets=tempfile(suffix,"associated_streets",0);
- if (p.osm.associated_streets) {
-
- process_associated_streets(p.osm.associated_streets, files_relproc);
+ process_associated_streets(p.osm.associated_streets, files_relproc);
- fclose(p.osm.associated_streets);
- files_relation_processing_destroy(files_relproc, suffix);
- if(!p.keep_tmpfiles) {
- tempfile_unlink(suffix,"associated_streets");
- }
- }
- }
- if (p.process_relations && p.process_ways && p.process_nodes && start_phase(&p,"processing house number interpolations")) {
- // OSM house number interpolations are handled like a relation.
- struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix);
- p.osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",0);
- if (p.osm.house_number_interpolations) {
+ fclose(p.osm.associated_streets);
+ files_relation_processing_destroy(files_relproc, suffix);
+ if(!p.keep_tmpfiles) {
+ tempfile_unlink(suffix,"associated_streets");
+ }
+ }
+ }
+ if (p.process_relations && p.process_ways && p.process_nodes
+ && start_phase(&p,"processing house number interpolations")) {
+ // OSM house number interpolations are handled like a relation.
+ struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix);
+ p.osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",0);
+ if (p.osm.house_number_interpolations) {
- process_house_number_interpolations(p.osm.house_number_interpolations, files_relproc);
+ process_house_number_interpolations(p.osm.house_number_interpolations, files_relproc);
- fclose(p.osm.house_number_interpolations);
- files_relation_processing_destroy(files_relproc, suffix);
- if(!p.keep_tmpfiles) {
- tempfile_unlink(suffix,"house_number_interpolations");
- }
- }
- }
- if (p.dump == 1 && start_phase(&p,"dumping")) {
- maptool_dump(&p, suffix);
- exit(0);
- }
- if (p.process_relations) {
- filenames[filename_count]="relations";
- referencenames[filename_count++]=NULL;
- filenames[filename_count]="towns_poly";
- referencenames[filename_count++]=NULL;
- }
- if (p.process_ways) {
- filenames[filename_count]="ways_split";
- referencenames[filename_count++]=NULL;
- filenames[filename_count]="coastline_result";
- referencenames[filename_count++]=NULL;
- }
- if (p.process_nodes) {
- filenames[filename_count]="nodes";
- referencenames[filename_count++]=NULL;
- filenames[filename_count]="way2poi_result";
- referencenames[filename_count++]=NULL;
- }
- for (i = suffix_start ; i < suffix_count ; i++) {
- suffix=suffixes[i];
- if (start_phase(&p,"generating tiles")) {
- maptool_load_countries(&p);
- maptool_generate_tiles(&p, suffix, filenames, filename_count, i == suffix_start, suffixes[0]);
- p.tilesdir_loaded=1;
- }
- if (start_phase(&p,"assembling map")) {
- maptool_load_countries(&p);
- maptool_load_tilesdir(&p, suffix);
- maptool_assemble_map(&p, suffix, filenames, referencenames, filename_count, i == suffix_start, i == suffix_count-1, suffixes[0]);
- }
- phase-=2;
- }
- phase+=2;
- start_phase(&p,"done");
- return 0;
+ fclose(p.osm.house_number_interpolations);
+ files_relation_processing_destroy(files_relproc, suffix);
+ if(!p.keep_tmpfiles) {
+ tempfile_unlink(suffix,"house_number_interpolations");
+ }
+ }
+ }
+ if (p.dump == 1 && start_phase(&p,"dumping")) {
+ maptool_dump(&p, suffix);
+ exit(0);
+ }
+ if (p.process_relations) {
+ filenames[filename_count]="relations";
+ referencenames[filename_count++]=NULL;
+ filenames[filename_count]="towns_poly";
+ referencenames[filename_count++]=NULL;
+ }
+ if (p.process_ways) {
+ filenames[filename_count]="ways_split";
+ referencenames[filename_count++]=NULL;
+ filenames[filename_count]="coastline_result";
+ referencenames[filename_count++]=NULL;
+ }
+ if (p.process_nodes) {
+ filenames[filename_count]="nodes";
+ referencenames[filename_count++]=NULL;
+ filenames[filename_count]="way2poi_result";
+ referencenames[filename_count++]=NULL;
+ }
+ for (i = suffix_start ; i < suffix_count ; i++) {
+ suffix=suffixes[i];
+ if (start_phase(&p,"generating tiles")) {
+ maptool_load_countries(&p);
+ maptool_generate_tiles(&p, suffix, filenames, filename_count, i == suffix_start, suffixes[0]);
+ p.tilesdir_loaded=1;
+ }
+ if (start_phase(&p,"assembling map")) {
+ maptool_load_countries(&p);
+ maptool_load_tilesdir(&p, suffix);
+ maptool_assemble_map(&p, suffix, filenames, referencenames, filename_count, i == suffix_start, i == suffix_count-1,
+ suffixes[0]);
+ }
+ phase-=2;
+ }
+ phase+=2;
+ start_phase(&p,"done");
+ return 0;
}
diff --git a/navit/maptool/misc.c b/navit/maptool/misc.c
index 0f0b375a8..226190658 100644
--- a/navit/maptool/misc.c
+++ b/navit/maptool/misc.c
@@ -48,406 +48,390 @@
#define phase1_coord_max 16384
struct rect world_bbox = {
- { WORLD_BOUNDINGBOX_MIN_X, WORLD_BOUNDINGBOX_MIN_Y},
- { WORLD_BOUNDINGBOX_MAX_X, WORLD_BOUNDINGBOX_MAX_Y},
+ { WORLD_BOUNDINGBOX_MIN_X, WORLD_BOUNDINGBOX_MIN_Y},
+ { WORLD_BOUNDINGBOX_MAX_X, WORLD_BOUNDINGBOX_MAX_Y},
};
void
-bbox_extend(struct coord *c, struct rect *r)
-{
- if (c->x < r->l.x)
- r->l.x=c->x;
- if (c->y < r->l.y)
- r->l.y=c->y;
- if (c->x > r->h.x)
- r->h.x=c->x;
- if (c->y > r->h.y)
- r->h.y=c->y;
+bbox_extend(struct coord *c, struct rect *r) {
+ if (c->x < r->l.x)
+ r->l.x=c->x;
+ if (c->y < r->l.y)
+ r->l.y=c->y;
+ if (c->x > r->h.x)
+ r->h.x=c->x;
+ if (c->y > r->h.y)
+ r->h.y=c->y;
}
void
-bbox(struct coord *c, int count, struct rect *r)
-{
- if (! count)
- return;
- r->l=*c;
- r->h=*c;
- while (--count) {
- c++;
- bbox_extend(c, r);
- }
+bbox(struct coord *c, int count, struct rect *r) {
+ if (! count)
+ return;
+ r->l=*c;
+ r->h=*c;
+ while (--count) {
+ c++;
+ bbox_extend(c, r);
+ }
}
int
-contains_bbox(int xl, int yl, int xh, int yh, struct rect *r)
-{
- if (r->h.x < xl || r->h.x > xh) {
- return 0;
- }
- if (r->l.x > xh || r->l.x < xl) {
- return 0;
- }
- if (r->h.y < yl || r->h.y > yh) {
- return 0;
- }
- if (r->l.y > yh || r->l.y < yl) {
- return 0;
- }
- return 1;
+contains_bbox(int xl, int yl, int xh, int yh, struct rect *r) {
+ if (r->h.x < xl || r->h.x > xh) {
+ return 0;
+ }
+ if (r->l.x > xh || r->l.x < xl) {
+ return 0;
+ }
+ if (r->h.y < yl || r->h.y > yh) {
+ return 0;
+ }
+ if (r->l.y > yh || r->l.y < yl) {
+ return 0;
+ }
+ return 1;
}
int
-bbox_contains_coord(struct rect *r, struct coord *c)
-{
- if (r->h.x < c->x)
- return 0;
- if (r->l.x > c->x)
- return 0;
- if (r->h.y < c->y)
- return 0;
- if (r->l.y > c->y)
- return 0;
- return 1;
+bbox_contains_coord(struct rect *r, struct coord *c) {
+ if (r->h.x < c->x)
+ return 0;
+ if (r->l.x > c->x)
+ return 0;
+ if (r->h.y < c->y)
+ return 0;
+ if (r->l.y > c->y)
+ return 0;
+ return 1;
}
int
-bbox_contains_bbox(struct rect *out, struct rect *in)
-{
- if (out->h.x < in->h.x)
- return 0;
- if (out->l.x > in->l.x)
- return 0;
- if (out->h.y < in->h.y)
- return 0;
- if (out->l.y > in->l.y)
- return 0;
- return 1;
+bbox_contains_bbox(struct rect *out, struct rect *in) {
+ if (out->h.x < in->h.x)
+ return 0;
+ if (out->l.x > in->l.x)
+ return 0;
+ if (out->h.y < in->h.y)
+ return 0;
+ if (out->l.y > in->l.y)
+ return 0;
+ return 1;
}
long long
-bbox_area(struct rect const *r)
-{
- return ((long long)r->h.x-r->l.x)*(r->h.y-r->l.y);
+bbox_area(struct rect const *r) {
+ return ((long long)r->h.x-r->l.x)*(r->h.y-r->l.y);
}
void
-phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes)
-{
- struct map_rect *mr;
- struct item *item;
- int count;
- struct coord ca[phase1_coord_max];
- struct attr attr;
- struct item_bin *item_bin;
-
- while (maps) {
- mr=map_rect_new(maps->data, NULL);
- while ((item = map_rect_get_item(mr))) {
- count=item_coord_get(item, ca, item->type < type_line ? 1: phase1_coord_max);
- item_bin=init_item(item->type);
- item_bin_add_coord(item_bin, ca, count);
- while (item_attr_get(item, attr_any, &attr)) {
- if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) {
- attr.u.str=map_convert_string(maps->data, attr.u.str);
- if (attr.u.str) {
- item_bin_add_attr(item_bin, &attr);
- map_convert_free(attr.u.str);
- }
- } else
- item_bin_add_attr(item_bin, &attr);
- }
- if (item->type >= type_line)
- item_bin_write(item_bin, out_ways);
- else
- item_bin_write(item_bin, out_nodes);
- }
- map_rect_destroy(mr);
- maps=g_list_next(maps);
- }
+phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes) {
+ struct map_rect *mr;
+ struct item *item;
+ int count;
+ struct coord ca[phase1_coord_max];
+ struct attr attr;
+ struct item_bin *item_bin;
+
+ while (maps) {
+ mr=map_rect_new(maps->data, NULL);
+ while ((item = map_rect_get_item(mr))) {
+ count=item_coord_get(item, ca, item->type < type_line ? 1: phase1_coord_max);
+ item_bin=init_item(item->type);
+ item_bin_add_coord(item_bin, ca, count);
+ while (item_attr_get(item, attr_any, &attr)) {
+ if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) {
+ attr.u.str=map_convert_string(maps->data, attr.u.str);
+ if (attr.u.str) {
+ item_bin_add_attr(item_bin, &attr);
+ map_convert_free(attr.u.str);
+ }
+ } else
+ item_bin_add_attr(item_bin, &attr);
+ }
+ if (item->type >= type_line)
+ item_bin_write(item_bin, out_ways);
+ else
+ item_bin_write(item_bin, out_nodes);
+ }
+ map_rect_destroy(mr);
+ maps=g_list_next(maps);
+ }
}
int
-item_order_by_type(enum item_type type)
-{
- int max=14;
- switch (type) {
- case type_town_label_1e7:
- case type_town_label_5e6:
- max=3;
- break;
- case type_town_label_2e6:
- case type_town_label_1e6:
- max=5;
- break;
- case type_town_label_5e5:
- case type_district_label_1e7:
- case type_district_label_5e6:
- case type_district_label_2e6:
- case type_district_label_1e6:
- case type_district_label_5e5:
- max=6;
- break;
- case type_town_label_2e5:
- case type_town_label_1e5:
- case type_district_label_2e5:
- case type_district_label_1e5:
- case type_street_n_lanes:
- case type_highway_city:
- case type_highway_land:
- case type_ramp:
- max=8;
- break;
- case type_town_label_5e4:
- case type_town_label_2e4:
- case type_town_label_1e4:
- case type_district_label_5e4:
- case type_district_label_2e4:
- case type_district_label_1e4:
- max=9;
- break;
- case type_poly_water_tiled:
- if(experimental)
- max=9;
- break;
- case type_street_4_land:
- case type_street_4_city:
- max=10;
- break;
- case type_town_label_5e3:
- case type_town_label_2e3:
- case type_town_label_1e3:
- case type_district_label_5e3:
- case type_district_label_2e3:
- case type_district_label_1e3:
- case type_street_3_city:
- case type_street_3_land:
- max=12;
- break;
- default:
- break;
- }
- return max;
+item_order_by_type(enum item_type type) {
+ int max=14;
+ switch (type) {
+ case type_town_label_1e7:
+ case type_town_label_5e6:
+ max=3;
+ break;
+ case type_town_label_2e6:
+ case type_town_label_1e6:
+ max=5;
+ break;
+ case type_town_label_5e5:
+ case type_district_label_1e7:
+ case type_district_label_5e6:
+ case type_district_label_2e6:
+ case type_district_label_1e6:
+ case type_district_label_5e5:
+ max=6;
+ break;
+ case type_town_label_2e5:
+ case type_town_label_1e5:
+ case type_district_label_2e5:
+ case type_district_label_1e5:
+ case type_street_n_lanes:
+ case type_highway_city:
+ case type_highway_land:
+ case type_ramp:
+ max=8;
+ break;
+ case type_town_label_5e4:
+ case type_town_label_2e4:
+ case type_town_label_1e4:
+ case type_district_label_5e4:
+ case type_district_label_2e4:
+ case type_district_label_1e4:
+ max=9;
+ break;
+ case type_poly_water_tiled:
+ if(experimental)
+ max=9;
+ break;
+ case type_street_4_land:
+ case type_street_4_city:
+ max=10;
+ break;
+ case type_town_label_5e3:
+ case type_town_label_2e3:
+ case type_town_label_1e3:
+ case type_district_label_5e3:
+ case type_district_label_2e3:
+ case type_district_label_1e3:
+ case type_street_3_city:
+ case type_street_3_land:
+ max=12;
+ break;
+ default:
+ break;
+ }
+ return max;
}
static void
-phase34_process_file(struct tile_info *info, FILE *in, FILE *reference)
-{
- struct item_bin *ib;
- struct attr_bin *a;
- int max;
-
- while ((ib=read_item(in))) {
- if (ib->type < 0x80000000)
- processed_nodes++;
- else
- processed_ways++;
- max=item_order_by_type(ib->type);
- a=item_bin_get_attr_bin(ib, attr_order, NULL);
- if(a) {
- int max2=((struct range *)(a+1))->max;
- if(max>max2)
- max=max2;
- }
- tile_write_item_minmax(info, ib, reference, 0, max);
- }
+phase34_process_file(struct tile_info *info, FILE *in, FILE *reference) {
+ struct item_bin *ib;
+ struct attr_bin *a;
+ int max;
+
+ while ((ib=read_item(in))) {
+ if (ib->type < 0x80000000)
+ processed_nodes++;
+ else
+ processed_ways++;
+ max=item_order_by_type(ib->type);
+ a=item_bin_get_attr_bin(ib, attr_order, NULL);
+ if(a) {
+ int max2=((struct range *)(a+1))->max;
+ if(max>max2)
+ max=max2;
+ }
+ tile_write_item_minmax(info, ib, reference, 0, max);
+ }
}
static void
-phase34_process_file_range(struct tile_info *info, FILE *in, FILE *reference)
-{
- struct item_bin *ib;
- int min,max;
-
- while ((ib=read_item_range(in, &min, &max))) {
- if (ib->type < 0x80000000)
- processed_nodes++;
- else
- processed_ways++;
- tile_write_item_minmax(info, ib, reference, min, max);
- }
+phase34_process_file_range(struct tile_info *info, FILE *in, FILE *reference) {
+ struct item_bin *ib;
+ int min,max;
+
+ while ((ib=read_item_range(in, &min, &max))) {
+ if (ib->type < 0x80000000)
+ processed_nodes++;
+ else
+ processed_ways++;
+ tile_write_item_minmax(info, ib, reference, min, max);
+ }
}
static int
-phase34(struct tile_info *info, struct zip_info *zip_info, FILE **in, FILE **reference, int in_count, int with_range)
-{
- int i;
-
- processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
- bytes_read=0;
- sig_alrm(0);
- if (! info->write)
- tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
- for (i = 0 ; i < in_count ; i++) {
- if (in[i]) {
- if (with_range)
- phase34_process_file_range(info, in[i], reference ? reference[i]:NULL);
- else
- phase34_process_file(info, in[i], reference ? reference[i]:NULL);
- }
- }
- if (! info->write)
- merge_tiles(info);
- sig_alrm(0);
- sig_alrm_end();
- write_tilesdir(info, zip_info, info->tilesdir_out);
-
- return 0;
+phase34(struct tile_info *info, struct zip_info *zip_info, FILE **in, FILE **reference, int in_count, int with_range) {
+ int i;
+
+ processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
+ bytes_read=0;
+ sig_alrm(0);
+ if (! info->write)
+ tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ for (i = 0 ; i < in_count ; i++) {
+ if (in[i]) {
+ if (with_range)
+ phase34_process_file_range(info, in[i], reference ? reference[i]:NULL);
+ else
+ phase34_process_file(info, in[i], reference ? reference[i]:NULL);
+ }
+ }
+ if (! info->write)
+ merge_tiles(info);
+ sig_alrm(0);
+ sig_alrm_end();
+ write_tilesdir(info, zip_info, info->tilesdir_out);
+
+ return 0;
}
void
-dump(FILE *in)
-{
- struct item_bin *ib;
- while ((ib=read_item(in))) {
- dump_itembin(ib);
- }
+dump(FILE *in) {
+ struct item_bin *ib;
+ while ((ib=read_item(in))) {
+ dump_itembin(ib);
+ }
}
int
-phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info)
-{
- struct tile_info info;
- info.write=0;
- info.maxlen=0;
- info.suffix=suffix;
- info.tiles_list=NULL;
- info.tilesdir_out=tilesdir_out;
- return phase34(&info, zip_info, in, NULL, in_count, with_range);
+phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info) {
+ struct tile_info info;
+ info.write=0;
+ info.maxlen=0;
+ info.suffix=suffix;
+ info.tiles_list=NULL;
+ info.tilesdir_out=tilesdir_out;
+ return phase34(&info, zip_info, in, NULL, in_count, with_range);
}
static int
-process_slice(FILE **in, FILE **reference, int in_count, int with_range, long long size, char *suffix, struct zip_info *zip_info)
-{
- struct tile_head *th;
- char *slice_data,*zip_data;
- int zipfiles=0;
- struct tile_info info;
- int i;
-
- slice_data=g_malloc(size);
- zip_data=slice_data;
- th=tile_head_root;
- while (th) {
- if (th->process) {
- th->zip_data=zip_data;
- zip_data+=th->total_size;
- }
- th=th->next;
- }
- for (i = 0 ; i < in_count ; i++) {
- if (in[i])
- fseek(in[i], 0, SEEK_SET);
- if (reference && reference[i]) {
- fseek(reference[i], 0, SEEK_SET);
- }
- }
- info.write=1;
- info.maxlen=zip_get_maxnamelen(zip_info);
- info.suffix=suffix;
- info.tiles_list=NULL;
- info.tilesdir_out=NULL;
- phase34(&info, zip_info, in, reference, in_count, with_range);
-
- for (th=tile_head_root;th;th=th->next) {
- if (!th->process)
- continue;
- if (th->name[0]) {
- if (th->total_size != th->total_size_used) {
- fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
- exit(1);
- }
- write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
- zipfiles++;
- } else {
- dbg_assert(fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info))==1);
- }
- }
- g_free(slice_data);
-
- return zipfiles;
+process_slice(FILE **in, FILE **reference, int in_count, int with_range, long long size, char *suffix,
+ struct zip_info *zip_info) {
+ struct tile_head *th;
+ char *slice_data,*zip_data;
+ int zipfiles=0;
+ struct tile_info info;
+ int i;
+
+ slice_data=g_malloc(size);
+ zip_data=slice_data;
+ th=tile_head_root;
+ while (th) {
+ if (th->process) {
+ th->zip_data=zip_data;
+ zip_data+=th->total_size;
+ }
+ th=th->next;
+ }
+ for (i = 0 ; i < in_count ; i++) {
+ if (in[i])
+ fseek(in[i], 0, SEEK_SET);
+ if (reference && reference[i]) {
+ fseek(reference[i], 0, SEEK_SET);
+ }
+ }
+ info.write=1;
+ info.maxlen=zip_get_maxnamelen(zip_info);
+ info.suffix=suffix;
+ info.tiles_list=NULL;
+ info.tilesdir_out=NULL;
+ phase34(&info, zip_info, in, reference, in_count, with_range);
+
+ for (th=tile_head_root; th; th=th->next) {
+ if (!th->process)
+ continue;
+ if (th->name[0]) {
+ if (th->total_size != th->total_size_used) {
+ fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
+ exit(1);
+ }
+ write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
+ zipfiles++;
+ } else {
+ dbg_assert(fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info))==1);
+ }
+ }
+ g_free(slice_data);
+
+ return zipfiles;
}
int
-phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info)
-{
- long long size;
- int slices;
- int zipnum,written_tiles;
- struct tile_head *th,*th2;
- create_tile_hash();
-
- th=tile_head_root;
- size=0;
- slices=0;
- fprintf(stderr, "Maximum slice size "LONGLONG_FMT"\n", slice_size);
- while (th) {
- if (size + th->total_size > slice_size) {
- fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
- size=0;
- slices++;
- }
- size+=th->total_size;
- th=th->next;
- }
- if (size)
- fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
- th=tile_head_root;
- size=0;
- slices=0;
- while (th) {
- th2=tile_head_root;
- while (th2) {
- th2->process=0;
- th2=th2->next;
- }
- size=0;
- while (th && size+th->total_size < slice_size) {
- size+=th->total_size;
- th->process=1;
- th=th->next;
- }
- /* process_slice() modifies zip_info, but need to retain old info */
- zipnum=zip_get_zipnum(zip_info);
- written_tiles=process_slice(in, references, in_count, with_range, size, suffix, zip_info);
- zip_set_zipnum(zip_info, zipnum+written_tiles);
- slices++;
- }
- return 0;
+phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info) {
+ long long size;
+ int slices;
+ int zipnum,written_tiles;
+ struct tile_head *th,*th2;
+ create_tile_hash();
+
+ th=tile_head_root;
+ size=0;
+ slices=0;
+ fprintf(stderr, "Maximum slice size "LONGLONG_FMT"\n", slice_size);
+ while (th) {
+ if (size + th->total_size > slice_size) {
+ fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
+ size=0;
+ slices++;
+ }
+ size+=th->total_size;
+ th=th->next;
+ }
+ if (size)
+ fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
+ th=tile_head_root;
+ size=0;
+ slices=0;
+ while (th) {
+ th2=tile_head_root;
+ while (th2) {
+ th2->process=0;
+ th2=th2->next;
+ }
+ size=0;
+ while (th && size+th->total_size < slice_size) {
+ size+=th->total_size;
+ th->process=1;
+ th=th->next;
+ }
+ /* process_slice() modifies zip_info, but need to retain old info */
+ zipnum=zip_get_zipnum(zip_info);
+ written_tiles=process_slice(in, references, in_count, with_range, size, suffix, zip_info);
+ zip_set_zipnum(zip_info, zipnum+written_tiles);
+ slices++;
+ }
+ return 0;
}
void
-process_binfile(FILE *in, FILE *out)
-{
- struct item_bin *ib;
- while ((ib=read_item(in))) {
- item_bin_write(ib, out);
- }
+process_binfile(FILE *in, FILE *out) {
+ struct item_bin *ib;
+ while ((ib=read_item(in))) {
+ item_bin_write(ib, out);
+ }
}
void
-add_aux_tiles(char *name, struct zip_info *info)
-{
- char buffer[4096];
- char *s;
- FILE *in;
- FILE *tmp;
- in=fopen(name,"rb");
- if (!in)
- return;
- while (fscanf(in,"%s",buffer) == 1) {
- s=strchr(buffer,'/');
- if (s)
- s++;
- else
- s=buffer;
- tmp=fopen(buffer,"rb");
- if (tmp) {
- fseek(tmp, 0, SEEK_END);
- add_aux_tile(info, s, buffer, ftell(tmp));
- fclose(tmp);
- }
- }
- fclose(in);
+add_aux_tiles(char *name, struct zip_info *info) {
+ char buffer[4096];
+ char *s;
+ FILE *in;
+ FILE *tmp;
+ in=fopen(name,"rb");
+ if (!in)
+ return;
+ while (fscanf(in,"%s",buffer) == 1) {
+ s=strchr(buffer,'/');
+ if (s)
+ s++;
+ else
+ s=buffer;
+ tmp=fopen(buffer,"rb");
+ if (tmp) {
+ fseek(tmp, 0, SEEK_END);
+ add_aux_tile(info, s, buffer, ftell(tmp));
+ fclose(tmp);
+ }
+ }
+ fclose(in);
}
diff --git a/navit/maptool/osm.c b/navit/maptool/osm.c
index c6d1fa6df..ed3713091 100644
--- a/navit/maptool/osm.c
+++ b/navit/maptool/osm.c
@@ -73,9 +73,9 @@ int attr_strings_buffer_free_offset;
struct coord coord_buffer[MAX_COORD_COUNT];
struct attr_mapping {
- enum item_type type;
- int attr_present_idx_count;
- int attr_present_idx[0];
+ enum item_type type;
+ int attr_present_idx_count;
+ int attr_present_idx[0];
};
static void nodes_ref_item_bin(struct item_bin *ib);
@@ -95,34 +95,34 @@ static void attr_longest_match_clear(void);
enum attr_strings_type {
- attr_string_phone,
- attr_string_fax,
- attr_string_email,
- attr_string_url,
- attr_string_district_name,
- attr_string_street_name,
- attr_string_street_name_systematic,
- attr_string_street_name_systematic_nat,
- attr_string_street_name_systematic_int,
- attr_string_ref,
- attr_string_exit_to,
- attr_string_street_destination,
- attr_string_street_destination_forward,
- attr_string_street_destination_backward,
- attr_string_house_number,
- attr_string_label,
- attr_string_postal,
- attr_string_population,
- attr_string_county_name,
- attr_string_last,
+ attr_string_phone,
+ attr_string_fax,
+ attr_string_email,
+ attr_string_url,
+ attr_string_district_name,
+ attr_string_street_name,
+ attr_string_street_name_systematic,
+ attr_string_street_name_systematic_nat,
+ attr_string_street_name_systematic_int,
+ attr_string_ref,
+ attr_string_exit_to,
+ attr_string_street_destination,
+ attr_string_street_destination_forward,
+ attr_string_street_destination_backward,
+ attr_string_house_number,
+ attr_string_label,
+ attr_string_postal,
+ attr_string_population,
+ attr_string_county_name,
+ attr_string_last,
};
char *attr_strings[attr_string_last];
-char *osm_types[]={"unknown","node","way","relation"};
+char *osm_types[]= {"unknown","node","way","relation"};
/*
- * These macros are designed to handle maptool internal node id reference representation. This representation does not leak
+ * These macros are designed to handle maptool internal node id reference representation. This representation does not leak
* to binfile, so it's safe to change it without breaking binfile binary compatibility.
* Currently it keeps low 31 bits in y coordinate and up to 30 high order bits in x coordinate, allowing for 61 bit osm node id in total.
*/
@@ -132,269 +132,269 @@ char *osm_types[]={"unknown","node","way","relation"};
#define GET_REF(c) ((((osmid)(c).x & ~REF_MARKER)<<31) + (c).y )
#define SET_REF(c,ref) do { (c).x = REF_MARKER | ((osmid)(ref)>>31); (c).y = (osmid)(ref) & 0x7fffffffull; } while(0)
-/* Table of country codes with possible is_in spellings.
- * Note: If you update this list, check also country array in country.c
+/* Table of country codes with possible is_in spellings.
+ * Note: If you update this list, check also country array in country.c
*/
struct country_table {
- int countryid;
- char *names;
- char *admin_levels;
- FILE *file;
- int size;
- struct rect r;
- int nparts;
+ int countryid;
+ char *names;
+ char *admin_levels;
+ FILE *file;
+ int size;
+ struct rect r;
+ int nparts;
} country_table[] = {
- { 4,"Afghanistan"},
- { 8,"Albania"},
- { 10,"Antarctica"},
- { 12,"Algeria"},
- { 16,"American Samoa"},
- { 20,"Andorra"},
- { 24,"Angola"},
- { 28,"Antigua and Barbuda"},
- { 31,"Azerbaijan"},
- { 32,"Argentina,República Argentina,AR "},
- { 36,"Australia,AUS"},
- { 40,"Austria,Österreich,AUT"},
- { 44,"Bahamas"},
- { 48,"Bahrain"},
- { 50,"Bangladesh"},
- { 51,"Armenia"},
- { 52,"Barbados"},
- { 56,"Belgium,Belgique,Belgie,België,Belgien","345c7M"},
- { 60,"Bermuda"},
- { 64,"Bhutan"},
- { 68,"Bolivia, Plurinational State of"},
- { 70,"Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина"},
- { 72,"Botswana"},
- { 74,"Bouvet Island"},
- { 76,"Brazil"},
- { 84,"Belize"},
- { 86,"British Indian Ocean Territory"},
- { 90,"Solomon Islands"},
- { 92,"Virgin Islands, British"},
- { 96,"Brunei Darussalam"},
- { 100,"Bulgaria,България"},
- { 104,"Myanmar"},
- { 108,"Burundi"},
- { 112,"Belarus"},
- { 116,"Cambodia"},
- { 120,"Cameroon"},
- { 124,"Canada"},
- { 132,"Cape Verde"},
- { 136,"Cayman Islands"},
- { 140,"Central African Republic"},
- { 144,"Sri Lanka"},
- { 148,"Chad"},
- { 152,"Chile"},
- { 156,"China"},
- { 158,"Taiwan, Province of China"},
- { 162,"Christmas Island"},
- { 166,"Cocos (Keeling) Islands"},
- { 170,"Colombia"},
- { 174,"Comoros"},
- { 175,"Mayotte"},
- { 178,"Congo"},
- { 180,"Congo, the Democratic Republic of the"},
- { 184,"Cook Islands"},
- { 188,"Costa Rica"},
- { 191,"Croatia,Republika Hrvatska,HR"},
- { 192,"Cuba"},
- { 196,"Cyprus"},
- { 203,"Czech Republic,Česká republika,CZ"},
- { 204,"Benin"},
- { 208,"Denmark,Danmark,DK"},
- { 212,"Dominica"},
- { 214,"Dominican Republic"},
- { 218,"Ecuador"},
- { 222,"El Salvador"},
- { 226,"Equatorial Guinea"},
- { 231,"Ethiopia"},
- { 232,"Eritrea"},
- { 233,"Estonia"},
- { 234,"Faroe Islands,Føroyar"},
- { 238,"Falkland Islands (Malvinas)"},
- { 239,"South Georgia and the South Sandwich Islands"},
- { 242,"Fiji"},
- { 246,"Finland,Suomi"},
- { 248,"Åland Islands"},
- { 250,"France,République française,FR","3s5c7M"},
- { 254,"French Guiana"},
- { 258,"French Polynesia"},
- { 260,"French Southern Territories"},
- { 262,"Djibouti"},
- { 266,"Gabon"},
- { 268,"Georgia"},
- { 270,"Gambia"},
- { 275,"Palestinian Territory, Occupied"},
- { 276,"Germany,Deutschland,Bundesrepublik Deutschland","345c7M"},
- { 288,"Ghana"},
- { 292,"Gibraltar"},
- { 296,"Kiribati"},
- { 300,"Greece"},
- { 304,"Greenland"},
- { 308,"Grenada"},
- { 312,"Guadeloupe"},
- { 316,"Guam"},
- { 320,"Guatemala"},
- { 324,"Guinea"},
- { 328,"Guyana"},
- { 332,"Haiti"},
- { 334,"Heard Island and McDonald Islands"},
- { 336,"Holy See (Vatican City State)"},
- { 340,"Honduras"},
- { 344,"Hong Kong"},
- { 348,"Hungary,Magyarország"},
- { 352,"Iceland"},
- { 356,"India"},
- { 360,"Indonesia"},
- { 364,"Iran, Islamic Republic of"},
- { 368,"Iraq"},
- { 372,"Ireland"},
- { 376,"Israel"},
- { 380,"Italy,Italia"},
- { 384,"Côte d'Ivoire"},
- { 388,"Jamaica"},
- { 392,"Japan"},
- { 398,"Kazakhstan"},
- { 400,"Jordan"},
- { 404,"Kenya"},
- { 408,"Korea, Democratic People's Republic of"},
- { 410,"Korea, Republic of"},
- { 414,"Kuwait"},
- { 417,"Kyrgyzstan"},
- { 418,"Lao People's Democratic Republic"},
- { 422,"Lebanon"},
- { 426,"Lesotho"},
- { 428,"Latvia"},
- { 430,"Liberia"},
- { 434,"Libyan Arab Jamahiriya"},
- { 438,"Liechtenstein"},
- { 440,"Lithuania,Lietuva"},
- { 442,"Luxembourg"},
- { 446,"Macao"},
- { 450,"Madagascar"},
- { 454,"Malawi"},
- { 458,"Malaysia"},
- { 462,"Maldives"},
- { 466,"Mali"},
- { 470,"Malta"},
- { 474,"Martinique"},
- { 478,"Mauritania"},
- { 480,"Mauritius"},
- { 484,"Mexico"},
- { 492,"Monaco"},
- { 496,"Mongolia"},
- { 498,"Moldova, Republic of"},
- { 499,"Montenegro,Црна Гора,Crna Gora"},
- { 500,"Montserrat"},
- { 504,"Morocco"},
- { 508,"Mozambique"},
- { 512,"Oman"},
- { 516,"Namibia"},
- { 520,"Nauru"},
- { 524,"Nepal"},
- { 528,"Nederland,The Netherlands,Niederlande,NL,Netherlands","3c567M"},
- { 530,"Netherlands Antilles"},
- { 531,"Curacao"},
- { 533,"Aruba"},
- { 534,"Sint Maarten (Dutch part)"},
- { 535,"Bonaire, Sint Eustatius and Saba"},
- { 540,"New Caledonia"},
- { 548,"Vanuatu"},
- { 554,"New Zealand"},
- { 558,"Nicaragua"},
- { 562,"Niger"},
- { 566,"Nigeria"},
- { 570,"Niue"},
- { 574,"Norfolk Island"},
- { 578,"Norway,Norge,Noreg,NO"},
- { 580,"Northern Mariana Islands"},
- { 581,"United States Minor Outlying Islands"},
- { 583,"Micronesia, Federated States of"},
- { 584,"Marshall Islands"},
- { 585,"Palau"},
- { 586,"Pakistan"},
- { 591,"Panama"},
- { 598,"Papua New Guinea"},
- { 600,"Paraguay"},
- { 604,"Peru"},
- { 608,"Philippines"},
- { 612,"Pitcairn"},
- { 616,"Poland,Polska,PL","3s5cmT"},
- { 620,"Portugal"},
- { 624,"Guinea-Bissau"},
- { 626,"Timor-Leste"},
- { 630,"Puerto Rico"},
- { 634,"Qatar"},
- { 638,"Réunion"},
- { 642,"România,Romania,RO"},
- { 643,"Россия,Российская Федерация,Russia,Russian Federation","3s5c7m"},
- { 646,"Rwanda"},
- { 652,"Saint Barthélemy"},
- { 654,"Saint Helena, Ascension and Tristan da Cunha"},
- { 659,"Saint Kitts and Nevis"},
- { 660,"Anguilla"},
- { 662,"Saint Lucia"},
- { 663,"Saint Martin (French part)"},
- { 666,"Saint Pierre and Miquelon"},
- { 670,"Saint Vincent and the Grenadines"},
- { 674,"San Marino"},
- { 678,"Sao Tome and Principe"},
- { 682,"Saudi Arabia"},
- { 686,"Senegal"},
- { 688,"Srbija,Србија,Serbia"},
- { 690,"Seychelles"},
- { 694,"Sierra Leone"},
- { 702,"Singapore"},
- { 703,"Slovakia,Slovensko,SK"},
- { 704,"Viet Nam"},
- { 705,"Slovenia,Republika Slovenija,SI"},
- { 706,"Somalia"},
- { 710,"South Africa"},
- { 716,"Zimbabwe"},
- { 724,"Spain,Espana,España,Reino de Espana,Reino de España","345scm"},
- { 728,"South Sudan"},
- { 732,"Western Sahara"},
- { 736,"Sudan"},
- { 740,"Suriname"},
- { 744,"Svalbard and Jan Mayen"},
- { 748,"Swaziland"},
- { 752,"Sweden,Sverige,Konungariket Sverige,SE"},
- { 756,"Switzerland,Schweiz","3s5c7M"},
- { 760,"Syrian Arab Republic"},
- { 762,"Tajikistan"},
- { 764,"Thailand"},
- { 768,"Togo"},
- { 772,"Tokelau"},
- { 776,"Tonga"},
- { 780,"Trinidad and Tobago"},
- { 784,"United Arab Emirates"},
- { 788,"Tunisia"},
- { 792,"Turkey"},
- { 795,"Turkmenistan"},
- { 796,"Turks and Caicos Islands"},
- { 798,"Tuvalu"},
- { 800,"Uganda"},
- { 804,"Ukraine","3s5c78"},
- { 807,"Macedonia,Македонија"},
- { 818,"Egypt"},
- { 826,"United Kingdom,UK","3s5c7m"},
- { 831,"Guernsey"},
- { 832,"Jersey"},
- { 833,"Isle of Man"},
- { 834,"Tanzania, United Republic of"},
- { 840,"USA","3s5c7m"},
- { 850,"Virgin Islands, U.S."},
- { 854,"Burkina Faso"},
- { 858,"Uruguay"},
- { 860,"Uzbekistan"},
- { 862,"Venezuela, Bolivarian Republic of"},
- { 876,"Wallis and Futuna"},
- { 882,"Samoa"},
- { 887,"Yemen"},
- { 894,"Zambia"},
- { 999,"Unknown"},
+ { 4,"Afghanistan"},
+ { 8,"Albania"},
+ { 10,"Antarctica"},
+ { 12,"Algeria"},
+ { 16,"American Samoa"},
+ { 20,"Andorra"},
+ { 24,"Angola"},
+ { 28,"Antigua and Barbuda"},
+ { 31,"Azerbaijan"},
+ { 32,"Argentina,República Argentina,AR "},
+ { 36,"Australia,AUS"},
+ { 40,"Austria,Österreich,AUT"},
+ { 44,"Bahamas"},
+ { 48,"Bahrain"},
+ { 50,"Bangladesh"},
+ { 51,"Armenia"},
+ { 52,"Barbados"},
+ { 56,"Belgium,Belgique,Belgie,België,Belgien","345c7M"},
+ { 60,"Bermuda"},
+ { 64,"Bhutan"},
+ { 68,"Bolivia, Plurinational State of"},
+ { 70,"Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина"},
+ { 72,"Botswana"},
+ { 74,"Bouvet Island"},
+ { 76,"Brazil"},
+ { 84,"Belize"},
+ { 86,"British Indian Ocean Territory"},
+ { 90,"Solomon Islands"},
+ { 92,"Virgin Islands, British"},
+ { 96,"Brunei Darussalam"},
+ { 100,"Bulgaria,България"},
+ { 104,"Myanmar"},
+ { 108,"Burundi"},
+ { 112,"Belarus"},
+ { 116,"Cambodia"},
+ { 120,"Cameroon"},
+ { 124,"Canada"},
+ { 132,"Cape Verde"},
+ { 136,"Cayman Islands"},
+ { 140,"Central African Republic"},
+ { 144,"Sri Lanka"},
+ { 148,"Chad"},
+ { 152,"Chile"},
+ { 156,"China"},
+ { 158,"Taiwan, Province of China"},
+ { 162,"Christmas Island"},
+ { 166,"Cocos (Keeling) Islands"},
+ { 170,"Colombia"},
+ { 174,"Comoros"},
+ { 175,"Mayotte"},
+ { 178,"Congo"},
+ { 180,"Congo, the Democratic Republic of the"},
+ { 184,"Cook Islands"},
+ { 188,"Costa Rica"},
+ { 191,"Croatia,Republika Hrvatska,HR"},
+ { 192,"Cuba"},
+ { 196,"Cyprus"},
+ { 203,"Czech Republic,Česká republika,CZ"},
+ { 204,"Benin"},
+ { 208,"Denmark,Danmark,DK"},
+ { 212,"Dominica"},
+ { 214,"Dominican Republic"},
+ { 218,"Ecuador"},
+ { 222,"El Salvador"},
+ { 226,"Equatorial Guinea"},
+ { 231,"Ethiopia"},
+ { 232,"Eritrea"},
+ { 233,"Estonia"},
+ { 234,"Faroe Islands,Føroyar"},
+ { 238,"Falkland Islands (Malvinas)"},
+ { 239,"South Georgia and the South Sandwich Islands"},
+ { 242,"Fiji"},
+ { 246,"Finland,Suomi"},
+ { 248,"Åland Islands"},
+ { 250,"France,République française,FR","3s5c7M"},
+ { 254,"French Guiana"},
+ { 258,"French Polynesia"},
+ { 260,"French Southern Territories"},
+ { 262,"Djibouti"},
+ { 266,"Gabon"},
+ { 268,"Georgia"},
+ { 270,"Gambia"},
+ { 275,"Palestinian Territory, Occupied"},
+ { 276,"Germany,Deutschland,Bundesrepublik Deutschland","345c7M"},
+ { 288,"Ghana"},
+ { 292,"Gibraltar"},
+ { 296,"Kiribati"},
+ { 300,"Greece"},
+ { 304,"Greenland"},
+ { 308,"Grenada"},
+ { 312,"Guadeloupe"},
+ { 316,"Guam"},
+ { 320,"Guatemala"},
+ { 324,"Guinea"},
+ { 328,"Guyana"},
+ { 332,"Haiti"},
+ { 334,"Heard Island and McDonald Islands"},
+ { 336,"Holy See (Vatican City State)"},
+ { 340,"Honduras"},
+ { 344,"Hong Kong"},
+ { 348,"Hungary,Magyarország"},
+ { 352,"Iceland"},
+ { 356,"India"},
+ { 360,"Indonesia"},
+ { 364,"Iran, Islamic Republic of"},
+ { 368,"Iraq"},
+ { 372,"Ireland"},
+ { 376,"Israel"},
+ { 380,"Italy,Italia"},
+ { 384,"Côte d'Ivoire"},
+ { 388,"Jamaica"},
+ { 392,"Japan"},
+ { 398,"Kazakhstan"},
+ { 400,"Jordan"},
+ { 404,"Kenya"},
+ { 408,"Korea, Democratic People's Republic of"},
+ { 410,"Korea, Republic of"},
+ { 414,"Kuwait"},
+ { 417,"Kyrgyzstan"},
+ { 418,"Lao People's Democratic Republic"},
+ { 422,"Lebanon"},
+ { 426,"Lesotho"},
+ { 428,"Latvia"},
+ { 430,"Liberia"},
+ { 434,"Libyan Arab Jamahiriya"},
+ { 438,"Liechtenstein"},
+ { 440,"Lithuania,Lietuva"},
+ { 442,"Luxembourg"},
+ { 446,"Macao"},
+ { 450,"Madagascar"},
+ { 454,"Malawi"},
+ { 458,"Malaysia"},
+ { 462,"Maldives"},
+ { 466,"Mali"},
+ { 470,"Malta"},
+ { 474,"Martinique"},
+ { 478,"Mauritania"},
+ { 480,"Mauritius"},
+ { 484,"Mexico"},
+ { 492,"Monaco"},
+ { 496,"Mongolia"},
+ { 498,"Moldova, Republic of"},
+ { 499,"Montenegro,Црна Гора,Crna Gora"},
+ { 500,"Montserrat"},
+ { 504,"Morocco"},
+ { 508,"Mozambique"},
+ { 512,"Oman"},
+ { 516,"Namibia"},
+ { 520,"Nauru"},
+ { 524,"Nepal"},
+ { 528,"Nederland,The Netherlands,Niederlande,NL,Netherlands","3c567M"},
+ { 530,"Netherlands Antilles"},
+ { 531,"Curacao"},
+ { 533,"Aruba"},
+ { 534,"Sint Maarten (Dutch part)"},
+ { 535,"Bonaire, Sint Eustatius and Saba"},
+ { 540,"New Caledonia"},
+ { 548,"Vanuatu"},
+ { 554,"New Zealand"},
+ { 558,"Nicaragua"},
+ { 562,"Niger"},
+ { 566,"Nigeria"},
+ { 570,"Niue"},
+ { 574,"Norfolk Island"},
+ { 578,"Norway,Norge,Noreg,NO"},
+ { 580,"Northern Mariana Islands"},
+ { 581,"United States Minor Outlying Islands"},
+ { 583,"Micronesia, Federated States of"},
+ { 584,"Marshall Islands"},
+ { 585,"Palau"},
+ { 586,"Pakistan"},
+ { 591,"Panama"},
+ { 598,"Papua New Guinea"},
+ { 600,"Paraguay"},
+ { 604,"Peru"},
+ { 608,"Philippines"},
+ { 612,"Pitcairn"},
+ { 616,"Poland,Polska,PL","3s5cmT"},
+ { 620,"Portugal"},
+ { 624,"Guinea-Bissau"},
+ { 626,"Timor-Leste"},
+ { 630,"Puerto Rico"},
+ { 634,"Qatar"},
+ { 638,"Réunion"},
+ { 642,"România,Romania,RO"},
+ { 643,"Россия,Российская Федерация,Russia,Russian Federation","3s5c7m"},
+ { 646,"Rwanda"},
+ { 652,"Saint Barthélemy"},
+ { 654,"Saint Helena, Ascension and Tristan da Cunha"},
+ { 659,"Saint Kitts and Nevis"},
+ { 660,"Anguilla"},
+ { 662,"Saint Lucia"},
+ { 663,"Saint Martin (French part)"},
+ { 666,"Saint Pierre and Miquelon"},
+ { 670,"Saint Vincent and the Grenadines"},
+ { 674,"San Marino"},
+ { 678,"Sao Tome and Principe"},
+ { 682,"Saudi Arabia"},
+ { 686,"Senegal"},
+ { 688,"Srbija,Србија,Serbia"},
+ { 690,"Seychelles"},
+ { 694,"Sierra Leone"},
+ { 702,"Singapore"},
+ { 703,"Slovakia,Slovensko,SK"},
+ { 704,"Viet Nam"},
+ { 705,"Slovenia,Republika Slovenija,SI"},
+ { 706,"Somalia"},
+ { 710,"South Africa"},
+ { 716,"Zimbabwe"},
+ { 724,"Spain,Espana,España,Reino de Espana,Reino de España","345scm"},
+ { 728,"South Sudan"},
+ { 732,"Western Sahara"},
+ { 736,"Sudan"},
+ { 740,"Suriname"},
+ { 744,"Svalbard and Jan Mayen"},
+ { 748,"Swaziland"},
+ { 752,"Sweden,Sverige,Konungariket Sverige,SE"},
+ { 756,"Switzerland,Schweiz","3s5c7M"},
+ { 760,"Syrian Arab Republic"},
+ { 762,"Tajikistan"},
+ { 764,"Thailand"},
+ { 768,"Togo"},
+ { 772,"Tokelau"},
+ { 776,"Tonga"},
+ { 780,"Trinidad and Tobago"},
+ { 784,"United Arab Emirates"},
+ { 788,"Tunisia"},
+ { 792,"Turkey"},
+ { 795,"Turkmenistan"},
+ { 796,"Turks and Caicos Islands"},
+ { 798,"Tuvalu"},
+ { 800,"Uganda"},
+ { 804,"Ukraine","3s5c78"},
+ { 807,"Macedonia,Македонија"},
+ { 818,"Egypt"},
+ { 826,"United Kingdom,UK","3s5c7m"},
+ { 831,"Guernsey"},
+ { 832,"Jersey"},
+ { 833,"Isle of Man"},
+ { 834,"Tanzania, United Republic of"},
+ { 840,"USA","3s5c7m"},
+ { 850,"Virgin Islands, U.S."},
+ { 854,"Burkina Faso"},
+ { 858,"Uruguay"},
+ { 860,"Uzbekistan"},
+ { 862,"Venezuela, Bolivarian Republic of"},
+ { 876,"Wallis and Futuna"},
+ { 882,"Samoa"},
+ { 887,"Yemen"},
+ { 894,"Zambia"},
+ { 999,"Unknown"},
};
// first char - item type
@@ -402,448 +402,446 @@ struct country_table {
// =? - used both for nodes and ways
// otherwise - nodes
-static char *attrmap={
- "n *=* point_unkn\n"
- "? addr:housenumber=* house_number\n"
- "? aeroway=aerodrome poi_airport\n"
- "? aeroway=airport poi_airport\n"
- "? aeroway=helipad poi_heliport\n"
- "? aeroway=terminal poi_airport\n"
- "? amenity=atm poi_atm\n"
- "? amenity=bank poi_bank\n"
- "? amenity=bar poi_bar\n"
- "n amenity=bench poi_bench\n"
- "? amenity=bicycle_rental poi_bicycle_rental\n"
- "? amenity=bicycle_parking poi_bicycle_parking\n"
- "? amenity=biergarten poi_biergarten\n"
- "? amenity=bus_station poi_bus_station\n"
- "? amenity=cafe poi_cafe\n"
- "? amenity=car_sharing poi_car_sharing\n"
- "? amenity=car_wash poi_car_wash\n"
- "? amenity=cinema poi_cinema\n"
- "? amenity=college poi_school_college\n"
- "? amenity=courthouse poi_justice\n"
- "? amenity=drinking_water poi_potable_water\n"
- "? amenity=fast_food poi_fastfood\n"
- "? amenity=fire_station poi_firebrigade\n"
- "? amenity=fountain poi_fountain\n"
- "? amenity=fuel poi_fuel\n"
- "? amenity=grave_yard poi_cemetery\n"
- "? amenity=hospital poi_hospital\n"
- "? amenity=hunting_stand poi_hunting_stand\n"
- "? amenity=kindergarten poi_kindergarten\n"
- "? amenity=library poi_library\n"
- "? amenity=nightclub poi_nightclub\n"
- "? amenity=park_bench poi_bench\n"
- "? amenity=parking poi_car_parking\n"
- "? amenity=pharmacy poi_pharmacy\n"
- "? amenity=place_of_worship,religion=christian poi_church\n"
- "? amenity=place_of_worship poi_worship\n"
- "? amenity=police poi_police\n"
- "? amenity=post_box poi_post_box\n"
- "? amenity=post_office poi_post_office\n"
- "? amenity=prison poi_prison\n"
- "? amenity=pub poi_pub\n"
- "? amenity=public_building poi_public_office\n"
- "? amenity=recycling poi_recycling\n"
- "? amenity=restaurant,cuisine=fine_dining poi_dining\n"
- "? amenity=restaurant poi_restaurant\n"
- "? amenity=school poi_school\n"
- "? amenity=shelter poi_shelter\n"
- "? amenity=taxi poi_taxi\n"
- "? amenity=tec_common tec_common\n"
- "? amenity=telephone poi_telephone\n"
- "? amenity=theatre poi_theater\n"
- "? amenity=toilets poi_restroom\n"
- "? amenity=townhall poi_townhall\n"
- "? amenity=university poi_school_university\n"
- "? amenity=vending_machine poi_vending_machine\n"
- "n barrier=bollard barrier_bollard\n"
- "n barrier=cycle_barrier barrier_cycle\n"
- "n barrier=lift_gate barrier_lift_gate\n"
- "? car=car_rental poi_car_rent\n"
- "? highway=bus_station poi_bus_station\n"
- "? highway=bus_stop poi_bus_stop\n"
- "n highway=mini_roundabout mini_roundabout\n"
- "n highway=motorway_junction highway_exit\n"
- "n highway=stop traffic_sign_stop\n"
- "n highway=toll_booth poi_toll_booth\n"
- "n highway=traffic_signals traffic_signals\n"
- "n highway=turning_circle turning_circle\n"
- "? historic=boundary_stone poi_boundary_stone\n"
- "? historic=castle poi_castle\n"
- "? historic=memorial poi_memorial\n"
- "? historic=monument poi_monument\n"
- "? historic=ruins poi_ruins\n"
+static char *attrmap= {
+ "n *=* point_unkn\n"
+ "? addr:housenumber=* house_number\n"
+ "? aeroway=aerodrome poi_airport\n"
+ "? aeroway=airport poi_airport\n"
+ "? aeroway=helipad poi_heliport\n"
+ "? aeroway=terminal poi_airport\n"
+ "? amenity=atm poi_atm\n"
+ "? amenity=bank poi_bank\n"
+ "? amenity=bar poi_bar\n"
+ "n amenity=bench poi_bench\n"
+ "? amenity=bicycle_rental poi_bicycle_rental\n"
+ "? amenity=bicycle_parking poi_bicycle_parking\n"
+ "? amenity=biergarten poi_biergarten\n"
+ "? amenity=bus_station poi_bus_station\n"
+ "? amenity=cafe poi_cafe\n"
+ "? amenity=car_sharing poi_car_sharing\n"
+ "? amenity=car_wash poi_car_wash\n"
+ "? amenity=cinema poi_cinema\n"
+ "? amenity=college poi_school_college\n"
+ "? amenity=courthouse poi_justice\n"
+ "? amenity=drinking_water poi_potable_water\n"
+ "? amenity=fast_food poi_fastfood\n"
+ "? amenity=fire_station poi_firebrigade\n"
+ "? amenity=fountain poi_fountain\n"
+ "? amenity=fuel poi_fuel\n"
+ "? amenity=grave_yard poi_cemetery\n"
+ "? amenity=hospital poi_hospital\n"
+ "? amenity=hunting_stand poi_hunting_stand\n"
+ "? amenity=kindergarten poi_kindergarten\n"
+ "? amenity=library poi_library\n"
+ "? amenity=nightclub poi_nightclub\n"
+ "? amenity=park_bench poi_bench\n"
+ "? amenity=parking poi_car_parking\n"
+ "? amenity=pharmacy poi_pharmacy\n"
+ "? amenity=place_of_worship,religion=christian poi_church\n"
+ "? amenity=place_of_worship poi_worship\n"
+ "? amenity=police poi_police\n"
+ "? amenity=post_box poi_post_box\n"
+ "? amenity=post_office poi_post_office\n"
+ "? amenity=prison poi_prison\n"
+ "? amenity=pub poi_pub\n"
+ "? amenity=public_building poi_public_office\n"
+ "? amenity=recycling poi_recycling\n"
+ "? amenity=restaurant,cuisine=fine_dining poi_dining\n"
+ "? amenity=restaurant poi_restaurant\n"
+ "? amenity=school poi_school\n"
+ "? amenity=shelter poi_shelter\n"
+ "? amenity=taxi poi_taxi\n"
+ "? amenity=tec_common tec_common\n"
+ "? amenity=telephone poi_telephone\n"
+ "? amenity=theatre poi_theater\n"
+ "? amenity=toilets poi_restroom\n"
+ "? amenity=townhall poi_townhall\n"
+ "? amenity=university poi_school_university\n"
+ "? amenity=vending_machine poi_vending_machine\n"
+ "n barrier=bollard barrier_bollard\n"
+ "n barrier=cycle_barrier barrier_cycle\n"
+ "n barrier=lift_gate barrier_lift_gate\n"
+ "? car=car_rental poi_car_rent\n"
+ "? highway=bus_station poi_bus_station\n"
+ "? highway=bus_stop poi_bus_stop\n"
+ "n highway=mini_roundabout mini_roundabout\n"
+ "n highway=motorway_junction highway_exit\n"
+ "n highway=stop traffic_sign_stop\n"
+ "n highway=toll_booth poi_toll_booth\n"
+ "n highway=traffic_signals traffic_signals\n"
+ "n highway=turning_circle turning_circle\n"
+ "? historic=boundary_stone poi_boundary_stone\n"
+ "? historic=castle poi_castle\n"
+ "? historic=memorial poi_memorial\n"
+ "? historic=monument poi_monument\n"
+ "? historic=ruins poi_ruins\n"
// "? historic=* poi_ruins\n"
- "? landuse=cemetery poi_cemetery\n"
- "? leisure=fishing poi_fish\n"
- "? leisure=golf_course poi_golf\n"
- "? leisure=marina poi_marine\n"
- "? leisure=playground poi_playground\n"
- "? leisure=slipway poi_boat_ramp\n"
- "? leisure=sports_centre poi_sport\n"
- "? leisure=stadium poi_stadium\n"
- "? man_made=tower poi_tower\n"
- "? military=airfield poi_military\n"
- "? military=barracks poi_military\n"
- "? military=bunker poi_military\n"
- "? military=danger_area poi_danger_area\n"
- "? military=range poi_military\n"
- "? natural=bay poi_bay\n"
- "? natural=peak,ele=* poi_peak\n" // show only major peaks with elevation
- "? natural=tree poi_tree\n"
- "n place=city town_label_2e5\n"
- "n place=hamlet town_label_2e2\n"
- "n place=locality town_label_2e0\n"
- "n place=suburb district_label\n"
- "n place=town town_label_2e4\n"
- "n place=village town_label_2e3\n"
- "n power=tower power_tower\n"
- "n power=sub_station power_substation\n"
- "n railway=halt poi_rail_halt\n"
- "n railway=level_crossing poi_level_crossing\n"
- "? railway=station poi_rail_station\n"
- "? railway=tram_stop poi_rail_tram_stop\n"
- "? shop=baker poi_shop_baker\n"
- "? shop=bakery poi_shop_baker\n"
- "? shop=beverages poi_shop_beverages\n"
- "? shop=bicycle poi_shop_bicycle\n"
- "? shop=butcher poi_shop_butcher\n"
- "? shop=car poi_car_dealer_parts\n"
- "? shop=car_repair poi_repair_service\n"
- "? shop=clothes poi_shop_apparel\n"
- "? shop=convenience poi_shop_grocery\n"
- "? shop=chemist poi_shop_drugstore\n"
- "? shop=florist poi_shop_florist\n"
- "? shop=fruit poi_shop_fruit\n"
- "? shop=furniture poi_shop_furniture\n"
- "? shop=garden_centre poi_shop_handg\n"
- "? shop=hardware poi_shop_handg\n"
- "? shop=hairdresser poi_hairdresser\n"
- "? shop=kiosk poi_shop_kiosk\n"
- "? shop=optician poi_shop_optician\n"
- "? shop=parfum poi_shop_parfum\n"
- "? shop=photo poi_shop_photo\n"
- "? shop=shoes poi_shop_shoes\n"
- "? shop=supermarket poi_shopping\n"
- "? shop=mall poi_mall\n"
- "? sport=10pin poi_bowling\n"
- "? sport=baseball poi_baseball\n"
- "? sport=basketball poi_basketball\n"
- "? sport=climbing poi_climbing\n"
- "? sport=golf poi_golf\n"
- "? sport=motor_sports poi_motor_sport\n"
- "? sport=skiing poi_skiing\n"
- "? sport=soccer poi_soccer\n"
- "? sport=stadium poi_stadium\n"
- "? sport=swimming poi_swimming\n"
- "? sport=tennis poi_tennis\n"
- "? tourism=attraction poi_attraction\n"
- "? tourism=camp_site poi_camp_rv\n"
- "? tourism=caravan_site poi_camp_rv\n"
- "? tourism=guest_house poi_guesthouse\n"
- "? tourism=hostel poi_hostel\n"
- "? tourism=hotel poi_hotel\n"
- "? tourism=information poi_information\n"
- "? tourism=motel poi_motel\n"
- "? tourism=museum poi_museum_history\n"
- "? tourism=picnic_site poi_picnic\n"
- "? tourism=theme_park poi_resort\n"
- "? tourism=viewpoint poi_viewpoint\n"
- "? tourism=zoo poi_zoo\n"
- "n traffic_sign=city_limit traffic_sign_city_limit\n"
- "n highway=speed_camera tec_common\n"
- "w *=* street_unkn\n"
- "w addr:interpolation=even house_number_interpolation_even\n"
- "w addr:interpolation=odd house_number_interpolation_odd\n"
- "w addr:interpolation=all house_number_interpolation_all\n"
- "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n"
- "w aerialway=cable_car lift_cable_car\n"
- "w aerialway=chair_lift lift_chair\n"
- "w aerialway=drag_lift lift_drag\n"
- "w aeroway=aerodrome poly_airport\n"
- "w aeroway=apron poly_apron\n"
- "w aeroway=runway aeroway_runway\n"
- "w aeroway=taxiway aeroway_taxiway\n"
- "w aeroway=terminal poly_terminal\n"
- "w amenity=college poly_college\n"
- "w amenity=grave_yard poly_cemetery\n"
- "w amenity=parking poly_car_parking\n"
- "w amenity=place_of_worship poly_building\n"
- "w amenity=university poly_university\n"
- "w boundary=administrative,admin_level=2 border_country\n"
- "w boundary=civil border_civil\n"
- "w boundary=national_park border_national_park\n"
- "w boundary=political border_political\n"
- "w building=* poly_building\n"
- "w contour_ext=elevation_major height_line_1\n"
- "w contour_ext=elevation_medium height_line_2\n"
- "w contour_ext=elevation_minor height_line_3\n"
- "w highway=bridleway bridleway\n"
- "w highway=bus_guideway bus_guideway\n"
- "w highway=construction street_construction\n"
- "w highway=cyclepath cycleway\n"
- "w highway=cycleway cycleway\n"
- "w highway=footway footway\n"
- "w highway=footway,piste:type=nordic footway_and_piste_nordic\n"
- "w highway=living_street living_street\n"
- "w highway=minor street_1_land\n"
- "w highway=parking_lane street_parking_lane\n"
- "w highway=path path\n"
- "w highway=path,bicycle=designated cycleway\n"
- "w highway=path,bicycle=official cycleway\n"
- "w highway=path,bicycle=designated,foot=designated cycleway\n"
- "w highway=path,bicycle=official,foot=official cycleway\n"
- "w highway=path,foot=designated footway\n"
- "w highway=path,foot=official footway\n"
- "w highway=path,horse=designated bridleway\n"
- "w highway=path,horse=official bridleway\n"
- "w highway=path,sac_scale=alpine_hiking hiking_alpine\n"
- "w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n"
- "w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n"
- "w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n"
- "w highway=path,sac_scale=hiking hiking\n"
- "w highway=path,sac_scale=mountain_hiking hiking_mountain\n"
- "w highway=pedestrian street_pedestrian\n"
- "w highway=pedestrian,area=1 poly_pedestrian\n"
- "w highway=plaza poly_plaza\n"
- "w highway=motorway highway_land\n"
- "w highway=motorway,rural=0 highway_city\n"
- "w highway=motorway_link ramp\n"
- "w highway=trunk street_n_lanes\n"
- "w highway=trunk_link ramp\n"
- "w highway=primary street_4_land\n"
- "w highway=primary,name=*,rural=1 street_4_land\n"
- "w highway=primary,name=* street_4_city\n"
- "w highway=primary,rural=0 street_4_city\n"
- "w highway=primary_link ramp\n"
- "w highway=secondary street_3_land\n"
- "w highway=secondary,name=*,rural=1 street_3_land\n"
- "w highway=secondary,name=* street_3_city\n"
- "w highway=secondary,rural=0 street_3_city\n"
- "w highway=secondary,area=1 poly_street_3\n"
- "w highway=secondary_link ramp\n"
- "w highway=tertiary street_2_land\n"
- "w highway=tertiary,name=*,rural=1 street_2_land\n"
- "w highway=tertiary,name=* street_2_city\n"
- "w highway=tertiary,rural=0 street_2_city\n"
- "w highway=tertiary,area=1 poly_street_2\n"
- "w highway=tertiary_link ramp\n"
- "w highway=residential street_1_city\n"
- "w highway=residential,area=1 poly_street_1\n"
- "w highway=unclassified street_1_city\n"
- "w highway=unclassified,area=1 poly_street_1\n"
- "w highway=road street_1_city\n"
- "w highway=service street_service\n"
- "w highway=service,area=1 poly_service\n"
- "w highway=service,service=parking_aisle street_parking_lane\n"
- "w highway=track track_gravelled\n"
- "w highway=track,surface=grass track_grass\n"
- "w highway=track,surface=gravel track_gravelled\n"
- "w highway=track,surface=ground track_ground\n"
- "w highway=track,surface=paved track_paved\n"
- "w highway=track,surface=unpaved track_unpaved\n"
- "w highway=track,tracktype=grade1 track_paved\n"
- "w highway=track,tracktype=grade2 track_gravelled\n"
- "w highway=track,tracktype=grade3 track_unpaved\n"
- "w highway=track,tracktype=grade4 track_ground\n"
- "w highway=track,tracktype=grade5 track_grass\n"
- "w highway=track,surface=paved,tracktype=grade1 track_paved\n"
- "w highway=track,surface=gravel,tracktype=grade2 track_gravelled\n"
- "w highway=track,surface=unpaved,tracktype=grade3 track_unpaved\n"
- "w highway=track,surface=ground,tracktype=grade4 track_ground\n"
- "w highway=track,surface=grass,tracktype=grade5 track_grass\n"
- "w highway=unsurfaced track_gravelled\n"
- "w highway=steps steps\n"
- "w historic=archaeological_site poly_archaeological_site\n"
- "w historic=battlefield poly_battlefield\n"
- "w historic=ruins poly_ruins\n"
- "w historic=town_gate poly_building\n"
- "w landuse=allotments poly_allotments\n"
- "w landuse=basin poly_basin\n"
- "w landuse=brownfield poly_brownfield\n"
- "w landuse=cemetery poly_cemetery\n"
- "w landuse=commercial poly_commercial\n"
- "w landuse=construction poly_construction\n"
- "w landuse=farm poly_farm\n"
- "w landuse=farmland poly_farm\n"
- "w landuse=farmyard poly_town\n"
- "w landuse=forest poly_wood\n"
- "w landuse=grass poly_meadow\n"
- "w landuse=greenfield poly_greenfield\n"
- "w landuse=industrial poly_industry\n"
- "w landuse=landfill poly_landfill\n"
- "w landuse=military poly_military\n"
- "w landuse=meadow poly_meadow\n"
- "w landuse=plaza poly_plaza\n"
- "w landuse=quarry poly_quarry\n"
- "w landuse=railway poly_railway\n"
- "w landuse=recreation_ground poly_recreation_ground\n"
- "w landuse=reservoir poly_reservoir\n"
- "w landuse=residential poly_town\n"
- "w landuse=residential,area=1 poly_town\n"
- "w landuse=retail poly_retail\n"
- "w landuse=village_green poly_village_green\n"
- "w landuse=vineyard poly_farm\n"
- "w landuse=depot poly_depot\n"
- "w landuse=garages poly_garages\n"
- "w landuse=greenhouse_horticulture poly_greenhouse\n"
- "w landuse=orchard poly_orchard\n"
- "w landuse=plant_nursery poly_plantnursery\n"
- "w landuse=port poly_port\n"
- "w landuse=salt_pond poly_saltpond\n"
- "w leisure=common poly_common\n"
- "w leisure=fishing poly_fishing\n"
- "w leisure=garden poly_garden\n"
- "w leisure=golf_course poly_golf_course\n"
- "w leisure=marina poly_marina\n"
- "w leisure=nature_reserve poly_nature_reserve\n"
- "w leisure=park poly_park\n"
- "w leisure=pitch poly_sports_pitch\n"
- "w leisure=playground poly_playground\n"
- "w leisure=sports_centre poly_sport\n"
- "w leisure=stadium poly_sports_stadium\n"
- "w leisure=track poly_sports_track\n"
- "w leisure=water_park poly_water_park\n"
- "w military=airfield poly_airfield\n"
- "w military=barracks poly_barracks\n"
- "w military=danger_area poly_danger_area\n"
- "w military=naval_base poly_naval_base\n"
- "w military=range poly_range\n"
- "w natural=beach poly_beach\n"
- "w natural=coastline water_line\n"
- "w natural=fell poly_fell\n"
- "w natural=glacier poly_glacier\n"
- "w natural=grassland poly_meadow\n"
- "w natural=heath poly_heath\n"
- "w natural=land poly_land\n"
- "w natural=marsh poly_marsh\n"
- "w natural=meadow poly_meadow\n"
- "w natural=mud poly_mud\n"
- "w natural=sand poly_beach\n"
- "w natural=scree poly_scree\n"
- "w natural=scrub poly_scrub\n"
- "w natural=water poly_water\n"
- "w natural=wetland poly_mud\n"
- "w natural=wood poly_wood\n"
- "w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n"
- "w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n"
- "w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n"
- "w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n"
- "w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n"
- "w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n"
- "w piste:type=nordic piste_nordic\n"
- "w place=suburb poly_place1\n"
- "w place=hamlet poly_place2\n"
- "w place=isolated_dwelling poly_place2\n"
- "w place=locality poly_place2\n"
- "w place=village poly_place3\n"
- "w place=municipality poly_place4\n"
- "w place=town poly_place5\n"
- "w place=city poly_place6\n"
- "w de:place=city poly_place6\n"
- "w power=line powerline\n"
- "w railway=abandoned rail_abandoned\n"
- "w railway=disused rail_disused\n"
- "w railway=light_rail rail_light\n"
- "w railway=monorail rail_mono\n"
- "w railway=narrow_gauge rail_narrow_gauge\n"
- "w railway=preserved rail_preserved\n"
- "w railway=rail rail\n"
- "w railway=subway rail_subway\n"
- "w railway=tram rail_tram\n"
- "w route=ferry ferry\n"
- "w route=ski piste_nordic\n"
- "w sport=* poly_sport\n"
- "w tourism=artwork poly_artwork\n"
- "w tourism=attraction poly_attraction\n"
- "w tourism=camp_site poly_camp_site\n"
- "w tourism=caravan_site poly_caravan_site\n"
- "w tourism=picnic_site poly_picnic_site\n"
- "w tourism=theme_park poly_theme_park\n"
- "w tourism=zoo poly_zoo\n"
- "w waterway=canal water_canal\n"
- "w waterway=drain water_drain\n"
- "w waterway=river water_river\n"
- "w waterway=riverbank poly_water\n"
- "w waterway=stream water_stream\n"
- "w barrier=ditch ditch\n"
- "w barrier=hedge hedge\n"
- "w barrier=fence fence\n"
- "w barrier=wall wall\n"
- "w barrier=retaining_wall retaining_wall\n"
- "w barrier=city_wall city_wall\n"
+ "? landuse=cemetery poi_cemetery\n"
+ "? leisure=fishing poi_fish\n"
+ "? leisure=golf_course poi_golf\n"
+ "? leisure=marina poi_marine\n"
+ "? leisure=playground poi_playground\n"
+ "? leisure=slipway poi_boat_ramp\n"
+ "? leisure=sports_centre poi_sport\n"
+ "? leisure=stadium poi_stadium\n"
+ "? man_made=tower poi_tower\n"
+ "? military=airfield poi_military\n"
+ "? military=barracks poi_military\n"
+ "? military=bunker poi_military\n"
+ "? military=danger_area poi_danger_area\n"
+ "? military=range poi_military\n"
+ "? natural=bay poi_bay\n"
+ "? natural=peak,ele=* poi_peak\n" // show only major peaks with elevation
+ "? natural=tree poi_tree\n"
+ "n place=city town_label_2e5\n"
+ "n place=hamlet town_label_2e2\n"
+ "n place=locality town_label_2e0\n"
+ "n place=suburb district_label\n"
+ "n place=town town_label_2e4\n"
+ "n place=village town_label_2e3\n"
+ "n power=tower power_tower\n"
+ "n power=sub_station power_substation\n"
+ "n railway=halt poi_rail_halt\n"
+ "n railway=level_crossing poi_level_crossing\n"
+ "? railway=station poi_rail_station\n"
+ "? railway=tram_stop poi_rail_tram_stop\n"
+ "? shop=baker poi_shop_baker\n"
+ "? shop=bakery poi_shop_baker\n"
+ "? shop=beverages poi_shop_beverages\n"
+ "? shop=bicycle poi_shop_bicycle\n"
+ "? shop=butcher poi_shop_butcher\n"
+ "? shop=car poi_car_dealer_parts\n"
+ "? shop=car_repair poi_repair_service\n"
+ "? shop=clothes poi_shop_apparel\n"
+ "? shop=convenience poi_shop_grocery\n"
+ "? shop=chemist poi_shop_drugstore\n"
+ "? shop=florist poi_shop_florist\n"
+ "? shop=fruit poi_shop_fruit\n"
+ "? shop=furniture poi_shop_furniture\n"
+ "? shop=garden_centre poi_shop_handg\n"
+ "? shop=hardware poi_shop_handg\n"
+ "? shop=hairdresser poi_hairdresser\n"
+ "? shop=kiosk poi_shop_kiosk\n"
+ "? shop=optician poi_shop_optician\n"
+ "? shop=parfum poi_shop_parfum\n"
+ "? shop=photo poi_shop_photo\n"
+ "? shop=shoes poi_shop_shoes\n"
+ "? shop=supermarket poi_shopping\n"
+ "? shop=mall poi_mall\n"
+ "? sport=10pin poi_bowling\n"
+ "? sport=baseball poi_baseball\n"
+ "? sport=basketball poi_basketball\n"
+ "? sport=climbing poi_climbing\n"
+ "? sport=golf poi_golf\n"
+ "? sport=motor_sports poi_motor_sport\n"
+ "? sport=skiing poi_skiing\n"
+ "? sport=soccer poi_soccer\n"
+ "? sport=stadium poi_stadium\n"
+ "? sport=swimming poi_swimming\n"
+ "? sport=tennis poi_tennis\n"
+ "? tourism=attraction poi_attraction\n"
+ "? tourism=camp_site poi_camp_rv\n"
+ "? tourism=caravan_site poi_camp_rv\n"
+ "? tourism=guest_house poi_guesthouse\n"
+ "? tourism=hostel poi_hostel\n"
+ "? tourism=hotel poi_hotel\n"
+ "? tourism=information poi_information\n"
+ "? tourism=motel poi_motel\n"
+ "? tourism=museum poi_museum_history\n"
+ "? tourism=picnic_site poi_picnic\n"
+ "? tourism=theme_park poi_resort\n"
+ "? tourism=viewpoint poi_viewpoint\n"
+ "? tourism=zoo poi_zoo\n"
+ "n traffic_sign=city_limit traffic_sign_city_limit\n"
+ "n highway=speed_camera tec_common\n"
+ "w *=* street_unkn\n"
+ "w addr:interpolation=even house_number_interpolation_even\n"
+ "w addr:interpolation=odd house_number_interpolation_odd\n"
+ "w addr:interpolation=all house_number_interpolation_all\n"
+ "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n"
+ "w aerialway=cable_car lift_cable_car\n"
+ "w aerialway=chair_lift lift_chair\n"
+ "w aerialway=drag_lift lift_drag\n"
+ "w aeroway=aerodrome poly_airport\n"
+ "w aeroway=apron poly_apron\n"
+ "w aeroway=runway aeroway_runway\n"
+ "w aeroway=taxiway aeroway_taxiway\n"
+ "w aeroway=terminal poly_terminal\n"
+ "w amenity=college poly_college\n"
+ "w amenity=grave_yard poly_cemetery\n"
+ "w amenity=parking poly_car_parking\n"
+ "w amenity=place_of_worship poly_building\n"
+ "w amenity=university poly_university\n"
+ "w boundary=administrative,admin_level=2 border_country\n"
+ "w boundary=civil border_civil\n"
+ "w boundary=national_park border_national_park\n"
+ "w boundary=political border_political\n"
+ "w building=* poly_building\n"
+ "w contour_ext=elevation_major height_line_1\n"
+ "w contour_ext=elevation_medium height_line_2\n"
+ "w contour_ext=elevation_minor height_line_3\n"
+ "w highway=bridleway bridleway\n"
+ "w highway=bus_guideway bus_guideway\n"
+ "w highway=construction street_construction\n"
+ "w highway=cyclepath cycleway\n"
+ "w highway=cycleway cycleway\n"
+ "w highway=footway footway\n"
+ "w highway=footway,piste:type=nordic footway_and_piste_nordic\n"
+ "w highway=living_street living_street\n"
+ "w highway=minor street_1_land\n"
+ "w highway=parking_lane street_parking_lane\n"
+ "w highway=path path\n"
+ "w highway=path,bicycle=designated cycleway\n"
+ "w highway=path,bicycle=official cycleway\n"
+ "w highway=path,bicycle=designated,foot=designated cycleway\n"
+ "w highway=path,bicycle=official,foot=official cycleway\n"
+ "w highway=path,foot=designated footway\n"
+ "w highway=path,foot=official footway\n"
+ "w highway=path,horse=designated bridleway\n"
+ "w highway=path,horse=official bridleway\n"
+ "w highway=path,sac_scale=alpine_hiking hiking_alpine\n"
+ "w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n"
+ "w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n"
+ "w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n"
+ "w highway=path,sac_scale=hiking hiking\n"
+ "w highway=path,sac_scale=mountain_hiking hiking_mountain\n"
+ "w highway=pedestrian street_pedestrian\n"
+ "w highway=pedestrian,area=1 poly_pedestrian\n"
+ "w highway=plaza poly_plaza\n"
+ "w highway=motorway highway_land\n"
+ "w highway=motorway,rural=0 highway_city\n"
+ "w highway=motorway_link ramp\n"
+ "w highway=trunk street_n_lanes\n"
+ "w highway=trunk_link ramp\n"
+ "w highway=primary street_4_land\n"
+ "w highway=primary,name=*,rural=1 street_4_land\n"
+ "w highway=primary,name=* street_4_city\n"
+ "w highway=primary,rural=0 street_4_city\n"
+ "w highway=primary_link ramp\n"
+ "w highway=secondary street_3_land\n"
+ "w highway=secondary,name=*,rural=1 street_3_land\n"
+ "w highway=secondary,name=* street_3_city\n"
+ "w highway=secondary,rural=0 street_3_city\n"
+ "w highway=secondary,area=1 poly_street_3\n"
+ "w highway=secondary_link ramp\n"
+ "w highway=tertiary street_2_land\n"
+ "w highway=tertiary,name=*,rural=1 street_2_land\n"
+ "w highway=tertiary,name=* street_2_city\n"
+ "w highway=tertiary,rural=0 street_2_city\n"
+ "w highway=tertiary,area=1 poly_street_2\n"
+ "w highway=tertiary_link ramp\n"
+ "w highway=residential street_1_city\n"
+ "w highway=residential,area=1 poly_street_1\n"
+ "w highway=unclassified street_1_city\n"
+ "w highway=unclassified,area=1 poly_street_1\n"
+ "w highway=road street_1_city\n"
+ "w highway=service street_service\n"
+ "w highway=service,area=1 poly_service\n"
+ "w highway=service,service=parking_aisle street_parking_lane\n"
+ "w highway=track track_gravelled\n"
+ "w highway=track,surface=grass track_grass\n"
+ "w highway=track,surface=gravel track_gravelled\n"
+ "w highway=track,surface=ground track_ground\n"
+ "w highway=track,surface=paved track_paved\n"
+ "w highway=track,surface=unpaved track_unpaved\n"
+ "w highway=track,tracktype=grade1 track_paved\n"
+ "w highway=track,tracktype=grade2 track_gravelled\n"
+ "w highway=track,tracktype=grade3 track_unpaved\n"
+ "w highway=track,tracktype=grade4 track_ground\n"
+ "w highway=track,tracktype=grade5 track_grass\n"
+ "w highway=track,surface=paved,tracktype=grade1 track_paved\n"
+ "w highway=track,surface=gravel,tracktype=grade2 track_gravelled\n"
+ "w highway=track,surface=unpaved,tracktype=grade3 track_unpaved\n"
+ "w highway=track,surface=ground,tracktype=grade4 track_ground\n"
+ "w highway=track,surface=grass,tracktype=grade5 track_grass\n"
+ "w highway=unsurfaced track_gravelled\n"
+ "w highway=steps steps\n"
+ "w historic=archaeological_site poly_archaeological_site\n"
+ "w historic=battlefield poly_battlefield\n"
+ "w historic=ruins poly_ruins\n"
+ "w historic=town_gate poly_building\n"
+ "w landuse=allotments poly_allotments\n"
+ "w landuse=basin poly_basin\n"
+ "w landuse=brownfield poly_brownfield\n"
+ "w landuse=cemetery poly_cemetery\n"
+ "w landuse=commercial poly_commercial\n"
+ "w landuse=construction poly_construction\n"
+ "w landuse=farm poly_farm\n"
+ "w landuse=farmland poly_farm\n"
+ "w landuse=farmyard poly_town\n"
+ "w landuse=forest poly_wood\n"
+ "w landuse=grass poly_meadow\n"
+ "w landuse=greenfield poly_greenfield\n"
+ "w landuse=industrial poly_industry\n"
+ "w landuse=landfill poly_landfill\n"
+ "w landuse=military poly_military\n"
+ "w landuse=meadow poly_meadow\n"
+ "w landuse=plaza poly_plaza\n"
+ "w landuse=quarry poly_quarry\n"
+ "w landuse=railway poly_railway\n"
+ "w landuse=recreation_ground poly_recreation_ground\n"
+ "w landuse=reservoir poly_reservoir\n"
+ "w landuse=residential poly_town\n"
+ "w landuse=residential,area=1 poly_town\n"
+ "w landuse=retail poly_retail\n"
+ "w landuse=village_green poly_village_green\n"
+ "w landuse=vineyard poly_farm\n"
+ "w landuse=depot poly_depot\n"
+ "w landuse=garages poly_garages\n"
+ "w landuse=greenhouse_horticulture poly_greenhouse\n"
+ "w landuse=orchard poly_orchard\n"
+ "w landuse=plant_nursery poly_plantnursery\n"
+ "w landuse=port poly_port\n"
+ "w landuse=salt_pond poly_saltpond\n"
+ "w leisure=common poly_common\n"
+ "w leisure=fishing poly_fishing\n"
+ "w leisure=garden poly_garden\n"
+ "w leisure=golf_course poly_golf_course\n"
+ "w leisure=marina poly_marina\n"
+ "w leisure=nature_reserve poly_nature_reserve\n"
+ "w leisure=park poly_park\n"
+ "w leisure=pitch poly_sports_pitch\n"
+ "w leisure=playground poly_playground\n"
+ "w leisure=sports_centre poly_sport\n"
+ "w leisure=stadium poly_sports_stadium\n"
+ "w leisure=track poly_sports_track\n"
+ "w leisure=water_park poly_water_park\n"
+ "w military=airfield poly_airfield\n"
+ "w military=barracks poly_barracks\n"
+ "w military=danger_area poly_danger_area\n"
+ "w military=naval_base poly_naval_base\n"
+ "w military=range poly_range\n"
+ "w natural=beach poly_beach\n"
+ "w natural=coastline water_line\n"
+ "w natural=fell poly_fell\n"
+ "w natural=glacier poly_glacier\n"
+ "w natural=grassland poly_meadow\n"
+ "w natural=heath poly_heath\n"
+ "w natural=land poly_land\n"
+ "w natural=marsh poly_marsh\n"
+ "w natural=meadow poly_meadow\n"
+ "w natural=mud poly_mud\n"
+ "w natural=sand poly_beach\n"
+ "w natural=scree poly_scree\n"
+ "w natural=scrub poly_scrub\n"
+ "w natural=water poly_water\n"
+ "w natural=wetland poly_mud\n"
+ "w natural=wood poly_wood\n"
+ "w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n"
+ "w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n"
+ "w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n"
+ "w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n"
+ "w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n"
+ "w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n"
+ "w piste:type=nordic piste_nordic\n"
+ "w place=suburb poly_place1\n"
+ "w place=hamlet poly_place2\n"
+ "w place=isolated_dwelling poly_place2\n"
+ "w place=locality poly_place2\n"
+ "w place=village poly_place3\n"
+ "w place=municipality poly_place4\n"
+ "w place=town poly_place5\n"
+ "w place=city poly_place6\n"
+ "w de:place=city poly_place6\n"
+ "w power=line powerline\n"
+ "w railway=abandoned rail_abandoned\n"
+ "w railway=disused rail_disused\n"
+ "w railway=light_rail rail_light\n"
+ "w railway=monorail rail_mono\n"
+ "w railway=narrow_gauge rail_narrow_gauge\n"
+ "w railway=preserved rail_preserved\n"
+ "w railway=rail rail\n"
+ "w railway=subway rail_subway\n"
+ "w railway=tram rail_tram\n"
+ "w route=ferry ferry\n"
+ "w route=ski piste_nordic\n"
+ "w sport=* poly_sport\n"
+ "w tourism=artwork poly_artwork\n"
+ "w tourism=attraction poly_attraction\n"
+ "w tourism=camp_site poly_camp_site\n"
+ "w tourism=caravan_site poly_caravan_site\n"
+ "w tourism=picnic_site poly_picnic_site\n"
+ "w tourism=theme_park poly_theme_park\n"
+ "w tourism=zoo poly_zoo\n"
+ "w waterway=canal water_canal\n"
+ "w waterway=drain water_drain\n"
+ "w waterway=river water_river\n"
+ "w waterway=riverbank poly_water\n"
+ "w waterway=stream water_stream\n"
+ "w barrier=ditch ditch\n"
+ "w barrier=hedge hedge\n"
+ "w barrier=fence fence\n"
+ "w barrier=wall wall\n"
+ "w barrier=retaining_wall retaining_wall\n"
+ "w barrier=city_wall city_wall\n"
};
static void
-build_attrmap_line(char *line)
-{
- char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv;
- struct attr_mapping *attr_mapping=g_malloc0(sizeof(struct attr_mapping));
- int idx,attr_mapping_count=0;
- t=line;
- p=strpbrk(t," \t");
- if (p) {
- while (*p && isspace(*p))
- *p++='\0';
- kvl=p;
- p=strpbrk(kvl," \t");;
- }
- if (p) {
- while (*p && isspace(*p))
- *p++='\0';
- i=p;
- }
- if (t[0] == 'w') {
- if (! i)
- i="street_unkn";
- } else {
- if (! i)
- i="point_unkn";
- }
- attr_mapping->type=item_from_name(i);
- if (!attr_mapping->type) {
- printf("no id found for '%s'\n",i);
- }
- while ((kv=strtok(kvl, ","))) {
- kvl=NULL;
- if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) {
- idx=attr_present_count++;
- g_hash_table_insert(attr_hash, kv, (gpointer)(long long)idx);
- }
- attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int));
- attr_mapping->attr_present_idx[attr_mapping_count++]=idx;
- attr_mapping->attr_present_idx_count=attr_mapping_count;
- }
- if (t[0]== 'w') {
- attr_mapping_way=g_realloc(attr_mapping_way, sizeof(*attr_mapping_way)*(attr_mapping_way_count+1));
- attr_mapping_way[attr_mapping_way_count++]=attr_mapping;
- if(item_is_poly_place(*attr_mapping)) {
- attr_mapping_rel2poly_place=g_realloc(attr_mapping_rel2poly_place, sizeof(*attr_mapping_rel2poly_place)*(attr_mapping_rel2poly_place_count+1));
- attr_mapping_rel2poly_place[attr_mapping_rel2poly_place_count++]=attr_mapping;
- }
- }
- if (t[0]== '?') {
- attr_mapping_way2poi=g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi)*(attr_mapping_way2poi_count+1));
- attr_mapping_way2poi[attr_mapping_way2poi_count++]=attr_mapping;
- }
- if (t[0]!= 'w') {
- attr_mapping_node=g_realloc(attr_mapping_node, sizeof(*attr_mapping_node)*(attr_mapping_node_count+1));
- attr_mapping_node[attr_mapping_node_count++]=attr_mapping;
- }
+build_attrmap_line(char *line) {
+ char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv;
+ struct attr_mapping *attr_mapping=g_malloc0(sizeof(struct attr_mapping));
+ int idx,attr_mapping_count=0;
+ t=line;
+ p=strpbrk(t," \t");
+ if (p) {
+ while (*p && isspace(*p))
+ *p++='\0';
+ kvl=p;
+ p=strpbrk(kvl," \t");;
+ }
+ if (p) {
+ while (*p && isspace(*p))
+ *p++='\0';
+ i=p;
+ }
+ if (t[0] == 'w') {
+ if (! i)
+ i="street_unkn";
+ } else {
+ if (! i)
+ i="point_unkn";
+ }
+ attr_mapping->type=item_from_name(i);
+ if (!attr_mapping->type) {
+ printf("no id found for '%s'\n",i);
+ }
+ while ((kv=strtok(kvl, ","))) {
+ kvl=NULL;
+ if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) {
+ idx=attr_present_count++;
+ g_hash_table_insert(attr_hash, kv, (gpointer)(long long)idx);
+ }
+ attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int));
+ attr_mapping->attr_present_idx[attr_mapping_count++]=idx;
+ attr_mapping->attr_present_idx_count=attr_mapping_count;
+ }
+ if (t[0]== 'w') {
+ attr_mapping_way=g_realloc(attr_mapping_way, sizeof(*attr_mapping_way)*(attr_mapping_way_count+1));
+ attr_mapping_way[attr_mapping_way_count++]=attr_mapping;
+ if(item_is_poly_place(*attr_mapping)) {
+ attr_mapping_rel2poly_place=g_realloc(attr_mapping_rel2poly_place,
+ sizeof(*attr_mapping_rel2poly_place)*(attr_mapping_rel2poly_place_count+1));
+ attr_mapping_rel2poly_place[attr_mapping_rel2poly_place_count++]=attr_mapping;
+ }
+ }
+ if (t[0]== '?') {
+ attr_mapping_way2poi=g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi)*(attr_mapping_way2poi_count+1));
+ attr_mapping_way2poi[attr_mapping_way2poi_count++]=attr_mapping;
+ }
+ if (t[0]!= 'w') {
+ attr_mapping_node=g_realloc(attr_mapping_node, sizeof(*attr_mapping_node)*(attr_mapping_node_count+1));
+ attr_mapping_node[attr_mapping_node_count++]=attr_mapping;
+ }
}
static void
-build_attrmap(FILE* rule_file)
-{
- attr_hash=g_hash_table_new(g_str_hash, g_str_equal);
- attr_present_count=1;
+build_attrmap(FILE* rule_file) {
+ attr_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ attr_present_count=1;
// build attribute map from rule file if given
- if( rule_file )
- {
+ if( rule_file ) {
char buffer[200], *p;
while (fgets( buffer, 200, rule_file )) {
p=strchr(buffer,'\n');
@@ -854,8 +852,7 @@ build_attrmap(FILE* rule_file)
fclose( rule_file );
}
// use hardcoded default attributes
- else
- {
+ else {
char *p,*map=g_strdup(attrmap);
while (map) {
p=strchr(map,'\n');
@@ -867,499 +864,483 @@ build_attrmap(FILE* rule_file)
}
}
- attr_present=g_malloc0(sizeof(*attr_present)*attr_present_count);
+ attr_present=g_malloc0(sizeof(*attr_present)*attr_present_count);
}
static void
-build_countrytable(void)
-{
- int i;
- char *names,*str,*tok;
- country_table_hash=g_hash_table_new(g_str_hash, g_str_equal);
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- names=g_strdup(country_table[i].names);
- str=names;
- while ((tok=strtok(str, ","))) {
- str=NULL;
- g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]);
- }
- }
+build_countrytable(void) {
+ int i;
+ char *names,*str,*tok;
+ country_table_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ names=g_strdup(country_table[i].names);
+ str=names;
+ while ((tok=strtok(str, ","))) {
+ str=NULL;
+ g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]);
+ }
+ }
}
static void
-osm_logv(char *prefix, char *objtype, osmid id, int cont, struct coord_geo *geo, char *fmt, va_list ap)
-{
- char str[4096];
- vsnprintf(str, sizeof(str), fmt, ap);
- if(cont)
- prefix="";
- if(objtype)
- fprintf(stderr,"%shttp://www.openstreetmap.org/%s/"OSMID_FMT" %s", prefix, objtype, id, str);
- else if(geo)
- fprintf(stderr,"%shttp://www.openstreetmap.org/#map=19/%.5f/%.5f %s",prefix, geo->lat, geo->lng, str);
- else
- fprintf(stderr,"%s[no osm object info] %s",prefix, str);
+osm_logv(char *prefix, char *objtype, osmid id, int cont, struct coord_geo *geo, char *fmt, va_list ap) {
+ char str[4096];
+ vsnprintf(str, sizeof(str), fmt, ap);
+ if(cont)
+ prefix="";
+ if(objtype)
+ fprintf(stderr,"%shttp://www.openstreetmap.org/%s/"OSMID_FMT" %s", prefix, objtype, id, str);
+ else if(geo)
+ fprintf(stderr,"%shttp://www.openstreetmap.org/#map=19/%.5f/%.5f %s",prefix, geo->lat, geo->lng, str);
+ else
+ fprintf(stderr,"%s[no osm object info] %s",prefix, str);
}
void
-osm_warning(char *type, osmid id, int cont, char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- osm_logv("OSM Warning:", type, id, cont, NULL, fmt, ap);
- va_end(ap);
+osm_warning(char *type, osmid id, int cont, char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ osm_logv("OSM Warning:", type, id, cont, NULL, fmt, ap);
+ va_end(ap);
}
void
-osm_info(char *type, osmid id, int cont, char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- osm_logv("OSM Info:", type, id, cont, NULL, fmt, ap);
- va_end(ap);
+osm_info(char *type, osmid id, int cont, char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ osm_logv("OSM Info:", type, id, cont, NULL, fmt, ap);
+ va_end(ap);
}
static void
-itembin_warning(struct item_bin *ib, int cont, char *fmt, ...)
-{
- char *type=NULL;
- osmid id;
- struct coord_geo geo;
- va_list ap;
- if(0!=(id=item_bin_get_nodeid(ib))) {
- type="node";
- } else if(0!=(id=item_bin_get_wayid(ib))) {
- type="way";
- } else if(0!=(id=item_bin_get_relationid(ib))) {
- type="relation";
- } else {
- struct coord *c=(struct coord *)(ib+1);
- transform_to_geo(projection_mg, c, &geo);
- }
-
- va_start(ap, fmt);
- osm_logv("OSM Warning:", type, id, cont, &geo, fmt, ap);
- va_end(ap);
+itembin_warning(struct item_bin *ib, int cont, char *fmt, ...) {
+ char *type=NULL;
+ osmid id;
+ struct coord_geo geo;
+ va_list ap;
+ if(0!=(id=item_bin_get_nodeid(ib))) {
+ type="node";
+ } else if(0!=(id=item_bin_get_wayid(ib))) {
+ type="way";
+ } else if(0!=(id=item_bin_get_relationid(ib))) {
+ type="relation";
+ } else {
+ struct coord *c=(struct coord *)(ib+1);
+ transform_to_geo(projection_mg, c, &geo);
+ }
+
+ va_start(ap, fmt);
+ osm_logv("OSM Warning:", type, id, cont, &geo, fmt, ap);
+ va_end(ap);
}
static void
-attr_strings_clear(void)
-{
- attr_strings_buffer_free_offset=0;
- memset(attr_strings, 0, sizeof(attr_strings));
+attr_strings_clear(void) {
+ attr_strings_buffer_free_offset=0;
+ memset(attr_strings, 0, sizeof(attr_strings));
}
static void
-attr_strings_save(enum attr_strings_type id, char *str)
-{
- int str_size=strlen(str)+1;
- dbg_assert(attr_strings_buffer_free_offset+str_size<sizeof(attr_strings_buffer));
- attr_strings[id]=attr_strings_buffer+attr_strings_buffer_free_offset;
- g_strlcpy(attr_strings[id], str, str_size);
- attr_strings_buffer_free_offset+=str_size;
+attr_strings_save(enum attr_strings_type id, char *str) {
+ int str_size=strlen(str)+1;
+ dbg_assert(attr_strings_buffer_free_offset+str_size<sizeof(attr_strings_buffer));
+ attr_strings[id]=attr_strings_buffer+attr_strings_buffer_free_offset;
+ g_strlcpy(attr_strings[id], str, str_size);
+ attr_strings_buffer_free_offset+=str_size;
}
static osmid
-item_bin_get_nodeid_from_attr(struct item_bin *ib, enum attr_type attr_type)
-{
- unsigned long long *ret=item_bin_get_attr(ib, attr_type, NULL);
- if (ret)
- return *ret;
- return 0;
+item_bin_get_nodeid_from_attr(struct item_bin *ib, enum attr_type attr_type) {
+ unsigned long long *ret=item_bin_get_attr(ib, attr_type, NULL);
+ if (ret)
+ return *ret;
+ return 0;
}
osmid
-item_bin_get_nodeid(struct item_bin *ib)
-{
- return item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid);
+item_bin_get_nodeid(struct item_bin *ib) {
+ return item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid);
}
osmid
-item_bin_get_wayid(struct item_bin *ib)
-{
- unsigned long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL);
- if (ret)
- return *ret;
- return 0;
+item_bin_get_wayid(struct item_bin *ib) {
+ unsigned long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL);
+ if (ret)
+ return *ret;
+ return 0;
}
osmid
-item_bin_get_relationid(struct item_bin *ib)
-{
- unsigned long long *ret=item_bin_get_attr(ib, attr_osm_relationid, NULL);
- if (ret)
- return *ret;
- return 0;
+item_bin_get_relationid(struct item_bin *ib) {
+ unsigned long long *ret=item_bin_get_attr(ib, attr_osm_relationid, NULL);
+ if (ret)
+ return *ret;
+ return 0;
}
osmid
-item_bin_get_id(struct item_bin *ib)
-{
- osmid ret;
- if (ib->type < 0x80000000)
- return item_bin_get_nodeid(ib);
- ret=item_bin_get_wayid(ib);
- if (!ret)
- ret=item_bin_get_relationid(ib);
- return ret;
+item_bin_get_id(struct item_bin *ib) {
+ osmid ret;
+ if (ib->type < 0x80000000)
+ return item_bin_get_nodeid(ib);
+ ret=item_bin_get_wayid(ib);
+ if (!ret)
+ ret=item_bin_get_relationid(ib);
+ return ret;
}
static int node_is_tagged;
static void relation_add_tag(char *k, char *v);
static int
-access_value(char *v)
-{
- if (!strcmp(v,"1"))
- return 1;
- if (!strcmp(v,"yes"))
- return 1;
- if (!strcmp(v,"designated"))
- return 1;
- if (!strcmp(v,"official"))
- return 1;
- if (!strcmp(v,"permissive"))
- return 1;
- if (!strcmp(v,"0"))
- return 2;
- if (!strcmp(v,"no"))
- return 2;
- if (!strcmp(v,"agricultural"))
- return 2;
- if (!strcmp(v,"forestry"))
- return 2;
- if (!strcmp(v,"private"))
- return 2;
- if (!strcmp(v,"delivery"))
- return 2;
- if (!strcmp(v,"destination"))
- return 2;
- return 3;
-}
-
-static void
+access_value(char *v) {
+ if (!strcmp(v,"1"))
+ return 1;
+ if (!strcmp(v,"yes"))
+ return 1;
+ if (!strcmp(v,"designated"))
+ return 1;
+ if (!strcmp(v,"official"))
+ return 1;
+ if (!strcmp(v,"permissive"))
+ return 1;
+ if (!strcmp(v,"0"))
+ return 2;
+ if (!strcmp(v,"no"))
+ return 2;
+ if (!strcmp(v,"agricultural"))
+ return 2;
+ if (!strcmp(v,"forestry"))
+ return 2;
+ if (!strcmp(v,"private"))
+ return 2;
+ if (!strcmp(v,"delivery"))
+ return 2;
+ if (!strcmp(v,"destination"))
+ return 2;
+ return 3;
+}
+
+static void
osm_update_attr_present(char *k, char *v);
void
-osm_add_tag(char *k, char *v)
-{
- int level=2;
- if (in_relation) {
- relation_add_tag(k,v);
- return;
- }
- if (! strcmp(k,"ele")){
- attr_strings_save(attr_string_label, v);
- level=9;
- }
- if (! strcmp(k,"time"))
- level=9;
- if (! strcmp(k,"created_by"))
- level=9;
- if (! strncmp(k,"tiger:",6) || !strcmp(k,"AND_nodes"))
- level=9;
- if (! strcmp(k,"converted_by") || ! strcmp(k,"source"))
- level=8;
- if (! strncmp(k,"osmarender:",11) || !strncmp(k,"svg:",4))
- level=8;
- if (! strcmp(k,"layer"))
- level=7;
- if (! strcasecmp(v,"true") || ! strcasecmp(v,"yes"))
- v="1";
- if (! strcasecmp(v,"false") || ! strcasecmp(v,"no"))
- v="0";
- if (! strcmp(k,"oneway")) {
- if (!strcmp(v,"1")) {
- flags[0] |= AF_ONEWAY | AF_ROUNDABOUT_VALID;
- }
- if (! strcmp(v,"-1")) {
- flags[0] |= AF_ONEWAYREV | AF_ROUNDABOUT_VALID;
- }
- if (!in_way)
- level=6;
- else
- level=5;
- }
- if (! strcmp(k,"junction")) {
- if (! strcmp(v,"roundabout"))
- flags[0] |= AF_ONEWAY | AF_ROUNDABOUT | AF_ROUNDABOUT_VALID;
- }
- if (! strcmp(k,"maxspeed")) {
- if (strstr(v, "mph")) {
- maxspeed_attr_value = (int)floor(atof(v) * 1.609344);
- } else {
- maxspeed_attr_value = atoi(v);
- }
- if (maxspeed_attr_value)
- flags[0] |= AF_SPEED_LIMIT;
- level=5;
- }
- if (! strcmp(k,"toll")) {
- if (!strcmp(v,"1")) {
- flags[0] |= AF_TOLL;
- }
- }
- if (! strcmp(k,"access")) {
- if (strcmp(v,"destination"))
- flagsa[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_HORSE|AF_BIKE|AF_PEDESTRIAN;
- else
- flags[0] |= AF_THROUGH_TRAFFIC_LIMIT;
- if (! strcmp(v,"hov"))
- flags[0] |= AF_HIGH_OCCUPANCY_CAR_ONLY;
- level=5;
- }
- if (! strcmp(k,"vehicle")) {
- flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_BIKE;
- level=5;
- }
- if (! strcmp(k,"motor_vehicle")) {
- flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED;
- level=5;
- }
- if (! strcmp(k,"bicycle")) {
- flags[access_value(v)] |= AF_BIKE;
- level=5;
- }
- if (! strcmp(k,"foot")) {
- flags[access_value(v)] |= AF_PEDESTRIAN;
- level=5;
- }
- if (! strcmp(k,"horse")) {
- flags[access_value(v)] |= AF_HORSE;
- level=5;
- }
- if (! strcmp(k,"moped")) {
- flags[access_value(v)] |= AF_MOPED;
- level=5;
- }
- if (! strcmp(k,"motorcycle")) {
- flags[access_value(v)] |= AF_MOTORCYCLE;
- level=5;
- }
- if (! strcmp(k,"motorcar")) {
- flags[access_value(v)] |= AF_CAR;
- level=5;
- }
- if (! strcmp(k,"hov")) {
- flags[access_value(v)] |= AF_HIGH_OCCUPANCY_CAR;
- level=5;
- }
- if (! strcmp(k,"bus")) {
- flags[access_value(v)] |= AF_PUBLIC_BUS;
- level=5;
- }
- if (! strcmp(k,"taxi")) {
- flags[access_value(v)] |= AF_TAXI;
- level=5;
- }
- if (! strcmp(k,"goods")) {
- flags[access_value(v)] |= AF_DELIVERY_TRUCK;
- level=5;
- }
- if (! strcmp(k,"hgv")) {
- flags[access_value(v)] |= AF_TRANSPORT_TRUCK;
- level=5;
- }
- if (! strcmp(k,"emergency")) {
- flags[access_value(v)] |= AF_EMERGENCY_VEHICLES;
- level=5;
- }
- if (! strcmp(k,"hazmat")) {
- flags[access_value(v)] |= AF_DANGEROUS_GOODS;
- level=5;
- }
- if (! strcmp(k,"tunnel") && !strcmp(v,"1")) {
- flags[0] |= AF_UNDERGROUND;
- }
- if (! strcmp(k,"note"))
- level=5;
- if (! strcmp(k,"name")) {
- attr_strings_save(attr_string_label, v);
- level=5;
- }
- if (! strcmp(k,"addr:email")) {
- attr_strings_save(attr_string_email, v);
- level=5;
- }
- if (! strcmp(k,"addr:suburb")) {
- attr_strings_save(attr_string_district_name, v);
- level=5;
- }
- if (! strcmp(k,"addr:housenumber")) {
- attr_strings_save(attr_string_house_number, v);
- level=5;
- }
- if (! strcmp(k,"addr:street")) {
- attr_strings_save(attr_string_street_name, v);
- level=5;
- }
- if (! strcmp(k,"phone")) {
- attr_strings_save(attr_string_phone, v);
- level=5;
- }
- if (! strcmp(k,"fax")) {
- attr_strings_save(attr_string_fax, v);
- level=5;
- }
- if (! strcmp(k,"postal_code")) {
- attr_strings_save(attr_string_postal, v);
- level=5;
- }
- if (! strcmp(k,"addr:postcode") && !attr_strings[attr_string_postal]) {
- attr_strings_save(attr_string_postal, v);
- level=5;
- }
- if (! strcmp(k,"openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) {
- attr_strings_save(attr_string_postal, v);
- level=5;
- }
- if (! strcmp(k,"population")) {
- attr_strings_save(attr_string_population, v);
- level=5;
- }
- if (! strcmp(k,"openGeoDB:population") && !attr_strings[attr_string_population]) {
- attr_strings_save(attr_string_population, v);
- level=5;
- }
- if ((! strcmp(k,"ref")) || (! strcmp(k,"destination:ref"))) {
- if (in_way)
- attr_strings_save(attr_string_street_name_systematic, v);
- /* for exit number of highway_exit poi */
- else attr_strings_save(attr_string_ref, v);
- level=5;
- }
- if (! strcmp(k,"nat_ref")) {
- if (in_way)
- attr_strings_save(attr_string_street_name_systematic_nat, v);
- level=5;
- }
- if (! strcmp(k,"int_ref")) {
- if (in_way)
- attr_strings_save(attr_string_street_name_systematic_int, v);
- level=5;
- }
- if (! strcmp(k,"destination")) {
- if (in_way)
- attr_strings_save(attr_string_street_destination, v);
- level=5;
- }
- if (! strcmp(k,"destination:forward"))
- {
- if (in_way)
- attr_strings_save(attr_string_street_destination_forward, v);
- level=5;
- }
- if (! strcmp(k,"destination:backward"))
- {
- if (in_way)
- attr_strings_save(attr_string_street_destination_backward, v);
- level=5;
- }
- if (! strcmp(k,"exit_to")) {
- attr_strings_save(attr_string_exit_to, v);
- level=5;
- }
- if (! strcmp(k,"openGeoDB:is_in")) {
- if (!is_in_buffer[0])
- g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
- level=5;
- }
- if (! strcmp(k,"is_in")) {
- if (!is_in_buffer[0])
- g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
- level=5;
- }
- if (! strcmp(k,"is_in:country")) {
- /**
- * Sometimes there is no is_in tag, only is_in:country.
- * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag.
- */
- g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
- level=5;
- }
- if (! strcmp(k,"place_county")) {
- /**
- * Ireland uses the place_county OSM tag to describe what county a town is in.
- * This would be equivalent to is_in: Town; Locality; Country
- * A real world example would be Node: Moycullen (52234625)
- * The tag is processed as Moycullen; Galway; Ireland
- * where Galway is the county
- */
- g_strlcpy(is_in_buffer, "Ireland", sizeof(is_in_buffer));
- attr_strings_save(attr_string_county_name, v);
- level=5;
- }
- if (! strcmp(k,"gnis:ST_alpha")) {
- /* assume a gnis tag means it is part of the USA:
- http://en.wikipedia.org/wiki/Geographic_Names_Information_System
- many US towns do not have is_in tags
- */
- g_strlcpy(is_in_buffer, "USA", sizeof(is_in_buffer));
- level=5;
- }
- if (! strcmp(k,"lanes")) {
- level=5;
- }
- if (attr_debug_level >= level) {
- int bytes_left = sizeof( debug_attr_buffer ) - strlen(debug_attr_buffer) - 1;
- if ( bytes_left > 0 )
- {
- snprintf(debug_attr_buffer+strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v);
- debug_attr_buffer[ sizeof( debug_attr_buffer ) - 1 ] = '\0';
- node_is_tagged=1;
- }
- }
- if (level < 6)
- node_is_tagged=1;
-
- osm_update_attr_present(k, v);
-}
-
-static void
-osm_update_attr_present(char *k, char *v)
-{
- const int bufsize=BUFFER_SIZE*2+2;
- int idx;
- char *p, buffer[bufsize];
-
- g_strlcpy(buffer,"*=*", bufsize);
- if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
- dbg_assert(idx<attr_present_count);
- attr_present[idx]=1;
- }
-
- snprintf(buffer,bufsize,"%s=*", k);
- for(p=buffer;*p;p++)
- if(isspace(*p)) *p='_';
- if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
- dbg_assert(idx<attr_present_count);
- attr_present[idx]=2;
- }
-
- snprintf(buffer,bufsize,"*=%s", v);
- for(p=buffer;*p;p++)
- if(isspace(*p)) *p='_';
- if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
- dbg_assert(idx<attr_present_count);
- attr_present[idx]=2;
- }
-
- snprintf(buffer,bufsize,"%s=%s", k, v);
- for(p=buffer;*p;p++)
- if(isspace(*p)) *p='_';
- if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
- dbg_assert(idx<attr_present_count);
- attr_present[idx]=4;
- }
+osm_add_tag(char *k, char *v) {
+ int level=2;
+ if (in_relation) {
+ relation_add_tag(k,v);
+ return;
+ }
+ if (! strcmp(k,"ele")) {
+ attr_strings_save(attr_string_label, v);
+ level=9;
+ }
+ if (! strcmp(k,"time"))
+ level=9;
+ if (! strcmp(k,"created_by"))
+ level=9;
+ if (! strncmp(k,"tiger:",6) || !strcmp(k,"AND_nodes"))
+ level=9;
+ if (! strcmp(k,"converted_by") || ! strcmp(k,"source"))
+ level=8;
+ if (! strncmp(k,"osmarender:",11) || !strncmp(k,"svg:",4))
+ level=8;
+ if (! strcmp(k,"layer"))
+ level=7;
+ if (! strcasecmp(v,"true") || ! strcasecmp(v,"yes"))
+ v="1";
+ if (! strcasecmp(v,"false") || ! strcasecmp(v,"no"))
+ v="0";
+ if (! strcmp(k,"oneway")) {
+ if (!strcmp(v,"1")) {
+ flags[0] |= AF_ONEWAY | AF_ROUNDABOUT_VALID;
+ }
+ if (! strcmp(v,"-1")) {
+ flags[0] |= AF_ONEWAYREV | AF_ROUNDABOUT_VALID;
+ }
+ if (!in_way)
+ level=6;
+ else
+ level=5;
+ }
+ if (! strcmp(k,"junction")) {
+ if (! strcmp(v,"roundabout"))
+ flags[0] |= AF_ONEWAY | AF_ROUNDABOUT | AF_ROUNDABOUT_VALID;
+ }
+ if (! strcmp(k,"maxspeed")) {
+ if (strstr(v, "mph")) {
+ maxspeed_attr_value = (int)floor(atof(v) * 1.609344);
+ } else {
+ maxspeed_attr_value = atoi(v);
+ }
+ if (maxspeed_attr_value)
+ flags[0] |= AF_SPEED_LIMIT;
+ level=5;
+ }
+ if (! strcmp(k,"toll")) {
+ if (!strcmp(v,"1")) {
+ flags[0] |= AF_TOLL;
+ }
+ }
+ if (! strcmp(k,"access")) {
+ if (strcmp(v,"destination"))
+ flagsa[access_value(v)] |=
+ AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_HORSE|AF_BIKE|AF_PEDESTRIAN;
+ else
+ flags[0] |= AF_THROUGH_TRAFFIC_LIMIT;
+ if (! strcmp(v,"hov"))
+ flags[0] |= AF_HIGH_OCCUPANCY_CAR_ONLY;
+ level=5;
+ }
+ if (! strcmp(k,"vehicle")) {
+ flags[access_value(v)] |=
+ AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_BIKE;
+ level=5;
+ }
+ if (! strcmp(k,"motor_vehicle")) {
+ flags[access_value(v)] |=
+ AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED;
+ level=5;
+ }
+ if (! strcmp(k,"bicycle")) {
+ flags[access_value(v)] |= AF_BIKE;
+ level=5;
+ }
+ if (! strcmp(k,"foot")) {
+ flags[access_value(v)] |= AF_PEDESTRIAN;
+ level=5;
+ }
+ if (! strcmp(k,"horse")) {
+ flags[access_value(v)] |= AF_HORSE;
+ level=5;
+ }
+ if (! strcmp(k,"moped")) {
+ flags[access_value(v)] |= AF_MOPED;
+ level=5;
+ }
+ if (! strcmp(k,"motorcycle")) {
+ flags[access_value(v)] |= AF_MOTORCYCLE;
+ level=5;
+ }
+ if (! strcmp(k,"motorcar")) {
+ flags[access_value(v)] |= AF_CAR;
+ level=5;
+ }
+ if (! strcmp(k,"hov")) {
+ flags[access_value(v)] |= AF_HIGH_OCCUPANCY_CAR;
+ level=5;
+ }
+ if (! strcmp(k,"bus")) {
+ flags[access_value(v)] |= AF_PUBLIC_BUS;
+ level=5;
+ }
+ if (! strcmp(k,"taxi")) {
+ flags[access_value(v)] |= AF_TAXI;
+ level=5;
+ }
+ if (! strcmp(k,"goods")) {
+ flags[access_value(v)] |= AF_DELIVERY_TRUCK;
+ level=5;
+ }
+ if (! strcmp(k,"hgv")) {
+ flags[access_value(v)] |= AF_TRANSPORT_TRUCK;
+ level=5;
+ }
+ if (! strcmp(k,"emergency")) {
+ flags[access_value(v)] |= AF_EMERGENCY_VEHICLES;
+ level=5;
+ }
+ if (! strcmp(k,"hazmat")) {
+ flags[access_value(v)] |= AF_DANGEROUS_GOODS;
+ level=5;
+ }
+ if (! strcmp(k,"tunnel") && !strcmp(v,"1")) {
+ flags[0] |= AF_UNDERGROUND;
+ }
+ if (! strcmp(k,"note"))
+ level=5;
+ if (! strcmp(k,"name")) {
+ attr_strings_save(attr_string_label, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:email")) {
+ attr_strings_save(attr_string_email, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:suburb")) {
+ attr_strings_save(attr_string_district_name, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:housenumber")) {
+ attr_strings_save(attr_string_house_number, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:street")) {
+ attr_strings_save(attr_string_street_name, v);
+ level=5;
+ }
+ if (! strcmp(k,"phone")) {
+ attr_strings_save(attr_string_phone, v);
+ level=5;
+ }
+ if (! strcmp(k,"fax")) {
+ attr_strings_save(attr_string_fax, v);
+ level=5;
+ }
+ if (! strcmp(k,"postal_code")) {
+ attr_strings_save(attr_string_postal, v);
+ level=5;
+ }
+ if (! strcmp(k,"addr:postcode") && !attr_strings[attr_string_postal]) {
+ attr_strings_save(attr_string_postal, v);
+ level=5;
+ }
+ if (! strcmp(k,"openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) {
+ attr_strings_save(attr_string_postal, v);
+ level=5;
+ }
+ if (! strcmp(k,"population")) {
+ attr_strings_save(attr_string_population, v);
+ level=5;
+ }
+ if (! strcmp(k,"openGeoDB:population") && !attr_strings[attr_string_population]) {
+ attr_strings_save(attr_string_population, v);
+ level=5;
+ }
+ if ((! strcmp(k,"ref")) || (! strcmp(k,"destination:ref"))) {
+ if (in_way)
+ attr_strings_save(attr_string_street_name_systematic, v);
+ /* for exit number of highway_exit poi */
+ else attr_strings_save(attr_string_ref, v);
+ level=5;
+ }
+ if (! strcmp(k,"nat_ref")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_name_systematic_nat, v);
+ level=5;
+ }
+ if (! strcmp(k,"int_ref")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_name_systematic_int, v);
+ level=5;
+ }
+ if (! strcmp(k,"destination")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_destination, v);
+ level=5;
+ }
+ if (! strcmp(k,"destination:forward")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_destination_forward, v);
+ level=5;
+ }
+ if (! strcmp(k,"destination:backward")) {
+ if (in_way)
+ attr_strings_save(attr_string_street_destination_backward, v);
+ level=5;
+ }
+ if (! strcmp(k,"exit_to")) {
+ attr_strings_save(attr_string_exit_to, v);
+ level=5;
+ }
+ if (! strcmp(k,"openGeoDB:is_in")) {
+ if (!is_in_buffer[0])
+ g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
+ level=5;
+ }
+ if (! strcmp(k,"is_in")) {
+ if (!is_in_buffer[0])
+ g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
+ level=5;
+ }
+ if (! strcmp(k,"is_in:country")) {
+ /**
+ * Sometimes there is no is_in tag, only is_in:country.
+ * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag.
+ */
+ g_strlcpy(is_in_buffer, v, sizeof(is_in_buffer));
+ level=5;
+ }
+ if (! strcmp(k,"place_county")) {
+ /**
+ * Ireland uses the place_county OSM tag to describe what county a town is in.
+ * This would be equivalent to is_in: Town; Locality; Country
+ * A real world example would be Node: Moycullen (52234625)
+ * The tag is processed as Moycullen; Galway; Ireland
+ * where Galway is the county
+ */
+ g_strlcpy(is_in_buffer, "Ireland", sizeof(is_in_buffer));
+ attr_strings_save(attr_string_county_name, v);
+ level=5;
+ }
+ if (! strcmp(k,"gnis:ST_alpha")) {
+ /* assume a gnis tag means it is part of the USA:
+ http://en.wikipedia.org/wiki/Geographic_Names_Information_System
+ many US towns do not have is_in tags
+ */
+ g_strlcpy(is_in_buffer, "USA", sizeof(is_in_buffer));
+ level=5;
+ }
+ if (! strcmp(k,"lanes")) {
+ level=5;
+ }
+ if (attr_debug_level >= level) {
+ int bytes_left = sizeof( debug_attr_buffer ) - strlen(debug_attr_buffer) - 1;
+ if ( bytes_left > 0 ) {
+ snprintf(debug_attr_buffer+strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v);
+ debug_attr_buffer[ sizeof( debug_attr_buffer ) - 1 ] = '\0';
+ node_is_tagged=1;
+ }
+ }
+ if (level < 6)
+ node_is_tagged=1;
+
+ osm_update_attr_present(k, v);
+}
+
+static void
+osm_update_attr_present(char *k, char *v) {
+ const int bufsize=BUFFER_SIZE*2+2;
+ int idx;
+ char *p, buffer[bufsize];
+
+ g_strlcpy(buffer,"*=*", bufsize);
+ if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
+ dbg_assert(idx<attr_present_count);
+ attr_present[idx]=1;
+ }
+
+ snprintf(buffer,bufsize,"%s=*", k);
+ for(p=buffer; *p; p++)
+ if(isspace(*p)) *p='_';
+ if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
+ dbg_assert(idx<attr_present_count);
+ attr_present[idx]=2;
+ }
+
+ snprintf(buffer,bufsize,"*=%s", v);
+ for(p=buffer; *p; p++)
+ if(isspace(*p)) *p='_';
+ if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
+ dbg_assert(idx<attr_present_count);
+ attr_present[idx]=2;
+ }
+
+ snprintf(buffer,bufsize,"%s=%s", k, v);
+ for(p=buffer; *p; p++)
+ if(isspace(*p)) *p='_';
+ if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) {
+ dbg_assert(idx<attr_present_count);
+ attr_present[idx]=4;
+ }
}
int coord_count;
static void
-extend_buffer(struct buffer *b)
-{
- b->malloced+=b->malloced_step;
- b->base=g_realloc(b->base, b->malloced);
+extend_buffer(struct buffer *b) {
+ b->malloced+=b->malloced_step;
+ b->base=g_realloc(b->base, b->malloced);
}
/** The node currently being processed. */
@@ -1369,256 +1350,246 @@ osmid id_last_node;
GHashTable *node_hash,*way_hash;
static void
-node_buffer_to_hash(void)
-{
- int i,count=node_buffer.size/sizeof(struct node_item);
- struct node_item *ni=(struct node_item *)node_buffer.base;
+node_buffer_to_hash(void) {
+ int i,count=node_buffer.size/sizeof(struct node_item);
+ struct node_item *ni=(struct node_item *)node_buffer.base;
- for (i = 0 ; i < count ; i++)
- g_hash_table_insert(node_hash, (gpointer)(long long)(ni[i].nd_id), (gpointer)(long long)i);
+ for (i = 0 ; i < count ; i++)
+ g_hash_table_insert(node_hash, (gpointer)(long long)(ni[i].nd_id), (gpointer)(long long)i);
}
void
-flush_nodes(int final)
-{
- fprintf(stderr,"flush_nodes %d\n",final);
- save_buffer("coords.tmp",&node_buffer,slices*slice_size);
- if (!final) {
- node_buffer.size=0;
- }
- slices++;
+flush_nodes(int final) {
+ fprintf(stderr,"flush_nodes %d\n",final);
+ save_buffer("coords.tmp",&node_buffer,slices*slice_size);
+ if (!final) {
+ node_buffer.size=0;
+ }
+ slices++;
}
static struct node_item*
allocate_node_item_in_buffer(void) {
- struct node_item* new_node;
- if (node_buffer.size + sizeof(struct node_item) > node_buffer.malloced)
- extend_buffer(&node_buffer);
- if (node_buffer.size + sizeof(struct node_item) > slice_size) {
- flush_nodes(0);
- }
- new_node=(struct node_item *)(node_buffer.base+node_buffer.size);
- node_buffer.size+=sizeof(struct node_item);
- return new_node;
+ struct node_item* new_node;
+ if (node_buffer.size + sizeof(struct node_item) > node_buffer.malloced)
+ extend_buffer(&node_buffer);
+ if (node_buffer.size + sizeof(struct node_item) > slice_size) {
+ flush_nodes(0);
+ }
+ new_node=(struct node_item *)(node_buffer.base+node_buffer.size);
+ node_buffer.size+=sizeof(struct node_item);
+ return new_node;
}
static void
remove_last_node_item_from_buffer(void) {
- node_buffer.size-=sizeof(struct node_item);
+ node_buffer.size-=sizeof(struct node_item);
}
void
-osm_add_node(osmid id, double lat, double lon)
-{
- in_node=1;
- attr_strings_clear();
- node_is_tagged=0;
- nodeid=id;
- item.type=type_point_unkn;
- debug_attr_buffer[0]='\0';
- is_in_buffer[0]='\0';
- debug_attr_buffer[0]='\0';
- osmid_attr.type=attr_osm_nodeid;
- osmid_attr.len=3;
- osmid_attr_value=id;
-
- current_node=allocate_node_item_in_buffer();
- dbg_assert(id < ((2ull<<NODE_ID_BITS)-1));
- current_node->nd_id=id;
- current_node->ref_way=0;
- current_node->c.x=lon*6371000.0*M_PI/180;
- current_node->c.y=log(tan(M_PI_4+lat*M_PI/360))*6371000.0;
- if (! node_hash) {
- if (current_node->nd_id > id_last_node) {
- id_last_node=current_node->nd_id;
- } else {
- fprintf(stderr,"INFO: Nodes out of sequence (new " OSMID_FMT " vs old " OSMID_FMT "), adding hash\n",
- (osmid)current_node->nd_id, id_last_node);
- node_hash=g_hash_table_new(NULL, NULL);
- node_buffer_to_hash();
- }
- } else
- if (!g_hash_table_lookup(node_hash, (gpointer)(long long)(current_node->nd_id)))
- g_hash_table_insert(node_hash, (gpointer)(long long)(current_node->nd_id),
- (gpointer)(long long)(current_node-(struct node_item *)node_buffer.base));
- else {
- remove_last_node_item_from_buffer();
- nodeid=0;
- }
+osm_add_node(osmid id, double lat, double lon) {
+ in_node=1;
+ attr_strings_clear();
+ node_is_tagged=0;
+ nodeid=id;
+ item.type=type_point_unkn;
+ debug_attr_buffer[0]='\0';
+ is_in_buffer[0]='\0';
+ debug_attr_buffer[0]='\0';
+ osmid_attr.type=attr_osm_nodeid;
+ osmid_attr.len=3;
+ osmid_attr_value=id;
+
+ current_node=allocate_node_item_in_buffer();
+ dbg_assert(id < ((2ull<<NODE_ID_BITS)-1));
+ current_node->nd_id=id;
+ current_node->ref_way=0;
+ current_node->c.x=lon*6371000.0*M_PI/180;
+ current_node->c.y=log(tan(M_PI_4+lat*M_PI/360))*6371000.0;
+ if (! node_hash) {
+ if (current_node->nd_id > id_last_node) {
+ id_last_node=current_node->nd_id;
+ } else {
+ fprintf(stderr,"INFO: Nodes out of sequence (new " OSMID_FMT " vs old " OSMID_FMT "), adding hash\n",
+ (osmid)current_node->nd_id, id_last_node);
+ node_hash=g_hash_table_new(NULL, NULL);
+ node_buffer_to_hash();
+ }
+ } else if (!g_hash_table_lookup(node_hash, (gpointer)(long long)(current_node->nd_id)))
+ g_hash_table_insert(node_hash, (gpointer)(long long)(current_node->nd_id),
+ (gpointer)(long long)(current_node-(struct node_item *)node_buffer.base));
+ else {
+ remove_last_node_item_from_buffer();
+ nodeid=0;
+ }
}
void
-clear_node_item_buffer(void)
-{
- int j,count=node_buffer.size/sizeof(struct node_item);
- struct node_item *ni=(struct node_item *)(node_buffer.base);
- for (j = 0 ; j < count ; j++) {
- ni[j].ref_way=0;
- }
+clear_node_item_buffer(void) {
+ int j,count=node_buffer.size/sizeof(struct node_item);
+ struct node_item *ni=(struct node_item *)(node_buffer.base);
+ for (j = 0 ; j < count ; j++) {
+ ni[j].ref_way=0;
+ }
}
static long long
-node_item_find_index_in_ordered_list(osmid id)
-{
- struct node_item *node_buffer_base=(struct node_item *)(node_buffer.base);
- long long node_count=node_buffer.size/sizeof(struct node_item);
- long long search_step=node_count>4 ? node_count/4 : 1;
- long long search_index=node_count/2;
- if (node_buffer_base[0].nd_id > id)
- return -1;
- if (node_buffer_base[node_count-1].nd_id < id)
- return -1;
- while (node_buffer_base[search_index].nd_id != id) {
- if (node_buffer_base[search_index].nd_id < id) {
- search_index+=search_step;
- if (search_step == 1) {
- if (search_index >= node_count)
- return -1;
- if (node_buffer_base[search_index].nd_id > id)
- return -1;
- } else {
- if (search_index >= node_count)
- search_index=node_count-1;
- }
- } else {
- search_index-=search_step;
- if (search_step == 1) {
- if (search_index < 0)
- return -1;
- if (node_buffer_base[search_index].nd_id < id)
- return -1;
- } else {
- if (search_index < 0)
- search_index=0;
- }
- }
- if (search_step > 1)
- search_step/=2;
- }
- return search_index;
+node_item_find_index_in_ordered_list(osmid id) {
+ struct node_item *node_buffer_base=(struct node_item *)(node_buffer.base);
+ long long node_count=node_buffer.size/sizeof(struct node_item);
+ long long search_step=node_count>4 ? node_count/4 : 1;
+ long long search_index=node_count/2;
+ if (node_buffer_base[0].nd_id > id)
+ return -1;
+ if (node_buffer_base[node_count-1].nd_id < id)
+ return -1;
+ while (node_buffer_base[search_index].nd_id != id) {
+ if (node_buffer_base[search_index].nd_id < id) {
+ search_index+=search_step;
+ if (search_step == 1) {
+ if (search_index >= node_count)
+ return -1;
+ if (node_buffer_base[search_index].nd_id > id)
+ return -1;
+ } else {
+ if (search_index >= node_count)
+ search_index=node_count-1;
+ }
+ } else {
+ search_index-=search_step;
+ if (search_step == 1) {
+ if (search_index < 0)
+ return -1;
+ if (node_buffer_base[search_index].nd_id < id)
+ return -1;
+ } else {
+ if (search_index < 0)
+ search_index=0;
+ }
+ }
+ if (search_step > 1)
+ search_step/=2;
+ }
+ return search_index;
}
static struct node_item *
-node_item_get(osmid id)
-{
- struct node_item *node_buffer_base=(struct node_item *)(node_buffer.base);
- long long result_index;
- if (node_hash) {
- // Use g_hash_table_lookup_extended instead of g_hash_table_lookup
- // to distinguish a key with a value 0 from a missing key.
- if (!g_hash_table_lookup_extended (node_hash, (gpointer)(id), NULL,
+node_item_get(osmid id) {
+ struct node_item *node_buffer_base=(struct node_item *)(node_buffer.base);
+ long long result_index;
+ if (node_hash) {
+ // Use g_hash_table_lookup_extended instead of g_hash_table_lookup
+ // to distinguish a key with a value 0 from a missing key.
+ if (!g_hash_table_lookup_extended (node_hash, (gpointer)(id), NULL,
(gpointer)&result_index)) {
- result_index=-1;
- }
- } else {
- result_index=node_item_find_index_in_ordered_list(id);
- }
- return result_index!=-1 ? node_buffer_base+result_index : NULL;
+ result_index=-1;
+ }
+ } else {
+ result_index=node_item_find_index_in_ordered_list(id);
+ }
+ return result_index!=-1 ? node_buffer_base+result_index : NULL;
}
#if 0
static int
-load_node(FILE *coords, int p, struct node_item *ret)
-{
- fseek(coords, p*sizeof(struct node_item), SEEK_SET);
- if (fread(ret, sizeof(*ret), 1, coords) != 1) {
- fprintf(stderr,"read failed\n");
- return 0;
- }
- return 1;
+load_node(FILE *coords, int p, struct node_item *ret) {
+ fseek(coords, p*sizeof(struct node_item), SEEK_SET);
+ if (fread(ret, sizeof(*ret), 1, coords) != 1) {
+ fprintf(stderr,"read failed\n");
+ return 0;
+ }
+ return 1;
}
#endif
#if 0
static int
-node_item_get_from_file(FILE *coords, osmid id, struct node_item *ret)
-{
- int count;
- int interval;
- int p;
- if (node_hash) {
- int i;
- i=(int)(long)(g_hash_table_lookup(node_hash, (gpointer)(long)id));
- fseek(coords, i*sizeof(*ret), SEEK_SET);
- if (fread(ret, sizeof(*ret), 1, coords) == 1)
- return 1;
- else
- return 0;
- }
-
- fseek(coords, 0, SEEK_END);
- count=ftello(coords)/sizeof(struct node_item);
- interval=count/4;
- p=count/2;
- if(interval==0) {
- // If fewer than 4 nodes defined so far set interval to 1 to
- // avoid infinite loop
- interval = 1;
- }
- if (!load_node(coords, p, ret))
- return 0;
- for (;;) {
- if (ret->id == id)
- return 1;
- if (ret->id < id) {
- p+=interval;
- if (interval == 1) {
- if (p >= count)
- return 0;
- if (!load_node(coords, p, ret))
- return 0;
- if (ret->id > id)
- return 0;
- } else {
- if (p >= count)
- p=count-1;
- if (!load_node(coords, p, ret))
- return 0;
- }
- } else {
- p-=interval;
- if (interval == 1) {
- if (p < 0)
- return 0;
- if (!load_node(coords, p, ret))
- return 0;
- if (ret->id < id)
- return 0;
- } else {
- if (p < 0)
- p=0;
- if (!load_node(coords, p, ret))
- return 0;
- }
- }
- if (interval > 1)
- interval/=2;
- }
-}
-#endif
+node_item_get_from_file(FILE *coords, osmid id, struct node_item *ret) {
+ int count;
+ int interval;
+ int p;
+ if (node_hash) {
+ int i;
+ i=(int)(long)(g_hash_table_lookup(node_hash, (gpointer)(long)id));
+ fseek(coords, i*sizeof(*ret), SEEK_SET);
+ if (fread(ret, sizeof(*ret), 1, coords) == 1)
+ return 1;
+ else
+ return 0;
+ }
+
+ fseek(coords, 0, SEEK_END);
+ count=ftello(coords)/sizeof(struct node_item);
+ interval=count/4;
+ p=count/2;
+ if(interval==0) {
+ // If fewer than 4 nodes defined so far set interval to 1 to
+ // avoid infinite loop
+ interval = 1;
+ }
+ if (!load_node(coords, p, ret))
+ return 0;
+ for (;;) {
+ if (ret->id == id)
+ return 1;
+ if (ret->id < id) {
+ p+=interval;
+ if (interval == 1) {
+ if (p >= count)
+ return 0;
+ if (!load_node(coords, p, ret))
+ return 0;
+ if (ret->id > id)
+ return 0;
+ } else {
+ if (p >= count)
+ p=count-1;
+ if (!load_node(coords, p, ret))
+ return 0;
+ }
+ } else {
+ p-=interval;
+ if (interval == 1) {
+ if (p < 0)
+ return 0;
+ if (!load_node(coords, p, ret))
+ return 0;
+ if (ret->id < id)
+ return 0;
+ } else {
+ if (p < 0)
+ p=0;
+ if (!load_node(coords, p, ret))
+ return 0;
+ }
+ }
+ if (interval > 1)
+ interval/=2;
+ }
+}
+#endif
void
-osm_add_way(osmid id)
-{
- static osmid wayid_last;
-
- in_way=1;
- wayid=id;
- coord_count=0;
- attr_strings_clear();
- item.type=type_street_unkn;
- debug_attr_buffer[0]='\0';
- maxspeed_attr_value=0;
- flags_attr_value = 0;
- memset(flags, 0, sizeof(flags));
- memset(flagsa, 0, sizeof(flagsa));
- debug_attr_buffer[0]='\0';
- osmid_attr_value=id;
- if (wayid < wayid_last && !way_hash) {
- fprintf(stderr,"INFO: Ways out of sequence (new "OSMID_FMT" vs old "OSMID_FMT"), adding hash\n", wayid, wayid_last);
- way_hash=g_hash_table_new(NULL, NULL);
- }
- wayid_last=wayid;
+osm_add_way(osmid id) {
+ static osmid wayid_last;
+
+ in_way=1;
+ wayid=id;
+ coord_count=0;
+ attr_strings_clear();
+ item.type=type_street_unkn;
+ debug_attr_buffer[0]='\0';
+ maxspeed_attr_value=0;
+ flags_attr_value = 0;
+ memset(flags, 0, sizeof(flags));
+ memset(flagsa, 0, sizeof(flagsa));
+ debug_attr_buffer[0]='\0';
+ osmid_attr_value=id;
+ if (wayid < wayid_last && !way_hash) {
+ fprintf(stderr,"INFO: Ways out of sequence (new "OSMID_FMT" vs old "OSMID_FMT"), adding hash\n", wayid, wayid_last);
+ way_hash=g_hash_table_new(NULL, NULL);
+ }
+ wayid_last=wayid;
}
char relation_type[BUFFER_SIZE];
@@ -1626,348 +1597,339 @@ char iso_code[BUFFER_SIZE];
int boundary;
void
-osm_add_relation(osmid id)
-{
- osmid_attr_value=id;
- in_relation=1;
- debug_attr_buffer[0]='\0';
- relation_type[0]='\0';
- iso_code[0]='\0';
- boundary=0;
- item_bin_init(tmp_item_bin, type_none);
- item_bin_add_attr_longlong(tmp_item_bin, attr_osm_relationid, osmid_attr_value);
+osm_add_relation(osmid id) {
+ osmid_attr_value=id;
+ in_relation=1;
+ debug_attr_buffer[0]='\0';
+ relation_type[0]='\0';
+ iso_code[0]='\0';
+ boundary=0;
+ item_bin_init(tmp_item_bin, type_none);
+ item_bin_add_attr_longlong(tmp_item_bin, attr_osm_relationid, osmid_attr_value);
}
static int
-country_id_from_iso2(char *iso)
-{
- int ret=0;
- if (iso) {
- struct country_search *search;
- struct attr country_iso2,country_id;
- struct item *item;
- country_iso2.type=attr_country_iso2;
- country_iso2.u.str=iso;
- search=country_search_new(&country_iso2,0);
- if ((item=country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id))
- ret=country_id.u.num;
-
- country_search_destroy(search);
- }
- return ret;
+country_id_from_iso2(char *iso) {
+ int ret=0;
+ if (iso) {
+ struct country_search *search;
+ struct attr country_iso2,country_id;
+ struct item *item;
+ country_iso2.type=attr_country_iso2;
+ country_iso2.u.str=iso;
+ search=country_search_new(&country_iso2,0);
+ if ((item=country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id))
+ ret=country_id.u.num;
+
+ country_search_destroy(search);
+ }
+ return ret;
}
static struct country_table *
-country_from_countryid(int id)
-{
- int i;
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- if (country_table[i].countryid == id)
- return &country_table[i];
- }
- return NULL;
+country_from_countryid(int id) {
+ int i;
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ if (country_table[i].countryid == id)
+ return &country_table[i];
+ }
+ return NULL;
}
struct country_table *
-country_from_iso2(char *iso)
-{
- return country_from_countryid(country_id_from_iso2(iso));
+country_from_iso2(char *iso) {
+ return country_from_countryid(country_id_from_iso2(iso));
}
void
-osm_end_relation(struct maptool_osm *osm)
-{
- enum item_type type;
+osm_end_relation(struct maptool_osm *osm) {
+ enum item_type type;
- in_relation=0;
+ in_relation=0;
- if(attr_longest_match(attr_mapping_rel2poly_place, attr_mapping_rel2poly_place_count, &type, 1)) {
- tmp_item_bin->type=type;
- }
- else
- type=type_none;
+ if(attr_longest_match(attr_mapping_rel2poly_place, attr_mapping_rel2poly_place_count, &type, 1)) {
+ tmp_item_bin->type=type;
+ } else
+ type=type_none;
- if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && (boundary || type!=type_none)) {
- item_bin_write(tmp_item_bin, osm->boundaries);
- }
+ if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && (boundary || type!=type_none)) {
+ item_bin_write(tmp_item_bin, osm->boundaries);
+ }
- if (!strcmp(relation_type, "restriction") && (tmp_item_bin->type == type_street_turn_restriction_no || tmp_item_bin->type == type_street_turn_restriction_only))
- item_bin_write(tmp_item_bin, osm->turn_restrictions);
+ if (!strcmp(relation_type, "restriction") && (tmp_item_bin->type == type_street_turn_restriction_no
+ || tmp_item_bin->type == type_street_turn_restriction_only))
+ item_bin_write(tmp_item_bin, osm->turn_restrictions);
- if (!strcmp(relation_type, "associatedStreet") )
- item_bin_write(tmp_item_bin, osm->associated_streets);
-
- attr_longest_match_clear();
+ if (!strcmp(relation_type, "associatedStreet") )
+ item_bin_write(tmp_item_bin, osm->associated_streets);
+
+ attr_longest_match_clear();
}
void
-osm_add_member(enum relation_member_type type, osmid ref, char *role)
-{
- const int bufsize=BUFFER_SIZE*3+3;
- char member_buffer[bufsize];
- struct attr memberattr = { attr_osm_member };
+osm_add_member(enum relation_member_type type, osmid ref, char *role) {
+ const int bufsize=BUFFER_SIZE*3+3;
+ char member_buffer[bufsize];
+ struct attr memberattr = { attr_osm_member };
- snprintf(member_buffer,bufsize, RELATION_MEMBER_PRINT_FORMAT, (int)type, (long long) ref, role);
- memberattr.u.str=member_buffer;
- item_bin_add_attr(tmp_item_bin, &memberattr);
+ snprintf(member_buffer,bufsize, RELATION_MEMBER_PRINT_FORMAT, (int)type, (long long) ref, role);
+ memberattr.u.str=member_buffer;
+ item_bin_add_attr(tmp_item_bin, &memberattr);
}
static void
-relation_add_tag(char *k, char *v)
-{
- int add_tag=1;
- if (!strcmp(k,"type")) {
- g_strlcpy(relation_type, v, sizeof(relation_type));
- add_tag=0;
- }
- else if (!strcmp(k,"restriction")) {
- if (!strncmp(v,"no_",3)) {
- tmp_item_bin->type=type_street_turn_restriction_no;
- add_tag=0;
- } else if (!strncmp(v,"only_",5)) {
- tmp_item_bin->type=type_street_turn_restriction_only;
- add_tag=0;
- } else {
- tmp_item_bin->type=type_none;
- osm_warning("relation", osmid_attr_value, 0, "Unknown restriction %s\n",v);
- }
- } else if (!strcmp(k,"boundary")) {
- if (!strcmp(v,"administrative") || !strcmp(v,"postal_code")) {
- boundary=1;
- }
- } else if (!strcmp(k,"ISO3166-1") || !strcmp(k,"ISO3166-1:alpha2")) {
- g_strlcpy(iso_code, v, sizeof(iso_code));
- }
- if (add_tag) {
- char *tag;
- tag=g_alloca(strlen(k)+strlen(v)+2);
- sprintf(tag,"%s=%s",k,v);
- item_bin_add_attr_string(tmp_item_bin, attr_osm_tag, tag);
- }
-
- osm_update_attr_present(k,v);
+relation_add_tag(char *k, char *v) {
+ int add_tag=1;
+ if (!strcmp(k,"type")) {
+ g_strlcpy(relation_type, v, sizeof(relation_type));
+ add_tag=0;
+ } else if (!strcmp(k,"restriction")) {
+ if (!strncmp(v,"no_",3)) {
+ tmp_item_bin->type=type_street_turn_restriction_no;
+ add_tag=0;
+ } else if (!strncmp(v,"only_",5)) {
+ tmp_item_bin->type=type_street_turn_restriction_only;
+ add_tag=0;
+ } else {
+ tmp_item_bin->type=type_none;
+ osm_warning("relation", osmid_attr_value, 0, "Unknown restriction %s\n",v);
+ }
+ } else if (!strcmp(k,"boundary")) {
+ if (!strcmp(v,"administrative") || !strcmp(v,"postal_code")) {
+ boundary=1;
+ }
+ } else if (!strcmp(k,"ISO3166-1") || !strcmp(k,"ISO3166-1:alpha2")) {
+ g_strlcpy(iso_code, v, sizeof(iso_code));
+ }
+ if (add_tag) {
+ char *tag;
+ tag=g_alloca(strlen(k)+strlen(v)+2);
+ sprintf(tag,"%s=%s",k,v);
+ item_bin_add_attr_string(tmp_item_bin, attr_osm_tag, tag);
+ }
+
+ osm_update_attr_present(k,v);
}
static int
-attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count)
-{
- int i,j,longest=0,ret=0,sum,val;
- struct attr_mapping *curr;
- for (i = 0 ; i < mapping_count ; i++) {
- sum=0;
- curr=mapping[i];
- for (j = 0 ; j < curr->attr_present_idx_count ; j++) {
- val=attr_present[curr->attr_present_idx[j]];
- if (val)
- sum+=val;
- else {
- sum=-1;
- break;
- }
- }
- if (sum > longest) {
- longest=sum;
- ret=0;
- }
- if (sum > 0 && sum == longest && ret < types_count)
- types[ret++]=curr->type;
- }
- return ret;
+attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count) {
+ int i,j,longest=0,ret=0,sum,val;
+ struct attr_mapping *curr;
+ for (i = 0 ; i < mapping_count ; i++) {
+ sum=0;
+ curr=mapping[i];
+ for (j = 0 ; j < curr->attr_present_idx_count ; j++) {
+ val=attr_present[curr->attr_present_idx[j]];
+ if (val)
+ sum+=val;
+ else {
+ sum=-1;
+ break;
+ }
+ }
+ if (sum > longest) {
+ longest=sum;
+ ret=0;
+ }
+ if (sum > 0 && sum == longest && ret < types_count)
+ types[ret++]=curr->type;
+ }
+ return ret;
}
static void
-attr_longest_match_clear(void)
-{
- memset(attr_present, 0, sizeof(*attr_present)*attr_present_count);
+attr_longest_match_clear(void) {
+ memset(attr_present, 0, sizeof(*attr_present)*attr_present_count);
}
void
-osm_end_way(struct maptool_osm *osm)
-{
- int i,count;
- int *def_flags,add_flags;
- enum item_type types[10];
- struct item_bin *item_bin;
- int count_lines=0, count_areas=0;
-
- in_way=0;
-
- if (! osm->ways)
- return;
-
- if (dedupe_ways_hash) {
- if (g_hash_table_lookup(dedupe_ways_hash, (gpointer)(long long)wayid))
- return;
- g_hash_table_insert(dedupe_ways_hash, (gpointer)(long long)wayid, (gpointer)1);
- }
-
- count=attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types)/sizeof(enum item_type));
- if (!count) {
- count=1;
- types[0]=type_street_unkn;
- }
- if (count >= 10) {
- fprintf(stderr,"way id "OSMID_FMT"\n",osmid_attr_value);
- dbg_assert(count < 10);
- }
- for (i = 0 ; i < count ; i++) {
- add_flags=0;
- if (types[i] == type_none)
- continue;
- if (ignore_unknown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
- continue;
- if (types[i] != type_street_unkn) {
- if(types[i]<type_area)
- count_lines++;
- else
- count_areas++;
- }
- item_bin=init_item(types[i]);
- item_bin_add_coord(item_bin, coord_buffer, coord_count);
- nodes_ref_item_bin(item_bin);
- def_flags=item_get_default_flags(types[i]);
- if (def_flags) {
- flags_attr_value=((*def_flags & ~flagsa[2]) | flags[0] | flags[1] | flagsa[1]) & ~flags[2];
- if (flags_attr_value != *def_flags)
- add_flags=1;
- }
- item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]);
- item_bin_add_attr_string(item_bin, attr_district_name, attr_strings[attr_string_district_name]);
- item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]);
- item_bin_add_attr_string(item_bin, attr_street_name_systematic_nat, attr_strings[attr_string_street_name_systematic_nat]);
- item_bin_add_attr_string(item_bin, attr_street_destination, attr_strings[attr_string_street_destination]);
- item_bin_add_attr_string(item_bin, attr_street_destination_forward, attr_strings[attr_string_street_destination_forward]);
- item_bin_add_attr_string(item_bin, attr_street_destination_backward, attr_strings[attr_string_street_destination_backward]);
- item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
- if (debug_attr_buffer[0])
- item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
- if (add_flags)
- item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value);
- if (maxspeed_attr_value)
- item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value);
- if(i>0)
- item_bin_add_attr_int(item_bin, attr_duplicate, 1);
- item_bin_write(item_bin,osm->ways);
-
- if (types[i]>=type_house_number_interpolation_even && types[i]<=type_house_number_interpolation_alphabetic){
- struct item_bin *item_bin_interpolation_way=init_item(types[i]);
- item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
- item_bin_add_attr_longlong(item_bin, attr_osm_nodeid_first_node, GET_REF(coord_buffer[0]));
- item_bin_add_attr_longlong(item_bin, attr_osm_nodeid_last_node, GET_REF(coord_buffer[coord_count-1]));
- item_bin_write(item_bin_interpolation_way, osm->house_number_interpolations);
- }
- }
- if(osm->line2poi) {
- count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type));
- dbg_assert(count < 10);
- for (i = 0 ; i < count ; i++) {
- if (types[i] == type_none || types[i] == type_point_unkn)
- continue;
- item_bin=init_item(types[i]);
- item_bin_add_coord(item_bin, coord_buffer, coord_count);
- item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]);
- item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
- item_bin_add_attr_string(item_bin, attr_district_name, attr_strings[attr_string_district_name]);
- item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
- item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
- item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
- item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
- item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
- item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
- item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
- item_bin_write(item_bin, count_areas<=count_lines ? osm->line2poi:osm->poly2poi);
- }
- }
- attr_longest_match_clear();
+osm_end_way(struct maptool_osm *osm) {
+ int i,count;
+ int *def_flags,add_flags;
+ enum item_type types[10];
+ struct item_bin *item_bin;
+ int count_lines=0, count_areas=0;
+
+ in_way=0;
+
+ if (! osm->ways)
+ return;
+
+ if (dedupe_ways_hash) {
+ if (g_hash_table_lookup(dedupe_ways_hash, (gpointer)(long long)wayid))
+ return;
+ g_hash_table_insert(dedupe_ways_hash, (gpointer)(long long)wayid, (gpointer)1);
+ }
+
+ count=attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types)/sizeof(enum item_type));
+ if (!count) {
+ count=1;
+ types[0]=type_street_unkn;
+ }
+ if (count >= 10) {
+ fprintf(stderr,"way id "OSMID_FMT"\n",osmid_attr_value);
+ dbg_assert(count < 10);
+ }
+ for (i = 0 ; i < count ; i++) {
+ add_flags=0;
+ if (types[i] == type_none)
+ continue;
+ if (ignore_unknown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
+ continue;
+ if (types[i] != type_street_unkn) {
+ if(types[i]<type_area)
+ count_lines++;
+ else
+ count_areas++;
+ }
+ item_bin=init_item(types[i]);
+ item_bin_add_coord(item_bin, coord_buffer, coord_count);
+ nodes_ref_item_bin(item_bin);
+ def_flags=item_get_default_flags(types[i]);
+ if (def_flags) {
+ flags_attr_value=((*def_flags & ~flagsa[2]) | flags[0] | flags[1] | flagsa[1]) & ~flags[2];
+ if (flags_attr_value != *def_flags)
+ add_flags=1;
+ }
+ item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]);
+ item_bin_add_attr_string(item_bin, attr_district_name, attr_strings[attr_string_district_name]);
+ item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]);
+ item_bin_add_attr_string(item_bin, attr_street_name_systematic_nat,
+ attr_strings[attr_string_street_name_systematic_nat]);
+ item_bin_add_attr_string(item_bin, attr_street_destination, attr_strings[attr_string_street_destination]);
+ item_bin_add_attr_string(item_bin, attr_street_destination_forward,
+ attr_strings[attr_string_street_destination_forward]);
+ item_bin_add_attr_string(item_bin, attr_street_destination_backward,
+ attr_strings[attr_string_street_destination_backward]);
+ item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
+ if (debug_attr_buffer[0])
+ item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
+ if (add_flags)
+ item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value);
+ if (maxspeed_attr_value)
+ item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value);
+ if(i>0)
+ item_bin_add_attr_int(item_bin, attr_duplicate, 1);
+ item_bin_write(item_bin,osm->ways);
+
+ if (types[i]>=type_house_number_interpolation_even && types[i]<=type_house_number_interpolation_alphabetic) {
+ struct item_bin *item_bin_interpolation_way=init_item(types[i]);
+ item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
+ item_bin_add_attr_longlong(item_bin, attr_osm_nodeid_first_node, GET_REF(coord_buffer[0]));
+ item_bin_add_attr_longlong(item_bin, attr_osm_nodeid_last_node, GET_REF(coord_buffer[coord_count-1]));
+ item_bin_write(item_bin_interpolation_way, osm->house_number_interpolations);
+ }
+ }
+ if(osm->line2poi) {
+ count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type));
+ dbg_assert(count < 10);
+ for (i = 0 ; i < count ; i++) {
+ if (types[i] == type_none || types[i] == type_point_unkn)
+ continue;
+ item_bin=init_item(types[i]);
+ item_bin_add_coord(item_bin, coord_buffer, coord_count);
+ item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]);
+ item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
+ item_bin_add_attr_string(item_bin, attr_district_name, attr_strings[attr_string_district_name]);
+ item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
+ item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
+ item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
+ item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
+ item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
+ item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
+ item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
+ item_bin_write(item_bin, count_areas<=count_lines ? osm->line2poi:osm->poly2poi);
+ }
+ }
+ attr_longest_match_clear();
}
void
-osm_end_node(struct maptool_osm *osm)
-{
- int count,i;
- char *postal;
- enum item_type types[10];
- struct item_bin *item_bin;
- in_node=0;
-
- if (!osm->nodes || ! node_is_tagged || ! nodeid)
- return;
- count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type));
- if (!count) {
- types[0]=type_point_unkn;
- count=1;
- }
- if (count >= 10) {
- fprintf(stderr,"node id "OSMID_FMT"\n",osmid_attr_value);
- dbg_assert(count < 10);
- }
- for (i = 0 ; i < count ; i++) {
- if (types[i] == type_none)
- continue;
- if (ignore_unknown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
- continue;
- item_bin=init_item(types[i]);
- if (item_is_town(*item_bin) && attr_strings[attr_string_population])
- item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population]));
- item_bin_add_coord(item_bin, &current_node->c, 1);
- item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]);
- item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
- item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
- item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
- item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
- item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
- item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
- item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
- item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
- item_bin_add_attr_string(item_bin, attr_ref, attr_strings[attr_string_ref]);
- item_bin_add_attr_string(item_bin, attr_exit_to, attr_strings[attr_string_exit_to]);
- item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
- postal=attr_strings[attr_string_postal];
- if (postal) {
- char *sep=strchr(postal,',');
- if (sep)
- *sep='\0';
- item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal);
- }
- item_bin_write(item_bin,osm->nodes);
- if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) {
- item_bin=init_item(item_bin->type);
- item_bin_add_coord(item_bin, &current_node->c, 1);
- item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer);
- item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
- item_bin_add_attr_string(item_bin, attr_town_postal, postal);
- item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
- item_bin_add_attr_string(item_bin, item_is_district(*item_bin)?attr_district_name:attr_town_name, attr_strings[attr_string_label]);
- item_bin_write(item_bin, osm->towns);
- }
- }
- processed_nodes_out++;
- attr_longest_match_clear();
+osm_end_node(struct maptool_osm *osm) {
+ int count,i;
+ char *postal;
+ enum item_type types[10];
+ struct item_bin *item_bin;
+ in_node=0;
+
+ if (!osm->nodes || ! node_is_tagged || ! nodeid)
+ return;
+ count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type));
+ if (!count) {
+ types[0]=type_point_unkn;
+ count=1;
+ }
+ if (count >= 10) {
+ fprintf(stderr,"node id "OSMID_FMT"\n",osmid_attr_value);
+ dbg_assert(count < 10);
+ }
+ for (i = 0 ; i < count ; i++) {
+ if (types[i] == type_none)
+ continue;
+ if (ignore_unknown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
+ continue;
+ item_bin=init_item(types[i]);
+ if (item_is_town(*item_bin) && attr_strings[attr_string_population])
+ item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population]));
+ item_bin_add_coord(item_bin, &current_node->c, 1);
+ item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label,
+ attr_strings[attr_string_label]);
+ item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
+ item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
+ item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
+ item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
+ item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
+ item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
+ item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
+ item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
+ item_bin_add_attr_string(item_bin, attr_ref, attr_strings[attr_string_ref]);
+ item_bin_add_attr_string(item_bin, attr_exit_to, attr_strings[attr_string_exit_to]);
+ item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
+ postal=attr_strings[attr_string_postal];
+ if (postal) {
+ char *sep=strchr(postal,',');
+ if (sep)
+ *sep='\0';
+ item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal);
+ }
+ item_bin_write(item_bin,osm->nodes);
+ if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) {
+ item_bin=init_item(item_bin->type);
+ item_bin_add_coord(item_bin, &current_node->c, 1);
+ item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer);
+ item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
+ item_bin_add_attr_string(item_bin, attr_town_postal, postal);
+ item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
+ item_bin_add_attr_string(item_bin, item_is_district(*item_bin)?attr_district_name:attr_town_name,
+ attr_strings[attr_string_label]);
+ item_bin_write(item_bin, osm->towns);
+ }
+ }
+ processed_nodes_out++;
+ attr_longest_match_clear();
}
#define MAX_TOWN_ADMIN_LEVELS 11
struct town_country {
- /* attrs[0] is reserved for postal code */
- /* attrs[1..] are for osm admin levels 3.. (admin_level=2 is always a country boundary)*/
- struct attr attrs[MAX_TOWN_ADMIN_LEVELS];
- struct country_table *country;
+ /* attrs[0] is reserved for postal code */
+ /* attrs[1..] are for osm admin levels 3.. (admin_level=2 is always a country boundary)*/
+ struct attr attrs[MAX_TOWN_ADMIN_LEVELS];
+ struct country_table *country;
};
static struct town_country *
-town_country_new(struct country_table *country)
-{
- struct town_country *ret=g_malloc0(sizeof(struct town_country));
- ret->country=country;
- return ret;
+town_country_new(struct country_table *country) {
+ struct town_country *ret=g_malloc0(sizeof(struct town_country));
+ ret->country=country;
+ return ret;
}
static void
-town_country_destroy(struct town_country *tc)
-{
- g_free(tc);
+town_country_destroy(struct town_country *tc) {
+ g_free(tc);
}
/**
@@ -1978,32 +1940,30 @@ town_country_destroy(struct town_country *tc)
* @returns refernce to then new town_country structure added to the list, or NULL if GList already had an entry for the country given
*/
static struct town_country *
-town_country_list_insert_if_new(GList **town_country_list, struct country_table *country)
-{
- GList *l;
- struct town_country *ret;
+town_country_list_insert_if_new(GList **town_country_list, struct country_table *country) {
+ GList *l;
+ struct town_country *ret;
- if(!country)
- return NULL;
+ if(!country)
+ return NULL;
- for(l=*town_country_list; l; l=g_list_next(l)) {
- if(((struct town_country*)l->data)->country==country)
- return NULL;
- }
+ for(l=*town_country_list; l; l=g_list_next(l)) {
+ if(((struct town_country*)l->data)->country==country)
+ return NULL;
+ }
- ret=town_country_new(country);
- *town_country_list=g_list_prepend(*town_country_list, ret);
- return ret;
+ ret=town_country_new(country);
+ *town_country_list=g_list_prepend(*town_country_list, ret);
+ return ret;
}
static GList *
-osm_process_town_unknown_country(void)
-{
- static struct country_table *unknown;
- if (!unknown)
- unknown=country_from_countryid(999);
+osm_process_town_unknown_country(void) {
+ static struct country_table *unknown;
+ if (!unknown)
+ unknown=country_from_countryid(999);
- return g_list_prepend(NULL, town_country_new(unknown));
+ return g_list_prepend(NULL, town_country_new(unknown));
}
@@ -2015,26 +1975,25 @@ osm_process_town_unknown_country(void)
* @returns refernce to a list of struct town_country* the town belongs to
*/
static char *
-osm_process_town_get_town_name_from_is_in(struct item_bin *ib, GHashTable *town_hash)
-{
- char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
- char *tok,*dup,*buf;
- char *town=NULL;
-
- if(!is_in)
- return NULL;
-
- dup=g_strdup(is_in);
- buf=dup;
- while (!town && (tok=strtok(buf, ",;"))) {
- while (*tok==' ')
- tok++;
- town=g_hash_table_lookup(town_hash, tok);
- buf=NULL;
- }
- g_free(dup);
+osm_process_town_get_town_name_from_is_in(struct item_bin *ib, GHashTable *town_hash) {
+ char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
+ char *tok,*dup,*buf;
+ char *town=NULL;
+
+ if(!is_in)
+ return NULL;
+
+ dup=g_strdup(is_in);
+ buf=dup;
+ while (!town && (tok=strtok(buf, ",;"))) {
+ while (*tok==' ')
+ tok++;
+ town=g_hash_table_lookup(town_hash, tok);
+ buf=NULL;
+ }
+ g_free(dup);
- return town;
+ return town;
}
@@ -2044,29 +2003,28 @@ osm_process_town_get_town_name_from_is_in(struct item_bin *ib, GHashTable *town_
* @returns refernce to a list of struct town_country* the town belongs to
*/
static GList *
-osm_process_town_by_is_in(struct item_bin *ib)
-{
- struct country_table *country;
- char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
- char *tok,*dup,*buf;
- GList *town_country_list=NULL;
-
- if(!is_in)
- return NULL;
-
- dup=g_strdup(is_in);
- buf=dup;
- while ((tok=strtok(buf, ",;"))) {
- while (*tok==' ')
- tok++;
- country=g_hash_table_lookup(country_table_hash,tok);
- town_country_list_insert_if_new(&town_country_list, country);
- buf=NULL;
- }
+osm_process_town_by_is_in(struct item_bin *ib) {
+ struct country_table *country;
+ char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
+ char *tok,*dup,*buf;
+ GList *town_country_list=NULL;
+
+ if(!is_in)
+ return NULL;
+
+ dup=g_strdup(is_in);
+ buf=dup;
+ while ((tok=strtok(buf, ",;"))) {
+ while (*tok==' ')
+ tok++;
+ country=g_hash_table_lookup(country_table_hash,tok);
+ town_country_list_insert_if_new(&town_country_list, country);
+ buf=NULL;
+ }
- g_free(dup);
+ g_free(dup);
- return town_country_list;
+ return town_country_list;
}
/**
@@ -2078,79 +2036,78 @@ osm_process_town_by_is_in(struct item_bin *ib)
* @returns nothing
*/
static void
-osm_process_town_by_boundary_update_attrs(struct item_bin *town, struct town_country *tc, GList *matches)
-{
- long long *nodeid;
- long long node_id=0;
- int max_possible_adm_level=-1;
- int max_adm_level=0;
- GList *l;
- int a;
-
- if(tc->country->admin_levels)
- max_possible_adm_level=strlen(tc->country->admin_levels)+3;
-
- nodeid=item_bin_get_attr(town, attr_osm_nodeid, NULL);
- if(nodeid)
- node_id=*nodeid;
-
- for(l=matches;l;l=g_list_next(l)) {
- struct boundary *b=l->data;
- char *boundary_admin_level_string;
- char *name;
- char *postal=osm_tag_value(b->ib, "postal_code");
-
- if (postal) {
- tc->attrs[0].type=attr_town_postal;
- tc->attrs[0].u.str=postal;
- }
-
- if(max_possible_adm_level==-1)
- continue;
-
- boundary_admin_level_string=osm_tag_value(b->ib, "admin_level");
-
- if (!boundary_admin_level_string)
- continue;
-
- a=atoi(boundary_admin_level_string);
- if (a > 2 && a < max_possible_adm_level) {
- enum attr_type attr_type=attr_none;
- switch(tc->country->admin_levels[a-3]) {
- case 's':
- attr_type=attr_state_name;
- break;
- case 'c':
- attr_type=attr_county_name;
- break;
- case 'M':
- /* Here we patch the boundary itself to convert it to town polygon later*/
- b->ib->type=type_poly_place6;
- case 'm':
- attr_type=attr_municipality_name;
- break;
- case 'T':
- /* Here we patch the boundary itself to convert it to town polygon later*/
- b->ib->type=type_poly_place6;
- break;
- }
- name=osm_tag_value(b->ib, "name");
- if (name && attr_type != attr_none) {
- tc->attrs[a-2].type=attr_type;
- tc->attrs[a-2].u.str=name;
- }
- }
- if(b->admin_centre && b->admin_centre==node_id) {
- if(!max_adm_level || max_adm_level<a) {
- max_adm_level=a;
- }
- }
- }
-
- /* Administrative centres are not to be contained in their own districts. */
- if(max_adm_level>0)
- for(a=max_possible_adm_level-1;a>max_adm_level && a>2;a--)
- tc->attrs[a-2].type=type_none;
+osm_process_town_by_boundary_update_attrs(struct item_bin *town, struct town_country *tc, GList *matches) {
+ long long *nodeid;
+ long long node_id=0;
+ int max_possible_adm_level=-1;
+ int max_adm_level=0;
+ GList *l;
+ int a;
+
+ if(tc->country->admin_levels)
+ max_possible_adm_level=strlen(tc->country->admin_levels)+3;
+
+ nodeid=item_bin_get_attr(town, attr_osm_nodeid, NULL);
+ if(nodeid)
+ node_id=*nodeid;
+
+ for(l=matches; l; l=g_list_next(l)) {
+ struct boundary *b=l->data;
+ char *boundary_admin_level_string;
+ char *name;
+ char *postal=osm_tag_value(b->ib, "postal_code");
+
+ if (postal) {
+ tc->attrs[0].type=attr_town_postal;
+ tc->attrs[0].u.str=postal;
+ }
+
+ if(max_possible_adm_level==-1)
+ continue;
+
+ boundary_admin_level_string=osm_tag_value(b->ib, "admin_level");
+
+ if (!boundary_admin_level_string)
+ continue;
+
+ a=atoi(boundary_admin_level_string);
+ if (a > 2 && a < max_possible_adm_level) {
+ enum attr_type attr_type=attr_none;
+ switch(tc->country->admin_levels[a-3]) {
+ case 's':
+ attr_type=attr_state_name;
+ break;
+ case 'c':
+ attr_type=attr_county_name;
+ break;
+ case 'M':
+ /* Here we patch the boundary itself to convert it to town polygon later*/
+ b->ib->type=type_poly_place6;
+ case 'm':
+ attr_type=attr_municipality_name;
+ break;
+ case 'T':
+ /* Here we patch the boundary itself to convert it to town polygon later*/
+ b->ib->type=type_poly_place6;
+ break;
+ }
+ name=osm_tag_value(b->ib, "name");
+ if (name && attr_type != attr_none) {
+ tc->attrs[a-2].type=attr_type;
+ tc->attrs[a-2].u.str=name;
+ }
+ }
+ if(b->admin_centre && b->admin_centre==node_id) {
+ if(!max_adm_level || max_adm_level<a) {
+ max_adm_level=a;
+ }
+ }
+ }
+
+ /* Administrative centres are not to be contained in their own districts. */
+ if(max_adm_level>0)
+ for(a=max_possible_adm_level-1; a>max_adm_level && a>2; a--)
+ tc->attrs[a-2].type=type_none;
}
/**
@@ -2162,1076 +2119,1061 @@ osm_process_town_by_boundary_update_attrs(struct item_bin *town, struct town_cou
* @returns refernce to the list of town_country structures
*/
static GList *
-osm_process_town_by_boundary(GList *bl, struct item_bin *town, struct coord *c)
-{
- GList *matches=boundary_find_matches(bl, c);
- GList *town_country_list=NULL;
- GList *l;
-
- for (l=matches;l;l=g_list_next(l)) {
- struct boundary *match=l->data;
- if (match->country) {
- struct town_country *tc=town_country_list_insert_if_new(&town_country_list, match->country);
- if(tc)
- osm_process_town_by_boundary_update_attrs(town, tc, matches);
- }
- }
-
- g_list_free(matches);
-
- return town_country_list;
-}
-
-static void
-osm_town_relations_to_poly(GList *boundaries, FILE *towns_poly)
-{
- while(boundaries) {
- struct boundary *b=boundaries->data;
- if(item_is_poly_place(*b->ib)) {
- GList *s=b->sorted_segments;
- while(s) {
- struct geom_poly_segment *seg=s->data;
- if((seg->type==geom_poly_segment_type_way_outer || seg->type==geom_poly_segment_type_way_unknown) && coord_is_equal(*seg->first,*seg->last)) {
- struct item_bin *ib=init_item(b->ib->type);
- void *a;
- item_bin_add_coord(ib, seg->first, seg->last-seg->first+1);
- a=osm_tag_value(b->ib, "name");
- if(a)
- item_bin_add_attr_string(ib,attr_label,a);
- a=osm_tag_value(b->ib, "osm_relationid");
- if(a)
- item_bin_add_attr_longlong(ib,attr_osm_relationid,atol(a));
- item_bin_write(ib, towns_poly);
- }
- s=g_list_next(s);
- }
- }
- osm_town_relations_to_poly(b->children, towns_poly);
- boundaries=g_list_next(boundaries);
- }
+osm_process_town_by_boundary(GList *bl, struct item_bin *town, struct coord *c) {
+ GList *matches=boundary_find_matches(bl, c);
+ GList *town_country_list=NULL;
+ GList *l;
+
+ for (l=matches; l; l=g_list_next(l)) {
+ struct boundary *match=l->data;
+ if (match->country) {
+ struct town_country *tc=town_country_list_insert_if_new(&town_country_list, match->country);
+ if(tc)
+ osm_process_town_by_boundary_update_attrs(town, tc, matches);
+ }
+ }
+
+ g_list_free(matches);
+
+ return town_country_list;
+}
+
+static void
+osm_town_relations_to_poly(GList *boundaries, FILE *towns_poly) {
+ while(boundaries) {
+ struct boundary *b=boundaries->data;
+ if(item_is_poly_place(*b->ib)) {
+ GList *s=b->sorted_segments;
+ while(s) {
+ struct geom_poly_segment *seg=s->data;
+ if((seg->type==geom_poly_segment_type_way_outer || seg->type==geom_poly_segment_type_way_unknown)
+ && coord_is_equal(*seg->first,*seg->last)) {
+ struct item_bin *ib=init_item(b->ib->type);
+ void *a;
+ item_bin_add_coord(ib, seg->first, seg->last-seg->first+1);
+ a=osm_tag_value(b->ib, "name");
+ if(a)
+ item_bin_add_attr_string(ib,attr_label,a);
+ a=osm_tag_value(b->ib, "osm_relationid");
+ if(a)
+ item_bin_add_attr_longlong(ib,attr_osm_relationid,atol(a));
+ item_bin_write(ib, towns_poly);
+ }
+ s=g_list_next(s);
+ }
+ }
+ osm_town_relations_to_poly(b->children, towns_poly);
+ boundaries=g_list_next(boundaries);
+ }
}
void
-osm_process_towns(FILE *in, FILE *boundaries, FILE *ways, char *suffix)
-{
- struct item_bin *ib;
- GList *bl;
- GHashTable *town_hash;
- FILE *towns_poly;
-
- processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
- bytes_read=0;
- sig_alrm(0);
-
- bl=process_boundaries(boundaries, ways);
-
- fprintf(stderr, "Processed boundaries\n");
-
- town_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- while ((ib=read_item(in))) {
- if (!item_is_district(*ib))
- {
- char *townname=item_bin_get_attr(ib, attr_town_name, NULL);
- char *dup=g_strdup(townname);
- g_hash_table_replace(town_hash, dup, dup);
- }
- }
- fseek(in, 0, SEEK_SET);
-
- fprintf(stderr, "Finished town table rebuild\n");
-
- while ((ib=read_item(in))) {
- struct coord *c=(struct coord *)(ib+1);
- GList *tc_list, *l;
- struct item_bin *ib_copy=NULL;
-
- processed_nodes++;
-
- tc_list=osm_process_town_by_boundary(bl, ib, c);
- if (!tc_list)
- tc_list=osm_process_town_by_is_in(ib);
-
- if (!tc_list && unknown_country)
- tc_list=osm_process_town_unknown_country();
-
- if (!tc_list) {
- itembin_warning(ib, 0, "Lost town %s %s\n", item_bin_get_attr(ib, attr_town_name, NULL), item_bin_get_attr(ib, attr_district_name, NULL));
- }
-
- if(tc_list && g_list_next(tc_list))
- ib_copy=item_bin_dup(ib);
-
- l=tc_list;
- while(l) {
- struct town_country *tc=l->data;
- char *is_in;
- long long *nodeid;
- char *town_name=NULL;
- int i;
-
- if (!tc->country->file) {
- char *name=g_strdup_printf("country_%d.unsorted.tmp", tc->country->countryid);
- tc->country->file=fopen(name,"wb");
- g_free(name);
- }
-
- if (item_is_district(*ib) && NULL!=(town_name=osm_process_town_get_town_name_from_is_in(ib, town_hash))) {
- struct attr attr_new_town_name;
- attr_new_town_name.type = attr_town_name;
- attr_new_town_name.u.str = town_name;
- item_bin_add_attr(ib, &attr_new_town_name);
- }
-
- if ((is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL))!=NULL)
- item_bin_remove_attr(ib, is_in);
-
- nodeid=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
-
- if (nodeid)
- item_bin_remove_attr(ib, nodeid);
-
- /* Treat district like a town, if we did not find the town it belongs to */
- if (!item_bin_get_attr(ib, attr_town_name, NULL)) {
- char *district_name = item_bin_get_attr(ib, attr_district_name, NULL);
-
- if (district_name) {
- struct attr attr_new_town_name;
- attr_new_town_name.type = attr_town_name;
- attr_new_town_name.u.str = district_name;
-
- item_bin_add_attr(ib, &attr_new_town_name);
- item_bin_remove_attr(ib, district_name);
- }
- }
-
- /* FIXME: preserved from old code, but we'll have to reconsider if we really should drop attribute
- * explicitely set on the town osm node and use an attribute derived from one of its surrounding boundaries. Thus we would
- * use town central district' postal code instead of town one. */
- if (tc->attrs[0].type != attr_none) {
- char *postal=item_bin_get_attr(ib, attr_town_postal, NULL);
- if (postal)
- item_bin_remove_attr(ib, postal);
- }
-
- for (i = 0 ; i < MAX_TOWN_ADMIN_LEVELS ; i++) {
- if (tc->attrs[i].type != attr_none)
- item_bin_add_attr(ib, &tc->attrs[i]);
- }
-
- if(item_bin_get_attr(ib, attr_district_name, NULL))
- item_bin_write_match(ib, attr_district_name, attr_district_name_match, 5, tc->country->file);
- else
- item_bin_write_match(ib, attr_town_name, attr_town_name_match, 5, tc->country->file);
-
- town_country_destroy(tc);
- processed_nodes_out++;
- l=g_list_next(l);
- if(l!=NULL)
- memcpy(ib, ib_copy, (ib_copy->len+1)*4);
- }
- g_free(ib_copy);
- g_list_free(tc_list);
- }
-
- towns_poly=tempfile(suffix,"towns_poly",1);
- osm_town_relations_to_poly(bl, towns_poly);
- fclose(towns_poly);
-
- g_hash_table_destroy(town_hash);
- free_boundaries(bl);
-
- sig_alrm(0);
- sig_alrm_end();
-
- fprintf(stderr, "Finished processing towns\n");
+osm_process_towns(FILE *in, FILE *boundaries, FILE *ways, char *suffix) {
+ struct item_bin *ib;
+ GList *bl;
+ GHashTable *town_hash;
+ FILE *towns_poly;
+
+ processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
+ bytes_read=0;
+ sig_alrm(0);
+
+ bl=process_boundaries(boundaries, ways);
+
+ fprintf(stderr, "Processed boundaries\n");
+
+ town_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+ while ((ib=read_item(in))) {
+ if (!item_is_district(*ib)) {
+ char *townname=item_bin_get_attr(ib, attr_town_name, NULL);
+ char *dup=g_strdup(townname);
+ g_hash_table_replace(town_hash, dup, dup);
+ }
+ }
+ fseek(in, 0, SEEK_SET);
+
+ fprintf(stderr, "Finished town table rebuild\n");
+
+ while ((ib=read_item(in))) {
+ struct coord *c=(struct coord *)(ib+1);
+ GList *tc_list, *l;
+ struct item_bin *ib_copy=NULL;
+
+ processed_nodes++;
+
+ tc_list=osm_process_town_by_boundary(bl, ib, c);
+ if (!tc_list)
+ tc_list=osm_process_town_by_is_in(ib);
+
+ if (!tc_list && unknown_country)
+ tc_list=osm_process_town_unknown_country();
+
+ if (!tc_list) {
+ itembin_warning(ib, 0, "Lost town %s %s\n", item_bin_get_attr(ib, attr_town_name, NULL), item_bin_get_attr(ib,
+ attr_district_name, NULL));
+ }
+
+ if(tc_list && g_list_next(tc_list))
+ ib_copy=item_bin_dup(ib);
+
+ l=tc_list;
+ while(l) {
+ struct town_country *tc=l->data;
+ char *is_in;
+ long long *nodeid;
+ char *town_name=NULL;
+ int i;
+
+ if (!tc->country->file) {
+ char *name=g_strdup_printf("country_%d.unsorted.tmp", tc->country->countryid);
+ tc->country->file=fopen(name,"wb");
+ g_free(name);
+ }
+
+ if (item_is_district(*ib) && NULL!=(town_name=osm_process_town_get_town_name_from_is_in(ib, town_hash))) {
+ struct attr attr_new_town_name;
+ attr_new_town_name.type = attr_town_name;
+ attr_new_town_name.u.str = town_name;
+ item_bin_add_attr(ib, &attr_new_town_name);
+ }
+
+ if ((is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL))!=NULL)
+ item_bin_remove_attr(ib, is_in);
+
+ nodeid=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
+
+ if (nodeid)
+ item_bin_remove_attr(ib, nodeid);
+
+ /* Treat district like a town, if we did not find the town it belongs to */
+ if (!item_bin_get_attr(ib, attr_town_name, NULL)) {
+ char *district_name = item_bin_get_attr(ib, attr_district_name, NULL);
+
+ if (district_name) {
+ struct attr attr_new_town_name;
+ attr_new_town_name.type = attr_town_name;
+ attr_new_town_name.u.str = district_name;
+
+ item_bin_add_attr(ib, &attr_new_town_name);
+ item_bin_remove_attr(ib, district_name);
+ }
+ }
+
+ /* FIXME: preserved from old code, but we'll have to reconsider if we really should drop attribute
+ * explicitely set on the town osm node and use an attribute derived from one of its surrounding boundaries. Thus we would
+ * use town central district' postal code instead of town one. */
+ if (tc->attrs[0].type != attr_none) {
+ char *postal=item_bin_get_attr(ib, attr_town_postal, NULL);
+ if (postal)
+ item_bin_remove_attr(ib, postal);
+ }
+
+ for (i = 0 ; i < MAX_TOWN_ADMIN_LEVELS ; i++) {
+ if (tc->attrs[i].type != attr_none)
+ item_bin_add_attr(ib, &tc->attrs[i]);
+ }
+
+ if(item_bin_get_attr(ib, attr_district_name, NULL))
+ item_bin_write_match(ib, attr_district_name, attr_district_name_match, 5, tc->country->file);
+ else
+ item_bin_write_match(ib, attr_town_name, attr_town_name_match, 5, tc->country->file);
+
+ town_country_destroy(tc);
+ processed_nodes_out++;
+ l=g_list_next(l);
+ if(l!=NULL)
+ memcpy(ib, ib_copy, (ib_copy->len+1)*4);
+ }
+ g_free(ib_copy);
+ g_list_free(tc_list);
+ }
+
+ towns_poly=tempfile(suffix,"towns_poly",1);
+ osm_town_relations_to_poly(bl, towns_poly);
+ fclose(towns_poly);
+
+ g_hash_table_destroy(town_hash);
+ free_boundaries(bl);
+
+ sig_alrm(0);
+ sig_alrm_end();
+
+ fprintf(stderr, "Finished processing towns\n");
}
void
-sort_countries(int keep_tmpfiles)
-{
- int i;
- struct country_table *co;
- 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_in=g_strdup_printf("country_%d.unsorted.tmp", co->countryid);
- name_out=g_strdup_printf("country_%d.tmp", co->countryid);
- co->r=world_bbox;
- item_bin_sort_file(name_in, name_out, &co->r, &co->size);
- if (!keep_tmpfiles)
- unlink(name_in);
- g_free(name_in);
- g_free(name_out);
- }
+sort_countries(int keep_tmpfiles) {
+ int i;
+ struct country_table *co;
+ 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_in=g_strdup_printf("country_%d.unsorted.tmp", co->countryid);
+ name_out=g_strdup_printf("country_%d.tmp", co->countryid);
+ co->r=world_bbox;
+ item_bin_sort_file(name_in, name_out, &co->r, &co->size);
+ if (!keep_tmpfiles)
+ unlink(name_in);
+ g_free(name_in);
+ g_free(name_out);
+ }
}
struct relation_member {
- enum relation_member_type type;
- long long id;
- char *role;
+ enum relation_member_type type;
+ long long id;
+ char *role;
};
static void
-parse_relation_member_string(char *relation_member_string, struct relation_member *memb)
-{
- int len;
- int type_numeric;
- sscanf(relation_member_string,RELATION_MEMBER_PARSE_FORMAT,&type_numeric,&memb->id,&len);
- memb->type=(enum relation_member_type)type_numeric;
- memb->role=relation_member_string+len;
+parse_relation_member_string(char *relation_member_string, struct relation_member *memb) {
+ int len;
+ int type_numeric;
+ sscanf(relation_member_string,RELATION_MEMBER_PARSE_FORMAT,&type_numeric,&memb->id,&len);
+ memb->type=(enum relation_member_type)type_numeric;
+ memb->role=relation_member_string+len;
}
static int
-search_relation_member(struct item_bin *ib, char *role, struct relation_member *memb, int *min_count)
-{
- char *str=NULL;
- int count=0;
- while ((str=item_bin_get_attr(ib, attr_osm_member, str))) {
- parse_relation_member_string(str, memb);
- count++;
- if (!strcmp(memb->role, role) && (!min_count || *min_count < count)) {
- if (min_count)
- *min_count=count;
- return 1;
- }
- }
- return 0;
+search_relation_member(struct item_bin *ib, char *role, struct relation_member *memb, int *min_count) {
+ char *str=NULL;
+ int count=0;
+ while ((str=item_bin_get_attr(ib, attr_osm_member, str))) {
+ parse_relation_member_string(str, memb);
+ count++;
+ if (!strcmp(memb->role, role) && (!min_count || *min_count < count)) {
+ if (min_count)
+ *min_count=count;
+ return 1;
+ }
+ }
+ return 0;
}
#if 0
static int
-load_way_index(FILE *ways_index, int p, long long *idx)
-{
- int step=sizeof(*idx)*2;
- fseek(ways_index, p*step, SEEK_SET);
- if (fread(idx, step, 1, ways_index) != 1) {
- fprintf(stderr,"read failed\n");
- return 0;
- }
- return 1;
+load_way_index(FILE *ways_index, int p, long long *idx) {
+ int step=sizeof(*idx)*2;
+ fseek(ways_index, p*step, SEEK_SET);
+ if (fread(idx, step, 1, ways_index) != 1) {
+ fprintf(stderr,"read failed\n");
+ return 0;
+ }
+ return 1;
}
#endif
#if 0
static int
-seek_to_way(FILE *way, FILE *ways_index, osmid wayid)
-{
- long offset;
- long long idx[2];
- int count,interval,p;
- if (way_hash) {
- if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long)wayid, NULL, (gpointer)&offset)))
- return 0;
- fseek(way, offset, SEEK_SET);
- return 1;
- }
- fseek(ways_index, 0, SEEK_END);
- count=ftello(ways_index)/sizeof(idx);
- interval=count/4;
- p=count/2;
- if(interval==0) {
- // If fewer than 4 nodes defined so far set interval to 1 to
- // avoid infinite loop
- interval = 1;
- }
- if (!load_way_index(ways_index, p, idx))
- return 0;
- for (;;) {
- if (idx[0] == wayid) {
- fseek(way, idx[1], SEEK_SET);
- return 1;
- }
- if (idx[0] < wayid) {
- p+=interval;
- if (interval == 1) {
- if (p >= count)
- return 0;
- if (!load_way_index(ways_index, p, idx))
- return 0;
- if (idx[0] > wayid)
- return 0;
- } else {
- if (p >= count)
- p=count-1;
- if (!load_way_index(ways_index, p, idx))
- return 0;
- }
- } else {
- p-=interval;
- if (interval == 1) {
- if (p < 0)
- return 0;
- if (!load_way_index(ways_index, p, idx))
- return 0;
- if (idx[0] < wayid)
- return 0;
- } else {
- if (p < 0)
- p=0;
- if (!load_way_index(ways_index, p, idx))
- return 0;
- }
- }
- if (interval > 1)
- interval/=2;
- }
+seek_to_way(FILE *way, FILE *ways_index, osmid wayid) {
+ long offset;
+ long long idx[2];
+ int count,interval,p;
+ if (way_hash) {
+ if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long)wayid, NULL, (gpointer)&offset)))
+ return 0;
+ fseek(way, offset, SEEK_SET);
+ return 1;
+ }
+ fseek(ways_index, 0, SEEK_END);
+ count=ftello(ways_index)/sizeof(idx);
+ interval=count/4;
+ p=count/2;
+ if(interval==0) {
+ // If fewer than 4 nodes defined so far set interval to 1 to
+ // avoid infinite loop
+ interval = 1;
+ }
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ for (;;) {
+ if (idx[0] == wayid) {
+ fseek(way, idx[1], SEEK_SET);
+ return 1;
+ }
+ if (idx[0] < wayid) {
+ p+=interval;
+ if (interval == 1) {
+ if (p >= count)
+ return 0;
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ if (idx[0] > wayid)
+ return 0;
+ } else {
+ if (p >= count)
+ p=count-1;
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ }
+ } else {
+ p-=interval;
+ if (interval == 1) {
+ if (p < 0)
+ return 0;
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ if (idx[0] < wayid)
+ return 0;
+ } else {
+ if (p < 0)
+ p=0;
+ if (!load_way_index(ways_index, p, idx))
+ return 0;
+ }
+ }
+ if (interval > 1)
+ interval/=2;
+ }
}
#endif
#if 0
static struct coord *
-get_way(FILE *way, FILE *ways_index, struct coord *c, long long wayid, struct item_bin *ret, int debug)
-{
- long long currid;
- int last;
- struct coord *ic;
- if (!seek_to_way(way, ways_index, wayid)) {
- if (debug)
- fprintf(stderr,"not found in index");
- return NULL;
- }
- while (item_bin_read(ret, way)) {
- currid=item_bin_get_wayid(ret);
- if (debug)
- fprintf(stderr,LONGLONG_FMT":",currid);
- if (currid != wayid)
- return NULL;
- ic=(struct coord *)(ret+1);
- last=ret->clen/2-1;
- if (debug)
- fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)",ic[0].x,ic[0].y,ic[last].x,ic[last].y);
- if (!c)
- return &ic[0];
- if (ic[0].x == c->x && ic[0].y == c->y)
- return &ic[last];
- if (ic[last].x == c->x && ic[last].y == c->y)
- return &ic[0];
- }
- return NULL;
+get_way(FILE *way, FILE *ways_index, struct coord *c, long long wayid, struct item_bin *ret, int debug) {
+ long long currid;
+ int last;
+ struct coord *ic;
+ if (!seek_to_way(way, ways_index, wayid)) {
+ if (debug)
+ fprintf(stderr,"not found in index");
+ return NULL;
+ }
+ while (item_bin_read(ret, way)) {
+ currid=item_bin_get_wayid(ret);
+ if (debug)
+ fprintf(stderr,LONGLONG_FMT":",currid);
+ if (currid != wayid)
+ return NULL;
+ ic=(struct coord *)(ret+1);
+ last=ret->clen/2-1;
+ if (debug)
+ fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)",ic[0].x,ic[0].y,ic[last].x,ic[last].y);
+ if (!c)
+ return &ic[0];
+ if (ic[0].x == c->x && ic[0].y == c->y)
+ return &ic[last];
+ if (ic[last].x == c->x && ic[last].y == c->y)
+ return &ic[0];
+ }
+ return NULL;
}
#endif
struct associated_street {
- osmid relid;
- char *name;
+ osmid relid;
+ char *name;
};
struct process_relation_member_func_priv {
- FILE *out;
- GList *allocations;
+ FILE *out;
+ GList *allocations;
};
static void
-process_associated_street_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv_unused)
-{
- struct process_relation_member_func_priv *fp=func_priv;
- struct associated_street *rel=relation_priv;
- if(!fp->out) {
- /* Pass 1, fill associated street names in relation_priv */
- char *name;
- if(!rel->name && item_is_street(*member) && (name=item_bin_get_attr(member,attr_street_name,NULL))!=NULL ) {
- rel->name=g_strdup(name);
- fp->allocations=g_list_prepend(fp->allocations, rel->name);
- }
- } else {
- /* Pass 2, add associated street names to relation members which do not have street name attr defined but
- have house number defined or are streets */
- int type_implies_streetname=item_is_street(*member) ||
- member->type==type_house_number_interpolation_even ||
- member->type==type_house_number_interpolation_odd ||
- member->type==type_house_number_interpolation_all ||
- member->type==type_house_number_interpolation_alphabetic;
- if(rel->name && !item_bin_get_attr(member,attr_street_name,NULL) && (type_implies_streetname || item_bin_get_attr(member,attr_house_number,NULL)))
- item_bin_add_attr_string(member, attr_street_name, rel->name);
- item_bin_write(member,fp->out);
- }
+process_associated_street_member(void *func_priv, void *relation_priv, struct item_bin *member,
+ void *member_priv_unused) {
+ struct process_relation_member_func_priv *fp=func_priv;
+ struct associated_street *rel=relation_priv;
+ if(!fp->out) {
+ /* Pass 1, fill associated street names in relation_priv */
+ char *name;
+ if(!rel->name && item_is_street(*member) && (name=item_bin_get_attr(member,attr_street_name,NULL))!=NULL ) {
+ rel->name=g_strdup(name);
+ fp->allocations=g_list_prepend(fp->allocations, rel->name);
+ }
+ } else {
+ /* Pass 2, add associated street names to relation members which do not have street name attr defined but
+ have house number defined or are streets */
+ int type_implies_streetname=item_is_street(*member) ||
+ member->type==type_house_number_interpolation_even ||
+ member->type==type_house_number_interpolation_odd ||
+ member->type==type_house_number_interpolation_all ||
+ member->type==type_house_number_interpolation_alphabetic;
+ if(rel->name && !item_bin_get_attr(member,attr_street_name,NULL) && (type_implies_streetname
+ || item_bin_get_attr(member,attr_house_number,NULL)))
+ item_bin_add_attr_string(member, attr_street_name, rel->name);
+ item_bin_write(member,fp->out);
+ }
}
struct house_number_interpolation {
- osmid wayid;
- char* street_name;
- osmid nodeid_first_node;
- char* house_number_first_node;
- osmid nodeid_last_node;
- char* house_number_last_node;
+ osmid wayid;
+ char* street_name;
+ osmid nodeid_first_node;
+ char* house_number_first_node;
+ osmid nodeid_last_node;
+ char* house_number_last_node;
};
static void
-process_house_number_interpolation_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv_unused)
-{
- struct process_relation_member_func_priv *fp=func_priv;
- struct house_number_interpolation *rel=relation_priv;
- if(!fp->out) {
- /* Pass 1, read street name & house numbers from first & last node.*/
- char *street_name;
- char *house_number;
- if((street_name=item_bin_get_attr(member,attr_street_name,NULL))) {
- rel->street_name=g_strdup(street_name);
- fp->allocations=g_list_prepend(fp->allocations, rel->street_name);
- }
- if ((house_number=item_bin_get_attr(member,attr_house_number,NULL))) {
- osmid* nodeid;
- char *house_number_dup;
- if((nodeid=item_bin_get_attr(member,attr_osm_nodeid,NULL))) {
- house_number_dup=g_strdup(house_number);
- fp->allocations=g_list_prepend(fp->allocations, house_number_dup);
- if (*nodeid==rel->nodeid_first_node){
- rel->house_number_first_node=house_number_dup;
- }else{
- rel->house_number_last_node=house_number_dup;
- }
- }
- }
- } else {
- /* Pass 2, add interpolation information to interpolation ways. */
- enum attr_type attr_for_interpolation = 0;
- switch (member->type){
- case type_house_number_interpolation_even:
- case type_house_number_interpolation_odd:
- attr_for_interpolation = attr_house_number_interpolation_no_ends_incrmt_2;
- break;
- case type_house_number_interpolation_all:
- attr_for_interpolation = attr_house_number_interpolation_no_ends_incrmt_1;
- break;
- default:
- // alphabetic interpolation not (yet) supported
- break;
- }
- if(attr_for_interpolation && rel->street_name){
- item_bin_add_attr_string(member, attr_street_name, rel->street_name);
- char* house_number_from_to = g_strconcat(rel->house_number_first_node, "-", rel->house_number_last_node, NULL);
- fp->allocations=g_list_prepend(fp->allocations, house_number_from_to);
- item_bin_add_attr_string(member, attr_for_interpolation, house_number_from_to);
- }
- item_bin_write(member,fp->out);
- }
+process_house_number_interpolation_member(void *func_priv, void *relation_priv, struct item_bin *member,
+ void *member_priv_unused) {
+ struct process_relation_member_func_priv *fp=func_priv;
+ struct house_number_interpolation *rel=relation_priv;
+ if(!fp->out) {
+ /* Pass 1, read street name & house numbers from first & last node.*/
+ char *street_name;
+ char *house_number;
+ if((street_name=item_bin_get_attr(member,attr_street_name,NULL))) {
+ rel->street_name=g_strdup(street_name);
+ fp->allocations=g_list_prepend(fp->allocations, rel->street_name);
+ }
+ if ((house_number=item_bin_get_attr(member,attr_house_number,NULL))) {
+ osmid* nodeid;
+ char *house_number_dup;
+ if((nodeid=item_bin_get_attr(member,attr_osm_nodeid,NULL))) {
+ house_number_dup=g_strdup(house_number);
+ fp->allocations=g_list_prepend(fp->allocations, house_number_dup);
+ if (*nodeid==rel->nodeid_first_node) {
+ rel->house_number_first_node=house_number_dup;
+ } else {
+ rel->house_number_last_node=house_number_dup;
+ }
+ }
+ }
+ } else {
+ /* Pass 2, add interpolation information to interpolation ways. */
+ enum attr_type attr_for_interpolation = 0;
+ switch (member->type) {
+ case type_house_number_interpolation_even:
+ case type_house_number_interpolation_odd:
+ attr_for_interpolation = attr_house_number_interpolation_no_ends_incrmt_2;
+ break;
+ case type_house_number_interpolation_all:
+ attr_for_interpolation = attr_house_number_interpolation_no_ends_incrmt_1;
+ break;
+ default:
+ // alphabetic interpolation not (yet) supported
+ break;
+ }
+ if(attr_for_interpolation && rel->street_name) {
+ item_bin_add_attr_string(member, attr_street_name, rel->street_name);
+ char* house_number_from_to = g_strconcat(rel->house_number_first_node, "-", rel->house_number_last_node, NULL);
+ fp->allocations=g_list_prepend(fp->allocations, house_number_from_to);
+ item_bin_add_attr_string(member, attr_for_interpolation, house_number_from_to);
+ }
+ item_bin_write(member,fp->out);
+ }
}
static void
-relation_func_writethrough(void *func_priv, void *relation_priv_unused, struct item_bin *member, void *member_priv_unused)
-{
- FILE *out=*(FILE **)func_priv;
- if(out)
- item_bin_write(member,out);
+relation_func_writethrough(void *func_priv, void *relation_priv_unused, struct item_bin *member,
+ void *member_priv_unused) {
+ FILE *out=*(FILE **)func_priv;
+ if(out)
+ item_bin_write(member,out);
}
static void
-process_associated_streets_setup(FILE *in, struct relations *relations, struct process_relation_member_func_priv *fp)
-{
- struct relation_member relm;
- long long relid;
- struct item_bin *ib;
- struct relations_func *relations_func;
- int min_count;
-
- fseek(in, 0, SEEK_SET);
- relations_func=relations_func_new(process_associated_street_member, fp);
- while ((ib=read_item(in))) {
- char *name=osm_tag_value(ib, "name");
- int namelen=name?strlen(name)+1:0;
- struct associated_street *rel=g_malloc0(sizeof(struct associated_street)+namelen);
- relid=item_bin_get_relationid(ib);
- rel->relid=relid;
- if(name) {
- rel->name=(char*)(rel+1);
- g_strlcpy(rel->name,name,namelen);
- }
- min_count=0;
- while(search_relation_member(ib, "street",&relm,&min_count)) {
- if(relm.type==rel_member_way)
- relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
- }
- min_count=0;
- while(search_relation_member(ib, "house",&relm,&min_count)) {
- relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
- }
- min_count=0;
- while(search_relation_member(ib, "addr:houselink",&relm,&min_count)) {
- relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
- }
- min_count=0;
- while(search_relation_member(ib, "address",&relm,&min_count)) {
- relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
- }
- }
- relations_func=relations_func_new(relation_func_writethrough, &fp->out);
- relations_add_relation_default_entry(relations, relations_func);
+process_associated_streets_setup(FILE *in, struct relations *relations, struct process_relation_member_func_priv *fp) {
+ struct relation_member relm;
+ long long relid;
+ struct item_bin *ib;
+ struct relations_func *relations_func;
+ int min_count;
+
+ fseek(in, 0, SEEK_SET);
+ relations_func=relations_func_new(process_associated_street_member, fp);
+ while ((ib=read_item(in))) {
+ char *name=osm_tag_value(ib, "name");
+ int namelen=name?strlen(name)+1:0;
+ struct associated_street *rel=g_malloc0(sizeof(struct associated_street)+namelen);
+ relid=item_bin_get_relationid(ib);
+ rel->relid=relid;
+ if(name) {
+ rel->name=(char*)(rel+1);
+ g_strlcpy(rel->name,name,namelen);
+ }
+ min_count=0;
+ while(search_relation_member(ib, "street",&relm,&min_count)) {
+ if(relm.type==rel_member_way)
+ relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
+ }
+ min_count=0;
+ while(search_relation_member(ib, "house",&relm,&min_count)) {
+ relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
+ }
+ min_count=0;
+ while(search_relation_member(ib, "addr:houselink",&relm,&min_count)) {
+ relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
+ }
+ min_count=0;
+ while(search_relation_member(ib, "address",&relm,&min_count)) {
+ relations_add_relation_member_entry(relations, relations_func, rel, NULL, relm.type, relm.id);
+ }
+ }
+ relations_func=relations_func_new(relation_func_writethrough, &fp->out);
+ relations_add_relation_default_entry(relations, relations_func);
}
void
-process_associated_streets(FILE *in, struct files_relation_processing *files_relproc)
-{
- struct relations *relations=relations_new();
- struct process_relation_member_func_priv fp={NULL,NULL};
- fseek(in, 0, SEEK_SET);
- process_associated_streets_setup(in, relations, &fp);
-
- /* Set noname relations names from their street members */
- fseek(files_relproc->ways_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->ways_in);
-
- /* Set street names on all members */
- fp.out=files_relproc->ways_out;
- fseek(files_relproc->ways_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->ways_in);
-
- fp.out=files_relproc->nodes_out;
- fseek(files_relproc->nodes_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes_in);
-
- if(files_relproc->nodes2_in) {
- fp.out=files_relproc->nodes2_out;
- fseek(files_relproc->nodes2_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes2_in);
- }
+process_associated_streets(FILE *in, struct files_relation_processing *files_relproc) {
+ struct relations *relations=relations_new();
+ struct process_relation_member_func_priv fp= {NULL,NULL};
+ fseek(in, 0, SEEK_SET);
+ process_associated_streets_setup(in, relations, &fp);
+
+ /* Set noname relations names from their street members */
+ fseek(files_relproc->ways_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->ways_in);
+
+ /* Set street names on all members */
+ fp.out=files_relproc->ways_out;
+ fseek(files_relproc->ways_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->ways_in);
+
+ fp.out=files_relproc->nodes_out;
+ fseek(files_relproc->nodes_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes_in);
+
+ if(files_relproc->nodes2_in) {
+ fp.out=files_relproc->nodes2_out;
+ fseek(files_relproc->nodes2_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes2_in);
+ }
- relations_destroy(relations);
- g_list_foreach(fp.allocations, (GFunc)free, NULL);
- g_list_free(fp.allocations);
+ relations_destroy(relations);
+ g_list_foreach(fp.allocations, (GFunc)free, NULL);
+ g_list_free(fp.allocations);
}
static void
-process_house_number_interpolations_setup(FILE *in, struct relations *relations, struct process_relation_member_func_priv *fp)
-{
- struct item_bin *ib;
- struct relations_func *relations_func_process_hn_interpol;
-
- fseek(in, 0, SEEK_SET);
- relations_func_process_hn_interpol=relations_func_new(process_house_number_interpolation_member, fp);
- while ((ib=read_item(in))) {
- struct house_number_interpolation *hn_interpol=g_malloc0(sizeof(struct house_number_interpolation));
- hn_interpol->wayid=item_bin_get_wayid(ib);
- hn_interpol->nodeid_first_node=item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid_first_node);
- hn_interpol->nodeid_last_node=item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid_last_node);
- dbg_assert(hn_interpol->wayid && hn_interpol->nodeid_first_node && hn_interpol->nodeid_last_node);
- relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_node, hn_interpol->nodeid_first_node);
- relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_node, hn_interpol->nodeid_last_node);
- relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_way, hn_interpol->wayid);
- }
- relations_add_relation_default_entry(relations, relations_func_new(relation_func_writethrough, &fp->out));
+process_house_number_interpolations_setup(FILE *in, struct relations *relations,
+ struct process_relation_member_func_priv *fp) {
+ struct item_bin *ib;
+ struct relations_func *relations_func_process_hn_interpol;
+
+ fseek(in, 0, SEEK_SET);
+ relations_func_process_hn_interpol=relations_func_new(process_house_number_interpolation_member, fp);
+ while ((ib=read_item(in))) {
+ struct house_number_interpolation *hn_interpol=g_malloc0(sizeof(struct house_number_interpolation));
+ hn_interpol->wayid=item_bin_get_wayid(ib);
+ hn_interpol->nodeid_first_node=item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid_first_node);
+ hn_interpol->nodeid_last_node=item_bin_get_nodeid_from_attr(ib, attr_osm_nodeid_last_node);
+ dbg_assert(hn_interpol->wayid && hn_interpol->nodeid_first_node && hn_interpol->nodeid_last_node);
+ relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_node,
+ hn_interpol->nodeid_first_node);
+ relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_node,
+ hn_interpol->nodeid_last_node);
+ relations_add_relation_member_entry(relations, relations_func_process_hn_interpol, hn_interpol, NULL, rel_member_way,
+ hn_interpol->wayid);
+ }
+ relations_add_relation_default_entry(relations, relations_func_new(relation_func_writethrough, &fp->out));
}
void
process_house_number_interpolations(FILE *in, struct files_relation_processing *files_relproc) {
- struct relations *relations=relations_new();
- struct process_relation_member_func_priv fp={NULL,NULL};
- fseek(in, 0, SEEK_SET);
- process_house_number_interpolations_setup(in, relations, &fp);
-
- /* Copy house numbers & street names from first/last node to interpolation way. */
- fseek(files_relproc->ways_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->ways_in);
-
- fseek(files_relproc->nodes_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes_in);
-
- /* Set street names on all members */
- fp.out=files_relproc->ways_out;
- fseek(files_relproc->ways_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->ways_in);
-
- fp.out=files_relproc->nodes_out;
- fseek(files_relproc->nodes_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes_in);
-
- if(files_relproc->nodes2_in) {
- fp.out=files_relproc->nodes2_out;
- fseek(files_relproc->nodes2_in, 0, SEEK_SET);
- relations_process(relations, NULL, files_relproc->nodes2_in);
- }
+ struct relations *relations=relations_new();
+ struct process_relation_member_func_priv fp= {NULL,NULL};
+ fseek(in, 0, SEEK_SET);
+ process_house_number_interpolations_setup(in, relations, &fp);
+
+ /* Copy house numbers & street names from first/last node to interpolation way. */
+ fseek(files_relproc->ways_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->ways_in);
+
+ fseek(files_relproc->nodes_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes_in);
+
+ /* Set street names on all members */
+ fp.out=files_relproc->ways_out;
+ fseek(files_relproc->ways_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->ways_in);
+
+ fp.out=files_relproc->nodes_out;
+ fseek(files_relproc->nodes_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes_in);
+
+ if(files_relproc->nodes2_in) {
+ fp.out=files_relproc->nodes2_out;
+ fseek(files_relproc->nodes2_in, 0, SEEK_SET);
+ relations_process(relations, NULL, files_relproc->nodes2_in);
+ }
- relations_destroy(relations);
- g_list_foreach(fp.allocations, (GFunc)free, NULL);
- g_list_free(fp.allocations);
+ relations_destroy(relations);
+ g_list_foreach(fp.allocations, (GFunc)free, NULL);
+ g_list_free(fp.allocations);
}
struct turn_restriction {
- osmid relid;
- enum item_type type;
- struct coord *c[3];
- int c_count[3];
- struct rect r;
- int order;
+ osmid relid;
+ enum item_type type;
+ struct coord *c[3];
+ int c_count[3];
+ struct rect r;
+ int order;
};
static void
-process_turn_restrictions_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv)
-{
- int i,count,type=(long)member_priv;
- struct turn_restriction *turn_restriction=relation_priv;
- struct coord *c=(struct coord *)(member+1);
- int ccount=member->clen/2;
-
- if (member->type < type_line)
- count=1;
- else
- count=2;
- turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count);
- turn_restriction->c[type][turn_restriction->c_count[type]++]=c[0];
- if (count > 1)
- turn_restriction->c[type][turn_restriction->c_count[type]++]=c[ccount-1];
- if(IS_REF(turn_restriction->r.l)) {
- turn_restriction->r.l=c[0];
- turn_restriction->r.h=c[0];
- i=1;
- } else
- i=0;
- for(;i<ccount;i++)
- bbox_extend(&c[i], &turn_restriction->r);
-
- i=item_order_by_type(member->type);
- if(i<turn_restriction->order)
- turn_restriction->order=i;
+process_turn_restrictions_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) {
+ int i,count,type=(long)member_priv;
+ struct turn_restriction *turn_restriction=relation_priv;
+ struct coord *c=(struct coord *)(member+1);
+ int ccount=member->clen/2;
+
+ if (member->type < type_line)
+ count=1;
+ else
+ count=2;
+ turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count);
+ turn_restriction->c[type][turn_restriction->c_count[type]++]=c[0];
+ if (count > 1)
+ turn_restriction->c[type][turn_restriction->c_count[type]++]=c[ccount-1];
+ if(IS_REF(turn_restriction->r.l)) {
+ turn_restriction->r.l=c[0];
+ turn_restriction->r.h=c[0];
+ i=1;
+ } else
+ i=0;
+ for(; i<ccount; i++)
+ bbox_extend(&c[i], &turn_restriction->r);
+
+ i=item_order_by_type(member->type);
+ if(i<turn_restriction->order)
+ turn_restriction->order=i;
}
static void
-process_turn_restrictions_fromto(struct turn_restriction *t, int type, struct coord **c)
-{
- int i,j;
- for (i = 0 ; i < t->c_count[type] ; i+=2) {
- for (j = 0 ; j < t->c_count[1] ; j++) {
- if (coord_is_equal(t->c[type][i],t->c[1][j])) {
- c[0]=&t->c[type][i+1];
- c[1]=&t->c[type][i];
- return;
- }
- if (coord_is_equal(t->c[type][i+1],t->c[1][j])) {
- c[0]=&t->c[type][i];
- c[1]=&t->c[type][i+1];
- return;
- }
- }
- }
+process_turn_restrictions_fromto(struct turn_restriction *t, int type, struct coord **c) {
+ int i,j;
+ for (i = 0 ; i < t->c_count[type] ; i+=2) {
+ for (j = 0 ; j < t->c_count[1] ; j++) {
+ if (coord_is_equal(t->c[type][i],t->c[1][j])) {
+ c[0]=&t->c[type][i+1];
+ c[1]=&t->c[type][i];
+ return;
+ }
+ if (coord_is_equal(t->c[type][i+1],t->c[1][j])) {
+ c[0]=&t->c[type][i];
+ c[1]=&t->c[type][i+1];
+ return;
+ }
+ }
+ }
}
static void
-process_turn_restrictions_dump_coord(struct coord *c, int count)
-{
- int i;
- for (i = 0 ; i < count ; i++) {
- fprintf(stderr,"(0x%x,0x%x)",c[i].x,c[i].y);
- }
+process_turn_restrictions_dump_coord(struct coord *c, int count) {
+ int i;
+ for (i = 0 ; i < count ; i++) {
+ fprintf(stderr,"(0x%x,0x%x)",c[i].x,c[i].y);
+ }
}
static void
-process_turn_restrictions_finish(GList *tr, FILE *out)
-{
- GList *l=tr;
- while (l) {
- struct turn_restriction *t=l->data;
- struct coord *c[4]={NULL,NULL,NULL,NULL};
- struct item_bin *ib=tmp_item_bin;
-
- if (!t->c_count[0]) {
- osm_warning("relation",t->relid,0,"turn restriction: from member not found\n");
- } else if (!t->c_count[1]) {
- osm_warning("relation",t->relid,0,"turn restriction: via member not found\n");
- } else if (!t->c_count[2]) {
- osm_warning("relation",t->relid,0,"turn restriction: to member not found\n");
- } else {
- process_turn_restrictions_fromto(t, 0, c);
- process_turn_restrictions_fromto(t, 2, c+2);
- if (!c[0] || !c[2]) {
- osm_warning("relation",t->relid,0,"turn restriction: via (");
- process_turn_restrictions_dump_coord(t->c[1], t->c_count[1]);
- fprintf(stderr,")");
- if (!c[0]) {
- fprintf(stderr," failed to connect to from (");
- process_turn_restrictions_dump_coord(t->c[0], t->c_count[0]);
- fprintf(stderr,")");
- }
- if (!c[2]) {
- fprintf(stderr," failed to connect to to (");
- process_turn_restrictions_dump_coord(t->c[2], t->c_count[2]);
- fprintf(stderr,")");
- }
- fprintf(stderr,"\n");
- } else {
- if (t->c_count[1] <= 2) {
- int order;
- char tilebuf[20]="";
- item_bin_init(ib,t->type);
- item_bin_add_coord(ib, c[0], 1);
- item_bin_add_coord(ib, c[1], 1);
- if (t->c_count[1] > 1)
- item_bin_add_coord(ib, c[3], 1);
- item_bin_add_coord(ib, c[2], 1);
-
- order=tile(&t->r,"",tilebuf,sizeof(tilebuf)-1,overlap,NULL);
- if(order > t->order)
- order=t->order;
- item_bin_add_attr_range(ib,attr_order,0,order);
-
- item_bin_write(ib, out);
- }
-
- }
- }
- g_free(t->c[0]);
- g_free(t->c[1]);
- g_free(t->c[2]);
- g_free(t);
- l=g_list_next(l);
- }
- g_list_free(tr);
+process_turn_restrictions_finish(GList *tr, FILE *out) {
+ GList *l=tr;
+ while (l) {
+ struct turn_restriction *t=l->data;
+ struct coord *c[4]= {NULL,NULL,NULL,NULL};
+ struct item_bin *ib=tmp_item_bin;
+
+ if (!t->c_count[0]) {
+ osm_warning("relation",t->relid,0,"turn restriction: from member not found\n");
+ } else if (!t->c_count[1]) {
+ osm_warning("relation",t->relid,0,"turn restriction: via member not found\n");
+ } else if (!t->c_count[2]) {
+ osm_warning("relation",t->relid,0,"turn restriction: to member not found\n");
+ } else {
+ process_turn_restrictions_fromto(t, 0, c);
+ process_turn_restrictions_fromto(t, 2, c+2);
+ if (!c[0] || !c[2]) {
+ osm_warning("relation",t->relid,0,"turn restriction: via (");
+ process_turn_restrictions_dump_coord(t->c[1], t->c_count[1]);
+ fprintf(stderr,")");
+ if (!c[0]) {
+ fprintf(stderr," failed to connect to from (");
+ process_turn_restrictions_dump_coord(t->c[0], t->c_count[0]);
+ fprintf(stderr,")");
+ }
+ if (!c[2]) {
+ fprintf(stderr," failed to connect to to (");
+ process_turn_restrictions_dump_coord(t->c[2], t->c_count[2]);
+ fprintf(stderr,")");
+ }
+ fprintf(stderr,"\n");
+ } else {
+ if (t->c_count[1] <= 2) {
+ int order;
+ char tilebuf[20]="";
+ item_bin_init(ib,t->type);
+ item_bin_add_coord(ib, c[0], 1);
+ item_bin_add_coord(ib, c[1], 1);
+ if (t->c_count[1] > 1)
+ item_bin_add_coord(ib, c[3], 1);
+ item_bin_add_coord(ib, c[2], 1);
+
+ order=tile(&t->r,"",tilebuf,sizeof(tilebuf)-1,overlap,NULL);
+ if(order > t->order)
+ order=t->order;
+ item_bin_add_attr_range(ib,attr_order,0,order);
+
+ item_bin_write(ib, out);
+ }
+
+ }
+ }
+ g_free(t->c[0]);
+ g_free(t->c[1]);
+ g_free(t->c[2]);
+ g_free(t);
+ l=g_list_next(l);
+ }
+ g_list_free(tr);
}
static GList *
-process_turn_restrictions_setup(FILE *in, struct relations *relations)
-{
- struct relation_member fromm,tom,viam,tmpm;
- long long relid;
- struct item_bin *ib;
- struct relations_func *relations_func;
- int min_count;
- GList *turn_restrictions=NULL;
-
- fseek(in, 0, SEEK_SET);
- relations_func=relations_func_new(process_turn_restrictions_member, NULL);
- while ((ib=read_item(in))) {
- struct turn_restriction *turn_restriction;
- relid=item_bin_get_relationid(ib);
- min_count=0;
- if (!search_relation_member(ib, "from",&fromm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: from member missing\n");
- continue;
- }
- if (search_relation_member(ib, "from",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
- continue;
- }
- min_count=0;
- if (!search_relation_member(ib, "to",&tom,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: to member missing\n");
- continue;
- }
- if (search_relation_member(ib, "to",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
- continue;
- }
- min_count=0;
- if (!search_relation_member(ib, "via",&viam,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: via member missing\n");
- continue;
- }
- if (search_relation_member(ib, "via",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
- continue;
- }
- if (fromm.type != rel_member_way) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
- osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
- continue;
- }
- if (tom.type != rel_member_way) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
- osm_warning(osm_types[tom.type],tom.id,1,"\n");
- continue;
- }
- if (viam.type != rel_member_node && viam.type != rel_member_way) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
- turn_restriction=g_new0(struct turn_restriction, 1);
- turn_restriction->relid=relid;
- turn_restriction->type=ib->type;
- turn_restriction->r.l.x=1<<30;
- turn_restriction->order=255;
- relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 0, fromm.type, fromm.id);
- relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 1, viam.type, viam.id);
- relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 2, tom.type, tom.id);
- turn_restrictions=g_list_append(turn_restrictions, turn_restriction);
- }
- return turn_restrictions;
+process_turn_restrictions_setup(FILE *in, struct relations *relations) {
+ struct relation_member fromm,tom,viam,tmpm;
+ long long relid;
+ struct item_bin *ib;
+ struct relations_func *relations_func;
+ int min_count;
+ GList *turn_restrictions=NULL;
+
+ fseek(in, 0, SEEK_SET);
+ relations_func=relations_func_new(process_turn_restrictions_member, NULL);
+ while ((ib=read_item(in))) {
+ struct turn_restriction *turn_restriction;
+ relid=item_bin_get_relationid(ib);
+ min_count=0;
+ if (!search_relation_member(ib, "from",&fromm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: from member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "from",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
+ continue;
+ }
+ min_count=0;
+ if (!search_relation_member(ib, "to",&tom,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: to member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "to",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
+ continue;
+ }
+ min_count=0;
+ if (!search_relation_member(ib, "via",&viam,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: via member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "via",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
+ continue;
+ }
+ if (fromm.type != rel_member_way) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
+ osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
+ continue;
+ }
+ if (tom.type != rel_member_way) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
+ osm_warning(osm_types[tom.type],tom.id,1,"\n");
+ continue;
+ }
+ if (viam.type != rel_member_node && viam.type != rel_member_way) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+ turn_restriction=g_new0(struct turn_restriction, 1);
+ turn_restriction->relid=relid;
+ turn_restriction->type=ib->type;
+ turn_restriction->r.l.x=1<<30;
+ turn_restriction->order=255;
+ relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 0, fromm.type, fromm.id);
+ relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 1, viam.type, viam.id);
+ relations_add_relation_member_entry(relations, relations_func, turn_restriction, (gpointer) 2, tom.type, tom.id);
+ turn_restrictions=g_list_append(turn_restrictions, turn_restriction);
+ }
+ return turn_restrictions;
}
void
-process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out)
-{
- struct relations *relations=relations_new();
- GList *turn_restrictions;
- fseek(in, 0, SEEK_SET);
- turn_restrictions=process_turn_restrictions_setup(in, relations);
- relations_process(relations, coords, ways);
- process_turn_restrictions_finish(turn_restrictions, out);
- relations_destroy(relations);
+process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) {
+ struct relations *relations=relations_new();
+ GList *turn_restrictions;
+ fseek(in, 0, SEEK_SET);
+ turn_restrictions=process_turn_restrictions_setup(in, relations);
+ relations_process(relations, coords, ways);
+ process_turn_restrictions_finish(turn_restrictions, out);
+ relations_destroy(relations);
}
#if 0
void
-process_turn_restrictions_old(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out)
-{
- struct relation_member fromm,tom,viam,tmpm;
- struct node_item ni;
- long long relid;
- char from_buffer[65536],to_buffer[65536],via_buffer[65536];
- struct item_bin *ib,*from=(struct item_bin *)from_buffer,*to=(struct item_bin *)to_buffer,*via=(struct item_bin *)via_buffer;
- struct coord *fromc,*toc,*viafrom,*viato,*tmp;
- int min_count;
- while ((ib=read_item(in))) {
- relid=item_bin_get_relationid(ib);
- min_count=0;
- if (!search_relation_member(ib, "from",&fromm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: from member missing\n");
- continue;
- }
- if (search_relation_member(ib, "from",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
- continue;
- }
- min_count=0;
- if (!search_relation_member(ib, "to",&tom,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: to member missing\n");
- continue;
- }
- if (search_relation_member(ib, "to",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
- continue;
- }
- min_count=0;
- if (!search_relation_member(ib, "via",&viam,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: via member missing\n");
- continue;
- }
- if (search_relation_member(ib, "via",&tmpm,&min_count)) {
- osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
- continue;
- }
- if (fromm.type != 2) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
- osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
- continue;
- }
- if (tom.type != 2) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
- osm_warning(osm_types[tom.type],tom.id,1,"\n");
- continue;
- }
- if (viam.type != 1 && viam.type != 2) {
- osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
- if (viam.type == 1) {
- if (!node_item_get_from_file(coords, viam.id, &ni)) {
- osm_warning("relation",relid,0,"turn restriction: failed to get via member ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
- viafrom=&ni.c;
- viato=&ni.c;
- } else {
- if (!(viafrom=get_way(ways, ways_index, NULL, viam.id, via, 0))) {
- osm_warning("relation",relid,0,"turn restriction: failed to get first via coordinate from ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
- if (!(viato=get_way(ways, ways_index, viafrom, viam.id, via, 0))) {
- osm_warning("relation",relid,0,"turn restriction: failed to get last via coordinate from ");
- osm_warning(osm_types[viam.type],viam.id,1,"\n");
- continue;
- }
-
- }
+process_turn_restrictions_old(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) {
+ struct relation_member fromm,tom,viam,tmpm;
+ struct node_item ni;
+ long long relid;
+ char from_buffer[65536],to_buffer[65536],via_buffer[65536];
+ struct item_bin *ib,*from=(struct item_bin *)from_buffer,*to=(struct item_bin *)to_buffer,
+ *via=(struct item_bin *)via_buffer;
+ struct coord *fromc,*toc,*viafrom,*viato,*tmp;
+ int min_count;
+ while ((ib=read_item(in))) {
+ relid=item_bin_get_relationid(ib);
+ min_count=0;
+ if (!search_relation_member(ib, "from",&fromm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: from member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "from",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
+ continue;
+ }
+ min_count=0;
+ if (!search_relation_member(ib, "to",&tom,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: to member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "to",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
+ continue;
+ }
+ min_count=0;
+ if (!search_relation_member(ib, "via",&viam,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: via member missing\n");
+ continue;
+ }
+ if (search_relation_member(ib, "via",&tmpm,&min_count)) {
+ osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
+ continue;
+ }
+ if (fromm.type != 2) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
+ osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
+ continue;
+ }
+ if (tom.type != 2) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
+ osm_warning(osm_types[tom.type],tom.id,1,"\n");
+ continue;
+ }
+ if (viam.type != 1 && viam.type != 2) {
+ osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+ if (viam.type == 1) {
+ if (!node_item_get_from_file(coords, viam.id, &ni)) {
+ osm_warning("relation",relid,0,"turn restriction: failed to get via member ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+ viafrom=&ni.c;
+ viato=&ni.c;
+ } else {
+ if (!(viafrom=get_way(ways, ways_index, NULL, viam.id, via, 0))) {
+ osm_warning("relation",relid,0,"turn restriction: failed to get first via coordinate from ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+ if (!(viato=get_way(ways, ways_index, viafrom, viam.id, via, 0))) {
+ osm_warning("relation",relid,0,"turn restriction: failed to get last via coordinate from ");
+ osm_warning(osm_types[viam.type],viam.id,1,"\n");
+ continue;
+ }
+
+ }
#if 0
- fprintf(stderr,"via "LONGLONG_FMT" vs %d\n",viam.id, ni.id);
- fprintf(stderr,"coord 0x%x,0x%x\n",ni.c.x,ni.c.y);
- fprintf(stderr,"Lookup "LONGLONG_FMT"\n",fromm.id);
+ fprintf(stderr,"via "LONGLONG_FMT" vs %d\n",viam.id, ni.id);
+ fprintf(stderr,"coord 0x%x,0x%x\n",ni.c.x,ni.c.y);
+ fprintf(stderr,"Lookup "LONGLONG_FMT"\n",fromm.id);
#endif
- if (!(fromc=get_way(ways, ways_index, viafrom, fromm.id, from, 0))) {
- if (viam.type == 1 || !(fromc=get_way(ways, ways_index, viato, fromm.id, from, 0))) {
- osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
- osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to from member ",viafrom->x,viafrom->y,viato->x,viato->y);
- osm_warning(osm_types[fromm.type],fromm.id,1," (");
- get_way(ways, ways_index, viafrom, fromm.id, from, 1);
- fprintf(stderr,")\n");
- continue;
- } else {
- tmp=viato;
- viato=viafrom;
- viafrom=tmp;
- }
- }
- if (!(toc=get_way(ways, ways_index, viato, tom.id, to, 0))) {
- osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
- osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to to member ",viafrom->x,viafrom->y,viato->x,viato->y);
- osm_warning(osm_types[tom.type],tom.id,1," (");
- get_way(ways, ways_index, viato, tom.id, to, 1);
- fprintf(stderr,")\n");
- continue;
- }
+ if (!(fromc=get_way(ways, ways_index, viafrom, fromm.id, from, 0))) {
+ if (viam.type == 1 || !(fromc=get_way(ways, ways_index, viato, fromm.id, from, 0))) {
+ osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
+ osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to from member ",viafrom->x,viafrom->y,viato->x,
+ viato->y);
+ osm_warning(osm_types[fromm.type],fromm.id,1," (");
+ get_way(ways, ways_index, viafrom, fromm.id, from, 1);
+ fprintf(stderr,")\n");
+ continue;
+ } else {
+ tmp=viato;
+ viato=viafrom;
+ viafrom=tmp;
+ }
+ }
+ if (!(toc=get_way(ways, ways_index, viato, tom.id, to, 0))) {
+ osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
+ osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to to member ",viafrom->x,viafrom->y,viato->x,
+ viato->y);
+ osm_warning(osm_types[tom.type],tom.id,1," (");
+ get_way(ways, ways_index, viato, tom.id, to, 1);
+ fprintf(stderr,")\n");
+ continue;
+ }
#if 0
- fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x)\n",fromc->x,fromc->y, ni.c.x, ni.c.y, toc->x, toc->y);
+ fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x)\n",fromc->x,fromc->y, ni.c.x, ni.c.y, toc->x, toc->y);
#endif
- item_bin_init(ib,ib->type);
- item_bin_add_coord(ib, fromc, 1);
- item_bin_add_coord(ib, viafrom, 1);
- if (viam.type == 2)
- item_bin_add_coord(ib, viato, 1);
- item_bin_add_coord(ib, toc, 1);
- item_bin_write(item_bin, out);
- }
+ item_bin_init(ib,ib->type);
+ item_bin_add_coord(ib, fromc, 1);
+ item_bin_add_coord(ib, viafrom, 1);
+ if (viam.type == 2)
+ item_bin_add_coord(ib, viato, 1);
+ item_bin_add_coord(ib, toc, 1);
+ item_bin_write(item_bin, out);
+ }
}
#endif
#if 0
static void
-process_countries(FILE *way, FILE *ways_index)
-{
- FILE *in=fopen("country_de.tmp","r");
- struct item_bin *ib;
- char buffer2[400000];
- struct item_bin *ib2=(struct item_bin *)buffer2;
- GList *segments=NULL,*sort_segments;
- fseek(in, 0, SEEK_SET);
- while ((ib=read_item(in))) {
- char *str=NULL;
- struct relation_member member;
- while ((str=item_bin_get_attr(ib, attr_osm_member, str))) {
- if (!parse_relation_member_string(str, &member))
- break;
- if (member.type == 2) {
- if (!seek_to_way(way, ways_index, member.id)) {
- fprintf(stderr,"not found in index");
- break;
- }
- while (item_bin_read(ib2, way)) {
- if (item_bin_get_wayid(ib2) != member.id)
- break;
- segments=g_list_prepend(segments,item_bin_to_poly_segment(ib2, geom_poly_segment_type_way_unknown));
- break;
- }
- }
- }
- }
- sort_segments=geom_poly_segments_sort(segments, geom_poly_segment_type_way_left_side);
- FILE *tmp=fopen("tst.txt","w");
- while (sort_segments) {
- struct geom_poly_segment *seg=sort_segments->data;
- if (!seg) {
- fprintf(stderr,"is null\n");
- } else {
- fprintf(stderr,"segment %p %s area "LONGLONG_FMT"\n",sort_segments,coord_is_equal(*seg->first, *seg->last) ? "closed":"open",geom_poly_area(seg->first,seg->last-seg->first+1));
- }
+process_countries(FILE *way, FILE *ways_index) {
+ FILE *in=fopen("country_de.tmp","r");
+ struct item_bin *ib;
+ char buffer2[400000];
+ struct item_bin *ib2=(struct item_bin *)buffer2;
+ GList *segments=NULL,*sort_segments;
+ fseek(in, 0, SEEK_SET);
+ while ((ib=read_item(in))) {
+ char *str=NULL;
+ struct relation_member member;
+ while ((str=item_bin_get_attr(ib, attr_osm_member, str))) {
+ if (!parse_relation_member_string(str, &member))
+ break;
+ if (member.type == 2) {
+ if (!seek_to_way(way, ways_index, member.id)) {
+ fprintf(stderr,"not found in index");
+ break;
+ }
+ while (item_bin_read(ib2, way)) {
+ if (item_bin_get_wayid(ib2) != member.id)
+ break;
+ segments=g_list_prepend(segments,item_bin_to_poly_segment(ib2, geom_poly_segment_type_way_unknown));
+ break;
+ }
+ }
+ }
+ }
+ sort_segments=geom_poly_segments_sort(segments, geom_poly_segment_type_way_left_side);
+ FILE *tmp=fopen("tst.txt","w");
+ while (sort_segments) {
+ struct geom_poly_segment *seg=sort_segments->data;
+ if (!seg) {
+ fprintf(stderr,"is null\n");
+ } else {
+ fprintf(stderr,"segment %p %s area "LONGLONG_FMT"\n",sort_segments,coord_is_equal(*seg->first,
+ *seg->last) ? "closed":"open",geom_poly_area(seg->first,seg->last-seg->first+1));
+ }
#if 0
- int count=seg->last-seg->first+1;
- item_bin_init(ib, type_border_country);
- item_bin_add_coord(ib, seg->first, count);
- item_bin_dump(ib, tmp);
+ int count=seg->last-seg->first+1;
+ item_bin_init(ib, type_border_country);
+ item_bin_add_coord(ib, seg->first, count);
+ item_bin_dump(ib, tmp);
#endif
- sort_segments=g_list_next(sort_segments);
- }
- fclose(tmp);
- fclose(in);
+ sort_segments=g_list_next(sort_segments);
+ }
+ fclose(tmp);
+ fclose(in);
}
#endif
static void
-node_ref_way(osmid node)
-{
- struct node_item *ni;
- ni=node_item_get(node);
- if (ni)
- ni->ref_way++;
+node_ref_way(osmid node) {
+ struct node_item *ni;
+ ni=node_item_get(node);
+ if (ni)
+ ni->ref_way++;
}
static void
-nodes_ref_item_bin(struct item_bin *ib)
-{
- int i;
- struct coord *c=(struct coord *)(ib+1);
- for (i = 0 ; i < ib->clen/2 ; i++)
- node_ref_way(GET_REF(c[i]));
+nodes_ref_item_bin(struct item_bin *ib) {
+ int i;
+ struct coord *c=(struct coord *)(ib+1);
+ for (i = 0 ; i < ib->clen/2 ; i++)
+ node_ref_way(GET_REF(c[i]));
}
void
-osm_add_nd(osmid ref)
-{
- SET_REF(coord_buffer[coord_count], ref);
- coord_count++;
- if (coord_count > MAX_COORD_COUNT) {
- fprintf(stderr,"ERROR: Overflow - more than %d coordinates in one way.\n", MAX_COORD_COUNT);
- exit(1);
- }
+osm_add_nd(osmid ref) {
+ SET_REF(coord_buffer[coord_count], ref);
+ coord_count++;
+ if (coord_count > MAX_COORD_COUNT) {
+ fprintf(stderr,"ERROR: Overflow - more than %d coordinates in one way.\n", MAX_COORD_COUNT);
+ exit(1);
+ }
}
static void
-write_item_way_subsection_index(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, long long *last_id)
-{
- osmid idx[2];
- idx[0]=item_bin_get_wayid(orig);
- idx[1]=ftello(out);
- if (way_hash) {
- if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long long)idx[0], NULL, NULL)))
- g_hash_table_insert(way_hash, (gpointer)(long long)idx[0], (gpointer)(long long)idx[1]);
- } else {
- if (!last_id || *last_id != idx[0])
- dbg_assert(fwrite(idx, sizeof(idx), 1, out_index)==1);
- if (last_id)
- *last_id=idx[0];
- }
+write_item_way_subsection_index(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig,
+ long long *last_id) {
+ osmid idx[2];
+ idx[0]=item_bin_get_wayid(orig);
+ idx[1]=ftello(out);
+ if (way_hash) {
+ if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long long)idx[0], NULL, NULL)))
+ g_hash_table_insert(way_hash, (gpointer)(long long)idx[0], (gpointer)(long long)idx[1]);
+ } else {
+ if (!last_id || *last_id != idx[0])
+ dbg_assert(fwrite(idx, sizeof(idx), 1, out_index)==1);
+ if (last_id)
+ *last_id=idx[0];
+ }
}
static void
-write_item_way_subsection(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, int first, int last, long long *last_id)
-{
- struct item_bin new;
- struct coord *c=(struct coord *)(orig+1);
- char *attr=(char *)(c+orig->clen/2);
- int attr_len=orig->len-orig->clen-2;
- processed_ways++;
- new.type=orig->type;
- new.clen=(last-first+1)*2;
- new.len=new.clen+attr_len+2;
- if (out_index)
- write_item_way_subsection_index(out, out_index, out_graph, orig, last_id);
- dbg_assert(fwrite(&new, sizeof(new), 1, out)==1);
- dbg_assert(fwrite(c+first, new.clen*4, 1, out)==1);
- dbg_assert(fwrite(attr, attr_len*4, 1, out)==1);
+write_item_way_subsection(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, int first, int last,
+ long long *last_id) {
+ struct item_bin new;
+ struct coord *c=(struct coord *)(orig+1);
+ char *attr=(char *)(c+orig->clen/2);
+ int attr_len=orig->len-orig->clen-2;
+ processed_ways++;
+ new.type=orig->type;
+ new.clen=(last-first+1)*2;
+ new.len=new.clen+attr_len+2;
+ if (out_index)
+ write_item_way_subsection_index(out, out_index, out_graph, orig, last_id);
+ dbg_assert(fwrite(&new, sizeof(new), 1, out)==1);
+ dbg_assert(fwrite(c+first, new.clen*4, 1, out)==1);
+ dbg_assert(fwrite(attr, attr_len*4, 1, out)==1);
}
void
-ref_ways(FILE *in)
-{
- struct item_bin *ib;
+ref_ways(FILE *in) {
+ struct item_bin *ib;
- fseek(in, 0, SEEK_SET);
- while ((ib=read_item(in)))
- nodes_ref_item_bin(ib);
+ fseek(in, 0, SEEK_SET);
+ while ((ib=read_item(in)))
+ nodes_ref_item_bin(ib);
}
void
-resolve_ways(FILE *in, FILE *out)
-{
- struct item_bin *ib;
- struct coord *c;
- int i;
- struct node_item *ni;
-
- fseek(in, 0, SEEK_SET);
- while ((ib=read_item(in))) {
- c=(struct coord *)(ib+1);
- for (i = 0 ; i < ib->clen/2 ; i++) {
- if(!IS_REF(c[i]))
- continue;
- ni=node_item_get(GET_REF(c[i]));
- if(ni) {
- c[i].x=ni->c.x;
- c[i].y=ni->c.y;
- }
-
- }
- item_bin_write(ib,out);
- }
+resolve_ways(FILE *in, FILE *out) {
+ struct item_bin *ib;
+ struct coord *c;
+ int i;
+ struct node_item *ni;
+
+ fseek(in, 0, SEEK_SET);
+ while ((ib=read_item(in))) {
+ c=(struct coord *)(ib+1);
+ for (i = 0 ; i < ib->clen/2 ; i++) {
+ if(!IS_REF(c[i]))
+ continue;
+ ni=node_item_get(GET_REF(c[i]));
+ if(ni) {
+ c[i].x=ni->c.x;
+ c[i].y=ni->c.y;
+ }
+
+ }
+ item_bin_write(ib,out);
+ }
}
/**
@@ -3242,274 +3184,269 @@ resolve_ways(FILE *in, FILE *out)
* @returns nothing
*/
void
-process_way2poi(FILE *in, FILE *out, int type)
-{
- struct item_bin *ib;
- while ((ib=read_item(in))) {
- int count=ib->clen/2;
- if(count>1 && ib->type<type_line) {
- struct coord *c=(struct coord *)(ib+1), c1, c2;
- int done=0;
- if(type==type_area) {
- if(count<3) {
- osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, less than 3 points defined\n");
- } else if(!geom_poly_centroid(c, count, &c1)) {
- osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, area is 0\n");
- } else {
- if(geom_poly_point_inside(c, count, &c1)) {
- c[0]=c1;
- } else {
- geom_poly_closest_point(c, count, &c1, &c2);
- c[0]=c2;
- }
- done=1;
- }
- }
- if(!done) {
- geom_line_middle(c,count,&c1);
- c[0]=c1;
- }
- write_item_way_subsection(out, NULL, NULL, ib, 0, 0, NULL);
- }
- }
+process_way2poi(FILE *in, FILE *out, int type) {
+ struct item_bin *ib;
+ while ((ib=read_item(in))) {
+ int count=ib->clen/2;
+ if(count>1 && ib->type<type_line) {
+ struct coord *c=(struct coord *)(ib+1), c1, c2;
+ int done=0;
+ if(type==type_area) {
+ if(count<3) {
+ osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, less than 3 points defined\n");
+ } else if(!geom_poly_centroid(c, count, &c1)) {
+ osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, area is 0\n");
+ } else {
+ if(geom_poly_point_inside(c, count, &c1)) {
+ c[0]=c1;
+ } else {
+ geom_poly_closest_point(c, count, &c1, &c2);
+ c[0]=c2;
+ }
+ done=1;
+ }
+ }
+ if(!done) {
+ geom_line_middle(c,count,&c1);
+ c[0]=c1;
+ }
+ write_item_way_subsection(out, NULL, NULL, ib, 0, 0, NULL);
+ }
+ }
}
int
-map_resolve_coords_and_split_at_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final)
-{
- struct coord *c;
- int i,ccount,last,remaining;
- osmid ndref;
- struct item_bin *ib;
- struct node_item *ni;
- long long last_id=0;
- processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
- sig_alrm(0);
- while ((ib=read_item(in))) {
- ccount=ib->clen/2;
- if (ccount <= 1)
- continue;
- c=(struct coord *)(ib+1);
- last=0;
- for (i = 0 ; i < ccount ; i++) {
- if (IS_REF(c[i])) {
- ndref=GET_REF(c[i]);
- ni=node_item_get(ndref);
- if (ni) {
- c[i]=ni->c;
- if (ni->ref_way > 1 && i != 0 && i != ccount-1 && i != last && item_get_default_flags(ib->type)) {
- write_item_way_subsection(out, out_index, out_graph, ib, last, i, &last_id);
- last=i;
- }
- } else if (final) {
- osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to ");
- osm_warning("node",ndref,1,"\n");
- remaining=(ib->len+1)*4-sizeof(struct item_bin)-i*sizeof(struct coord);
- memmove(&c[i], &c[i+1], remaining);
- ib->clen-=2;
- ib->len-=2;
- i--;
- ccount--;
- }
- }
- }
- if (ccount) {
- write_item_way_subsection(out, out_index, out_graph, ib, last, ccount-1, &last_id);
- if (final && ib->type == type_water_line && out_coastline) {
- write_item_way_subsection(out_coastline, NULL, NULL, ib, last, ccount-1, NULL);
- }
- }
- }
- sig_alrm(0);
- sig_alrm_end();
- return 0;
+map_resolve_coords_and_split_at_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph,
+ FILE *out_coastline, int final) {
+ struct coord *c;
+ int i,ccount,last,remaining;
+ osmid ndref;
+ struct item_bin *ib;
+ struct node_item *ni;
+ long long last_id=0;
+ processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0;
+ sig_alrm(0);
+ while ((ib=read_item(in))) {
+ ccount=ib->clen/2;
+ if (ccount <= 1)
+ continue;
+ c=(struct coord *)(ib+1);
+ last=0;
+ for (i = 0 ; i < ccount ; i++) {
+ if (IS_REF(c[i])) {
+ ndref=GET_REF(c[i]);
+ ni=node_item_get(ndref);
+ if (ni) {
+ c[i]=ni->c;
+ if (ni->ref_way > 1 && i != 0 && i != ccount-1 && i != last && item_get_default_flags(ib->type)) {
+ write_item_way_subsection(out, out_index, out_graph, ib, last, i, &last_id);
+ last=i;
+ }
+ } else if (final) {
+ osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to ");
+ osm_warning("node",ndref,1,"\n");
+ remaining=(ib->len+1)*4-sizeof(struct item_bin)-i*sizeof(struct coord);
+ memmove(&c[i], &c[i+1], remaining);
+ ib->clen-=2;
+ ib->len-=2;
+ i--;
+ ccount--;
+ }
+ }
+ }
+ if (ccount) {
+ write_item_way_subsection(out, out_index, out_graph, ib, last, ccount-1, &last_id);
+ if (final && ib->type == type_water_line && out_coastline) {
+ write_item_way_subsection(out_coastline, NULL, NULL, ib, last, ccount-1, NULL);
+ }
+ }
+ }
+ sig_alrm(0);
+ sig_alrm_end();
+ return 0;
}
static void
-index_country_add(struct zip_info *info, int country_id, char*first_key, char *last_key, char *tile, char *filename, int size, FILE *out)
-{
- struct item_bin *item_bin=init_item(type_countryindex);
- int num=0, zip_num;
- char tilename[32];
+index_country_add(struct zip_info *info, int country_id, char*first_key, char *last_key, char *tile, char *filename,
+ int size, FILE *out) {
+ struct item_bin *item_bin=init_item(type_countryindex);
+ int num=0, zip_num;
+ char tilename[32];
+
+ do {
+ snprintf(tilename,sizeof(tilename),"%ss%d", tile, num);
+ num++;
+ zip_num=add_aux_tile(info, tilename, filename, size);
+ } while (zip_num == -1);
- do {
- snprintf(tilename,sizeof(tilename),"%ss%d", tile, num);
- num++;
- zip_num=add_aux_tile(info, tilename, filename, size);
- } while (zip_num == -1);
-
- item_bin_add_attr_int(item_bin, attr_country_id, country_id);
+ item_bin_add_attr_int(item_bin, attr_country_id, country_id);
- if(first_key)
- item_bin_add_attr_string(item_bin, attr_first_key, first_key);
+ if(first_key)
+ item_bin_add_attr_string(item_bin, attr_first_key, first_key);
- if(last_key)
- item_bin_add_attr_string(item_bin, attr_last_key, last_key);
+ if(last_key)
+ item_bin_add_attr_string(item_bin, attr_last_key, last_key);
- item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_num);
- item_bin_write(item_bin, out);
+ item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_num);
+ item_bin_write(item_bin, out);
}
void
-write_countrydir(struct zip_info *zip_info, int max_index_size)
-{
- int i;
- int max=11;
- char filename[32];
- struct country_table *co;
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- co=&country_table[i];
- if(co->size) {
- FILE *in;
- char countrypart[32];
- char partsuffix[32];
- FILE *out=NULL;
- char *outname=NULL;
- int partsize;
- char buffer[50000];
- struct item_bin *ib=(struct item_bin*)buffer;
- int ibsize;
- char tileco[32]="";
- char tileprev[32]="";
- char tilecur[32]="";
- char *countryindexname;
- FILE *countryindex;
- char key[1024]="",first_key[1024]="",last_key[1024]="";
-
- tile(&co->r, "", tileco, max, overlap, NULL);
-
- snprintf(filename,sizeof(filename),"country_%d.tmp", co->countryid);
- in=fopen(filename,"rb");
-
- snprintf(countrypart,sizeof(countrypart),"country_%d_p",co->countryid);
-
- countryindex=tempfile("0",countrypart,1);
- countryindexname=tempfile_name("0",countrypart);
-
- partsize=0;
-
- while(1) {
- int r=item_bin_read(ib,in);
- struct attr_bin *a;
- ibsize=r>0?(ib->len+1)*4 : 0;
- if(ibsize) {
- g_strlcpy(tileprev,tilecur,sizeof(tileprev));
- a=item_bin_get_attr_bin(ib, attr_tile_name, NULL);
- if(a) {
- g_strlcpy(tilecur,(char *)(a+1),sizeof(tilecur));
- item_bin_remove_attr(ib,a+1);
- }
- else
- tilecur[0]=0;
-
- a=item_bin_get_attr_bin_last(ib);
- if(a && ATTR_IS_STRING(a->type))
- g_strlcpy(key,(char *)(a+1),sizeof(key));
- }
-
- /* If output file is already opened, and:
- - we have reached end of input file, or
- - adding new tile would make index part too big, or
- - item just read belongs to a different tile than the previous one,
- then close existing output file, put reference to the country index tile.*/
- if(out && (!r || (partsize && ((partsize+ibsize)>max_index_size)) || strcmp(tileprev,tilecur)) ) {
- partsize=ftello(out);
- fclose(out);
- out=NULL;
- index_country_add(zip_info,co->countryid,first_key,last_key,strlen(tileco)>strlen(tileprev)?tileco:tileprev,outname,partsize,countryindex);
- g_free(outname);
- outname=NULL;
- g_strlcpy(first_key,key,sizeof(first_key));
- }
-
- /* No items left, finish this country index. */
- if(!r)
- break;
-
- /* Open new output file. */
- if(!out) {
- co->nparts++;
- snprintf(partsuffix,sizeof(partsuffix),"%d",co->nparts);
- out=tempfile(partsuffix,countrypart,1);
- outname=tempfile_name(partsuffix,countrypart);
- partsize=0;
- }
-
- item_bin_write(ib,out);
- partsize+=ibsize;
- g_strlcpy(last_key,key,sizeof(last_key));
- }
-
- partsize=ftello(countryindex);
- if(partsize)
- index_country_add(zip_info,co->countryid,NULL,NULL,tileco,countryindexname, partsize, zip_get_index(zip_info));
- fclose(countryindex);
- g_free(countryindexname);
- fclose(in);
- }
- }
+write_countrydir(struct zip_info *zip_info, int max_index_size) {
+ int i;
+ int max=11;
+ char filename[32];
+ struct country_table *co;
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ co=&country_table[i];
+ if(co->size) {
+ FILE *in;
+ char countrypart[32];
+ char partsuffix[32];
+ FILE *out=NULL;
+ char *outname=NULL;
+ int partsize;
+ char buffer[50000];
+ struct item_bin *ib=(struct item_bin*)buffer;
+ int ibsize;
+ char tileco[32]="";
+ char tileprev[32]="";
+ char tilecur[32]="";
+ char *countryindexname;
+ FILE *countryindex;
+ char key[1024]="",first_key[1024]="",last_key[1024]="";
+
+ tile(&co->r, "", tileco, max, overlap, NULL);
+
+ snprintf(filename,sizeof(filename),"country_%d.tmp", co->countryid);
+ in=fopen(filename,"rb");
+
+ snprintf(countrypart,sizeof(countrypart),"country_%d_p",co->countryid);
+
+ countryindex=tempfile("0",countrypart,1);
+ countryindexname=tempfile_name("0",countrypart);
+
+ partsize=0;
+
+ while(1) {
+ int r=item_bin_read(ib,in);
+ struct attr_bin *a;
+ ibsize=r>0?(ib->len+1)*4 : 0;
+ if(ibsize) {
+ g_strlcpy(tileprev,tilecur,sizeof(tileprev));
+ a=item_bin_get_attr_bin(ib, attr_tile_name, NULL);
+ if(a) {
+ g_strlcpy(tilecur,(char *)(a+1),sizeof(tilecur));
+ item_bin_remove_attr(ib,a+1);
+ } else
+ tilecur[0]=0;
+
+ a=item_bin_get_attr_bin_last(ib);
+ if(a && ATTR_IS_STRING(a->type))
+ g_strlcpy(key,(char *)(a+1),sizeof(key));
+ }
+
+ /* If output file is already opened, and:
+ - we have reached end of input file, or
+ - adding new tile would make index part too big, or
+ - item just read belongs to a different tile than the previous one,
+ then close existing output file, put reference to the country index tile.*/
+ if(out && (!r || (partsize && ((partsize+ibsize)>max_index_size)) || strcmp(tileprev,tilecur)) ) {
+ partsize=ftello(out);
+ fclose(out);
+ out=NULL;
+ index_country_add(zip_info,co->countryid,first_key,last_key,strlen(tileco)>strlen(tileprev)?tileco:tileprev,outname,
+ partsize,countryindex);
+ g_free(outname);
+ outname=NULL;
+ g_strlcpy(first_key,key,sizeof(first_key));
+ }
+
+ /* No items left, finish this country index. */
+ if(!r)
+ break;
+
+ /* Open new output file. */
+ if(!out) {
+ co->nparts++;
+ snprintf(partsuffix,sizeof(partsuffix),"%d",co->nparts);
+ out=tempfile(partsuffix,countrypart,1);
+ outname=tempfile_name(partsuffix,countrypart);
+ partsize=0;
+ }
+
+ item_bin_write(ib,out);
+ partsize+=ibsize;
+ g_strlcpy(last_key,key,sizeof(last_key));
+ }
+
+ partsize=ftello(countryindex);
+ if(partsize)
+ index_country_add(zip_info,co->countryid,NULL,NULL,tileco,countryindexname, partsize, zip_get_index(zip_info));
+ fclose(countryindex);
+ g_free(countryindexname);
+ fclose(in);
+ }
+ }
}
void
-load_countries(void)
-{
- char filename[32];
- FILE *f;
- int i;
- struct country_table *co;
-
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- co=&country_table[i];
- sprintf(filename,"country_%d.tmp", co->countryid);
- f=fopen(filename,"rb");
- if (f) {
- int i,first=1;
- struct item_bin *ib;
- while ((ib=read_item(f))) {
- struct coord *c=(struct coord *)(ib+1);
- co->size+=ib->len*4+4;
- for (i = 0 ; i < ib->clen/2 ; i++) {
- if (first) {
- co->r.l=c[i];
- co->r.h=c[i];
- first=0;
- } else
- bbox_extend(&c[i], &co->r);
- }
- }
- fseek(f, 0, SEEK_END);
- co->size=ftello(f);
- fclose(f);
- }
- }
+load_countries(void) {
+ char filename[32];
+ FILE *f;
+ int i;
+ struct country_table *co;
+
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ co=&country_table[i];
+ sprintf(filename,"country_%d.tmp", co->countryid);
+ f=fopen(filename,"rb");
+ if (f) {
+ int i,first=1;
+ struct item_bin *ib;
+ while ((ib=read_item(f))) {
+ struct coord *c=(struct coord *)(ib+1);
+ co->size+=ib->len*4+4;
+ for (i = 0 ; i < ib->clen/2 ; i++) {
+ if (first) {
+ co->r.l=c[i];
+ co->r.h=c[i];
+ first=0;
+ } else
+ bbox_extend(&c[i], &co->r);
+ }
+ }
+ fseek(f, 0, SEEK_END);
+ co->size=ftello(f);
+ fclose(f);
+ }
+ }
}
void
-remove_countryfiles(void)
-{
- int i,j;
- char filename[32];
- struct country_table *co;
-
- for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
- co=&country_table[i];
- if (co->size) {
- sprintf(filename,"country_%d.tmp", co->countryid);
- unlink(filename);
- }
- for(j=0; j<=co->nparts;j++) {
- char partsuffix[32];
- sprintf(filename,"country_%d_p", co->countryid);
- sprintf(partsuffix,"%d",j);
- tempfile_unlink(partsuffix,filename);
- }
- }
-}
-
-void osm_init(FILE* rule_file)
-{
- build_attrmap(rule_file);
- build_countrytable();
+remove_countryfiles(void) {
+ int i,j;
+ char filename[32];
+ struct country_table *co;
+
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ co=&country_table[i];
+ if (co->size) {
+ sprintf(filename,"country_%d.tmp", co->countryid);
+ unlink(filename);
+ }
+ for(j=0; j<=co->nparts; j++) {
+ char partsuffix[32];
+ sprintf(filename,"country_%d_p", co->countryid);
+ sprintf(partsuffix,"%d",j);
+ tempfile_unlink(partsuffix,filename);
+ }
+ }
+}
+
+void osm_init(FILE* rule_file) {
+ build_attrmap(rule_file);
+ build_countrytable();
}
diff --git a/navit/maptool/osm_o5m.c b/navit/maptool/osm_o5m.c
index d6957067d..eae223806 100644
--- a/navit/maptool/osm_o5m.c
+++ b/navit/maptool/osm_o5m.c
@@ -5,25 +5,25 @@
static int print;
-static char *types[]={"node","way","relation"};
+static char *types[]= {"node","way","relation"};
struct o5m {
- unsigned char buffer[65536*2];
- int buffer_size;
- unsigned char *buffer_start;
- unsigned char *buffer_end;
- FILE *in;
- int error;
+ unsigned char buffer[65536*2];
+ int buffer_size;
+ unsigned char *buffer_start;
+ unsigned char *buffer_end;
+ FILE *in;
+ int error;
- int lat, lon, uid, version;
- unsigned long long id, rid[3], changeset;
- time_t timestamp;
- char *user;
+ int lat, lon, uid, version;
+ unsigned long long id, rid[3], changeset;
+ time_t timestamp;
+ char *user;
};
static struct string_table {
- char strings[15000][256];
- int pos;
+ char strings[15000][256];
+ int pos;
} st;
static double latlon_scale=10000000.0;
@@ -31,322 +31,311 @@ static double latlon_scale=10000000.0;
#define buffer_end(o,x) ((o)->buffer_start+(x) > (o)->buffer_end && !fill_buffer((o), (x)))
static int
-fill_buffer(struct o5m *o, int min)
-{
- int count;
+fill_buffer(struct o5m *o, int min) {
+ int count;
- memmove(o->buffer, o->buffer_start, o->buffer_end-o->buffer_start);
- o->buffer_end-=o->buffer_start-o->buffer;
- o->buffer_start=o->buffer;
- count=fread(o->buffer_end, 1, o->buffer+o->buffer_size-o->buffer_end, o->in);
- if (!count)
- return 0;
- o->buffer_end+=count;
- return (min <= o->buffer_end - o->buffer);
+ memmove(o->buffer, o->buffer_start, o->buffer_end-o->buffer_start);
+ o->buffer_end-=o->buffer_start-o->buffer;
+ o->buffer_start=o->buffer;
+ count=fread(o->buffer_end, 1, o->buffer+o->buffer_size-o->buffer_end, o->in);
+ if (!count)
+ return 0;
+ o->buffer_end+=count;
+ return (min <= o->buffer_end - o->buffer);
}
static unsigned long long
-get_uval(unsigned char **p)
-{
- unsigned char c;
- unsigned long long ret=0;
- int shift=0;
+get_uval(unsigned char **p) {
+ unsigned char c;
+ unsigned long long ret=0;
+ int shift=0;
- for (;;) {
- c=*((*p)++);
- ret+=((unsigned long long)c & 0x7f) << shift;
- if (!(c & 0x80))
- return ret;
- shift+=7;
- }
+ for (;;) {
+ c=*((*p)++);
+ ret+=((unsigned long long)c & 0x7f) << shift;
+ if (!(c & 0x80))
+ return ret;
+ shift+=7;
+ }
}
static long long
-get_sval(unsigned char **p)
-{
- unsigned long long ret=get_uval(p);
- if (ret & 1) {
- return -((long long)(ret >> 1)+1);
- } else {
- return ret >> 1;
- }
+get_sval(unsigned char **p) {
+ unsigned long long ret=get_uval(p);
+ if (ret & 1) {
+ return -((long long)(ret >> 1)+1);
+ } else {
+ return ret >> 1;
+ }
}
static void
-get_strings(struct string_table *st, unsigned char **p, char **s1, char **s2)
-{
- int len,xlen=0;
- *s1=(char *)*p;
- len=strlen(*s1);
- xlen=1;
- if (s2) {
- *s2=*s1+len+1;
- len+=strlen(*s2);
- xlen++;
- }
- (*p)+=len+xlen;
- if (len <= 250) {
- memcpy(st->strings[st->pos++], *s1, len+xlen);
- if (st->pos >= 15000)
- st->pos=0;
- }
+get_strings(struct string_table *st, unsigned char **p, char **s1, char **s2) {
+ int len,xlen=0;
+ *s1=(char *)*p;
+ len=strlen(*s1);
+ xlen=1;
+ if (s2) {
+ *s2=*s1+len+1;
+ len+=strlen(*s2);
+ xlen++;
+ }
+ (*p)+=len+xlen;
+ if (len <= 250) {
+ memcpy(st->strings[st->pos++], *s1, len+xlen);
+ if (st->pos >= 15000)
+ st->pos=0;
+ }
}
static void
-get_strings_ref(struct string_table *st, int ref, char **s1, char **s2)
-{
- int pos=st->pos-ref;
-
- if (pos < 0)
- pos+=15000;
- *s1=st->strings[pos];
- if (s2)
- *s2=*s1+strlen(*s1)+1;
+get_strings_ref(struct string_table *st, int ref, char **s1, char **s2) {
+ int pos=st->pos-ref;
+
+ if (pos < 0)
+ pos+=15000;
+ *s1=st->strings[pos];
+ if (s2)
+ *s2=*s1+strlen(*s1)+1;
}
static void
-print_escaped(char *s)
-{
- for (;;) {
- switch (*s) {
- case 0:
- return;
- case 9:
- case 13:
- case 34:
- case 38:
- case 39:
- case 60:
- case 62:
- printf("&#%d;",*s);
- break;
- default:
- putc(*s,stdout);
- break;
- }
- s++;
- }
+print_escaped(char *s) {
+ for (;;) {
+ switch (*s) {
+ case 0:
+ return;
+ case 9:
+ case 13:
+ case 34:
+ case 38:
+ case 39:
+ case 60:
+ case 62:
+ printf("&#%d;",*s);
+ break;
+ default:
+ putc(*s,stdout);
+ break;
+ }
+ s++;
+ }
}
static void
-o5m_reset(struct o5m *o)
-{
- o->lat=0;
- o->lon=0;
- o->id=0;
- o->rid[0]=0;
- o->rid[1]=0;
- o->rid[2]=0;
- o->changeset=0;
- o->timestamp=0;
+o5m_reset(struct o5m *o) {
+ o->lat=0;
+ o->lon=0;
+ o->id=0;
+ o->rid[0]=0;
+ o->rid[1]=0;
+ o->rid[2]=0;
+ o->changeset=0;
+ o->timestamp=0;
}
static void
-o5m_print_start(struct o5m *o, int c)
-{
- printf("\t<%s id=\""LONGLONG_FMT"\"",types[c-0x10],o->id);
+o5m_print_start(struct o5m *o, int c) {
+ printf("\t<%s id=\""LONGLONG_FMT"\"",types[c-0x10],o->id);
}
static void
-o5m_print_version(struct o5m *o, int tags)
-{
- char timestamp_str[64];
- if (o->version) {
- strftime(timestamp_str, sizeof(timestamp_str), "%Y-%m-%dT%H:%M:%SZ", gmtime(&o->timestamp));
- printf(" version=\"%d\" timestamp=\"%s\" changeset=\""LONGLONG_FMT"\"",o->version,timestamp_str,o->changeset);
- if (o->uid) {
- printf(" uid=\"%d\" user=\"",o->uid);
- print_escaped(o->user);
- printf("\"");
- }
- }
- printf("%s\n",tags?">":"/>");
+o5m_print_version(struct o5m *o, int tags) {
+ char timestamp_str[64];
+ if (o->version) {
+ strftime(timestamp_str, sizeof(timestamp_str), "%Y-%m-%dT%H:%M:%SZ", gmtime(&o->timestamp));
+ printf(" version=\"%d\" timestamp=\"%s\" changeset=\""LONGLONG_FMT"\"",o->version,timestamp_str,o->changeset);
+ if (o->uid) {
+ printf(" uid=\"%d\" user=\"",o->uid);
+ print_escaped(o->user);
+ printf("\"");
+ }
+ }
+ printf("%s\n",tags?">":"/>");
}
static void
-o5m_print_end(char c)
-{
- printf("\t</%s>\n",types[c-0x10]);
+o5m_print_end(char c) {
+ printf("\t</%s>\n",types[c-0x10]);
}
int
-map_collect_data_osm_o5m(FILE *in, struct maptool_osm *osm)
-{
- struct o5m o;
- unsigned char c, *end, *rend;
- int len, rlen, ref, tags;
- char *uidstr, *role;
+map_collect_data_osm_o5m(FILE *in, struct maptool_osm *osm) {
+ struct o5m o;
+ unsigned char c, *end, *rend;
+ int len, rlen, ref, tags;
+ char *uidstr, *role;
+
+ if (print) {
+ printf("<?xml version='1.0' encoding='UTF-8'?>\n");
+ printf("<osm version=\"0.6\" generator=\"osmconvert 0.1X6\">\n");
+ }
- if (print) {
- printf("<?xml version='1.0' encoding='UTF-8'?>\n");
- printf("<osm version=\"0.6\" generator=\"osmconvert 0.1X6\">\n");
- }
+ o5m_reset(&o);
+ o.buffer_size=sizeof(o.buffer);
+ o.buffer_start=o.buffer;
+ o.buffer_end=o.buffer;
+ o.error=0;
+ o.in=in;
- o5m_reset(&o);
- o.buffer_size=sizeof(o.buffer);
- o.buffer_start=o.buffer;
- o.buffer_end=o.buffer;
- o.error=0;
- o.in=in;
-
- fill_buffer(&o,1);
- for (;;) {
- if (buffer_end(&o, 1)) {
- fprintf(stderr,"unexpected eof\n");
- return 1;
- }
- c=*(o.buffer_start++);
- switch (c) {
- case 0x10:
- case 0x11:
- case 0x12:
- (void)buffer_end(&o, 4);
- len=get_uval(&o.buffer_start);
- if (o.buffer_start > o.buffer_end) {
- fprintf(stderr,"unexpected eof\n");
- return 0;
- }
- if (buffer_end(&o, len)) {
- fprintf(stderr,"unexpected eof or buffer too small, item type %d, item size %d\n", c, len);
- return 0;
- }
- end=o.buffer_start+len;
- o.id+=get_sval(&o.buffer_start);
- o.version=get_uval(&o.buffer_start);
- if (o.version) {
- o.timestamp+=get_sval(&o.buffer_start);
- if (o.timestamp) {
- o.changeset+=get_sval(&o.buffer_start);
- ref=get_uval(&o.buffer_start);
- if (ref)
- get_strings_ref(&st, ref, &uidstr, &o.user);
- else
- get_strings(&st, &o.buffer_start, &uidstr, &o.user);
- o.uid=get_uval((unsigned char **)&uidstr);
- }
- }
- if (print)
- o5m_print_start(&o, c);
- switch (c) {
- case 0x10:
- o.lon+=get_sval(&o.buffer_start);
- o.lat+=get_sval(&o.buffer_start);
- osm_add_node(o.id, o.lat/latlon_scale,o.lon/latlon_scale);
- tags=end > o.buffer_start;
- if (print) {
- printf(" lat=\"%.7f\" lon=\"%.7f\"",o.lat/10000000.0,o.lon/10000000.0);
- o5m_print_version(&o, tags);
- }
- break;
- case 0x11:
- osm_add_way(o.id);
- rlen=get_uval(&o.buffer_start);
- tags=end > o.buffer_start;
- rend=o.buffer_start+rlen;
- if (print)
- o5m_print_version(&o, tags);
- while (o.buffer_start < rend) {
- o.rid[0]+=get_sval(&o.buffer_start);
- osm_add_nd(o.rid[0]);
- if (print)
- printf("\t\t<nd ref=\""LONGLONG_FMT"\"/>\n",o.rid[0]);
- }
- break;
- case 0x12:
- osm_add_relation(o.id);
- rlen=get_uval(&o.buffer_start);
- tags=end > o.buffer_start;
- rend=o.buffer_start+rlen;
- if (print)
- o5m_print_version(&o, tags);
- while (o.buffer_start < rend) {
- long long delta=get_sval(&o.buffer_start);
- int r;
- ref=get_uval(&o.buffer_start);
- if (ref)
- get_strings_ref(&st, ref, &role, NULL);
- else
- get_strings(&st, &o.buffer_start, &role, NULL);
- r=role[0]-'0';
- if (r < 0)
- r=0;
- if (r > 2)
- r=2;
- o.rid[r]+=delta;
- osm_add_member(r+1, o.rid[r], role+1);
- if (print)
- printf("\t\t<member type=\"%s\" ref=\""LONGLONG_FMT"\" role=\"%s\"/>\n",types[r], o.rid[r], role+1);
- }
- break;
- }
- while (end > o.buffer_start) {
- char *k, *v;
- ref=get_uval(&o.buffer_start);
- if (ref)
- get_strings_ref(&st, ref, &k, &v);
- else
- get_strings(&st, &o.buffer_start, &k, &v);
- osm_add_tag(k, v);
- if (print) {
- printf("\t\t<tag k=\"");
- print_escaped(k);
- printf("\" v=\"");
- print_escaped(v);
- printf("\"/>\n");
- }
- }
- if (print && tags) {
- o5m_print_end(c);
- }
- switch (c) {
- case 0x10:
- osm_end_node(osm);
- break;
- case 0x11:
- osm_end_way(osm);
- break;
- case 0x12:
- osm_end_relation(osm);
- break;
- }
- break;
- case 0xdb:
- if (print)
- printf("\t<bounds minlat=\"-180.0000000\" minlon=\"-90.0000000\" maxlat=\"180.0000000\" maxlon=\"90.0000000\"/>\n");
- len=get_uval(&o.buffer_start);
- if (o.buffer_start > o.buffer_end) {
- return 0;
- }
- if (buffer_end(&o, len)) {
- return 0;
- }
- o.buffer_start+=len;
- break;
- case 0xe0:
- if (buffer_end(&o, 5))
- return 0;
- o.buffer_start+=5;
- break;
- case 0xfe:
- return 1;
- case 0xff:
- o5m_reset(&o);
- break;
- default:
- fprintf(stderr,"Unknown tag 0x%x\n",c);
- /* Fall through */
- case 0xdc: /* File timestamp: silently ignore it */
- len=get_uval(&o.buffer_start);
- if (o.buffer_start > o.buffer_end) {
- return 0;
- }
- if (buffer_end(&o, len)) {
- return 0;
- }
- o.buffer_start+=len;
- break;
- }
- }
- return 0;
+ fill_buffer(&o,1);
+ for (;;) {
+ if (buffer_end(&o, 1)) {
+ fprintf(stderr,"unexpected eof\n");
+ return 1;
+ }
+ c=*(o.buffer_start++);
+ switch (c) {
+ case 0x10:
+ case 0x11:
+ case 0x12:
+ (void)buffer_end(&o, 4);
+ len=get_uval(&o.buffer_start);
+ if (o.buffer_start > o.buffer_end) {
+ fprintf(stderr,"unexpected eof\n");
+ return 0;
+ }
+ if (buffer_end(&o, len)) {
+ fprintf(stderr,"unexpected eof or buffer too small, item type %d, item size %d\n", c, len);
+ return 0;
+ }
+ end=o.buffer_start+len;
+ o.id+=get_sval(&o.buffer_start);
+ o.version=get_uval(&o.buffer_start);
+ if (o.version) {
+ o.timestamp+=get_sval(&o.buffer_start);
+ if (o.timestamp) {
+ o.changeset+=get_sval(&o.buffer_start);
+ ref=get_uval(&o.buffer_start);
+ if (ref)
+ get_strings_ref(&st, ref, &uidstr, &o.user);
+ else
+ get_strings(&st, &o.buffer_start, &uidstr, &o.user);
+ o.uid=get_uval((unsigned char **)&uidstr);
+ }
+ }
+ if (print)
+ o5m_print_start(&o, c);
+ switch (c) {
+ case 0x10:
+ o.lon+=get_sval(&o.buffer_start);
+ o.lat+=get_sval(&o.buffer_start);
+ osm_add_node(o.id, o.lat/latlon_scale,o.lon/latlon_scale);
+ tags=end > o.buffer_start;
+ if (print) {
+ printf(" lat=\"%.7f\" lon=\"%.7f\"",o.lat/10000000.0,o.lon/10000000.0);
+ o5m_print_version(&o, tags);
+ }
+ break;
+ case 0x11:
+ osm_add_way(o.id);
+ rlen=get_uval(&o.buffer_start);
+ tags=end > o.buffer_start;
+ rend=o.buffer_start+rlen;
+ if (print)
+ o5m_print_version(&o, tags);
+ while (o.buffer_start < rend) {
+ o.rid[0]+=get_sval(&o.buffer_start);
+ osm_add_nd(o.rid[0]);
+ if (print)
+ printf("\t\t<nd ref=\""LONGLONG_FMT"\"/>\n",o.rid[0]);
+ }
+ break;
+ case 0x12:
+ osm_add_relation(o.id);
+ rlen=get_uval(&o.buffer_start);
+ tags=end > o.buffer_start;
+ rend=o.buffer_start+rlen;
+ if (print)
+ o5m_print_version(&o, tags);
+ while (o.buffer_start < rend) {
+ long long delta=get_sval(&o.buffer_start);
+ int r;
+ ref=get_uval(&o.buffer_start);
+ if (ref)
+ get_strings_ref(&st, ref, &role, NULL);
+ else
+ get_strings(&st, &o.buffer_start, &role, NULL);
+ r=role[0]-'0';
+ if (r < 0)
+ r=0;
+ if (r > 2)
+ r=2;
+ o.rid[r]+=delta;
+ osm_add_member(r+1, o.rid[r], role+1);
+ if (print)
+ printf("\t\t<member type=\"%s\" ref=\""LONGLONG_FMT"\" role=\"%s\"/>\n",types[r], o.rid[r], role+1);
+ }
+ break;
+ }
+ while (end > o.buffer_start) {
+ char *k, *v;
+ ref=get_uval(&o.buffer_start);
+ if (ref)
+ get_strings_ref(&st, ref, &k, &v);
+ else
+ get_strings(&st, &o.buffer_start, &k, &v);
+ osm_add_tag(k, v);
+ if (print) {
+ printf("\t\t<tag k=\"");
+ print_escaped(k);
+ printf("\" v=\"");
+ print_escaped(v);
+ printf("\"/>\n");
+ }
+ }
+ if (print && tags) {
+ o5m_print_end(c);
+ }
+ switch (c) {
+ case 0x10:
+ osm_end_node(osm);
+ break;
+ case 0x11:
+ osm_end_way(osm);
+ break;
+ case 0x12:
+ osm_end_relation(osm);
+ break;
+ }
+ break;
+ case 0xdb:
+ if (print)
+ printf("\t<bounds minlat=\"-180.0000000\" minlon=\"-90.0000000\" maxlat=\"180.0000000\" maxlon=\"90.0000000\"/>\n");
+ len=get_uval(&o.buffer_start);
+ if (o.buffer_start > o.buffer_end) {
+ return 0;
+ }
+ if (buffer_end(&o, len)) {
+ return 0;
+ }
+ o.buffer_start+=len;
+ break;
+ case 0xe0:
+ if (buffer_end(&o, 5))
+ return 0;
+ o.buffer_start+=5;
+ break;
+ case 0xfe:
+ return 1;
+ case 0xff:
+ o5m_reset(&o);
+ break;
+ default:
+ fprintf(stderr,"Unknown tag 0x%x\n",c);
+ /* Fall through */
+ case 0xdc: /* File timestamp: silently ignore it */
+ len=get_uval(&o.buffer_start);
+ if (o.buffer_start > o.buffer_end) {
+ return 0;
+ }
+ if (buffer_end(&o, len)) {
+ return 0;
+ }
+ o.buffer_start+=len;
+ break;
+ }
+ }
+ return 0;
}
diff --git a/navit/maptool/osm_protobuf.c b/navit/maptool/osm_protobuf.c
index d75bca8b5..9eb06afc1 100644
--- a/navit/maptool/osm_protobuf.c
+++ b/navit/maptool/osm_protobuf.c
@@ -47,266 +47,252 @@ static double latlon_scale=10000000.0;
}
static OSMPBF__BlobHeader *
-read_header(FILE *f)
-{
- unsigned char *buffer,lenb[4];
- int len;
+read_header(FILE *f) {
+ unsigned char *buffer,lenb[4];
+ int len;
- if (fread(lenb, 4, 1, f) != 1)
- return NULL;
- len=(lenb[0] << 24) | (lenb[1] << 16) | (lenb[2] << 8) | lenb[3];
- SANITY_CHECK_LENGTH(len, MAX_HEADER_LENGTH)
- buffer=alloca(len);
- if (fread(buffer, len, 1, f) != 1)
- return NULL;
- return osmpbf__blob_header__unpack(&protobuf_c_system_allocator, len, buffer);
+ if (fread(lenb, 4, 1, f) != 1)
+ return NULL;
+ len=(lenb[0] << 24) | (lenb[1] << 16) | (lenb[2] << 8) | lenb[3];
+ SANITY_CHECK_LENGTH(len, MAX_HEADER_LENGTH)
+ buffer=alloca(len);
+ if (fread(buffer, len, 1, f) != 1)
+ return NULL;
+ return osmpbf__blob_header__unpack(&protobuf_c_system_allocator, len, buffer);
}
static OSMPBF__Blob *
-read_blob(OSMPBF__BlobHeader *header, FILE *f, unsigned char *buffer)
-{
- int len=header->datasize;
- SANITY_CHECK_LENGTH(len, MAX_BLOB_LENGTH)
- if (fread(buffer, len, 1, f) != 1)
- return NULL;
- return osmpbf__blob__unpack(&protobuf_c_system_allocator, len, buffer);
+read_blob(OSMPBF__BlobHeader *header, FILE *f, unsigned char *buffer) {
+ int len=header->datasize;
+ SANITY_CHECK_LENGTH(len, MAX_BLOB_LENGTH)
+ if (fread(buffer, len, 1, f) != 1)
+ return NULL;
+ return osmpbf__blob__unpack(&protobuf_c_system_allocator, len, buffer);
}
static unsigned char *
-uncompress_blob(OSMPBF__Blob *blob)
-{
- unsigned char *ret=g_malloc(blob->raw_size);
- int zerr;
- z_stream strm;
+uncompress_blob(OSMPBF__Blob *blob) {
+ unsigned char *ret=g_malloc(blob->raw_size);
+ int zerr;
+ z_stream strm;
- if (!ret)
- return NULL;
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in=blob->zlib_data.len;
- strm.next_in=blob->zlib_data.data;
- strm.avail_out=blob->raw_size;
- strm.next_out=ret;
- zerr = inflateInit(&strm);
- if (zerr != Z_OK) {
- g_free(ret);
- return NULL;
- }
- zerr = inflate(&strm, Z_NO_FLUSH);
- if (zerr != Z_STREAM_END) {
- g_free(ret);
- return NULL;
- }
- inflateEnd(&strm);
- return ret;
+ if (!ret)
+ return NULL;
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.avail_in=blob->zlib_data.len;
+ strm.next_in=blob->zlib_data.data;
+ strm.avail_out=blob->raw_size;
+ strm.next_out=ret;
+ zerr = inflateInit(&strm);
+ if (zerr != Z_OK) {
+ g_free(ret);
+ return NULL;
+ }
+ zerr = inflate(&strm, Z_NO_FLUSH);
+ if (zerr != Z_STREAM_END) {
+ g_free(ret);
+ return NULL;
+ }
+ inflateEnd(&strm);
+ return ret;
}
static int
-get_string(char *buffer, int buffer_size, OSMPBF__PrimitiveBlock *primitive_block, int id, int escape)
-{
- int len=primitive_block->stringtable->s[id].len;
- char *data=(char *)primitive_block->stringtable->s[id].data;
- if (primitive_block->stringtable->s[id].len >= buffer_size) {
- buffer[0]='\0';
- return 0;
- }
- if (escape) {
- int i;
- char *p=buffer;
- for (i = 0 ; i < len ; i++) {
- switch(data[i]) {
- case '\t':
- case '\r':
- case '\n':
- case '>':
- case '<':
- case '\'':
- case '"':
- case '&':
- sprintf(p,"&#%d;",data[i]);
- p+=strlen(p);
- break;
- default:
- *p++=data[i];
- }
- }
- *p++='\0';
- return 1;
- } else {
- strncpy(buffer, data, len);
- buffer[len]='\0';
- return 1;
- }
+get_string(char *buffer, int buffer_size, OSMPBF__PrimitiveBlock *primitive_block, int id, int escape) {
+ int len=primitive_block->stringtable->s[id].len;
+ char *data=(char *)primitive_block->stringtable->s[id].data;
+ if (primitive_block->stringtable->s[id].len >= buffer_size) {
+ buffer[0]='\0';
+ return 0;
+ }
+ if (escape) {
+ int i;
+ char *p=buffer;
+ for (i = 0 ; i < len ; i++) {
+ switch(data[i]) {
+ case '\t':
+ case '\r':
+ case '\n':
+ case '>':
+ case '<':
+ case '\'':
+ case '"':
+ case '&':
+ sprintf(p,"&#%d;",data[i]);
+ p+=strlen(p);
+ break;
+ default:
+ *p++=data[i];
+ }
+ }
+ *p++='\0';
+ return 1;
+ } else {
+ strncpy(buffer, data, len);
+ buffer[len]='\0';
+ return 1;
+ }
}
static void
-process_osmheader(OSMPBF__Blob *blob, unsigned char *data)
-{
- OSMPBF__HeaderBlock *header_block;
- header_block=osmpbf__header_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
- osmpbf__header_block__free_unpacked(header_block, &protobuf_c_system_allocator);
+process_osmheader(OSMPBF__Blob *blob, unsigned char *data) {
+ OSMPBF__HeaderBlock *header_block;
+ header_block=osmpbf__header_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
+ osmpbf__header_block__free_unpacked(header_block, &protobuf_c_system_allocator);
}
#if 0
static void
-process_user(OSMPBF__PrimitiveBlock *primitive_block, int user_sid, int uid, int swap)
-{
- char userbuff[1024];
- get_string(userbuff, sizeof(userbuff), primitive_block, user_sid, 1);
- if (userbuff[0] && uid != -1) {
- if (swap)
- printf(" uid=\"%d\" user=\"%s\"",uid,userbuff);
- else
- printf(" user=\"%s\" uid=\"%d\"",userbuff,uid);
- }
+process_user(OSMPBF__PrimitiveBlock *primitive_block, int user_sid, int uid, int swap) {
+ char userbuff[1024];
+ get_string(userbuff, sizeof(userbuff), primitive_block, user_sid, 1);
+ if (userbuff[0] && uid != -1) {
+ if (swap)
+ printf(" uid=\"%d\" user=\"%s\"",uid,userbuff);
+ else
+ printf(" user=\"%s\" uid=\"%d\"",userbuff,uid);
+ }
}
static void
-process_timestamp(long long timestamp)
-{
- time_t ts;
- struct tm *tm;
- char tsbuff[1024];
- ts=timestamp;
- tm=gmtime(&ts);
- strftime(tsbuff, sizeof(tsbuff), "%Y-%m-%dT%H:%M:%SZ", tm);
- printf(" timestamp=\"%s\"",tsbuff);
+process_timestamp(long long timestamp) {
+ time_t ts;
+ struct tm *tm;
+ char tsbuff[1024];
+ ts=timestamp;
+ tm=gmtime(&ts);
+ strftime(tsbuff, sizeof(tsbuff), "%Y-%m-%dT%H:%M:%SZ", tm);
+ printf(" timestamp=\"%s\"",tsbuff);
}
#endif
static void
-process_tag(OSMPBF__PrimitiveBlock *primitive_block, int key, int val)
-{
- char keybuff[1024];
- char valbuff[1024];
- get_string(keybuff, sizeof(keybuff), primitive_block, key, 0);
- get_string(valbuff, sizeof(valbuff), primitive_block, val, 0);
- osm_add_tag(keybuff, valbuff);
+process_tag(OSMPBF__PrimitiveBlock *primitive_block, int key, int val) {
+ char keybuff[1024];
+ char valbuff[1024];
+ get_string(keybuff, sizeof(keybuff), primitive_block, key, 0);
+ get_string(valbuff, sizeof(valbuff), primitive_block, val, 0);
+ osm_add_tag(keybuff, valbuff);
}
static void
-process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, struct maptool_osm *osm)
-{
- int i,j=0,has_tags;
- long long id=0,lat=0,lon=0,changeset=0,timestamp=0;
- int user_sid=0,uid=0;
+process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, struct maptool_osm *osm) {
+ int i,j=0,has_tags;
+ long long id=0,lat=0,lon=0,changeset=0,timestamp=0;
+ int user_sid=0,uid=0;
- if (!dense)
- return;
+ if (!dense)
+ return;
- for (i = 0 ; i < dense->n_id ; i++) {
- id+=dense->id[i];
- lat+=dense->lat[i];
- lon+=dense->lon[i];
- changeset+=dense->denseinfo->changeset[i];
- user_sid+=dense->denseinfo->user_sid[i];
- uid+=dense->denseinfo->uid[i];
- timestamp+=dense->denseinfo->timestamp[i];
- has_tags=dense->keys_vals && dense->keys_vals[j];
- osm_add_node(id, lat/latlon_scale,lon/latlon_scale);
- if (has_tags) {
- while (dense->keys_vals[j]) {
- process_tag(primitive_block, dense->keys_vals[j], dense->keys_vals[j+1]);
- j+=2;
- }
- }
- osm_end_node(osm);
- j++;
- }
+ for (i = 0 ; i < dense->n_id ; i++) {
+ id+=dense->id[i];
+ lat+=dense->lat[i];
+ lon+=dense->lon[i];
+ changeset+=dense->denseinfo->changeset[i];
+ user_sid+=dense->denseinfo->user_sid[i];
+ uid+=dense->denseinfo->uid[i];
+ timestamp+=dense->denseinfo->timestamp[i];
+ has_tags=dense->keys_vals && dense->keys_vals[j];
+ osm_add_node(id, lat/latlon_scale,lon/latlon_scale);
+ if (has_tags) {
+ while (dense->keys_vals[j]) {
+ process_tag(primitive_block, dense->keys_vals[j], dense->keys_vals[j+1]);
+ j+=2;
+ }
+ }
+ osm_end_node(osm);
+ j++;
+ }
}
#if 0
static void
-process_info(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Info *info)
-{
- printf(" version=\"%d\" changeset=\"%Ld\"",info->version,info->changeset);
- process_user(primitive_block, info->user_sid, info->uid, 1);
- process_timestamp(info->timestamp);
+process_info(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Info *info) {
+ printf(" version=\"%d\" changeset=\"%Ld\"",info->version,info->changeset);
+ process_user(primitive_block, info->user_sid, info->uid, 1);
+ process_timestamp(info->timestamp);
}
#endif
static void
-process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, struct maptool_osm *osm)
-{
- int i;
- long long ref=0;
+process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, struct maptool_osm *osm) {
+ int i;
+ long long ref=0;
- osm_add_way(way->id);
- for (i = 0 ; i < way->n_refs ; i++) {
- ref+=way->refs[i];
- osm_add_nd(ref);
- }
- for (i = 0 ; i < way->n_keys ; i++)
- process_tag(primitive_block, way->keys[i], way->vals[i]);
- osm_end_way(osm);
+ osm_add_way(way->id);
+ for (i = 0 ; i < way->n_refs ; i++) {
+ ref+=way->refs[i];
+ osm_add_nd(ref);
+ }
+ for (i = 0 ; i < way->n_keys ; i++)
+ process_tag(primitive_block, way->keys[i], way->vals[i]);
+ osm_end_way(osm);
}
static void
-process_relation(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Relation *relation, struct maptool_osm *osm)
-{
- int i;
- long long ref=0;
- char rolebuff[1024];
+process_relation(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Relation *relation, struct maptool_osm *osm) {
+ int i;
+ long long ref=0;
+ char rolebuff[1024];
- osm_add_relation(relation->id);
- for (i = 0 ; i < relation->n_roles_sid ; i++) {
- ref+=relation->memids[i];
- get_string(rolebuff, sizeof(rolebuff), primitive_block, relation->roles_sid[i], 1);
- osm_add_member(relation->types[i]+1,ref,rolebuff);
- }
- for (i = 0 ; i < relation->n_keys ; i++)
- process_tag(primitive_block, relation->keys[i], relation->vals[i]);
- osm_end_relation(osm);
+ osm_add_relation(relation->id);
+ for (i = 0 ; i < relation->n_roles_sid ; i++) {
+ ref+=relation->memids[i];
+ get_string(rolebuff, sizeof(rolebuff), primitive_block, relation->roles_sid[i], 1);
+ osm_add_member(relation->types[i]+1,ref,rolebuff);
+ }
+ for (i = 0 ; i < relation->n_keys ; i++)
+ process_tag(primitive_block, relation->keys[i], relation->vals[i]);
+ osm_end_relation(osm);
}
static void
-process_osmdata(OSMPBF__Blob *blob, unsigned char *data, struct maptool_osm *osm)
-{
- int i,j;
- OSMPBF__PrimitiveBlock *primitive_block;
- primitive_block=osmpbf__primitive_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
- for (i = 0 ; i < primitive_block->n_primitivegroup ; i++) {
- OSMPBF__PrimitiveGroup *primitive_group=primitive_block->primitivegroup[i];
- process_dense(primitive_block, primitive_group->dense, osm);
- for (j = 0 ; j < primitive_group->n_ways ; j++)
- process_way(primitive_block, primitive_group->ways[j], osm);
- for (j = 0 ; j < primitive_group->n_relations ; j++)
- process_relation(primitive_block, primitive_group->relations[j], osm);
- }
- osmpbf__primitive_block__free_unpacked(primitive_block, &protobuf_c_system_allocator);
+process_osmdata(OSMPBF__Blob *blob, unsigned char *data, struct maptool_osm *osm) {
+ int i,j;
+ OSMPBF__PrimitiveBlock *primitive_block;
+ primitive_block=osmpbf__primitive_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
+ for (i = 0 ; i < primitive_block->n_primitivegroup ; i++) {
+ OSMPBF__PrimitiveGroup *primitive_group=primitive_block->primitivegroup[i];
+ process_dense(primitive_block, primitive_group->dense, osm);
+ for (j = 0 ; j < primitive_group->n_ways ; j++)
+ process_way(primitive_block, primitive_group->ways[j], osm);
+ for (j = 0 ; j < primitive_group->n_relations ; j++)
+ process_relation(primitive_block, primitive_group->relations[j], osm);
+ }
+ osmpbf__primitive_block__free_unpacked(primitive_block, &protobuf_c_system_allocator);
}
int
-map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm)
-{
- OSMPBF__BlobHeader *header;
- OSMPBF__Blob *blob;
- unsigned char *data;
- unsigned char *buffer=g_malloc(MAX_BLOB_LENGTH);
+map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm) {
+ OSMPBF__BlobHeader *header;
+ OSMPBF__Blob *blob;
+ unsigned char *data;
+ unsigned char *buffer=g_malloc(MAX_BLOB_LENGTH);
- while ((header=read_header(in))) {
- blob=read_blob(header, in, buffer);
- data=uncompress_blob(blob);
- if (!strcmp(header->type,"OSMHeader")) {
- process_osmheader(blob, data);
- } else if (!strcmp(header->type,"OSMData")) {
- process_osmdata(blob, data, osm);
- } else {
- printf("skipping fileblock of unknown type '%s'\n", header->type);
- g_free(buffer);
- return 0;
- }
- g_free(data);
- osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
- osmpbf__blob_header__free_unpacked(header, &protobuf_c_system_allocator);
- }
- g_free(buffer);
- return 1;
+ while ((header=read_header(in))) {
+ blob=read_blob(header, in, buffer);
+ data=uncompress_blob(blob);
+ if (!strcmp(header->type,"OSMHeader")) {
+ process_osmheader(blob, data);
+ } else if (!strcmp(header->type,"OSMData")) {
+ process_osmdata(blob, data, osm);
+ } else {
+ printf("skipping fileblock of unknown type '%s'\n", header->type);
+ g_free(buffer);
+ return 0;
+ }
+ g_free(data);
+ osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
+ osmpbf__blob_header__free_unpacked(header, &protobuf_c_system_allocator);
+ }
+ g_free(buffer);
+ return 1;
}
diff --git a/navit/maptool/osm_protobufdb.c b/navit/maptool/osm_protobufdb.c
index 51cdceae4..0d0f7de29 100644
--- a/navit/maptool/osm_protobufdb.c
+++ b/navit/maptool/osm_protobufdb.c
@@ -32,178 +32,171 @@
static double latlon_scale=10000000.0;
struct db_config {
- int node_ids_per_file;
- int node_ids_per_blob;
- int node_ids_per_group;
- int way_ids_per_file;
- int way_ids_per_blob;
- int way_ids_per_group;
- int relation_ids_per_file;
- int relation_ids_per_blob;
- int relation_ids_per_group;
+ int node_ids_per_file;
+ int node_ids_per_blob;
+ int node_ids_per_group;
+ int way_ids_per_file;
+ int way_ids_per_blob;
+ int way_ids_per_group;
+ int relation_ids_per_file;
+ int relation_ids_per_blob;
+ int relation_ids_per_group;
} db_config = {
- 200000, 30000, 500,
- 40000, 1000, 30,
- 10000, 500, 20,
+ 200000, 30000, 500,
+ 40000, 1000, 30,
+ 10000, 500, 20,
};
struct osm_protobufdb_context {
- int current_file, current_block, active_block;
- int in_node, in_way, in_relation;
- OSMPBF__Node n;
- OSMPBF__Way w;
- OSMPBF__Relation r;
- OSMPBF__Info i;
- FILE *f;
- OSMPBF__PrimitiveBlock *pb;
- OSMPBF__PrimitiveGroup *pg;
- GHashTable *string_hash;
- OSMPBF__DenseInfo *di;
- OSMPBF__DenseNodes *dn;
- OSMPBF__StringTable *st;
+ int current_file, current_block, active_block;
+ int in_node, in_way, in_relation;
+ OSMPBF__Node n;
+ OSMPBF__Way w;
+ OSMPBF__Relation r;
+ OSMPBF__Info i;
+ FILE *f;
+ OSMPBF__PrimitiveBlock *pb;
+ OSMPBF__PrimitiveGroup *pg;
+ GHashTable *string_hash;
+ OSMPBF__DenseInfo *di;
+ OSMPBF__DenseNodes *dn;
+ OSMPBF__StringTable *st;
} context;
static int
-osm_protobufdb_write_blob(OSMPBF__Blob *blob, FILE *out)
-{
- unsigned char lenb[4];
- int len,blen;
- unsigned char *buffer;
- OSMPBF__BlobHeader header=OSMPBF__BLOB_HEADER__INIT;
-
-
-
- blen=osmpbf__blob__get_packed_size(blob);
- header.type="OSMData";
- header.datasize=blen;
- len=osmpbf__blob_header__get_packed_size(&header);
- buffer=alloca(len);
- lenb[0]=len>>24;
- lenb[1]=len>>16;
- lenb[2]=len>>8;
- lenb[3]=len;
- osmpbf__blob_header__pack(&header, buffer);
- if (fwrite(lenb, sizeof(lenb), 1, out) != 1)
- return 0;
- if (fwrite(buffer, len, 1, out) != 1)
- return 0;
- buffer=alloca(blen);
- osmpbf__blob__pack(blob, buffer);
- if (fwrite(buffer, blen, 1, out) != 1)
- return 0;
- return 1;
+osm_protobufdb_write_blob(OSMPBF__Blob *blob, FILE *out) {
+ unsigned char lenb[4];
+ int len,blen;
+ unsigned char *buffer;
+ OSMPBF__BlobHeader header=OSMPBF__BLOB_HEADER__INIT;
+
+
+
+ blen=osmpbf__blob__get_packed_size(blob);
+ header.type="OSMData";
+ header.datasize=blen;
+ len=osmpbf__blob_header__get_packed_size(&header);
+ buffer=alloca(len);
+ lenb[0]=len>>24;
+ lenb[1]=len>>16;
+ lenb[2]=len>>8;
+ lenb[3]=len;
+ osmpbf__blob_header__pack(&header, buffer);
+ if (fwrite(lenb, sizeof(lenb), 1, out) != 1)
+ return 0;
+ if (fwrite(buffer, len, 1, out) != 1)
+ return 0;
+ buffer=alloca(blen);
+ osmpbf__blob__pack(blob, buffer);
+ if (fwrite(buffer, blen, 1, out) != 1)
+ return 0;
+ return 1;
}
#if 0
void
-dump_block(OSMPBF__PrimitiveBlock *pb)
-{
- int i,j;
- printf("%d groups\n",pb->n_primitivegroup);
- for (i = 0 ; i < pb->n_primitivegroup ; i++) {
- printf("%d relations\n",pb->primitivegroup[i]->n_relations);
- for (j = 0 ; j < pb->primitivegroup[i]->n_relations ; j++) {
- printf("Info %d\n",pb->primitivegroup[i]->relations[j]->info->version);
- }
- }
+dump_block(OSMPBF__PrimitiveBlock *pb) {
+ int i,j;
+ printf("%d groups\n",pb->n_primitivegroup);
+ for (i = 0 ; i < pb->n_primitivegroup ; i++) {
+ printf("%d relations\n",pb->primitivegroup[i]->n_relations);
+ for (j = 0 ; j < pb->primitivegroup[i]->n_relations ; j++) {
+ printf("Info %d\n",pb->primitivegroup[i]->relations[j]->info->version);
+ }
+ }
}
#endif
static int
-osm_protobufdb_finish_block(struct osm_protobufdb_context *ctx)
-{
- OSMPBF__Blob *blob,empty_blob=OSMPBF__BLOB__INIT;
- int len;
- if (!ctx->pb)
- return 0;
- len=osmpbf__primitive_block__get_packed_size(ctx->pb);
-
- while (ctx->current_block < ctx->active_block) {
- osm_protobufdb_write_blob(&empty_blob, ctx->f);
- ctx->current_block++;
- }
- blob=g_malloc(sizeof(*blob));
- *blob=empty_blob;
- blob->has_raw=1;
- blob->has_raw_size=1;
- blob->raw.data=g_malloc(len);
- osmpbf__primitive_block__pack(ctx->pb, blob->raw.data);
- blob->raw.len=len;
- blob->raw_size=len;
- osm_protobufdb_write_blob(blob, ctx->f);
- osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
- osmpbf__primitive_block__free_unpacked(ctx->pb, &protobuf_c_system_allocator);
- ctx->pb=NULL;
- ctx->current_block++;
- return 1;
+osm_protobufdb_finish_block(struct osm_protobufdb_context *ctx) {
+ OSMPBF__Blob *blob,empty_blob=OSMPBF__BLOB__INIT;
+ int len;
+ if (!ctx->pb)
+ return 0;
+ len=osmpbf__primitive_block__get_packed_size(ctx->pb);
+
+ while (ctx->current_block < ctx->active_block) {
+ osm_protobufdb_write_blob(&empty_blob, ctx->f);
+ ctx->current_block++;
+ }
+ blob=g_malloc(sizeof(*blob));
+ *blob=empty_blob;
+ blob->has_raw=1;
+ blob->has_raw_size=1;
+ blob->raw.data=g_malloc(len);
+ osmpbf__primitive_block__pack(ctx->pb, blob->raw.data);
+ blob->raw.len=len;
+ blob->raw_size=len;
+ osm_protobufdb_write_blob(blob, ctx->f);
+ osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
+ osmpbf__primitive_block__free_unpacked(ctx->pb, &protobuf_c_system_allocator);
+ ctx->pb=NULL;
+ ctx->current_block++;
+ return 1;
}
static int
-osm_protobufdb_start_block(struct osm_protobufdb_context *ctx, int blocknum)
-{
- OSMPBF__PrimitiveBlock pb=OSMPBF__PRIMITIVE_BLOCK__INIT;
- OSMPBF__StringTable st=OSMPBF__STRING_TABLE__INIT;
- if (ctx->active_block == blocknum)
- return 0;
- osm_protobufdb_finish_block(ctx);
- ctx->active_block=blocknum;
- ctx->pb=g_malloc(sizeof(*ctx->pb));
- *ctx->pb=pb;
- ctx->pb->stringtable=g_malloc(sizeof(*ctx->pb->stringtable));
- *ctx->pb->stringtable=st;
- ctx->st=ctx->pb->stringtable;
- return 1;
+osm_protobufdb_start_block(struct osm_protobufdb_context *ctx, int blocknum) {
+ OSMPBF__PrimitiveBlock pb=OSMPBF__PRIMITIVE_BLOCK__INIT;
+ OSMPBF__StringTable st=OSMPBF__STRING_TABLE__INIT;
+ if (ctx->active_block == blocknum)
+ return 0;
+ osm_protobufdb_finish_block(ctx);
+ ctx->active_block=blocknum;
+ ctx->pb=g_malloc(sizeof(*ctx->pb));
+ *ctx->pb=pb;
+ ctx->pb->stringtable=g_malloc(sizeof(*ctx->pb->stringtable));
+ *ctx->pb->stringtable=st;
+ ctx->st=ctx->pb->stringtable;
+ return 1;
}
static int
-osm_protobufdb_start_group(struct osm_protobufdb_context *ctx, int groupnum)
-{
- OSMPBF__PrimitiveGroup pg=OSMPBF__PRIMITIVE_GROUP__INIT;
- if (ctx->pb->n_primitivegroup <= groupnum) {
- ctx->pb->primitivegroup=g_realloc(ctx->pb->primitivegroup, (groupnum+1)*sizeof(ctx->pb->primitivegroup[0]));
- while (ctx->pb->n_primitivegroup <= groupnum) {
- ctx->pb->primitivegroup[ctx->pb->n_primitivegroup]=g_malloc(sizeof(*context.pg));
- *ctx->pb->primitivegroup[ctx->pb->n_primitivegroup++]=pg;
- }
- g_hash_table_destroy(ctx->string_hash);
- ctx->string_hash=g_hash_table_new(g_str_hash, g_str_equal);
- }
- ctx->pg=ctx->pb->primitivegroup[groupnum];
- if (!ctx->pg) {
- ctx->pg=g_malloc(sizeof(*context.pg));
- *ctx->pg=pg;
- ctx->pb->primitivegroup[groupnum]=ctx->pg;
- }
- return 1;
+osm_protobufdb_start_group(struct osm_protobufdb_context *ctx, int groupnum) {
+ OSMPBF__PrimitiveGroup pg=OSMPBF__PRIMITIVE_GROUP__INIT;
+ if (ctx->pb->n_primitivegroup <= groupnum) {
+ ctx->pb->primitivegroup=g_realloc(ctx->pb->primitivegroup, (groupnum+1)*sizeof(ctx->pb->primitivegroup[0]));
+ while (ctx->pb->n_primitivegroup <= groupnum) {
+ ctx->pb->primitivegroup[ctx->pb->n_primitivegroup]=g_malloc(sizeof(*context.pg));
+ *ctx->pb->primitivegroup[ctx->pb->n_primitivegroup++]=pg;
+ }
+ g_hash_table_destroy(ctx->string_hash);
+ ctx->string_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ }
+ ctx->pg=ctx->pb->primitivegroup[groupnum];
+ if (!ctx->pg) {
+ ctx->pg=g_malloc(sizeof(*context.pg));
+ *ctx->pg=pg;
+ ctx->pb->primitivegroup[groupnum]=ctx->pg;
+ }
+ return 1;
}
#if 0
static int
-osm_protobufdb_start_densenode(struct osm_protobufdb_context *ctx)
-{
- OSMPBF__DenseInfo di=OSMPBF__DENSE_INFO__INIT;
- OSMPBF__DenseNodes dn=OSMPBF__DENSE_NODES__INIT;
-
- if (!ctx->pg->dense) {
- ctx->dn=g_malloc(sizeof(*context.dn));
- *ctx->dn=dn;
- ctx->pg->dense=ctx->dn;
- } else
- ctx->dn=ctx->pg->dense;
- if (!ctx->dn->denseinfo) {
- ctx->di=g_malloc(sizeof(*context.di));
- *ctx->di=di;
- ctx->dn->denseinfo=ctx->di;
- } else
- ctx->di=ctx->dn->denseinfo;
- return 1;
+osm_protobufdb_start_densenode(struct osm_protobufdb_context *ctx) {
+ OSMPBF__DenseInfo di=OSMPBF__DENSE_INFO__INIT;
+ OSMPBF__DenseNodes dn=OSMPBF__DENSE_NODES__INIT;
+
+ if (!ctx->pg->dense) {
+ ctx->dn=g_malloc(sizeof(*context.dn));
+ *ctx->dn=dn;
+ ctx->pg->dense=ctx->dn;
+ } else
+ ctx->dn=ctx->pg->dense;
+ if (!ctx->dn->denseinfo) {
+ ctx->di=g_malloc(sizeof(*context.di));
+ *ctx->di=di;
+ ctx->dn->denseinfo=ctx->di;
+ } else
+ ctx->di=ctx->dn->denseinfo;
+ return 1;
}
static void
-osm_protobufdb_write_primitive_group(OSMPBF__PrimitiveGroup *pg, OSMPBF__PrimitiveBlock *pb)
-{
- pb->primitivegroup=g_realloc(pb->primitivegroup,(pb->n_primitivegroup+1)*sizeof(OSMPBF__PrimitiveGroup *));
- pb->primitivegroup[pb->n_primitivegroup++]=pg;
+osm_protobufdb_write_primitive_group(OSMPBF__PrimitiveGroup *pg, OSMPBF__PrimitiveBlock *pb) {
+ pb->primitivegroup=g_realloc(pb->primitivegroup,(pb->n_primitivegroup+1)*sizeof(OSMPBF__PrimitiveGroup *));
+ pb->primitivegroup[pb->n_primitivegroup++]=pg;
}
#endif
@@ -219,556 +212,532 @@ osm_protobufdb_write_primitive_group(OSMPBF__PrimitiveGroup *pg, OSMPBF__Primiti
#if 0
static int
-osm_protobufdb_insert_densenode(long long id, OSMPBF__Node *offset, OSMPBF__Info *offseti, OSMPBF__DenseNodes *dn)
-{
- int i,l,p;
- memset(offset, 0, sizeof(*offset));
- offseti->timestamp=0;
- offseti->changeset=0;
- offseti->user_sid=0;
- offseti->uid=0;
- l=dn->n_id;
- for (i = 0 ; i < l ; i++) {
- offset->id+=dn->id[i];
- offset->lat+=dn->lat[i];
- offset->lon+=dn->lon[i];
- offseti->timestamp+=dn->denseinfo->timestamp[i];
- offseti->changeset+=dn->denseinfo->changeset[i];
- offseti->user_sid+=dn->denseinfo->user_sid[i];
- offseti->uid+=dn->denseinfo->uid[i];
- }
- p=l;
- insert(dn, id, p);
- insert(dn, lat, p);
- insert(dn, lon, p);
- insert(dn->denseinfo, version, p);
- insert(dn->denseinfo, timestamp, p);
- insert(dn->denseinfo, changeset, p);
- insert(dn->denseinfo, user_sid, p);
- insert(dn->denseinfo, uid, p);
- return p;
+osm_protobufdb_insert_densenode(long long id, OSMPBF__Node *offset, OSMPBF__Info *offseti, OSMPBF__DenseNodes *dn) {
+ int i,l,p;
+ memset(offset, 0, sizeof(*offset));
+ offseti->timestamp=0;
+ offseti->changeset=0;
+ offseti->user_sid=0;
+ offseti->uid=0;
+ l=dn->n_id;
+ for (i = 0 ; i < l ; i++) {
+ offset->id+=dn->id[i];
+ offset->lat+=dn->lat[i];
+ offset->lon+=dn->lon[i];
+ offseti->timestamp+=dn->denseinfo->timestamp[i];
+ offseti->changeset+=dn->denseinfo->changeset[i];
+ offseti->user_sid+=dn->denseinfo->user_sid[i];
+ offseti->uid+=dn->denseinfo->uid[i];
+ }
+ p=l;
+ insert(dn, id, p);
+ insert(dn, lat, p);
+ insert(dn, lon, p);
+ insert(dn->denseinfo, version, p);
+ insert(dn->denseinfo, timestamp, p);
+ insert(dn->denseinfo, changeset, p);
+ insert(dn->denseinfo, user_sid, p);
+ insert(dn->denseinfo, uid, p);
+ return p;
}
static void
-osm_protobufdb_modify_densenode(OSMPBF__Node *node, OSMPBF__Info *info, OSMPBF__Node *offset, OSMPBF__Info *offseti, int pos, OSMPBF__DenseNodes *dn)
-{
- int i;
- if (pos+1 < dn->n_id) {
- dn->id[pos+1]+=dn->id[pos]-node->id;
- dn->lat[pos+1]+=dn->lat[pos]-node->lat;
- dn->lon[pos+1]+=dn->lon[pos]-node->lon;
- dn->denseinfo->timestamp[pos+1]+=dn->denseinfo->timestamp[pos]-info->timestamp;
- dn->denseinfo->changeset[pos+1]+=dn->denseinfo->changeset[pos]-info->changeset;
- dn->denseinfo->user_sid[pos+1]+=dn->denseinfo->user_sid[pos]-info->user_sid;
- dn->denseinfo->uid[pos+1]+=dn->denseinfo->uid[pos]-info->uid;
- }
- dn->id[pos]=node->id-offset->id;
- dn->lat[pos]=node->lat-offset->lat;
- dn->lon[pos]=node->lon-offset->lon;
- dn->keys_vals=g_realloc(dn->keys_vals, (dn->n_keys_vals+node->n_keys+node->n_vals+1)*sizeof(dn->keys_vals[0]));
- for (i = 0 ; i < node->n_keys ; i++) {
- dn->keys_vals[dn->n_keys_vals++]=node->keys[i];
- dn->keys_vals[dn->n_keys_vals++]=node->vals[i];
- }
- dn->keys_vals[dn->n_keys_vals++]=0;
- dn->denseinfo->version[pos]=info->version;
- dn->denseinfo->timestamp[pos]=info->timestamp-offseti->timestamp;
- dn->denseinfo->changeset[pos]=info->changeset-offseti->changeset;
- dn->denseinfo->user_sid[pos]=info->user_sid-offseti->user_sid;
- dn->denseinfo->uid[pos]=info->uid-offseti->uid;
+osm_protobufdb_modify_densenode(OSMPBF__Node *node, OSMPBF__Info *info, OSMPBF__Node *offset, OSMPBF__Info *offseti,
+ int pos, OSMPBF__DenseNodes *dn) {
+ int i;
+ if (pos+1 < dn->n_id) {
+ dn->id[pos+1]+=dn->id[pos]-node->id;
+ dn->lat[pos+1]+=dn->lat[pos]-node->lat;
+ dn->lon[pos+1]+=dn->lon[pos]-node->lon;
+ dn->denseinfo->timestamp[pos+1]+=dn->denseinfo->timestamp[pos]-info->timestamp;
+ dn->denseinfo->changeset[pos+1]+=dn->denseinfo->changeset[pos]-info->changeset;
+ dn->denseinfo->user_sid[pos+1]+=dn->denseinfo->user_sid[pos]-info->user_sid;
+ dn->denseinfo->uid[pos+1]+=dn->denseinfo->uid[pos]-info->uid;
+ }
+ dn->id[pos]=node->id-offset->id;
+ dn->lat[pos]=node->lat-offset->lat;
+ dn->lon[pos]=node->lon-offset->lon;
+ dn->keys_vals=g_realloc(dn->keys_vals, (dn->n_keys_vals+node->n_keys+node->n_vals+1)*sizeof(dn->keys_vals[0]));
+ for (i = 0 ; i < node->n_keys ; i++) {
+ dn->keys_vals[dn->n_keys_vals++]=node->keys[i];
+ dn->keys_vals[dn->n_keys_vals++]=node->vals[i];
+ }
+ dn->keys_vals[dn->n_keys_vals++]=0;
+ dn->denseinfo->version[pos]=info->version;
+ dn->denseinfo->timestamp[pos]=info->timestamp-offseti->timestamp;
+ dn->denseinfo->changeset[pos]=info->changeset-offseti->changeset;
+ dn->denseinfo->user_sid[pos]=info->user_sid-offseti->user_sid;
+ dn->denseinfo->uid[pos]=info->uid-offseti->uid;
}
#endif
static int
-osm_protobufdb_insert_node(long long id, OSMPBF__PrimitiveGroup *pg)
-{
- int l,p;
- OSMPBF__Node node=OSMPBF__NODE__INIT;
- l=pg->n_nodes;
- p=l;
- insert(pg, nodes, p);
- pg->nodes[p]=g_malloc(sizeof(*pg->nodes[0]));
- *pg->nodes[p]=node;
- return p;
+osm_protobufdb_insert_node(long long id, OSMPBF__PrimitiveGroup *pg) {
+ int l,p;
+ OSMPBF__Node node=OSMPBF__NODE__INIT;
+ l=pg->n_nodes;
+ p=l;
+ insert(pg, nodes, p);
+ pg->nodes[p]=g_malloc(sizeof(*pg->nodes[0]));
+ *pg->nodes[p]=node;
+ return p;
}
static void
-osm_protobufdb_modify_node(OSMPBF__Node *node, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg)
-{
- OSMPBF__Node *n=pg->nodes[pos];
- OSMPBF__Info *old_info;
-
- g_free(n->keys);
- g_free(n->vals);
- old_info=n->info;
- *n=*node;
- if (!info) {
- if (old_info)
- osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
- n->info=NULL;
- } else {
- if (old_info)
- n->info=old_info;
- else
- n->info=g_malloc(sizeof(*info));
- *n->info=*info;
- }
-
+osm_protobufdb_modify_node(OSMPBF__Node *node, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg) {
+ OSMPBF__Node *n=pg->nodes[pos];
+ OSMPBF__Info *old_info;
+
+ g_free(n->keys);
+ g_free(n->vals);
+ old_info=n->info;
+ *n=*node;
+ if (!info) {
+ if (old_info)
+ osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
+ n->info=NULL;
+ } else {
+ if (old_info)
+ n->info=old_info;
+ else
+ n->info=g_malloc(sizeof(*info));
+ *n->info=*info;
+ }
+
}
static int
-osm_protobufdb_insert_way(long long id, OSMPBF__PrimitiveGroup *pg)
-{
- int l,p;
- OSMPBF__Way way=OSMPBF__WAY__INIT;
- l=pg->n_ways;
- p=l;
- insert(pg, ways, p);
- pg->ways[p]=g_malloc(sizeof(*pg->ways[0]));
- *pg->ways[p]=way;
- return p;
+osm_protobufdb_insert_way(long long id, OSMPBF__PrimitiveGroup *pg) {
+ int l,p;
+ OSMPBF__Way way=OSMPBF__WAY__INIT;
+ l=pg->n_ways;
+ p=l;
+ insert(pg, ways, p);
+ pg->ways[p]=g_malloc(sizeof(*pg->ways[0]));
+ *pg->ways[p]=way;
+ return p;
}
static void
-osm_protobufdb_modify_way(OSMPBF__Way *way, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg)
-{
- OSMPBF__Way *w=pg->ways[pos];
- OSMPBF__Info *old_info;
- int i;
- long long ref=0;
-
- g_free(w->keys);
- g_free(w->vals);
- g_free(w->refs);
- old_info=w->info;
- *w=*way;
- for (i = 0 ; i < w->n_refs ; i++) {
- w->refs[i]-=ref;
- ref+=w->refs[i];
- }
- if (!info) {
- if (old_info)
- osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
- w->info=NULL;
- } else {
- if (old_info)
- w->info=old_info;
- else
- w->info=g_malloc(sizeof(*info));
- *w->info=*info;
- }
-
+osm_protobufdb_modify_way(OSMPBF__Way *way, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg) {
+ OSMPBF__Way *w=pg->ways[pos];
+ OSMPBF__Info *old_info;
+ int i;
+ long long ref=0;
+
+ g_free(w->keys);
+ g_free(w->vals);
+ g_free(w->refs);
+ old_info=w->info;
+ *w=*way;
+ for (i = 0 ; i < w->n_refs ; i++) {
+ w->refs[i]-=ref;
+ ref+=w->refs[i];
+ }
+ if (!info) {
+ if (old_info)
+ osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
+ w->info=NULL;
+ } else {
+ if (old_info)
+ w->info=old_info;
+ else
+ w->info=g_malloc(sizeof(*info));
+ *w->info=*info;
+ }
+
}
static int
-osm_protobufdb_insert_relation(long long id, OSMPBF__PrimitiveGroup *pg)
-{
- int l,p;
- OSMPBF__Relation relation=OSMPBF__RELATION__INIT;
- l=pg->n_relations;
- p=l;
- insert(pg, relations, p);
- pg->relations[p]=g_malloc(sizeof(*pg->relations[0]));
- *pg->relations[p]=relation;
- return p;
+osm_protobufdb_insert_relation(long long id, OSMPBF__PrimitiveGroup *pg) {
+ int l,p;
+ OSMPBF__Relation relation=OSMPBF__RELATION__INIT;
+ l=pg->n_relations;
+ p=l;
+ insert(pg, relations, p);
+ pg->relations[p]=g_malloc(sizeof(*pg->relations[0]));
+ *pg->relations[p]=relation;
+ return p;
}
static void
-osm_protobufdb_modify_relation(OSMPBF__Relation *relation, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg)
-{
- OSMPBF__Relation *r=pg->relations[pos];
- OSMPBF__Info *old_info;
- int i;
- long long ref=0;
-
- g_free(r->keys);
- g_free(r->vals);
- g_free(r->roles_sid);
- g_free(r->memids);
- g_free(r->types);
- old_info=r->info;
- *r=*relation;
- for (i = 0 ; i < r->n_memids ; i++) {
- r->memids[i]-=ref;
- ref+=r->memids[i];
- }
- if (!info) {
- if (old_info)
- osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
- r->info=NULL;
- } else {
- if (old_info)
- r->info=old_info;
- else
- r->info=g_malloc(sizeof(*info));
- *r->info=*info;
- }
-
+osm_protobufdb_modify_relation(OSMPBF__Relation *relation, OSMPBF__Info *info, int pos, OSMPBF__PrimitiveGroup *pg) {
+ OSMPBF__Relation *r=pg->relations[pos];
+ OSMPBF__Info *old_info;
+ int i;
+ long long ref=0;
+
+ g_free(r->keys);
+ g_free(r->vals);
+ g_free(r->roles_sid);
+ g_free(r->memids);
+ g_free(r->types);
+ old_info=r->info;
+ *r=*relation;
+ for (i = 0 ; i < r->n_memids ; i++) {
+ r->memids[i]-=ref;
+ ref+=r->memids[i];
+ }
+ if (!info) {
+ if (old_info)
+ osmpbf__info__free_unpacked(old_info, &protobuf_c_system_allocator);
+ r->info=NULL;
+ } else {
+ if (old_info)
+ r->info=old_info;
+ else
+ r->info=g_malloc(sizeof(*info));
+ *r->info=*info;
+ }
+
}
static int
-osm_protobufdb_string(struct osm_protobufdb_context *ctx, char *str)
-{
- char *strd;
- OSMPBF__StringTable *st=ctx->st;
-
- gpointer value;
- assert(ctx->string_hash != NULL);
- if (g_hash_table_lookup_extended(ctx->string_hash, str, NULL, &value)) {
- return (long)value;
- }
- if (!st->n_s) {
- st->n_s++;
- }
- strd=g_strdup(str);
- st->s=g_realloc(st->s, sizeof(st->s[0])*(st->n_s+1));
- if (st->n_s == 1) {
- st->s[0].data=NULL;
- st->s[0].len=0;
- }
- st->s[st->n_s].data=(unsigned char *)strd;
- st->s[st->n_s].len=strlen(strd);
- g_hash_table_insert(ctx->string_hash, strd, (gpointer)st->n_s);
- return st->n_s++;
+osm_protobufdb_string(struct osm_protobufdb_context *ctx, char *str) {
+ char *strd;
+ OSMPBF__StringTable *st=ctx->st;
+
+ gpointer value;
+ assert(ctx->string_hash != NULL);
+ if (g_hash_table_lookup_extended(ctx->string_hash, str, NULL, &value)) {
+ return (long)value;
+ }
+ if (!st->n_s) {
+ st->n_s++;
+ }
+ strd=g_strdup(str);
+ st->s=g_realloc(st->s, sizeof(st->s[0])*(st->n_s+1));
+ if (st->n_s == 1) {
+ st->s[0].data=NULL;
+ st->s[0].len=0;
+ }
+ st->s[st->n_s].data=(unsigned char *)strd;
+ st->s[st->n_s].len=strlen(strd);
+ g_hash_table_insert(ctx->string_hash, strd, (gpointer)st->n_s);
+ return st->n_s++;
}
static int
-osm_protobufdb_finish_file(struct osm_protobufdb_context *ctx)
-{
- osm_protobufdb_finish_block(ctx);
- if (ctx->f) {
- fclose(ctx->f);
- ctx->f=NULL;
- }
- ctx->current_file=-1;
- return 1;
+osm_protobufdb_finish_file(struct osm_protobufdb_context *ctx) {
+ osm_protobufdb_finish_block(ctx);
+ if (ctx->f) {
+ fclose(ctx->f);
+ ctx->f=NULL;
+ }
+ ctx->current_file=-1;
+ return 1;
}
static int
-osm_protobufdb_start_file(struct osm_protobufdb_context *ctx, int type, int num)
-{
- char name[1024];
- if (ctx->current_file == num)
- return 0;
- osm_protobufdb_finish_file(ctx);
- sprintf(name,"tst/%d-%08d",type,num);
- ctx->f=fopen(name,"w");
- ctx->current_file=num;
- ctx->current_block=0;
- ctx->active_block=-1;
- return 1;
+osm_protobufdb_start_file(struct osm_protobufdb_context *ctx, int type, int num) {
+ char name[1024];
+ if (ctx->current_file == num)
+ return 0;
+ osm_protobufdb_finish_file(ctx);
+ sprintf(name,"tst/%d-%08d",type,num);
+ ctx->f=fopen(name,"w");
+ ctx->current_file=num;
+ ctx->current_block=0;
+ ctx->active_block=-1;
+ return 1;
}
static void
-test(void)
-{
- context.current_file=-1;
+test(void) {
+ context.current_file=-1;
}
static void
-finish(void)
-{
- osm_protobufdb_finish_file(&context);
+finish(void) {
+ osm_protobufdb_finish_file(&context);
}
static long long
-osm_protobufdb_timestamp(char *str)
-{
- struct tm tm;
- int res=sscanf(str,"%d-%d-%dT%d:%d:%dZ",&tm.tm_year,&tm.tm_mon,&tm.tm_mday,&tm.tm_hour,&tm.tm_min,&tm.tm_sec);
- if (res != 6)
- return 0;
- tm.tm_year-=1900;
- tm.tm_mon-=1;
+osm_protobufdb_timestamp(char *str) {
+ struct tm tm;
+ int res=sscanf(str,"%d-%d-%dT%d:%d:%dZ",&tm.tm_year,&tm.tm_mon,&tm.tm_mday,&tm.tm_hour,&tm.tm_min,&tm.tm_sec);
+ if (res != 6)
+ return 0;
+ tm.tm_year-=1900;
+ tm.tm_mon-=1;
#if defined(HAVE_API_WIN32_BASE) || defined(ANDROID)
- return 0;
+ return 0;
#else
- return timegm(&tm);
+ return timegm(&tm);
#endif
}
static void
-osm_protobufdb_parse_info(struct osm_protobufdb_context *ctx, char *str)
-{
- char version[1024];
- char changeset[1024];
- char user[1024];
- char uid[1024];
- char timestamp[1024];
-
- OSMPBF__Info *i=&ctx->i, ii=OSMPBF__INFO__INIT;
- *i=ii;
- if (osm_xml_get_attribute(str, "version", version, sizeof(version))) {
- i->version=atoi(version);
- i->has_version=1;
- }
- if (osm_xml_get_attribute(str, "changeset", changeset, sizeof(changeset))) {
- i->changeset=atoll(changeset);
- i->has_changeset=1;
- }
- if (osm_xml_get_attribute(str, "user", user, sizeof(user))) {
- osm_xml_decode_entities(user);
- i->user_sid=osm_protobufdb_string(ctx, user);
- i->has_user_sid=1;
- }
- if (osm_xml_get_attribute(str, "uid", uid, sizeof(uid))) {
- i->uid=atoi(uid);
- i->has_uid=1;
- }
- if (osm_xml_get_attribute(str, "timestamp", timestamp, sizeof(timestamp))) {
- i->timestamp=osm_protobufdb_timestamp(timestamp);
- i->has_timestamp=1;
- }
+osm_protobufdb_parse_info(struct osm_protobufdb_context *ctx, char *str) {
+ char version[1024];
+ char changeset[1024];
+ char user[1024];
+ char uid[1024];
+ char timestamp[1024];
+
+ OSMPBF__Info *i=&ctx->i, ii=OSMPBF__INFO__INIT;
+ *i=ii;
+ if (osm_xml_get_attribute(str, "version", version, sizeof(version))) {
+ i->version=atoi(version);
+ i->has_version=1;
+ }
+ if (osm_xml_get_attribute(str, "changeset", changeset, sizeof(changeset))) {
+ i->changeset=atoll(changeset);
+ i->has_changeset=1;
+ }
+ if (osm_xml_get_attribute(str, "user", user, sizeof(user))) {
+ osm_xml_decode_entities(user);
+ i->user_sid=osm_protobufdb_string(ctx, user);
+ i->has_user_sid=1;
+ }
+ if (osm_xml_get_attribute(str, "uid", uid, sizeof(uid))) {
+ i->uid=atoi(uid);
+ i->has_uid=1;
+ }
+ if (osm_xml_get_attribute(str, "timestamp", timestamp, sizeof(timestamp))) {
+ i->timestamp=osm_protobufdb_timestamp(timestamp);
+ i->has_timestamp=1;
+ }
}
static int
-osm_protobufdb_parse_node(struct osm_protobufdb_context *ctx, char *str)
-{
- char id[1024];
- char lat[1024];
- char lon[1024];
- OSMPBF__Node *n=&ctx->n, ni=OSMPBF__NODE__INIT;
-
- *n=ni;
- if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
- return 0;
- if (!osm_xml_get_attribute(str, "lat", lat, sizeof(lat)))
- return 0;
- if (!osm_xml_get_attribute(str, "lon", lon, sizeof(lon)))
- return 0;
- n->id=atoll(id);
- n->lat=atof(lat)*latlon_scale+0.5;
- n->lon=atof(lon)*latlon_scale+0.5;
- int file=n->id/db_config.node_ids_per_file;
- int fileo=n->id%db_config.node_ids_per_file;
- int blob=fileo/db_config.node_ids_per_blob;
- int blobo=fileo%db_config.node_ids_per_blob;
- int group=blobo/db_config.node_ids_per_group;
-
- osm_protobufdb_start_file(ctx, 1, file);
- osm_protobufdb_start_block(ctx, blob);
- osm_protobufdb_start_group(ctx, group);
- osm_protobufdb_parse_info(ctx, str);
- ctx->in_node=1;
- return 1;
+osm_protobufdb_parse_node(struct osm_protobufdb_context *ctx, char *str) {
+ char id[1024];
+ char lat[1024];
+ char lon[1024];
+ OSMPBF__Node *n=&ctx->n, ni=OSMPBF__NODE__INIT;
+
+ *n=ni;
+ if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
+ return 0;
+ if (!osm_xml_get_attribute(str, "lat", lat, sizeof(lat)))
+ return 0;
+ if (!osm_xml_get_attribute(str, "lon", lon, sizeof(lon)))
+ return 0;
+ n->id=atoll(id);
+ n->lat=atof(lat)*latlon_scale+0.5;
+ n->lon=atof(lon)*latlon_scale+0.5;
+ int file=n->id/db_config.node_ids_per_file;
+ int fileo=n->id%db_config.node_ids_per_file;
+ int blob=fileo/db_config.node_ids_per_blob;
+ int blobo=fileo%db_config.node_ids_per_blob;
+ int group=blobo/db_config.node_ids_per_group;
+
+ osm_protobufdb_start_file(ctx, 1, file);
+ osm_protobufdb_start_block(ctx, blob);
+ osm_protobufdb_start_group(ctx, group);
+ osm_protobufdb_parse_info(ctx, str);
+ ctx->in_node=1;
+ return 1;
}
static int
-osm_protobufdb_end_node(struct osm_protobufdb_context *ctx)
-{
- int p;
- p=osm_protobufdb_insert_node(ctx->n.id, ctx->pg);
- osm_protobufdb_modify_node(&ctx->n, &ctx->i, p, ctx->pg);
- ctx->in_node=0;
- return 1;
+osm_protobufdb_end_node(struct osm_protobufdb_context *ctx) {
+ int p;
+ p=osm_protobufdb_insert_node(ctx->n.id, ctx->pg);
+ osm_protobufdb_modify_node(&ctx->n, &ctx->i, p, ctx->pg);
+ ctx->in_node=0;
+ return 1;
}
static int
-osm_protobufdb_parse_way(struct osm_protobufdb_context *ctx, char *str)
-{
- char id[1024];
- OSMPBF__Way *w=&ctx->w, wi=OSMPBF__WAY__INIT;
-
- *w=wi;
- if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
- return 0;
- w->id=atoll(id);
- int file=w->id/db_config.way_ids_per_file;
- int fileo=w->id%db_config.way_ids_per_file;
- int blob=fileo/db_config.way_ids_per_blob;
- int blobo=fileo%db_config.way_ids_per_blob;
- int group=blobo/db_config.way_ids_per_group;
-
- osm_protobufdb_start_file(ctx, 2, file);
- osm_protobufdb_start_block(ctx, blob);
- osm_protobufdb_start_group(ctx, group);
- osm_protobufdb_parse_info(ctx, str);
- ctx->in_way=1;
- return 1;
+osm_protobufdb_parse_way(struct osm_protobufdb_context *ctx, char *str) {
+ char id[1024];
+ OSMPBF__Way *w=&ctx->w, wi=OSMPBF__WAY__INIT;
+
+ *w=wi;
+ if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
+ return 0;
+ w->id=atoll(id);
+ int file=w->id/db_config.way_ids_per_file;
+ int fileo=w->id%db_config.way_ids_per_file;
+ int blob=fileo/db_config.way_ids_per_blob;
+ int blobo=fileo%db_config.way_ids_per_blob;
+ int group=blobo/db_config.way_ids_per_group;
+
+ osm_protobufdb_start_file(ctx, 2, file);
+ osm_protobufdb_start_block(ctx, blob);
+ osm_protobufdb_start_group(ctx, group);
+ osm_protobufdb_parse_info(ctx, str);
+ ctx->in_way=1;
+ return 1;
}
static int
-osm_protobufdb_end_way(struct osm_protobufdb_context *ctx)
-{
- int p;
- p=osm_protobufdb_insert_way(ctx->w.id, ctx->pg);
- osm_protobufdb_modify_way(&ctx->w, &ctx->i, p, ctx->pg);
- ctx->in_way=0;
- return 1;
+osm_protobufdb_end_way(struct osm_protobufdb_context *ctx) {
+ int p;
+ p=osm_protobufdb_insert_way(ctx->w.id, ctx->pg);
+ osm_protobufdb_modify_way(&ctx->w, &ctx->i, p, ctx->pg);
+ ctx->in_way=0;
+ return 1;
}
static int
-osm_protobufdb_parse_relation(struct osm_protobufdb_context *ctx, char *str)
-{
- char id[1024];
- OSMPBF__Relation *r=&ctx->r, ri=OSMPBF__RELATION__INIT;
-
- *r=ri;
- if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
- return 0;
- r->id=atoll(id);
- int file=r->id/db_config.relation_ids_per_file;
- int fileo=r->id%db_config.relation_ids_per_file;
- int blob=fileo/db_config.relation_ids_per_blob;
- int blobo=fileo%db_config.relation_ids_per_blob;
- int group=blobo/db_config.relation_ids_per_group;
-
- osm_protobufdb_start_file(ctx, 3, file);
- osm_protobufdb_start_block(ctx, blob);
- osm_protobufdb_start_group(ctx, group);
- osm_protobufdb_parse_info(ctx, str);
- ctx->in_relation=1;
- return 1;
+osm_protobufdb_parse_relation(struct osm_protobufdb_context *ctx, char *str) {
+ char id[1024];
+ OSMPBF__Relation *r=&ctx->r, ri=OSMPBF__RELATION__INIT;
+
+ *r=ri;
+ if (!osm_xml_get_attribute(str, "id", id, sizeof(id)))
+ return 0;
+ r->id=atoll(id);
+ int file=r->id/db_config.relation_ids_per_file;
+ int fileo=r->id%db_config.relation_ids_per_file;
+ int blob=fileo/db_config.relation_ids_per_blob;
+ int blobo=fileo%db_config.relation_ids_per_blob;
+ int group=blobo/db_config.relation_ids_per_group;
+
+ osm_protobufdb_start_file(ctx, 3, file);
+ osm_protobufdb_start_block(ctx, blob);
+ osm_protobufdb_start_group(ctx, group);
+ osm_protobufdb_parse_info(ctx, str);
+ ctx->in_relation=1;
+ return 1;
}
static int
-osm_protobufdb_end_relation(struct osm_protobufdb_context *ctx)
-{
- int p;
- p=osm_protobufdb_insert_relation(ctx->r.id, ctx->pg);
- osm_protobufdb_modify_relation(&ctx->r, &ctx->i, p, ctx->pg);
- ctx->in_node=0;
- return 1;
+osm_protobufdb_end_relation(struct osm_protobufdb_context *ctx) {
+ int p;
+ p=osm_protobufdb_insert_relation(ctx->r.id, ctx->pg);
+ osm_protobufdb_modify_relation(&ctx->r, &ctx->i, p, ctx->pg);
+ ctx->in_node=0;
+ return 1;
}
static int
-osm_protobufdb_parse_tag(struct osm_protobufdb_context *ctx, char *str)
-{
- OSMPBF__Node *n=&ctx->n;
- OSMPBF__Way *w=&ctx->w;
- OSMPBF__Relation *r=&ctx->r;
- char k_buffer[BUFFER_SIZE];
- char v_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(str, "k", k_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(str, "v", v_buffer, BUFFER_SIZE))
- return 0;
- osm_xml_decode_entities(v_buffer);
- if (ctx->in_node) {
- n->keys=g_realloc(n->keys, (n->n_keys+1)*sizeof(n->keys[0]));
- n->vals=g_realloc(n->vals, (n->n_vals+1)*sizeof(n->vals[0]));
- n->keys[n->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
- n->vals[n->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
- }
- if (ctx->in_way) {
- w->keys=g_realloc(w->keys, (w->n_keys+1)*sizeof(w->keys[0]));
- w->vals=g_realloc(w->vals, (w->n_vals+1)*sizeof(w->vals[0]));
- w->keys[w->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
- w->vals[w->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
- }
- if (ctx->in_relation) {
- r->keys=g_realloc(r->keys, (r->n_keys+1)*sizeof(r->keys[0]));
- r->vals=g_realloc(r->vals, (r->n_vals+1)*sizeof(r->vals[0]));
- r->keys[r->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
- r->vals[r->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
- }
- return 1;
+osm_protobufdb_parse_tag(struct osm_protobufdb_context *ctx, char *str) {
+ OSMPBF__Node *n=&ctx->n;
+ OSMPBF__Way *w=&ctx->w;
+ OSMPBF__Relation *r=&ctx->r;
+ char k_buffer[BUFFER_SIZE];
+ char v_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(str, "k", k_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(str, "v", v_buffer, BUFFER_SIZE))
+ return 0;
+ osm_xml_decode_entities(v_buffer);
+ if (ctx->in_node) {
+ n->keys=g_realloc(n->keys, (n->n_keys+1)*sizeof(n->keys[0]));
+ n->vals=g_realloc(n->vals, (n->n_vals+1)*sizeof(n->vals[0]));
+ n->keys[n->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
+ n->vals[n->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
+ }
+ if (ctx->in_way) {
+ w->keys=g_realloc(w->keys, (w->n_keys+1)*sizeof(w->keys[0]));
+ w->vals=g_realloc(w->vals, (w->n_vals+1)*sizeof(w->vals[0]));
+ w->keys[w->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
+ w->vals[w->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
+ }
+ if (ctx->in_relation) {
+ r->keys=g_realloc(r->keys, (r->n_keys+1)*sizeof(r->keys[0]));
+ r->vals=g_realloc(r->vals, (r->n_vals+1)*sizeof(r->vals[0]));
+ r->keys[r->n_keys++]=osm_protobufdb_string(ctx, k_buffer);
+ r->vals[r->n_vals++]=osm_protobufdb_string(ctx, v_buffer);
+ }
+ return 1;
}
static int
-osm_protobufdb_parse_nd(struct osm_protobufdb_context *ctx, char *str)
-{
- OSMPBF__Way *w=&ctx->w;
- char ref_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(str, "ref", ref_buffer, BUFFER_SIZE))
- return 0;
- if (ctx->in_way) {
- w->refs=g_realloc(w->refs, (w->n_refs+1)*sizeof(w->refs[0]));
- w->refs[w->n_refs++]=atoll(ref_buffer);
- }
- return 1;
+osm_protobufdb_parse_nd(struct osm_protobufdb_context *ctx, char *str) {
+ OSMPBF__Way *w=&ctx->w;
+ char ref_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(str, "ref", ref_buffer, BUFFER_SIZE))
+ return 0;
+ if (ctx->in_way) {
+ w->refs=g_realloc(w->refs, (w->n_refs+1)*sizeof(w->refs[0]));
+ w->refs[w->n_refs++]=atoll(ref_buffer);
+ }
+ return 1;
}
static int
-osm_protobufdb_parse_member(struct osm_protobufdb_context *ctx, char *str)
-{
- OSMPBF__Relation *r=&ctx->r;
- char type_buffer[BUFFER_SIZE];
- char ref_buffer[BUFFER_SIZE];
- char role_buffer[BUFFER_SIZE];
- int type=0;
- if (!osm_xml_get_attribute(str, "type", type_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(str, "ref", ref_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(str, "role", role_buffer, BUFFER_SIZE))
- return 0;
- if (!strcmp(type_buffer,"node"))
- type=0;
- else if (!strcmp(type_buffer,"way"))
- type=1;
- else if (!strcmp(type_buffer,"relation"))
- type=2;
- if (ctx->in_relation) {
- r->roles_sid=g_realloc(r->roles_sid, (r->n_roles_sid+1)*sizeof(r->roles_sid[0]));
- r->roles_sid[r->n_roles_sid++]=osm_protobufdb_string(ctx, role_buffer);
- r->memids=g_realloc(r->memids, (r->n_memids+1)*sizeof(r->memids[0]));
- r->memids[r->n_memids++]=atoll(ref_buffer);
- r->types=g_realloc(r->types, (r->n_types+1)*sizeof(r->types[0]));
- r->types[r->n_types++]=type;
- }
- return 1;
+osm_protobufdb_parse_member(struct osm_protobufdb_context *ctx, char *str) {
+ OSMPBF__Relation *r=&ctx->r;
+ char type_buffer[BUFFER_SIZE];
+ char ref_buffer[BUFFER_SIZE];
+ char role_buffer[BUFFER_SIZE];
+ int type=0;
+ if (!osm_xml_get_attribute(str, "type", type_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(str, "ref", ref_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(str, "role", role_buffer, BUFFER_SIZE))
+ return 0;
+ if (!strcmp(type_buffer,"node"))
+ type=0;
+ else if (!strcmp(type_buffer,"way"))
+ type=1;
+ else if (!strcmp(type_buffer,"relation"))
+ type=2;
+ if (ctx->in_relation) {
+ r->roles_sid=g_realloc(r->roles_sid, (r->n_roles_sid+1)*sizeof(r->roles_sid[0]));
+ r->roles_sid[r->n_roles_sid++]=osm_protobufdb_string(ctx, role_buffer);
+ r->memids=g_realloc(r->memids, (r->n_memids+1)*sizeof(r->memids[0]));
+ r->memids[r->n_memids++]=atoll(ref_buffer);
+ r->types=g_realloc(r->types, (r->n_types+1)*sizeof(r->types[0]));
+ r->types[r->n_types++]=type;
+ }
+ return 1;
}
int
-osm_protobufdb_load(FILE *in, char *dir)
-{
- int size=BUFFER_SIZE;
- char buffer[size];
- char *p;
- sig_alrm(0);
- test();
- while (fgets(buffer, size, in)) {
- int closed=strstr(buffer,"/>")?1:0;
- p=strchr(buffer,'<');
- if (! p) {
- fprintf(stderr,"WARNING: wrong line %s\n", buffer);
- continue;
- }
- if (!strncmp(p, "<?xml ",6)) {
- } else if (!strncmp(p, "<osm ",5)) {
- } else if (!strncmp(p, "<bound ",7)) {
- } else if (!strncmp(p, "<node ",6)) {
- if (!osm_protobufdb_parse_node(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- if (closed)
- osm_protobufdb_end_node(&context);
- processed_nodes++;
- } else if (!strncmp(p, "<tag ",5)) {
- if (!osm_protobufdb_parse_tag(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "<way ",5)) {
- if (!osm_protobufdb_parse_way(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- if (closed)
- osm_protobufdb_end_way(&context);
- processed_ways++;
- } else if (!strncmp(p, "<nd ",4)) {
- if (!osm_protobufdb_parse_nd(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "<relation ",10)) {
- if (!osm_protobufdb_parse_relation(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- processed_relations++;
- } else if (!strncmp(p, "<member ",8)) {
- if (!osm_protobufdb_parse_member(&context, p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "</node>",7)) {
- osm_protobufdb_end_node(&context);
- } else if (!strncmp(p, "</way>",6)) {
- osm_protobufdb_end_way(&context);
- } else if (!strncmp(p, "</relation>",11)) {
- osm_protobufdb_end_relation(&context);
- } else if (!strncmp(p, "</osm>",6)) {
- } else {
- fprintf(stderr,"WARNING: unknown tag in %s\n", buffer);
- }
- }
- finish();
- return 1;
+osm_protobufdb_load(FILE *in, char *dir) {
+ int size=BUFFER_SIZE;
+ char buffer[size];
+ char *p;
+ sig_alrm(0);
+ test();
+ while (fgets(buffer, size, in)) {
+ int closed=strstr(buffer,"/>")?1:0;
+ p=strchr(buffer,'<');
+ if (! p) {
+ fprintf(stderr,"WARNING: wrong line %s\n", buffer);
+ continue;
+ }
+ if (!strncmp(p, "<?xml ",6)) {
+ } else if (!strncmp(p, "<osm ",5)) {
+ } else if (!strncmp(p, "<bound ",7)) {
+ } else if (!strncmp(p, "<node ",6)) {
+ if (!osm_protobufdb_parse_node(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ if (closed)
+ osm_protobufdb_end_node(&context);
+ processed_nodes++;
+ } else if (!strncmp(p, "<tag ",5)) {
+ if (!osm_protobufdb_parse_tag(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "<way ",5)) {
+ if (!osm_protobufdb_parse_way(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ if (closed)
+ osm_protobufdb_end_way(&context);
+ processed_ways++;
+ } else if (!strncmp(p, "<nd ",4)) {
+ if (!osm_protobufdb_parse_nd(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "<relation ",10)) {
+ if (!osm_protobufdb_parse_relation(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ processed_relations++;
+ } else if (!strncmp(p, "<member ",8)) {
+ if (!osm_protobufdb_parse_member(&context, p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "</node>",7)) {
+ osm_protobufdb_end_node(&context);
+ } else if (!strncmp(p, "</way>",6)) {
+ osm_protobufdb_end_way(&context);
+ } else if (!strncmp(p, "</relation>",11)) {
+ osm_protobufdb_end_relation(&context);
+ } else if (!strncmp(p, "</osm>",6)) {
+ } else {
+ fprintf(stderr,"WARNING: unknown tag in %s\n", buffer);
+ }
+ }
+ finish();
+ return 1;
}
diff --git a/navit/maptool/osm_psql.c b/navit/maptool/osm_psql.c
index 8e8ded6c5..9987d9f4d 100644
--- a/navit/maptool/osm_psql.c
+++ b/navit/maptool/osm_psql.c
@@ -28,242 +28,246 @@
#include <postgresql/libpq-fe.h>
int
-map_collect_data_osm_db(char *dbstr, struct maptool_osm *osm)
-{
- PGconn *conn;
- PGresult *res;
- char query[256];
-
- sig_alrm(0);
- conn=PQconnectdb(dbstr);
- if (! conn) {
- fprintf(stderr,"Failed to connect to database with '%s'\n",dbstr);
- exit(1);
- }
- fprintf(stderr,"connected to database with '%s'\n",dbstr);
- res=PQexec(conn, "begin");
- if (! res) {
- fprintf(stderr, "Cannot begin transaction: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- res=PQexec(conn, "set transaction isolation level serializable");
- if (! res) {
- fprintf(stderr, "Cannot set isolation level: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- res=PQexec(conn, "declare nodes cursor for select id, ST_Y(geom), ST_X(geom) from nodes order by id");
- if (! res) {
- fprintf(stderr, "Cannot setup cursor for nodes: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- res=PQexec(conn, "declare ways cursor for select id from ways order by id");
- if (! res) {
- fprintf(stderr, "Cannot setup cursor for ways: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- res=PQexec(conn, "declare relations cursor for select id from relations order by id");
- if (! res) {
- fprintf(stderr, "Cannot setup cursor for relations: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
-
- for (;;) {
- int j=0, count=0;
- long min, max, id, tag_id;
- PGresult *node, *tag;
- node=PQexec(conn, "fetch 100000 from nodes");
- if (! node) {
- fprintf(stderr, "Cannot setup cursor for nodes: %s\n", PQerrorMessage(conn));
- PQclear(node);
- exit(1);
- }
- count=PQntuples(node);
- fprintf(stderr, "fetch got %i nodes\n", count);
- if (! count)
- break;
- min=atol(PQgetvalue(node, 0, 0));
- max=atol(PQgetvalue(node, count-1, 0));
- sprintf(query,"select node_id,k,v from node_tags where node_id >= %ld and node_id <= %ld order by node_id", min, max);
- tag=PQexec(conn, query);
- if (! tag) {
- fprintf(stderr, "Cannot query node_tag: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- fprintf(stderr, "query node_tag got : %i tuples\n", PQntuples(tag));
- for (int i = 0 ; i < count ; i++) {
- id=atol(PQgetvalue(node, i, 0));
- osm_add_node(id, atof(PQgetvalue(node, i, 1)), atof(PQgetvalue(node, i, 2)));
- processed_nodes++;
- while (j < PQntuples(tag)) {
- tag_id=atol(PQgetvalue(tag, j, 0));
- if (tag_id == id) {
- osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
- j++;
- }
- if (tag_id < id)
- j++;
- if (tag_id > id)
- break;
- }
- osm_end_node(osm);
- }
- PQclear(tag);
- PQclear(node);
- }
-
- for (;;) {
- int j=0, k=0, count=0, tagged=0;
- long min, max, id, tag_id, node_id;
- PGresult *node,*way,*tag;
- way=PQexec(conn, "fetch 25000 from ways");
- if (! way) {
- fprintf(stderr, "Cannot setup cursor for ways: %s\n", PQerrorMessage(conn));
- PQclear(way);
- exit(1);
- }
- count=PQntuples(way);
- fprintf(stderr, "fetch got %i ways\n", count);
- if (! count)
- break;
- min=atol(PQgetvalue(way, 0, 0));
- max=atol(PQgetvalue(way, count-1, 0));
- fprintf(stderr, "continue with %i ways\n", count);
- sprintf(query,"select way_id,node_id from way_nodes where way_id >= %ld and way_id <= %ld order by way_id,sequence_id", min, max);
- node=PQexec(conn, query);
- if (! node) {
- fprintf(stderr, "Cannot query way_node: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- sprintf(query,"select way_id,k,v from way_tags where way_id >= %ld and way_id <= %ld order by way_id", min, max);
- tag=PQexec(conn, query);
- if (! tag) {
- fprintf(stderr, "Cannot query way_tag: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- for (int i = 0 ; i < count ; i++) {
- id=atol(PQgetvalue(way, i, 0));
- osm_add_way(id);
- tagged=0;
- processed_ways++;
- while (k < PQntuples(node)) {
- node_id=atol(PQgetvalue(node, k, 0));
- if (node_id == id) {
- osm_add_nd(atoll(PQgetvalue(node, k, 1)));
- tagged=1;
- k++;
- }
- if (node_id < id)
- k++;
- if (node_id > id)
- break;
- }
- while (j < PQntuples(tag)) {
- tag_id=atol(PQgetvalue(tag, j, 0));
- if (tag_id == id) {
- osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
- tagged=1;
- j++;
- }
- if (tag_id < id)
- j++;
- if (tag_id > id)
- break;
- }
- if (tagged)
- osm_end_way(osm);
- }
- PQclear(tag);
- PQclear(node);
- PQclear(way);
- }
-
- for (;;) {
- int j=0, k=0, count=0, tagged=0;
- long min, max, id;
- PGresult *tag, *relation, *member;
- relation=PQexec(conn, "fetch 40000 from relations");
- if (! relation) {
- fprintf(stderr, "Cannot setup cursor for relations: %s\n", PQerrorMessage(conn));
- PQclear(relation);
- exit(1);
- }
- count=PQntuples(relation);
- fprintf(stderr, "Got %i relations\n", count);
- if (! count)
- break;
- min=atol(PQgetvalue(relation, 0, 0));
- max=atol(PQgetvalue(relation, count-1, 0));
- sprintf(query,"select relation_id,k,v from relation_tags where relation_id >= %ld and relation_id <= %ld order by relation_id", min, max);
- tag=PQexec(conn, query);
- if (! tag) {
- fprintf(stderr, "Cannot query relation_tag: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- sprintf(query,"select relation_id, member_id, member_type, member_role from relation_members where relation_id >= %ld and relation_id <= %ld order by relation_id, sequence_id", min, max);
- member=PQexec(conn, query);
- if (! member) {
- fprintf(stderr, "Cannot query relation_members: %s\n", PQerrorMessage(conn));
- exit(1);
- }
- for (int i = 0 ; i < count ; i++) {
- id=atol(PQgetvalue(relation, i, 0));
- osm_add_relation(id);
- tagged = 0;
- while (j < PQntuples(tag)) {
- long tag_relation_id=atol(PQgetvalue(tag, j, 0));
- if (tag_relation_id == id) {
- osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
- tagged=1;
- j++;
- }
- if (tag_relation_id < id)
- j++;
- if (tag_relation_id > id)
- break;
- }
- while (k < PQntuples(member)) {
- long member_relation_id=atol(PQgetvalue(member, k, 0));
- if (member_relation_id == id) {
- int relmember_type=0; //type unknown
- if (!strcmp(PQgetvalue(member,k, 2),"W")){
- relmember_type=2;
- }else{
- if (!strcmp(PQgetvalue(member,k, 2),"N")){
- relmember_type=1;
- }else{
- if (!strcmp(PQgetvalue(member,k, 2),"R")){
- relmember_type=3;
- }
- }
- }
- osm_add_member(relmember_type,atoll(PQgetvalue(member,k, 1)),PQgetvalue(member,k, 3));
- k++;
- }
- if (member_relation_id < id)
- k++;
- if (member_relation_id > id)
- break;
- }
- if (tagged)
- osm_end_relation(osm);
- }
- PQclear(relation);
- PQclear(member);
- PQclear(tag);
- }
- res=PQexec(conn, "commit");
- if (! res) {
- fprintf(stderr, "Cannot commit transaction: %s\n", PQerrorMessage(conn));
- PQclear(res);
- exit(1);
- }
- sig_alrm(0);
- sig_alrm_end();
- return 1;
+map_collect_data_osm_db(char *dbstr, struct maptool_osm *osm) {
+ PGconn *conn;
+ PGresult *res;
+ char query[256];
+
+ sig_alrm(0);
+ conn=PQconnectdb(dbstr);
+ if (! conn) {
+ fprintf(stderr,"Failed to connect to database with '%s'\n",dbstr);
+ exit(1);
+ }
+ fprintf(stderr,"connected to database with '%s'\n",dbstr);
+ res=PQexec(conn, "begin");
+ if (! res) {
+ fprintf(stderr, "Cannot begin transaction: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ res=PQexec(conn, "set transaction isolation level serializable");
+ if (! res) {
+ fprintf(stderr, "Cannot set isolation level: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ res=PQexec(conn, "declare nodes cursor for select id, ST_Y(geom), ST_X(geom) from nodes order by id");
+ if (! res) {
+ fprintf(stderr, "Cannot setup cursor for nodes: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ res=PQexec(conn, "declare ways cursor for select id from ways order by id");
+ if (! res) {
+ fprintf(stderr, "Cannot setup cursor for ways: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ res=PQexec(conn, "declare relations cursor for select id from relations order by id");
+ if (! res) {
+ fprintf(stderr, "Cannot setup cursor for relations: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+
+ for (;;) {
+ int j=0, count=0;
+ long min, max, id, tag_id;
+ PGresult *node, *tag;
+ node=PQexec(conn, "fetch 100000 from nodes");
+ if (! node) {
+ fprintf(stderr, "Cannot setup cursor for nodes: %s\n", PQerrorMessage(conn));
+ PQclear(node);
+ exit(1);
+ }
+ count=PQntuples(node);
+ fprintf(stderr, "fetch got %i nodes\n", count);
+ if (! count)
+ break;
+ min=atol(PQgetvalue(node, 0, 0));
+ max=atol(PQgetvalue(node, count-1, 0));
+ sprintf(query,"select node_id,k,v from node_tags where node_id >= %ld and node_id <= %ld order by node_id", min, max);
+ tag=PQexec(conn, query);
+ if (! tag) {
+ fprintf(stderr, "Cannot query node_tag: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ fprintf(stderr, "query node_tag got : %i tuples\n", PQntuples(tag));
+ for (int i = 0 ; i < count ; i++) {
+ id=atol(PQgetvalue(node, i, 0));
+ osm_add_node(id, atof(PQgetvalue(node, i, 1)), atof(PQgetvalue(node, i, 2)));
+ processed_nodes++;
+ while (j < PQntuples(tag)) {
+ tag_id=atol(PQgetvalue(tag, j, 0));
+ if (tag_id == id) {
+ osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
+ j++;
+ }
+ if (tag_id < id)
+ j++;
+ if (tag_id > id)
+ break;
+ }
+ osm_end_node(osm);
+ }
+ PQclear(tag);
+ PQclear(node);
+ }
+
+ for (;;) {
+ int j=0, k=0, count=0, tagged=0;
+ long min, max, id, tag_id, node_id;
+ PGresult *node,*way,*tag;
+ way=PQexec(conn, "fetch 25000 from ways");
+ if (! way) {
+ fprintf(stderr, "Cannot setup cursor for ways: %s\n", PQerrorMessage(conn));
+ PQclear(way);
+ exit(1);
+ }
+ count=PQntuples(way);
+ fprintf(stderr, "fetch got %i ways\n", count);
+ if (! count)
+ break;
+ min=atol(PQgetvalue(way, 0, 0));
+ max=atol(PQgetvalue(way, count-1, 0));
+ fprintf(stderr, "continue with %i ways\n", count);
+ sprintf(query,"select way_id,node_id from way_nodes where way_id >= %ld and way_id <= %ld order by way_id,sequence_id",
+ min, max);
+ node=PQexec(conn, query);
+ if (! node) {
+ fprintf(stderr, "Cannot query way_node: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ sprintf(query,"select way_id,k,v from way_tags where way_id >= %ld and way_id <= %ld order by way_id", min, max);
+ tag=PQexec(conn, query);
+ if (! tag) {
+ fprintf(stderr, "Cannot query way_tag: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ for (int i = 0 ; i < count ; i++) {
+ id=atol(PQgetvalue(way, i, 0));
+ osm_add_way(id);
+ tagged=0;
+ processed_ways++;
+ while (k < PQntuples(node)) {
+ node_id=atol(PQgetvalue(node, k, 0));
+ if (node_id == id) {
+ osm_add_nd(atoll(PQgetvalue(node, k, 1)));
+ tagged=1;
+ k++;
+ }
+ if (node_id < id)
+ k++;
+ if (node_id > id)
+ break;
+ }
+ while (j < PQntuples(tag)) {
+ tag_id=atol(PQgetvalue(tag, j, 0));
+ if (tag_id == id) {
+ osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
+ tagged=1;
+ j++;
+ }
+ if (tag_id < id)
+ j++;
+ if (tag_id > id)
+ break;
+ }
+ if (tagged)
+ osm_end_way(osm);
+ }
+ PQclear(tag);
+ PQclear(node);
+ PQclear(way);
+ }
+
+ for (;;) {
+ int j=0, k=0, count=0, tagged=0;
+ long min, max, id;
+ PGresult *tag, *relation, *member;
+ relation=PQexec(conn, "fetch 40000 from relations");
+ if (! relation) {
+ fprintf(stderr, "Cannot setup cursor for relations: %s\n", PQerrorMessage(conn));
+ PQclear(relation);
+ exit(1);
+ }
+ count=PQntuples(relation);
+ fprintf(stderr, "Got %i relations\n", count);
+ if (! count)
+ break;
+ min=atol(PQgetvalue(relation, 0, 0));
+ max=atol(PQgetvalue(relation, count-1, 0));
+ sprintf(query,
+ "select relation_id,k,v from relation_tags where relation_id >= %ld and relation_id <= %ld order by relation_id", min,
+ max);
+ tag=PQexec(conn, query);
+ if (! tag) {
+ fprintf(stderr, "Cannot query relation_tag: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ sprintf(query,
+ "select relation_id, member_id, member_type, member_role from relation_members where relation_id >= %ld and relation_id <= %ld order by relation_id, sequence_id",
+ min, max);
+ member=PQexec(conn, query);
+ if (! member) {
+ fprintf(stderr, "Cannot query relation_members: %s\n", PQerrorMessage(conn));
+ exit(1);
+ }
+ for (int i = 0 ; i < count ; i++) {
+ id=atol(PQgetvalue(relation, i, 0));
+ osm_add_relation(id);
+ tagged = 0;
+ while (j < PQntuples(tag)) {
+ long tag_relation_id=atol(PQgetvalue(tag, j, 0));
+ if (tag_relation_id == id) {
+ osm_add_tag(PQgetvalue(tag, j, 1), PQgetvalue(tag, j, 2));
+ tagged=1;
+ j++;
+ }
+ if (tag_relation_id < id)
+ j++;
+ if (tag_relation_id > id)
+ break;
+ }
+ while (k < PQntuples(member)) {
+ long member_relation_id=atol(PQgetvalue(member, k, 0));
+ if (member_relation_id == id) {
+ int relmember_type=0; //type unknown
+ if (!strcmp(PQgetvalue(member,k, 2),"W")) {
+ relmember_type=2;
+ } else {
+ if (!strcmp(PQgetvalue(member,k, 2),"N")) {
+ relmember_type=1;
+ } else {
+ if (!strcmp(PQgetvalue(member,k, 2),"R")) {
+ relmember_type=3;
+ }
+ }
+ }
+ osm_add_member(relmember_type,atoll(PQgetvalue(member,k, 1)),PQgetvalue(member,k, 3));
+ k++;
+ }
+ if (member_relation_id < id)
+ k++;
+ if (member_relation_id > id)
+ break;
+ }
+ if (tagged)
+ osm_end_relation(osm);
+ }
+ PQclear(relation);
+ PQclear(member);
+ PQclear(tag);
+ }
+ res=PQexec(conn, "commit");
+ if (! res) {
+ fprintf(stderr, "Cannot commit transaction: %s\n", PQerrorMessage(conn));
+ PQclear(res);
+ exit(1);
+ }
+ sig_alrm(0);
+ sig_alrm_end();
+ return 1;
}
#endif
diff --git a/navit/maptool/osm_relations.c b/navit/maptool/osm_relations.c
index 591ca7d9d..fdacd3069 100644
--- a/navit/maptool/osm_relations.c
+++ b/navit/maptool/osm_relations.c
@@ -23,67 +23,63 @@
/** Information about all members of a relation type and how to process them. */
struct relations {
- /** Hashes for nodes, ways and relations which are members. */
- GHashTable *member_hash[3];
- /** Default entries for processing items which are not a member of any relation. */
- GList *default_members;
+ /** Hashes for nodes, ways and relations which are members. */
+ GHashTable *member_hash[3];
+ /** Default entries for processing items which are not a member of any relation. */
+ GList *default_members;
};
struct relations_func {
- void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv);
- void *func_priv;
+ void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv);
+ void *func_priv;
};
struct relations_member {
- osmid memberid;
- void *relation_priv,*member_priv;
- struct relations_func *func;
+ osmid memberid;
+ void *relation_priv,*member_priv;
+ struct relations_func *func;
};
static guint
-relations_member_hash(gconstpointer key)
-{
- const struct relations_member *memb=key;
- return (memb->memberid >> 32)^(memb->memberid & 0xffffffff);
+relations_member_hash(gconstpointer key) {
+ const struct relations_member *memb=key;
+ return (memb->memberid >> 32)^(memb->memberid & 0xffffffff);
}
static gboolean
-relations_member_equal(gconstpointer a, gconstpointer b)
-{
- const struct relations_member *memba=a;
- const struct relations_member *membb=b;
- return (memba->memberid == membb->memberid);
+relations_member_equal(gconstpointer a, gconstpointer b) {
+ const struct relations_member *memba=a;
+ const struct relations_member *membb=b;
+ return (memba->memberid == membb->memberid);
}
struct relations *
-relations_new(void)
-{
- struct relations *ret=g_new0(struct relations, 1);
- int i;
-
- for (i = 0 ; i < 3 ; i++)
- ret->member_hash[i]=g_hash_table_new(relations_member_hash, relations_member_equal);
- return ret;
+relations_new(void) {
+ struct relations *ret=g_new0(struct relations, 1);
+ int i;
+
+ for (i = 0 ; i < 3 ; i++)
+ ret->member_hash[i]=g_hash_table_new(relations_member_hash, relations_member_equal);
+ return ret;
}
struct relations_func *
-relations_func_new(void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv), void *func_priv)
-{
- struct relations_func *relations_func=g_new(struct relations_func, 1);
- relations_func->func=func;
- relations_func->func_priv=func_priv;
- return relations_func;
+relations_func_new(void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv),
+ void *func_priv) {
+ struct relations_func *relations_func=g_new(struct relations_func, 1);
+ relations_func->func=func;
+ relations_func->func_priv=func_priv;
+ return relations_func;
}
static struct relations_member *
-relations_member_new(struct relations_func *func, void *relation_priv, void *member_priv, osmid id)
-{
- struct relations_member *memb=g_new(struct relations_member, 1);
- memb->memberid=id;
- memb->relation_priv=relation_priv;
- memb->member_priv=member_priv;
- memb->func=func;
- return memb;
+relations_member_new(struct relations_func *func, void *relation_priv, void *member_priv, osmid id) {
+ struct relations_member *memb=g_new(struct relations_member, 1);
+ memb->memberid=id;
+ memb->relation_priv=relation_priv;
+ memb->member_priv=member_priv;
+ memb->func=func;
+ return memb;
}
/*
* @brief Add an entry for a relation member to the relations collection.
@@ -98,12 +94,11 @@ relations_member_new(struct relations_func *func, void *relation_priv, void *mem
*/
void
relations_add_relation_member_entry(struct relations *rel, struct relations_func *func, void
- *relation_priv, void *member_priv, enum relation_member_type type, osmid id)
-{
- struct relations_member *memb=relations_member_new(func, relation_priv, member_priv, id);
- GHashTable *member_hash=rel->member_hash[type-1];
- // The real key is the OSM ID, but we recycle "memb" as key to avoid a second allocating for the key.
- g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb));
+ *relation_priv, void *member_priv, enum relation_member_type type, osmid id) {
+ struct relations_member *memb=relations_member_new(func, relation_priv, member_priv, id);
+ GHashTable *member_hash=rel->member_hash[type-1];
+ // The real key is the OSM ID, but we recycle "memb" as key to avoid a second allocating for the key.
+ g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb));
}
/*
@@ -115,10 +110,9 @@ relations_add_relation_member_entry(struct relations *rel, struct relations_func
* @param in func structure defining function to call when this member is read
*/
void
-relations_add_relation_default_entry(struct relations *rel, struct relations_func *func)
-{
- struct relations_member *memb=relations_member_new(func, NULL, NULL, 0);
- rel->default_members=g_list_append(rel->default_members, memb);
+relations_add_relation_default_entry(struct relations *rel, struct relations_func *func) {
+ struct relations_member *memb=relations_member_new(func, NULL, NULL, 0);
+ rel->default_members=g_list_append(rel->default_members, memb);
}
@@ -131,70 +125,67 @@ relations_add_relation_default_entry(struct relations *rel, struct relations_fun
* @param in ways file containing items in item_bin format. This file may contain both nodes, ways, and relations in that format.
*/
void
-relations_process(struct relations *rel, FILE *nodes, FILE *ways)
-{
- char buffer[128];
- struct item_bin *ib=(struct item_bin *)buffer;
- osmid *id;
- struct coord *c=(struct coord *)(ib+1),cn={0,0};
- struct node_item *ni;
- GList *l;
-
- if (nodes) {
- item_bin_init(ib, type_point_unkn);
- item_bin_add_coord(ib, &cn, 1);
- item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0);
- id=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
- while ((ni=read_node_item(nodes))) {
- *id=ni->nd_id;
- *c=ni->c;
- l=g_hash_table_lookup(rel->member_hash[0], id);
- while (l) {
- struct relations_member *memb=l->data;
- memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
- l=g_list_next(l);
- }
- }
- }
- if (ways) {
- while ((ib=read_item(ways))) {
- l=NULL;
- if(NULL!=(id=item_bin_get_attr(ib, attr_osm_nodeid, NULL)))
- l=g_hash_table_lookup(rel->member_hash[0], id);
- else if(NULL!=(id=item_bin_get_attr(ib, attr_osm_wayid, NULL)))
- l=g_hash_table_lookup(rel->member_hash[1], id);
- else if(NULL!=(id=item_bin_get_attr(ib, attr_osm_relationid, NULL)))
- l=g_hash_table_lookup(rel->member_hash[2], id);
- if(!l)
- l=rel->default_members;
- while (l) {
- struct relations_member *memb=l->data;
- memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
- l=g_list_next(l);
- }
- }
- }
+relations_process(struct relations *rel, FILE *nodes, FILE *ways) {
+ char buffer[128];
+ struct item_bin *ib=(struct item_bin *)buffer;
+ osmid *id;
+ struct coord *c=(struct coord *)(ib+1),cn= {0,0};
+ struct node_item *ni;
+ GList *l;
+
+ if (nodes) {
+ item_bin_init(ib, type_point_unkn);
+ item_bin_add_coord(ib, &cn, 1);
+ item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0);
+ id=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
+ while ((ni=read_node_item(nodes))) {
+ *id=ni->nd_id;
+ *c=ni->c;
+ l=g_hash_table_lookup(rel->member_hash[0], id);
+ while (l) {
+ struct relations_member *memb=l->data;
+ memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
+ l=g_list_next(l);
+ }
+ }
+ }
+ if (ways) {
+ while ((ib=read_item(ways))) {
+ l=NULL;
+ if(NULL!=(id=item_bin_get_attr(ib, attr_osm_nodeid, NULL)))
+ l=g_hash_table_lookup(rel->member_hash[0], id);
+ else if(NULL!=(id=item_bin_get_attr(ib, attr_osm_wayid, NULL)))
+ l=g_hash_table_lookup(rel->member_hash[1], id);
+ else if(NULL!=(id=item_bin_get_attr(ib, attr_osm_relationid, NULL)))
+ l=g_hash_table_lookup(rel->member_hash[2], id);
+ if(!l)
+ l=rel->default_members;
+ while (l) {
+ struct relations_member *memb=l->data;
+ memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
+ l=g_list_next(l);
+ }
+ }
+ }
}
static void
-relations_destroy_func(void *key, GList *l, void *data)
-{
- GList *ll=l;
- while (ll) {
- g_free(ll->data);
- ll=g_list_next(ll);
- }
- g_list_free(l);
+relations_destroy_func(void *key, GList *l, void *data) {
+ GList *ll=l;
+ while (ll) {
+ g_free(ll->data);
+ ll=g_list_next(ll);
+ }
+ g_list_free(l);
}
void
-relations_destroy(struct relations *relations)
-{
- int i;
-
- for (i = 0 ; i < 3 ; i++) {
- g_hash_table_foreach(relations->member_hash[i], (GHFunc)relations_destroy_func, NULL);
- g_hash_table_destroy(relations->member_hash[i]);
- }
- g_free(relations);
+relations_destroy(struct relations *relations) {
+ int i;
+
+ for (i = 0 ; i < 3 ; i++) {
+ g_hash_table_foreach(relations->member_hash[i], (GHFunc)relations_destroy_func, NULL);
+ g_hash_table_destroy(relations->member_hash[i]);
+ }
+ g_free(relations);
}
diff --git a/navit/maptool/osm_xml.c b/navit/maptool/osm_xml.c
index c107a8048..876576716 100644
--- a/navit/maptool/osm_xml.c
+++ b/navit/maptool/osm_xml.c
@@ -27,219 +27,210 @@
#include "maptool.h"
int
-osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size)
-{
- int len=strlen(attribute);
- char *pos,*i,s,*attr;
- attr=g_alloca(len+2);
- strcpy(attr, attribute);
- strcpy(attr+len, "=");
- pos=strstr(xml, attr);
- if (! pos)
- return 0;
- pos+=len+1;
- s=*pos++;
- if (! s)
- return 0;
- i=strchr(pos, s);
- if (! i)
- return 0;
- if (i - pos > buffer_size) {
- fprintf(stderr,"Buffer overflow %ld vs %d\n", (long)(i-pos), buffer_size);
- return 0;
- }
- strncpy(buffer, pos, i-pos);
- buffer[i-pos]='\0';
- return 1;
+osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size) {
+ int len=strlen(attribute);
+ char *pos,*i,s,*attr;
+ attr=g_alloca(len+2);
+ strcpy(attr, attribute);
+ strcpy(attr+len, "=");
+ pos=strstr(xml, attr);
+ if (! pos)
+ return 0;
+ pos+=len+1;
+ s=*pos++;
+ if (! s)
+ return 0;
+ i=strchr(pos, s);
+ if (! i)
+ return 0;
+ if (i - pos > buffer_size) {
+ fprintf(stderr,"Buffer overflow %ld vs %d\n", (long)(i-pos), buffer_size);
+ return 0;
+ }
+ strncpy(buffer, pos, i-pos);
+ buffer[i-pos]='\0';
+ return 1;
}
static struct entity {
- char *entity;
- char c;
+ char *entity;
+ char c;
} entities[]= {
- {"&quot;",'"'},
- {"&apos;",'\''},
- {"&amp;",'&'},
- {"&lt;",'<'},
- {"&gt;",'>'},
- {"&#34;",'"'},
- {"&#39;",'\''},
- {"&#38;",'&'},
- {"&#60;",'<'},
- {"&#62;",'>'},
- {"&#123;",'{'},
- {"&#125;",'}'},
+ {"&quot;",'"'},
+ {"&apos;",'\''},
+ {"&amp;",'&'},
+ {"&lt;",'<'},
+ {"&gt;",'>'},
+ {"&#34;",'"'},
+ {"&#39;",'\''},
+ {"&#38;",'&'},
+ {"&#60;",'<'},
+ {"&#62;",'>'},
+ {"&#123;",'{'},
+ {"&#125;",'}'},
};
void
-osm_xml_decode_entities(char *buffer)
-{
- char *pos=buffer;
- int i,len;
+osm_xml_decode_entities(char *buffer) {
+ char *pos=buffer;
+ int i,len;
- while ((pos=strchr(pos, '&'))) {
- for (i = 0 ; i < sizeof(entities)/sizeof(struct entity); i++) {
- len=strlen(entities[i].entity);
- if (!strncmp(pos, entities[i].entity, len)) {
- *pos=entities[i].c;
- memmove(pos+1, pos+len, strlen(pos+len)+1);
- break;
- }
- }
- pos++;
- }
+ while ((pos=strchr(pos, '&'))) {
+ for (i = 0 ; i < sizeof(entities)/sizeof(struct entity); i++) {
+ len=strlen(entities[i].entity);
+ if (!strncmp(pos, entities[i].entity, len)) {
+ *pos=entities[i].c;
+ memmove(pos+1, pos+len, strlen(pos+len)+1);
+ break;
+ }
+ }
+ pos++;
+ }
}
static int
-parse_tag(char *p)
-{
- char k_buffer[BUFFER_SIZE];
- char v_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "k", k_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "v", v_buffer, BUFFER_SIZE))
- return 0;
- osm_xml_decode_entities(v_buffer);
- osm_add_tag(k_buffer, v_buffer);
- return 1;
+parse_tag(char *p) {
+ char k_buffer[BUFFER_SIZE];
+ char v_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "k", k_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "v", v_buffer, BUFFER_SIZE))
+ return 0;
+ osm_xml_decode_entities(v_buffer);
+ osm_add_tag(k_buffer, v_buffer);
+ return 1;
}
static int
-parse_node(char *p)
-{
- char id_buffer[BUFFER_SIZE];
- char lat_buffer[BUFFER_SIZE];
- char lon_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "lat", lat_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "lon", lon_buffer, BUFFER_SIZE))
- return 0;
- osm_add_node(atoll(id_buffer), atof(lat_buffer), atof(lon_buffer));
- return 1;
+parse_node(char *p) {
+ char id_buffer[BUFFER_SIZE];
+ char lat_buffer[BUFFER_SIZE];
+ char lon_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "lat", lat_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "lon", lon_buffer, BUFFER_SIZE))
+ return 0;
+ osm_add_node(atoll(id_buffer), atof(lat_buffer), atof(lon_buffer));
+ return 1;
}
static int
-parse_way(char *p)
-{
- char id_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
- return 0;
- osm_add_way(atoll(id_buffer));
- return 1;
+parse_way(char *p) {
+ char id_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
+ return 0;
+ osm_add_way(atoll(id_buffer));
+ return 1;
}
static int
-parse_relation(char *p)
-{
- char id_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
- return 0;
- osm_add_relation(atoll(id_buffer));
- return 1;
+parse_relation(char *p) {
+ char id_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "id", id_buffer, BUFFER_SIZE))
+ return 0;
+ osm_add_relation(atoll(id_buffer));
+ return 1;
}
static int
-parse_member(char *p)
-{
- char type_buffer[BUFFER_SIZE];
- char ref_buffer[BUFFER_SIZE];
- char role_buffer[BUFFER_SIZE];
- enum relation_member_type type;
- if (!osm_xml_get_attribute(p, "type", type_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
- return 0;
- if (!osm_xml_get_attribute(p, "role", role_buffer, BUFFER_SIZE))
- return 0;
- if (!strcmp(type_buffer,"node"))
- type=rel_member_node;
- else if (!strcmp(type_buffer,"way"))
- type=rel_member_way;
- else if (!strcmp(type_buffer,"relation"))
- type=rel_member_relation;
- else {
- fprintf(stderr,"Unknown type '%s'\n",type_buffer);
- return 0;
- }
- osm_add_member(type, atoll(ref_buffer), role_buffer);
-
- return 1;
+parse_member(char *p) {
+ char type_buffer[BUFFER_SIZE];
+ char ref_buffer[BUFFER_SIZE];
+ char role_buffer[BUFFER_SIZE];
+ enum relation_member_type type;
+ if (!osm_xml_get_attribute(p, "type", type_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
+ return 0;
+ if (!osm_xml_get_attribute(p, "role", role_buffer, BUFFER_SIZE))
+ return 0;
+ if (!strcmp(type_buffer,"node"))
+ type=rel_member_node;
+ else if (!strcmp(type_buffer,"way"))
+ type=rel_member_way;
+ else if (!strcmp(type_buffer,"relation"))
+ type=rel_member_relation;
+ else {
+ fprintf(stderr,"Unknown type '%s'\n",type_buffer);
+ return 0;
+ }
+ osm_add_member(type, atoll(ref_buffer), role_buffer);
+
+ return 1;
}
static int
-parse_nd(char *p)
-{
- char ref_buffer[BUFFER_SIZE];
- if (!osm_xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
- return 0;
- osm_add_nd(atoll(ref_buffer));
- return 1;
+parse_nd(char *p) {
+ char ref_buffer[BUFFER_SIZE];
+ if (!osm_xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
+ return 0;
+ osm_add_nd(atoll(ref_buffer));
+ return 1;
}
static int
-xml_declaration_in_line(char* buffer){
- return !strncmp(buffer, "<?xml ", 6);
+xml_declaration_in_line(char* buffer) {
+ return !strncmp(buffer, "<?xml ", 6);
}
int
-map_collect_data_osm(FILE *in, struct maptool_osm *osm)
-{
- int size=BUFFER_SIZE;
- char buffer[BUFFER_SIZE];
- char *p;
- sig_alrm(0);
- if (!fgets(buffer, size, in) || !xml_declaration_in_line(buffer)){
- fprintf(stderr,"FATAL: First line does not start with XML declaration;\n"
- "this does not look like a valid OSM file.\n");
- exit(EXIT_FAILURE);
- }
- while (fgets(buffer, size, in)) {
- p=strchr(buffer,'<');
- if (! p) {
- fprintf(stderr,"FATAL: wrong line in input data (does not start with '<'): %s\n", buffer);
- fprintf(stderr,"This does not look like a valid OSM file.\n"
- "Note that maptool can only process OSM files without wrapped or empty lines.\n");
- exit(EXIT_FAILURE);
- }
- if (!strncmp(p, "<osm ",5)) {
- } else if (!strncmp(p, "<bound ",7)) {
- } else if (!strncmp(p, "<node ",6)) {
- if (!parse_node(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- processed_nodes++;
- } else if (!strncmp(p, "<tag ",5)) {
- if (!parse_tag(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "<way ",5)) {
- if (!parse_way(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- processed_ways++;
- } else if (!strncmp(p, "<nd ",4)) {
- if (!parse_nd(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "<relation ",10)) {
- if (!parse_relation(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- processed_relations++;
- } else if (!strncmp(p, "<member ",8)) {
- if (!parse_member(p))
- fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
- } else if (!strncmp(p, "</node>",7)) {
- osm_end_node(osm);
- } else if (!strncmp(p, "</way>",6)) {
- osm_end_way(osm);
- } else if (!strncmp(p, "</relation>",11)) {
- osm_end_relation(osm);
- } else if (!strncmp(p, "</osm>",6)) {
- } else {
- fprintf(stderr,"WARNING: unknown tag in %s\n", buffer);
- }
- }
- sig_alrm(0);
- sig_alrm_end();
- return 1;
+map_collect_data_osm(FILE *in, struct maptool_osm *osm) {
+ int size=BUFFER_SIZE;
+ char buffer[BUFFER_SIZE];
+ char *p;
+ sig_alrm(0);
+ if (!fgets(buffer, size, in) || !xml_declaration_in_line(buffer)) {
+ fprintf(stderr,"FATAL: First line does not start with XML declaration;\n"
+ "this does not look like a valid OSM file.\n");
+ exit(EXIT_FAILURE);
+ }
+ while (fgets(buffer, size, in)) {
+ p=strchr(buffer,'<');
+ if (! p) {
+ fprintf(stderr,"FATAL: wrong line in input data (does not start with '<'): %s\n", buffer);
+ fprintf(stderr,"This does not look like a valid OSM file.\n"
+ "Note that maptool can only process OSM files without wrapped or empty lines.\n");
+ exit(EXIT_FAILURE);
+ }
+ if (!strncmp(p, "<osm ",5)) {
+ } else if (!strncmp(p, "<bound ",7)) {
+ } else if (!strncmp(p, "<node ",6)) {
+ if (!parse_node(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ processed_nodes++;
+ } else if (!strncmp(p, "<tag ",5)) {
+ if (!parse_tag(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "<way ",5)) {
+ if (!parse_way(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ processed_ways++;
+ } else if (!strncmp(p, "<nd ",4)) {
+ if (!parse_nd(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "<relation ",10)) {
+ if (!parse_relation(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ processed_relations++;
+ } else if (!strncmp(p, "<member ",8)) {
+ if (!parse_member(p))
+ fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
+ } else if (!strncmp(p, "</node>",7)) {
+ osm_end_node(osm);
+ } else if (!strncmp(p, "</way>",6)) {
+ osm_end_way(osm);
+ } else if (!strncmp(p, "</relation>",11)) {
+ osm_end_relation(osm);
+ } else if (!strncmp(p, "</osm>",6)) {
+ } else {
+ fprintf(stderr,"WARNING: unknown tag in %s\n", buffer);
+ }
+ }
+ sig_alrm(0);
+ sig_alrm_end();
+ return 1;
}
diff --git a/navit/maptool/sourcesink.c b/navit/maptool/sourcesink.c
index 97aa7de7d..3eb01667a 100644
--- a/navit/maptool/sourcesink.c
+++ b/navit/maptool/sourcesink.c
@@ -25,145 +25,132 @@
#include "maptool.h"
struct item_bin_sink *
-item_bin_sink_new(void)
-{
- struct item_bin_sink *ret=g_new0(struct item_bin_sink, 1);
+item_bin_sink_new(void) {
+ struct item_bin_sink *ret=g_new0(struct item_bin_sink, 1);
- return ret;
+ return ret;
}
struct item_bin_sink_func *
-item_bin_sink_func_new(int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data))
-{
- struct item_bin_sink_func *ret=g_new0(struct item_bin_sink_func, 1);
- ret->func=func;
- return ret;
+item_bin_sink_func_new(int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data)) {
+ struct item_bin_sink_func *ret=g_new0(struct item_bin_sink_func, 1);
+ ret->func=func;
+ return ret;
}
void
-item_bin_sink_func_destroy(struct item_bin_sink_func *func)
-{
- g_free(func);
+item_bin_sink_func_destroy(struct item_bin_sink_func *func) {
+ g_free(func);
}
void
-item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func)
-{
- sink->sink_funcs=g_list_append(sink->sink_funcs, func);
+item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func) {
+ sink->sink_funcs=g_list_append(sink->sink_funcs, func);
}
void
-item_bin_sink_destroy(struct item_bin_sink *sink)
-{
- /* g_list_foreach(sink->sink_funcs, (GFunc)g_free, NULL); */
- g_list_free(sink->sink_funcs);
- g_free(sink);
+item_bin_sink_destroy(struct item_bin_sink *sink) {
+ /* g_list_foreach(sink->sink_funcs, (GFunc)g_free, NULL); */
+ g_list_free(sink->sink_funcs);
+ g_free(sink);
}
int
-item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data)
-{
- GList *list=sink->sink_funcs;
- int ret=0;
- while (list) {
- struct item_bin_sink_func *func=list->data;
- ret=func->func(func, ib, tile_data);
- if (ret)
- break;
- list=g_list_next(list);
- }
- return ret;
+item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data) {
+ GList *list=sink->sink_funcs;
+ int ret=0;
+ while (list) {
+ struct item_bin_sink_func *func=list->data;
+ ret=func->func(func, ib, tile_data);
+ if (ret)
+ break;
+ list=g_list_next(list);
+ }
+ return ret;
}
struct item_bin_sink *
-file_reader_new(FILE *in, int limit, int offset)
-{
- struct item_bin_sink *ret;
- if (!in)
- return NULL;
- ret=item_bin_sink_new();
- ret->priv_data[0]=in;
- ret->priv_data[1]=(void *)(long)limit;
- ret->priv_data[2]=(void *)(long)offset;
- fseek(in, 0, SEEK_SET);
- return ret;
+file_reader_new(FILE *in, int limit, int offset) {
+ struct item_bin_sink *ret;
+ if (!in)
+ return NULL;
+ ret=item_bin_sink_new();
+ ret->priv_data[0]=in;
+ ret->priv_data[1]=(void *)(long)limit;
+ ret->priv_data[2]=(void *)(long)offset;
+ fseek(in, 0, SEEK_SET);
+ return ret;
}
int
-file_reader_finish(struct item_bin_sink *sink)
-{
- struct item_bin *ib;
- int ret =0;
- FILE *in=sink->priv_data[0];
- int limit=(int)(long)sink->priv_data[1];
- int offset=(int)(long)sink->priv_data[2];
- while ((ib=read_item(in))) {
- if (offset > 0) {
- offset--;
- } else {
- ret=item_bin_write_to_sink(ib, sink, NULL);
- if (ret || (limit != -1 && !--limit)) {
- item_bin_sink_destroy(sink);
- return ret;
- }
- }
- }
- item_bin_sink_destroy(sink);
- return 0;
+file_reader_finish(struct item_bin_sink *sink) {
+ struct item_bin *ib;
+ int ret =0;
+ FILE *in=sink->priv_data[0];
+ int limit=(int)(long)sink->priv_data[1];
+ int offset=(int)(long)sink->priv_data[2];
+ while ((ib=read_item(in))) {
+ if (offset > 0) {
+ offset--;
+ } else {
+ ret=item_bin_write_to_sink(ib, sink, NULL);
+ if (ret || (limit != -1 && !--limit)) {
+ item_bin_sink_destroy(sink);
+ return ret;
+ }
+ }
+ }
+ item_bin_sink_destroy(sink);
+ return 0;
}
int
-file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data)
-{
- FILE *out=func->priv_data[0];
- item_bin_write(ib, out);
- return 0;
+file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data) {
+ FILE *out=func->priv_data[0];
+ item_bin_write(ib, out);
+ return 0;
}
struct item_bin_sink_func *
-file_writer_new(FILE *out)
-{
- struct item_bin_sink_func *file_writer;
- if (!out)
- return NULL;
- file_writer=item_bin_sink_func_new(file_writer_process);
- file_writer->priv_data[0]=out;
- return file_writer;
+file_writer_new(FILE *out) {
+ struct item_bin_sink_func *file_writer;
+ if (!out)
+ return NULL;
+ file_writer=item_bin_sink_func_new(file_writer_process);
+ file_writer->priv_data[0]=out;
+ return file_writer;
}
int
-file_writer_finish(struct item_bin_sink_func *file_writer)
-{
- item_bin_sink_func_destroy(file_writer);
- return 0;
+file_writer_finish(struct item_bin_sink_func *file_writer) {
+ item_bin_sink_func_destroy(file_writer);
+ return 0;
}
int
-tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data)
-{
- int *buffer,*buffer2;
- int len=ib->len+1;
- GHashTable *hash=tile_collector->priv_data[0];
- buffer=g_hash_table_lookup(hash, tile_data->buffer);
- buffer2=g_malloc((len+(buffer ? buffer[0] : 1))*4);
- if (buffer) {
- memcpy(buffer2, buffer, buffer[0]*4);
- } else
- buffer2[0]=1;
- memcpy(buffer2+buffer2[0], ib, len*4);
- buffer2[0]+=len;
- g_hash_table_insert(hash, g_strdup(tile_data->buffer), buffer2);
- return 0;
+tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data) {
+ int *buffer,*buffer2;
+ int len=ib->len+1;
+ GHashTable *hash=tile_collector->priv_data[0];
+ buffer=g_hash_table_lookup(hash, tile_data->buffer);
+ buffer2=g_malloc((len+(buffer ? buffer[0] : 1))*4);
+ if (buffer) {
+ memcpy(buffer2, buffer, buffer[0]*4);
+ } else
+ buffer2[0]=1;
+ memcpy(buffer2+buffer2[0], ib, len*4);
+ buffer2[0]+=len;
+ g_hash_table_insert(hash, g_strdup(tile_data->buffer), buffer2);
+ return 0;
}
struct item_bin_sink_func *
-tile_collector_new(struct item_bin_sink *out)
-{
- struct item_bin_sink_func *tile_collector;
- tile_collector=item_bin_sink_func_new(tile_collector_process);
- tile_collector->priv_data[0]=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
- tile_collector->priv_data[1]=out;
- return tile_collector;
+tile_collector_new(struct item_bin_sink *out) {
+ struct item_bin_sink_func *tile_collector;
+ tile_collector=item_bin_sink_func_new(tile_collector_process);
+ tile_collector->priv_data[0]=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ tile_collector->priv_data[1]=out;
+ return tile_collector;
}
diff --git a/navit/maptool/tempfile.c b/navit/maptool/tempfile.c
index d00acd21b..65614d945 100644
--- a/navit/maptool/tempfile.c
+++ b/navit/maptool/tempfile.c
@@ -24,44 +24,40 @@
#include "debug.h"
char *
-tempfile_name(char *suffix, char *name)
-{
- return g_strdup_printf("%s_%s.tmp",name, suffix);
+tempfile_name(char *suffix, char *name) {
+ return g_strdup_printf("%s_%s.tmp",name, suffix);
}
FILE *
-tempfile(char *suffix, char *name, int mode)
-{
- char *buffer=tempfile_name(suffix, name);
- FILE *ret=NULL;
- switch (mode) {
- case 0:
- ret=fopen(buffer, "rb");
- break;
- case 1:
- ret=fopen(buffer, "wb+");
- break;
- case 2:
- ret=fopen(buffer, "ab");
- break;
- }
- g_free(buffer);
- return ret;
+tempfile(char *suffix, char *name, int mode) {
+ char *buffer=tempfile_name(suffix, name);
+ FILE *ret=NULL;
+ switch (mode) {
+ case 0:
+ ret=fopen(buffer, "rb");
+ break;
+ case 1:
+ ret=fopen(buffer, "wb+");
+ break;
+ case 2:
+ ret=fopen(buffer, "ab");
+ break;
+ }
+ g_free(buffer);
+ return ret;
}
void
-tempfile_unlink(char *suffix, char *name)
-{
- char buffer[4096];
- sprintf(buffer,"%s_%s.tmp",name, suffix);
- unlink(buffer);
+tempfile_unlink(char *suffix, char *name) {
+ char buffer[4096];
+ sprintf(buffer,"%s_%s.tmp",name, suffix);
+ unlink(buffer);
}
void
-tempfile_rename(char *suffix, char *from, char *to)
-{
- char buffer_from[4096],buffer_to[4096];
- sprintf(buffer_from,"%s_%s.tmp",from,suffix);
- sprintf(buffer_to,"%s_%s.tmp",to,suffix);
- dbg_assert(rename(buffer_from, buffer_to) == 0);
-
+tempfile_rename(char *suffix, char *from, char *to) {
+ char buffer_from[4096],buffer_to[4096];
+ sprintf(buffer_from,"%s_%s.tmp",from,suffix);
+ sprintf(buffer_to,"%s_%s.tmp",to,suffix);
+ dbg_assert(rename(buffer_from, buffer_to) == 0);
+
}
diff --git a/navit/maptool/tile.c b/navit/maptool/tile.c
index fc8f39076..1e2f0022d 100644
--- a/navit/maptool/tile.c
+++ b/navit/maptool/tile.c
@@ -50,643 +50,622 @@ GList *aux_tile_list;
struct tile_head *tile_head_root;
GHashTable *strings_hash,*tile_hash,*tile_hash2;
-static char* string_hash_lookup( const char* key )
-{
- char* key_ptr = NULL;
+static char* string_hash_lookup( const char* key ) {
+ char* key_ptr = NULL;
- if ( strings_hash == NULL ) {
- strings_hash = g_hash_table_new(g_str_hash, g_str_equal);
- }
+ if ( strings_hash == NULL ) {
+ strings_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ }
- if ( ( key_ptr = g_hash_table_lookup(strings_hash, key )) == NULL ) {
- key_ptr = g_strdup( key );
- g_hash_table_insert(strings_hash, key_ptr, (gpointer)key_ptr );
+ if ( ( key_ptr = g_hash_table_lookup(strings_hash, key )) == NULL ) {
+ key_ptr = g_strdup( key );
+ g_hash_table_insert(strings_hash, key_ptr, (gpointer)key_ptr );
- }
- return key_ptr;
+ }
+ return key_ptr;
}
-static char** th_get_subtile( const struct tile_head* th, int idx )
-{
- char* subtile_ptr = NULL;
- subtile_ptr = (char*)th + sizeof( struct tile_head ) + idx * sizeof( char *);
- return (char**)subtile_ptr;
+static char** th_get_subtile( const struct tile_head* th, int idx ) {
+ char* subtile_ptr = NULL;
+ subtile_ptr = (char*)th + sizeof( struct tile_head ) + idx * sizeof( char *);
+ return (char**)subtile_ptr;
}
int
-tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr)
-{
- int x0,x2,x4;
- int y0,y2,y4;
- int xo,yo;
- int i;
- struct rect rr=*r;
-
- x0=world_bbox.l.x;
- y0=world_bbox.l.y;
- x4=world_bbox.h.x;
- y4=world_bbox.h.y;
-
- if(rr.l.x<x0)
- rr.l.x=x0;
- if(rr.h.x<x0)
- rr.h.x=x0;
- if(rr.l.y<y0)
- rr.l.y=y0;
- if(rr.h.y<y0)
- rr.h.y=y0;
- if(rr.l.x>x4)
- rr.l.x=x4;
- if(rr.h.x>x4)
- rr.h.x=x4;
- if(rr.l.y>y4)
- rr.l.y=y4;
- if(rr.h.y>y4)
- rr.h.y=y4;
-
- for (i = 0 ; i < max ; i++) {
- x2=(x0+x4)/2;
- y2=(y0+y4)/2;
- xo=(x4-x0)*overlap/100;
- yo=(y4-y0)*overlap/100;
- if ( contains_bbox(x0,y0,x2+xo,y2+yo,&rr)) {
- strcat(ret,"d");
- x4=x2+xo;
- y4=y2+yo;
- } else if (contains_bbox(x2-xo,y0,x4,y2+yo,&rr)) {
- strcat(ret,"c");
- x0=x2-xo;
- y4=y2+yo;
- } else if (contains_bbox(x0,y2-yo,x2+xo,y4,&rr)) {
- strcat(ret,"b");
- x4=x2+xo;
- y0=y2-yo;
- } else if (contains_bbox(x2-xo,y2-yo,x4,y4,&rr)) {
- strcat(ret,"a");
- x0=x2-xo;
- y0=y2-yo;
- } else
- break;
- }
- if (tr) {
- tr->l.x=x0;
- tr->l.y=y0;
- tr->h.x=x4;
- tr->h.y=y4;
- }
- if (suffix)
- strcat(ret,suffix);
- return i;
+tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr) {
+ int x0,x2,x4;
+ int y0,y2,y4;
+ int xo,yo;
+ int i;
+ struct rect rr=*r;
+
+ x0=world_bbox.l.x;
+ y0=world_bbox.l.y;
+ x4=world_bbox.h.x;
+ y4=world_bbox.h.y;
+
+ if(rr.l.x<x0)
+ rr.l.x=x0;
+ if(rr.h.x<x0)
+ rr.h.x=x0;
+ if(rr.l.y<y0)
+ rr.l.y=y0;
+ if(rr.h.y<y0)
+ rr.h.y=y0;
+ if(rr.l.x>x4)
+ rr.l.x=x4;
+ if(rr.h.x>x4)
+ rr.h.x=x4;
+ if(rr.l.y>y4)
+ rr.l.y=y4;
+ if(rr.h.y>y4)
+ rr.h.y=y4;
+
+ for (i = 0 ; i < max ; i++) {
+ x2=(x0+x4)/2;
+ y2=(y0+y4)/2;
+ xo=(x4-x0)*overlap/100;
+ yo=(y4-y0)*overlap/100;
+ if ( contains_bbox(x0,y0,x2+xo,y2+yo,&rr)) {
+ strcat(ret,"d");
+ x4=x2+xo;
+ y4=y2+yo;
+ } else if (contains_bbox(x2-xo,y0,x4,y2+yo,&rr)) {
+ strcat(ret,"c");
+ x0=x2-xo;
+ y4=y2+yo;
+ } else if (contains_bbox(x0,y2-yo,x2+xo,y4,&rr)) {
+ strcat(ret,"b");
+ x4=x2+xo;
+ y0=y2-yo;
+ } else if (contains_bbox(x2-xo,y2-yo,x4,y4,&rr)) {
+ strcat(ret,"a");
+ x0=x2-xo;
+ y0=y2-yo;
+ } else
+ break;
+ }
+ if (tr) {
+ tr->l.x=x0;
+ tr->l.y=y0;
+ tr->h.x=x4;
+ tr->h.y=y4;
+ }
+ if (suffix)
+ strcat(ret,suffix);
+ return i;
}
void
-tile_bbox(char *tile, struct rect *r, int overlap)
-{
- struct coord c;
- int xo,yo;
- *r=world_bbox;
- while (*tile) {
- c.x=(r->l.x+r->h.x)/2;
- c.y=(r->l.y+r->h.y)/2;
- xo=(r->h.x-r->l.x)*overlap/100;
- yo=(r->h.y-r->l.y)*overlap/100;
- switch (*tile) {
- case 'a':
- r->l.x=c.x-xo;
- r->l.y=c.y-yo;
- break;
- case 'b':
- r->h.x=c.x+xo;
- r->l.y=c.y-yo;
- break;
- case 'c':
- r->l.x=c.x-xo;
- r->h.y=c.y+yo;
- break;
- case 'd':
- r->h.x=c.x+xo;
- r->h.y=c.y+yo;
- break;
- }
- tile++;
- }
+tile_bbox(char *tile, struct rect *r, int overlap) {
+ struct coord c;
+ int xo,yo;
+ *r=world_bbox;
+ while (*tile) {
+ c.x=(r->l.x+r->h.x)/2;
+ c.y=(r->l.y+r->h.y)/2;
+ xo=(r->h.x-r->l.x)*overlap/100;
+ yo=(r->h.y-r->l.y)*overlap/100;
+ switch (*tile) {
+ case 'a':
+ r->l.x=c.x-xo;
+ r->l.y=c.y-yo;
+ break;
+ case 'b':
+ r->h.x=c.x+xo;
+ r->l.y=c.y-yo;
+ break;
+ case 'c':
+ r->l.x=c.x-xo;
+ r->h.y=c.y+yo;
+ break;
+ case 'd':
+ r->h.x=c.x+xo;
+ r->h.y=c.y+yo;
+ break;
+ }
+ tile++;
+ }
}
int
-tile_len(char *tile)
-{
- int ret=0;
- while (tile[0] >= 'a' && tile[0] <= 'd') {
- tile++;
- ret++;
- }
- return ret;
+tile_len(char *tile) {
+ int ret=0;
+ while (tile[0] >= 'a' && tile[0] <= 'd') {
+ tile++;
+ ret++;
+ }
+ return ret;
}
static void
-tile_extend(char *tile, struct item_bin *ib, GList **tiles_list)
-{
- struct tile_head *th=NULL;
- if (debug_tile(tile))
- fprintf(stderr,"Tile:Writing %d bytes to '%s' (%p,%p) 0x%x "LONGLONG_FMT"\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type, item_bin_get_id(ib));
- if (tile_hash2)
- th=g_hash_table_lookup(tile_hash2, tile);
- if (!th)
- th=g_hash_table_lookup(tile_hash, tile);
- if (! th) {
- th=g_malloc(sizeof(struct tile_head)+ sizeof( char* ) );
- // strcpy(th->subtiles, tile);
- th->num_subtiles=1;
- th->total_size=0;
- th->total_size_used=0;
- th->zipnum=0;
- th->zip_data=NULL;
- th->name=string_hash_lookup(tile);
- *th_get_subtile( th, 0 ) = th->name;
-
- if (tile_hash2)
- g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th);
- if (tiles_list)
- *tiles_list=g_list_append(*tiles_list, string_hash_lookup( th->name ) );
- processed_tiles++;
- if (debug_tile(tile))
- fprintf(stderr,"new '%s'\n", tile);
- }
- th->total_size+=ib->len*4+4;
- if (debug_tile(tile))
- fprintf(stderr,"New total size of %s(%p):%d\n", th->name, th, th->total_size);
- g_hash_table_insert(tile_hash, string_hash_lookup( th->name ), th);
+tile_extend(char *tile, struct item_bin *ib, GList **tiles_list) {
+ struct tile_head *th=NULL;
+ if (debug_tile(tile))
+ fprintf(stderr,"Tile:Writing %d bytes to '%s' (%p,%p) 0x%x "LONGLONG_FMT"\n", (ib->len+1)*4, tile,
+ g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type,
+ item_bin_get_id(ib));
+ if (tile_hash2)
+ th=g_hash_table_lookup(tile_hash2, tile);
+ if (!th)
+ th=g_hash_table_lookup(tile_hash, tile);
+ if (! th) {
+ th=g_malloc(sizeof(struct tile_head)+ sizeof( char* ) );
+ // strcpy(th->subtiles, tile);
+ th->num_subtiles=1;
+ th->total_size=0;
+ th->total_size_used=0;
+ th->zipnum=0;
+ th->zip_data=NULL;
+ th->name=string_hash_lookup(tile);
+ *th_get_subtile( th, 0 ) = th->name;
+
+ if (tile_hash2)
+ g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th);
+ if (tiles_list)
+ *tiles_list=g_list_append(*tiles_list, string_hash_lookup( th->name ) );
+ processed_tiles++;
+ if (debug_tile(tile))
+ fprintf(stderr,"new '%s'\n", tile);
+ }
+ th->total_size+=ib->len*4+4;
+ if (debug_tile(tile))
+ fprintf(stderr,"New total size of %s(%p):%d\n", th->name, th, th->total_size);
+ g_hash_table_insert(tile_hash, string_hash_lookup( th->name ), th);
}
static int
-tile_data_size(char *tile)
-{
- struct tile_head *th;
- th=g_hash_table_lookup(tile_hash, tile);
- if (! th)
- return 0;
- return th->total_size;
+tile_data_size(char *tile) {
+ struct tile_head *th;
+ th=g_hash_table_lookup(tile_hash, tile);
+ if (! th)
+ return 0;
+ return th->total_size;
}
static int
-merge_tile(char *base, char *sub)
-{
- struct tile_head *thb, *ths;
- thb=g_hash_table_lookup(tile_hash, base);
- ths=g_hash_table_lookup(tile_hash, sub);
- if (! ths)
- return 0;
- if (debug_tile(base) || debug_tile(sub))
- fprintf(stderr,"merging '%s'(%p) (%d) with '%s'(%p) (%d)\n", base, thb, thb ? thb->total_size : 0, sub, ths, ths->total_size);
- if (! thb) {
- thb=ths;
- g_hash_table_remove(tile_hash, sub);
- thb->name=string_hash_lookup(base);
- g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb);
-
- } else {
- thb=g_realloc(thb, sizeof(struct tile_head)+( ths->num_subtiles+thb->num_subtiles ) * sizeof( char*) );
- memcpy( th_get_subtile( thb, thb->num_subtiles ), th_get_subtile( ths, 0 ), ths->num_subtiles * sizeof( char*) );
- thb->num_subtiles+=ths->num_subtiles;
- thb->total_size+=ths->total_size;
- g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb);
- g_hash_table_remove(tile_hash, sub);
- g_free(ths);
- }
- return 1;
+merge_tile(char *base, char *sub) {
+ struct tile_head *thb, *ths;
+ thb=g_hash_table_lookup(tile_hash, base);
+ ths=g_hash_table_lookup(tile_hash, sub);
+ if (! ths)
+ return 0;
+ if (debug_tile(base) || debug_tile(sub))
+ fprintf(stderr,"merging '%s'(%p) (%d) with '%s'(%p) (%d)\n", base, thb, thb ? thb->total_size : 0, sub, ths,
+ ths->total_size);
+ if (! thb) {
+ thb=ths;
+ g_hash_table_remove(tile_hash, sub);
+ thb->name=string_hash_lookup(base);
+ g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb);
+
+ } else {
+ thb=g_realloc(thb, sizeof(struct tile_head)+( ths->num_subtiles+thb->num_subtiles ) * sizeof( char*) );
+ memcpy( th_get_subtile( thb, thb->num_subtiles ), th_get_subtile( ths, 0 ), ths->num_subtiles * sizeof( char*) );
+ thb->num_subtiles+=ths->num_subtiles;
+ thb->total_size+=ths->total_size;
+ g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb);
+ g_hash_table_remove(tile_hash, sub);
+ g_free(ths);
+ }
+ return 1;
}
static gint
-get_tiles_list_cmp(gconstpointer s1, gconstpointer s2)
-{
- return strcmp((char *)s1, (char *)s2);
+get_tiles_list_cmp(gconstpointer s1, gconstpointer s2) {
+ return strcmp((char *)s1, (char *)s2);
}
static void
-get_tiles_list_func(char *key, struct tile_head *th, GList **list)
-{
- *list=g_list_prepend(*list, key);
+get_tiles_list_func(char *key, struct tile_head *th, GList **list) {
+ *list=g_list_prepend(*list, key);
}
static GList *
-get_tiles_list(void)
-{
- GList *ret=NULL;
- g_hash_table_foreach(tile_hash, (GHFunc)get_tiles_list_func, &ret);
- ret=g_list_sort(ret, get_tiles_list_cmp);
- return ret;
+get_tiles_list(void) {
+ GList *ret=NULL;
+ g_hash_table_foreach(tile_hash, (GHFunc)get_tiles_list_func, &ret);
+ ret=g_list_sort(ret, get_tiles_list_cmp);
+ return ret;
}
#if 0
static void
-write_tile(char *key, struct tile_head *th, gpointer dummy)
-{
- FILE *f;
- char buffer[1024];
- fprintf(stderr,"DEBUG: Writing %s\n", key);
- strcpy(buffer,"tiles/");
- strcat(buffer,key);
+write_tile(char *key, struct tile_head *th, gpointer dummy) {
+ FILE *f;
+ char buffer[1024];
+ fprintf(stderr,"DEBUG: Writing %s\n", key);
+ strcpy(buffer,"tiles/");
+ strcat(buffer,key);
#if 0
- strcat(buffer,".bin");
+ strcat(buffer,".bin");
#endif
- f=fopen(buffer, "wb+");
- while (th) {
- fwrite(th->data, th->size, 1, f);
- th=th->next;
- }
- fclose(f);
+ f=fopen(buffer, "wb+");
+ while (th) {
+ fwrite(th->data, th->size, 1, f);
+ th=th->next;
+ }
+ fclose(f);
}
#endif
static void
-write_item(char *tile, struct item_bin *ib, FILE *reference)
-{
- struct tile_head *th;
- int size;
-
- th=g_hash_table_lookup(tile_hash2, tile);
- if (debug_itembin(ib)) {
- fprintf(stderr,"tile head %p\n",th);
- }
- if (! th)
- th=g_hash_table_lookup(tile_hash, tile);
- if (th) {
- if (debug_itembin(ib)) {
- fprintf(stderr,"Match %s %d %s\n",tile,th->process,th->name);
- dump_itembin(ib);
- }
- if (th->process != 0 && th->process != 1) {
- fprintf(stderr,"error with tile '%s' of length %d\n", tile, (int)strlen(tile));
- abort();
- }
- if (! th->process) {
- if (reference)
- fseek(reference, 8, SEEK_CUR);
- return;
- }
- if (debug_tile(tile))
- fprintf(stderr,"Data:Writing %d bytes to '%s' (%p,%p) 0x%x\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type);
- size=(ib->len+1)*4;
- if (th->total_size_used+size > th->total_size) {
- fprintf(stderr,"Overflow in tile %s (used %d max %d item %d)\n", tile, th->total_size_used, th->total_size, size);
- exit(1);
- return;
- }
- if (reference) {
- int offset=th->total_size_used/4;
- dbg_assert(fwrite(&th->zipnum, sizeof(th->zipnum), 1, reference)==1);
- dbg_assert(fwrite(&offset, sizeof(th->total_size_used), 1, reference)==1);
- }
- if (th->zip_data)
- memcpy(th->zip_data+th->total_size_used, ib, size);
- th->total_size_used+=size;
- } else {
- fprintf(stderr,"no tile hash found for %s\n", tile);
- exit(1);
- }
+write_item(char *tile, struct item_bin *ib, FILE *reference) {
+ struct tile_head *th;
+ int size;
+
+ th=g_hash_table_lookup(tile_hash2, tile);
+ if (debug_itembin(ib)) {
+ fprintf(stderr,"tile head %p\n",th);
+ }
+ if (! th)
+ th=g_hash_table_lookup(tile_hash, tile);
+ if (th) {
+ if (debug_itembin(ib)) {
+ fprintf(stderr,"Match %s %d %s\n",tile,th->process,th->name);
+ dump_itembin(ib);
+ }
+ if (th->process != 0 && th->process != 1) {
+ fprintf(stderr,"error with tile '%s' of length %d\n", tile, (int)strlen(tile));
+ abort();
+ }
+ if (! th->process) {
+ if (reference)
+ fseek(reference, 8, SEEK_CUR);
+ return;
+ }
+ if (debug_tile(tile))
+ fprintf(stderr,"Data:Writing %d bytes to '%s' (%p,%p) 0x%x\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash,
+ tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type);
+ size=(ib->len+1)*4;
+ if (th->total_size_used+size > th->total_size) {
+ fprintf(stderr,"Overflow in tile %s (used %d max %d item %d)\n", tile, th->total_size_used, th->total_size, size);
+ exit(1);
+ return;
+ }
+ if (reference) {
+ int offset=th->total_size_used/4;
+ dbg_assert(fwrite(&th->zipnum, sizeof(th->zipnum), 1, reference)==1);
+ dbg_assert(fwrite(&offset, sizeof(th->total_size_used), 1, reference)==1);
+ }
+ if (th->zip_data)
+ memcpy(th->zip_data+th->total_size_used, ib, size);
+ th->total_size_used+=size;
+ } else {
+ fprintf(stderr,"no tile hash found for %s\n", tile);
+ exit(1);
+ }
}
void
-tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name)
-{
- if (info->write)
- write_item(name, ib, reference);
- else
- tile_extend(name, ib, info->tiles_list);
+tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name) {
+ if (info->write)
+ write_item(name, ib, reference);
+ else
+ tile_extend(name, ib, info->tiles_list);
}
void
-tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max)
-{
- struct rect r;
- char buffer[1024];
- bbox((struct coord *)(ib+1), ib->clen/2, &r);
- buffer[0]='\0';
- tile(&r, info->suffix, buffer, max, overlap, NULL);
- tile_write_item_to_tile(info, ib, reference, buffer);
+tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max) {
+ struct rect r;
+ char buffer[1024];
+ bbox((struct coord *)(ib+1), ib->clen/2, &r);
+ buffer[0]='\0';
+ tile(&r, info->suffix, buffer, max, overlap, NULL);
+ tile_write_item_to_tile(info, ib, reference, buffer);
}
int
-add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size)
-{
- struct aux_tile *at;
- GList *l;
- l=aux_tile_list;
- while (l) {
- at=l->data;
- if (!strcmp(at->name, name)) {
- return -1;
- }
- l=g_list_next(l);
- }
- at=g_new0(struct aux_tile, 1);
- at->name=g_strdup(name);
- at->filename=g_strdup(filename);
- at->size=size;
- aux_tile_list=g_list_append(aux_tile_list, at);
- fprintf(stderr,"Adding %s as %s\n",filename, name);
- return zip_add_member(zip_info);
+add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size) {
+ struct aux_tile *at;
+ GList *l;
+ l=aux_tile_list;
+ while (l) {
+ at=l->data;
+ if (!strcmp(at->name, name)) {
+ return -1;
+ }
+ l=g_list_next(l);
+ }
+ at=g_new0(struct aux_tile, 1);
+ at->name=g_strdup(name);
+ at->filename=g_strdup(filename);
+ at->size=size;
+ aux_tile_list=g_list_append(aux_tile_list, at);
+ fprintf(stderr,"Adding %s as %s\n",filename, name);
+ return zip_add_member(zip_info);
}
int
-write_aux_tiles(struct zip_info *zip_info)
-{
- GList *l=aux_tile_list;
- struct aux_tile *at;
- char *buffer;
- FILE *f;
- int count=0;
-
- while (l) {
- at=l->data;
- buffer=g_malloc(at->size);
- f=fopen(at->filename,"rb");
- assert(f != NULL);
-
- if (fread(buffer, at->size, 1, f) == 0){
- dbg(lvl_warning, "fread failed");
- fclose(f);
- } else {
- fclose(f);
- write_zipmember(zip_info, at->name, zip_get_maxnamelen(zip_info), buffer, at->size);
- count++;
- l=g_list_next(l);
- zip_add_member(zip_info);
- }
- g_free(buffer);
- }
- return count;
+write_aux_tiles(struct zip_info *zip_info) {
+ GList *l=aux_tile_list;
+ struct aux_tile *at;
+ char *buffer;
+ FILE *f;
+ int count=0;
+
+ while (l) {
+ at=l->data;
+ buffer=g_malloc(at->size);
+ f=fopen(at->filename,"rb");
+ assert(f != NULL);
+
+ if (fread(buffer, at->size, 1, f) == 0) {
+ dbg(lvl_warning, "fread failed");
+ fclose(f);
+ } else {
+ fclose(f);
+ write_zipmember(zip_info, at->name, zip_get_maxnamelen(zip_info), buffer, at->size);
+ count++;
+ l=g_list_next(l);
+ zip_add_member(zip_info);
+ }
+ g_free(buffer);
+ }
+ return count;
}
static int
-add_tile_hash(struct tile_head *th)
-{
- int idx,len,maxnamelen=0;
- char **data;
+add_tile_hash(struct tile_head *th) {
+ int idx,len,maxnamelen=0;
+ char **data;
- for( idx = 0; idx < th->num_subtiles; idx++ ) {
+ for( idx = 0; idx < th->num_subtiles; idx++ ) {
- data = th_get_subtile( th, idx );
+ data = th_get_subtile( th, idx );
- if (debug_tile(((char *)data)) || debug_tile(th->name)) {
- fprintf(stderr,"Parent for '%s' is '%s'\n", *data, th->name);
- }
+ if (debug_tile(((char *)data)) || debug_tile(th->name)) {
+ fprintf(stderr,"Parent for '%s' is '%s'\n", *data, th->name);
+ }
- g_hash_table_insert(tile_hash2, *data, th);
+ g_hash_table_insert(tile_hash2, *data, th);
- len = strlen( *data );
+ len = strlen( *data );
- if (len > maxnamelen) {
- maxnamelen=len;
- }
- }
- return maxnamelen;
+ if (len > maxnamelen) {
+ maxnamelen=len;
+ }
+ }
+ return maxnamelen;
}
int
-create_tile_hash(void)
-{
- struct tile_head *th;
- int len,maxnamelen=0;
-
- tile_hash2=g_hash_table_new(g_str_hash, g_str_equal);
- th=tile_head_root;
- while (th) {
- len=add_tile_hash(th);
- if (len > maxnamelen)
- maxnamelen=len;
- th=th->next;
- }
- return maxnamelen;
+create_tile_hash(void) {
+ struct tile_head *th;
+ int len,maxnamelen=0;
+
+ tile_hash2=g_hash_table_new(g_str_hash, g_str_equal);
+ th=tile_head_root;
+ while (th) {
+ len=add_tile_hash(th);
+ if (len > maxnamelen)
+ maxnamelen=len;
+ th=th->next;
+ }
+ return maxnamelen;
}
static void
-create_tile_hash_list(GList *list)
-{
- GList *next;
- struct tile_head *th;
-
- tile_hash2=g_hash_table_new(g_str_hash, g_str_equal);
-
- next=g_list_first(list);
- while (next) {
- th=g_hash_table_lookup(tile_hash, next->data);
- if (!th) {
- fprintf(stderr,"No tile found for '%s'\n", (char *)(next->data));
- }
- add_tile_hash(th);
- next=g_list_next(next);
- }
+create_tile_hash_list(GList *list) {
+ GList *next;
+ struct tile_head *th;
+
+ tile_hash2=g_hash_table_new(g_str_hash, g_str_equal);
+
+ next=g_list_first(list);
+ while (next) {
+ th=g_hash_table_lookup(tile_hash, next->data);
+ if (!th) {
+ fprintf(stderr,"No tile found for '%s'\n", (char *)(next->data));
+ }
+ add_tile_hash(th);
+ next=g_list_next(next);
+ }
}
void
-load_tilesdir(FILE *in)
-{
- char tile[32],subtile[32],c;
- int size,zipnum=0;
- struct tile_head **last;
- create_tile_hash();
- tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
- last=&tile_head_root;
- while (fscanf(in,"%[^:]:%d",tile,&size) == 2) {
- struct tile_head *th=g_malloc(sizeof(struct tile_head));
- if (!strcmp(tile,"index"))
- tile[0]='\0';
- th->num_subtiles=0;
- th->total_size=size;
- th->total_size_used=0;
- th->zipnum=zipnum++;
- th->zip_data=NULL;
- th->name=string_hash_lookup(tile);
- while (fscanf(in,":%[^:\n]",subtile) == 1) {
- th=g_realloc(th, sizeof(struct tile_head)+(th->num_subtiles+1)*sizeof(char*));
- *th_get_subtile( th, th->num_subtiles ) = string_hash_lookup(subtile);
- th->num_subtiles++;
- }
- *last=th;
- last=&th->next;
- add_tile_hash(th);
- g_hash_table_insert(tile_hash, th->name, th);
- if (fread(&c, 1, 1, in) != 1 || c != '\n') {
- printf("syntax error\n");
- }
- }
- *last=NULL;
+load_tilesdir(FILE *in) {
+ char tile[32],subtile[32],c;
+ int size,zipnum=0;
+ struct tile_head **last;
+ create_tile_hash();
+ tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ last=&tile_head_root;
+ while (fscanf(in,"%[^:]:%d",tile,&size) == 2) {
+ struct tile_head *th=g_malloc(sizeof(struct tile_head));
+ if (!strcmp(tile,"index"))
+ tile[0]='\0';
+ th->num_subtiles=0;
+ th->total_size=size;
+ th->total_size_used=0;
+ th->zipnum=zipnum++;
+ th->zip_data=NULL;
+ th->name=string_hash_lookup(tile);
+ while (fscanf(in,":%[^:\n]",subtile) == 1) {
+ th=g_realloc(th, sizeof(struct tile_head)+(th->num_subtiles+1)*sizeof(char*));
+ *th_get_subtile( th, th->num_subtiles ) = string_hash_lookup(subtile);
+ th->num_subtiles++;
+ }
+ *last=th;
+ last=&th->next;
+ add_tile_hash(th);
+ g_hash_table_insert(tile_hash, th->name, th);
+ if (fread(&c, 1, 1, in) != 1 || c != '\n') {
+ printf("syntax error\n");
+ }
+ }
+ *last=NULL;
}
void
-write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out)
-{
- int idx,len,maxlen;
- GList *next,*tiles_list;
- char **data;
- struct tile_head *th,**last=NULL;
-
- tiles_list=get_tiles_list();
- info->tiles_list=&tiles_list;
- if (! info->write)
- create_tile_hash_list(tiles_list);
- next=g_list_first(tiles_list);
- last=&tile_head_root;
- maxlen=info->maxlen;
- if (! maxlen) {
- while (next) {
- if (strlen(next->data) > maxlen)
- maxlen=strlen(next->data);
- next=g_list_next(next);
- }
- }
- len=maxlen;
- while (len >= 0) {
- next=g_list_first(tiles_list);
- while (next) {
- if (strlen(next->data) == len) {
- th=g_hash_table_lookup(tile_hash, next->data);
- if (!info->write) {
- *last=th;
- last=&th->next;
- th->next=NULL;
- th->zipnum=zip_get_zipnum(zip_info);
- fprintf(out,"%s:%d",strlen((char *)next->data)?(char *)next->data:"index",th->total_size);
-
- for ( idx = 0; idx< th->num_subtiles; idx++ ){
- data= th_get_subtile( th, idx );
- fprintf(out,":%s", *data);
- }
-
- fprintf(out,"\n");
- }
- if (th->name[strlen(info->suffix)])
- index_submap_add(info, th);
- zip_add_member(zip_info);
- processed_tiles++;
- }
- next=g_list_next(next);
- }
- len--;
- }
- g_list_free(tiles_list);
- if (info->suffix[0] && info->write) {
- struct item_bin *item_bin=init_item(type_submap);
- item_bin_add_coord_rect(item_bin, &world_bbox);
- item_bin_add_attr_range(item_bin, attr_order, 0, 255);
- item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_get_zipnum(zip_info)-1);
- item_bin_write(item_bin, zip_get_index(zip_info));
- }
+write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out) {
+ int idx,len,maxlen;
+ GList *next,*tiles_list;
+ char **data;
+ struct tile_head *th,**last=NULL;
+
+ tiles_list=get_tiles_list();
+ info->tiles_list=&tiles_list;
+ if (! info->write)
+ create_tile_hash_list(tiles_list);
+ next=g_list_first(tiles_list);
+ last=&tile_head_root;
+ maxlen=info->maxlen;
+ if (! maxlen) {
+ while (next) {
+ if (strlen(next->data) > maxlen)
+ maxlen=strlen(next->data);
+ next=g_list_next(next);
+ }
+ }
+ len=maxlen;
+ while (len >= 0) {
+ next=g_list_first(tiles_list);
+ while (next) {
+ if (strlen(next->data) == len) {
+ th=g_hash_table_lookup(tile_hash, next->data);
+ if (!info->write) {
+ *last=th;
+ last=&th->next;
+ th->next=NULL;
+ th->zipnum=zip_get_zipnum(zip_info);
+ fprintf(out,"%s:%d",strlen((char *)next->data)?(char *)next->data:"index",th->total_size);
+
+ for ( idx = 0; idx< th->num_subtiles; idx++ ) {
+ data= th_get_subtile( th, idx );
+ fprintf(out,":%s", *data);
+ }
+
+ fprintf(out,"\n");
+ }
+ if (th->name[strlen(info->suffix)])
+ index_submap_add(info, th);
+ zip_add_member(zip_info);
+ processed_tiles++;
+ }
+ next=g_list_next(next);
+ }
+ len--;
+ }
+ g_list_free(tiles_list);
+ if (info->suffix[0] && info->write) {
+ struct item_bin *item_bin=init_item(type_submap);
+ item_bin_add_coord_rect(item_bin, &world_bbox);
+ item_bin_add_attr_range(item_bin, attr_order, 0, 255);
+ item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_get_zipnum(zip_info)-1);
+ item_bin_write(item_bin, zip_get_index(zip_info));
+ }
}
void
-merge_tiles(struct tile_info *info)
-{
- struct tile_head *th;
- char basetile[1024];
- char subtile[1024];
- GList *tiles_list_sorted,*last;
- int i,i_min,len,size_all,size[5],size_min,work_done;
- long long zip_size;
-
- do {
- tiles_list_sorted=get_tiles_list();
- fprintf(stderr,"PROGRESS: sorting %d tiles\n", g_list_length(tiles_list_sorted));
- tiles_list_sorted=g_list_sort(tiles_list_sorted, (GCompareFunc)strcmp);
- fprintf(stderr,"PROGRESS: sorting %d tiles done\n", g_list_length(tiles_list_sorted));
- last=g_list_last(tiles_list_sorted);
- zip_size=0;
- while (last) {
- th=g_hash_table_lookup(tile_hash, last->data);
- zip_size+=th->total_size;
- last=g_list_previous(last);
- }
- last=g_list_last(tiles_list_sorted);
- work_done=0;
- while (last) {
- processed_tiles++;
- len=tile_len(last->data);
- if (len >= 1) {
- strcpy(basetile,last->data);
- basetile[len-1]='\0';
- strcat(basetile, info->suffix);
- strcpy(subtile,last->data);
- for (i = 0 ; i < 4 ; i++) {
- subtile[len-1]='a'+i;
- size[i]=tile_data_size(subtile);
- }
- size[4]=tile_data_size(basetile);
- size_all=size[0]+size[1]+size[2]+size[3]+size[4];
- if (size_all < 65536 && size_all > 0 && size_all != size[4]) {
- for (i = 0 ; i < 4 ; i++) {
- subtile[len-1]='a'+i;
- work_done+=merge_tile(basetile, subtile);
- }
- } else {
- for (;;) {
- size_min=size_all;
- i_min=-1;
- for (i = 0 ; i < 4 ; i++) {
- if (size[i] && size[i] < size_min) {
- size_min=size[i];
- i_min=i;
- }
- }
- if (i_min == -1)
- break;
- if (size[4]+size_min >= 65536)
- break;
- subtile[len-1]='a'+i_min;
- work_done+=merge_tile(basetile, subtile);
- size[4]+=size[i_min];
- size[i_min]=0;
- }
- }
- }
- last=g_list_previous(last);
- }
- g_list_free(tiles_list_sorted);
- fprintf(stderr,"PROGRESS: merged %d tiles\n", work_done);
- } while (work_done);
+merge_tiles(struct tile_info *info) {
+ struct tile_head *th;
+ char basetile[1024];
+ char subtile[1024];
+ GList *tiles_list_sorted,*last;
+ int i,i_min,len,size_all,size[5],size_min,work_done;
+ long long zip_size;
+
+ do {
+ tiles_list_sorted=get_tiles_list();
+ fprintf(stderr,"PROGRESS: sorting %d tiles\n", g_list_length(tiles_list_sorted));
+ tiles_list_sorted=g_list_sort(tiles_list_sorted, (GCompareFunc)strcmp);
+ fprintf(stderr,"PROGRESS: sorting %d tiles done\n", g_list_length(tiles_list_sorted));
+ last=g_list_last(tiles_list_sorted);
+ zip_size=0;
+ while (last) {
+ th=g_hash_table_lookup(tile_hash, last->data);
+ zip_size+=th->total_size;
+ last=g_list_previous(last);
+ }
+ last=g_list_last(tiles_list_sorted);
+ work_done=0;
+ while (last) {
+ processed_tiles++;
+ len=tile_len(last->data);
+ if (len >= 1) {
+ strcpy(basetile,last->data);
+ basetile[len-1]='\0';
+ strcat(basetile, info->suffix);
+ strcpy(subtile,last->data);
+ for (i = 0 ; i < 4 ; i++) {
+ subtile[len-1]='a'+i;
+ size[i]=tile_data_size(subtile);
+ }
+ size[4]=tile_data_size(basetile);
+ size_all=size[0]+size[1]+size[2]+size[3]+size[4];
+ if (size_all < 65536 && size_all > 0 && size_all != size[4]) {
+ for (i = 0 ; i < 4 ; i++) {
+ subtile[len-1]='a'+i;
+ work_done+=merge_tile(basetile, subtile);
+ }
+ } else {
+ for (;;) {
+ size_min=size_all;
+ i_min=-1;
+ for (i = 0 ; i < 4 ; i++) {
+ if (size[i] && size[i] < size_min) {
+ size_min=size[i];
+ i_min=i;
+ }
+ }
+ if (i_min == -1)
+ break;
+ if (size[4]+size_min >= 65536)
+ break;
+ subtile[len-1]='a'+i_min;
+ work_done+=merge_tile(basetile, subtile);
+ size[4]+=size[i_min];
+ size[i_min]=0;
+ }
+ }
+ }
+ last=g_list_previous(last);
+ }
+ g_list_free(tiles_list_sorted);
+ fprintf(stderr,"PROGRESS: merged %d tiles\n", work_done);
+ } while (work_done);
}
struct attr map_information_attrs[32];
void
-index_init(struct zip_info *info, int version)
-{
- struct item_bin *item_bin;
- int i;
- map_information_attrs[0].type=attr_version;
- map_information_attrs[0].u.num=version;
- item_bin=init_item(type_map_information);
- for (i = 0 ; i < 32 ; i++) {
- if (!map_information_attrs[i].type)
- break;
- item_bin_add_attr(item_bin, &map_information_attrs[i]);
- }
- item_bin_write(item_bin, zip_get_index(info));
+index_init(struct zip_info *info, int version) {
+ struct item_bin *item_bin;
+ int i;
+ map_information_attrs[0].type=attr_version;
+ map_information_attrs[0].u.num=version;
+ item_bin=init_item(type_map_information);
+ for (i = 0 ; i < 32 ; i++) {
+ if (!map_information_attrs[i].type)
+ break;
+ item_bin_add_attr(item_bin, &map_information_attrs[i]);
+ }
+ item_bin_write(item_bin, zip_get_index(info));
}
void
-index_submap_add(struct tile_info *info, struct tile_head *th)
-{
- int tlen=tile_len(th->name);
- int len=tlen;
- char *index_tile;
- struct rect r;
- struct item_bin *item_bin;
-
- index_tile=g_alloca(len+1+strlen(info->suffix));
- strcpy(index_tile, th->name);
- if (len > 6)
- len=6;
- else
- len=0;
- index_tile[len]=0;
- strcat(index_tile, info->suffix);
- tile_bbox(th->name, &r, overlap);
-
- item_bin=init_item(type_submap);
- item_bin_add_coord_rect(item_bin, &r);
- item_bin_add_attr_range(item_bin, attr_order, (tlen > 4)?tlen-4 : 0, 255);
- item_bin_add_attr_int(item_bin, attr_zipfile_ref, th->zipnum);
- tile_write_item_to_tile(info, item_bin, NULL, index_tile);
+index_submap_add(struct tile_info *info, struct tile_head *th) {
+ int tlen=tile_len(th->name);
+ int len=tlen;
+ char *index_tile;
+ struct rect r;
+ struct item_bin *item_bin;
+
+ index_tile=g_alloca(len+1+strlen(info->suffix));
+ strcpy(index_tile, th->name);
+ if (len > 6)
+ len=6;
+ else
+ len=0;
+ index_tile[len]=0;
+ strcat(index_tile, info->suffix);
+ tile_bbox(th->name, &r, overlap);
+
+ item_bin=init_item(type_submap);
+ item_bin_add_coord_rect(item_bin, &r);
+ item_bin_add_attr_range(item_bin, attr_order, (tlen > 4)?tlen-4 : 0, 255);
+ item_bin_add_attr_int(item_bin, attr_zipfile_ref, th->zipnum);
+ tile_write_item_to_tile(info, item_bin, NULL, index_tile);
}
diff --git a/navit/maptool/zip.c b/navit/maptool/zip.c
index fa95c1674..33ca52eb1 100644
--- a/navit/maptool/zip.c
+++ b/navit/maptool/zip.c
@@ -26,342 +26,322 @@
#include "zipfile.h"
struct zip_info {
- int zipnum;
- int dir_size;
- long long offset;
- int compression_level;
- int maxnamelen;
- int zip64;
- short date;
- short time;
- FILE *res2;
- FILE *index;
- FILE *dir;
+ int zipnum;
+ int dir_size;
+ long long offset;
+ int compression_level;
+ int maxnamelen;
+ int zip64;
+ short date;
+ short time;
+ FILE *res2;
+ FILE *index;
+ FILE *dir;
};
static int
-zip_write(struct zip_info *info, void *data, int len)
-{
- if (fwrite(data, len, 1, info->res2) != 1)
- return 0;
- return 1;
+zip_write(struct zip_info *info, void *data, int len) {
+ if (fwrite(data, len, 1, info->res2) != 1)
+ return 0;
+ return 1;
}
#ifdef HAVE_ZLIB
static int
-compress2_int(Byte *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
-{
- z_stream stream;
- int err;
-
- stream.next_in = (Bytef*)source;
- stream.avail_in = (uInt)sourceLen;
- stream.next_out = dest;
- stream.avail_out = (uInt)*destLen;
- if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
-
- stream.zalloc = (alloc_func)0;
- stream.zfree = (free_func)0;
- stream.opaque = (voidpf)0;
-
- err = deflateInit2(&stream, level, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY);
- if (err != Z_OK) return err;
-
- err = deflate(&stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- deflateEnd(&stream);
- return err == Z_OK ? Z_BUF_ERROR : err;
- }
- *destLen = stream.total_out;
-
- err = deflateEnd(&stream);
- return err;
+compress2_int(Byte *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level) {
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+ stream.opaque = (voidpf)0;
+
+ err = deflateInit2(&stream, level, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY);
+ if (err != Z_OK) return err;
+
+ err = deflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ deflateEnd(&stream);
+ return err == Z_OK ? Z_BUF_ERROR : err;
+ }
+ *destLen = stream.total_out;
+
+ err = deflateEnd(&stream);
+ return err;
}
#endif
void
-write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size)
-{
- struct zip_lfh lfh = {
- 0x04034b50,
- 0x0a,
- 0x0,
- 0x0,
- zip_info->time,
- zip_info->date,
- 0x0,
- 0x0,
- 0x0,
- filelen,
- 0x0,
- };
- struct zip_cd cd = {
- 0x02014b50,
- 0x17,
- 0x00,
- 0x0a,
- 0x00,
- 0x0000,
- 0x0,
- zip_info->time,
- zip_info->date,
- 0x0,
- 0x0,
- 0x0,
- filelen,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0,
- zip_info->offset,
- };
- struct zip_cd_ext cd_ext = {
- 0x1,
- 0x8,
- zip_info->offset,
- };
- char *filename;
- int crc=0,len,comp_size=data_size;
- uLongf destlen=data_size+data_size/500+12;
- char *compbuffer;
-
- compbuffer = g_malloc(destlen);
- crc=crc32(0, NULL, 0);
- crc=crc32(crc, (unsigned char *)data, data_size);
- lfh.zipmthd=zip_info->compression_level ? 8:0;
+write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size) {
+ struct zip_lfh lfh = {
+ 0x04034b50,
+ 0x0a,
+ 0x0,
+ 0x0,
+ zip_info->time,
+ zip_info->date,
+ 0x0,
+ 0x0,
+ 0x0,
+ filelen,
+ 0x0,
+ };
+ struct zip_cd cd = {
+ 0x02014b50,
+ 0x17,
+ 0x00,
+ 0x0a,
+ 0x00,
+ 0x0000,
+ 0x0,
+ zip_info->time,
+ zip_info->date,
+ 0x0,
+ 0x0,
+ 0x0,
+ filelen,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0,
+ zip_info->offset,
+ };
+ struct zip_cd_ext cd_ext = {
+ 0x1,
+ 0x8,
+ zip_info->offset,
+ };
+ char *filename;
+ int crc=0,len,comp_size=data_size;
+ uLongf destlen=data_size+data_size/500+12;
+ char *compbuffer;
+
+ compbuffer = g_malloc(destlen);
+ crc=crc32(0, NULL, 0);
+ crc=crc32(crc, (unsigned char *)data, data_size);
+ lfh.zipmthd=zip_info->compression_level ? 8:0;
#ifdef HAVE_ZLIB
- if (zip_info->compression_level) {
- int error=compress2_int((Byte *)compbuffer, &destlen, (Bytef *)data, data_size, zip_info->compression_level);
- if (error == Z_OK) {
- if (destlen < data_size) {
- data=compbuffer;
- comp_size=destlen;
- } else
- lfh.zipmthd=0;
- } else {
- fprintf(stderr,"compress2 returned %d\n", error);
- }
- }
+ if (zip_info->compression_level) {
+ int error=compress2_int((Byte *)compbuffer, &destlen, (Bytef *)data, data_size, zip_info->compression_level);
+ if (error == Z_OK) {
+ if (destlen < data_size) {
+ data=compbuffer;
+ comp_size=destlen;
+ } else
+ lfh.zipmthd=0;
+ } else {
+ fprintf(stderr,"compress2 returned %d\n", error);
+ }
+ }
#endif
- lfh.zipcrc=crc;
- lfh.zipsize=comp_size;
- lfh.zipuncmp=data_size;
- cd.zipccrc=crc;
- cd.zipcsiz=lfh.zipsize;
- cd.zipcunc=data_size;
- cd.zipcmthd=lfh.zipmthd;
- if (zip_info->zip64) {
- cd.zipofst=0xffffffff;
- cd.zipcxtl+=sizeof(cd_ext);
- }
- filename=g_alloca(filelen+1);
- strcpy(filename, name);
- len=strlen(filename);
- while (len < filelen) {
- filename[len++]='_';
- }
- filename[filelen]='\0';
- zip_write(zip_info, &lfh, sizeof(lfh));
- zip_write(zip_info, filename, filelen);
- zip_info->offset+=sizeof(lfh)+filelen;
- zip_write(zip_info, data, comp_size);
- zip_info->offset+=comp_size;
- dbg_assert(fwrite(&cd, sizeof(cd), 1, zip_info->dir)==1);
- dbg_assert(fwrite(filename, filelen, 1, zip_info->dir)==1);
- zip_info->dir_size+=sizeof(cd)+filelen;
- if (zip_info->zip64) {
- dbg_assert(fwrite(&cd_ext, sizeof(cd_ext), 1, zip_info->dir)==1);
- zip_info->dir_size+=sizeof(cd_ext);
- }
-
- g_free(compbuffer);
+ lfh.zipcrc=crc;
+ lfh.zipsize=comp_size;
+ lfh.zipuncmp=data_size;
+ cd.zipccrc=crc;
+ cd.zipcsiz=lfh.zipsize;
+ cd.zipcunc=data_size;
+ cd.zipcmthd=lfh.zipmthd;
+ if (zip_info->zip64) {
+ cd.zipofst=0xffffffff;
+ cd.zipcxtl+=sizeof(cd_ext);
+ }
+ filename=g_alloca(filelen+1);
+ strcpy(filename, name);
+ len=strlen(filename);
+ while (len < filelen) {
+ filename[len++]='_';
+ }
+ filename[filelen]='\0';
+ zip_write(zip_info, &lfh, sizeof(lfh));
+ zip_write(zip_info, filename, filelen);
+ zip_info->offset+=sizeof(lfh)+filelen;
+ zip_write(zip_info, data, comp_size);
+ zip_info->offset+=comp_size;
+ dbg_assert(fwrite(&cd, sizeof(cd), 1, zip_info->dir)==1);
+ dbg_assert(fwrite(filename, filelen, 1, zip_info->dir)==1);
+ zip_info->dir_size+=sizeof(cd)+filelen;
+ if (zip_info->zip64) {
+ dbg_assert(fwrite(&cd_ext, sizeof(cd_ext), 1, zip_info->dir)==1);
+ zip_info->dir_size+=sizeof(cd_ext);
+ }
+
+ g_free(compbuffer);
}
int
-zip_write_index(struct zip_info *info)
-{
- int size=ftell(info->index);
- char *buffer;
-
- buffer=g_alloca(size);
- fseek(info->index, 0, SEEK_SET);
-
- if (fread(buffer, size, 1, info->index) == 0){
- dbg(lvl_warning, "fread failed");
- return 1;
- }
- else{
- write_zipmember(info, "index", strlen("index"), buffer, size);
- }
- info->zipnum++;
- return 0;
+zip_write_index(struct zip_info *info) {
+ int size=ftell(info->index);
+ char *buffer;
+
+ buffer=g_alloca(size);
+ fseek(info->index, 0, SEEK_SET);
+
+ if (fread(buffer, size, 1, info->index) == 0) {
+ dbg(lvl_warning, "fread failed");
+ return 1;
+ } else {
+ write_zipmember(info, "index", strlen("index"), buffer, size);
+ }
+ info->zipnum++;
+ return 0;
}
static void
-zip_write_file_data(struct zip_info *info, FILE *in)
-{
- size_t size;
- char buffer[4096];
- while ((size=fread(buffer, 1, 4096, in)))
- zip_write(info, buffer, size);
+zip_write_file_data(struct zip_info *info, FILE *in) {
+ size_t size;
+ char buffer[4096];
+ while ((size=fread(buffer, 1, 4096, in)))
+ zip_write(info, buffer, size);
}
int
-zip_write_directory(struct zip_info *info)
-{
- struct zip_eoc eoc = {
- 0x06054b50,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0000,
- 0x0,
- 0x0,
- 0x0,
- };
- struct zip64_eoc eoc64 = {
- 0x06064b50,
- 0x0,
- 0x0,
- 0x0403,
- 0x0,
- 0x0,
- 0x0,
- 0x0,
- 0x0,
- 0x0,
- };
- struct zip64_eocl eocl = {
- 0x07064b50,
- 0x0,
- 0x0,
- 0x0,
- };
-
- fseek(info->dir, 0, SEEK_SET);
- zip_write_file_data(info, info->dir);
- if (info->zip64) {
- eoc64.zip64esize=sizeof(eoc64)-12;
- eoc64.zip64enum=info->zipnum;
- eoc64.zip64ecenn=info->zipnum;
- eoc64.zip64ecsz=info->dir_size;
- eoc64.zip64eofst=info->offset;
- zip_write(info, &eoc64, sizeof(eoc64));
- eocl.zip64lofst=info->offset+info->dir_size;
- zip_write(info, &eocl, sizeof(eocl));
- }
- eoc.zipenum=info->zipnum;
- eoc.zipecenn=info->zipnum;
- eoc.zipecsz=info->dir_size;
- eoc.zipeofst=info->offset;
- zip_write(info, &eoc, sizeof(eoc));
- sig_alrm(0);
+zip_write_directory(struct zip_info *info) {
+ struct zip_eoc eoc = {
+ 0x06054b50,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0000,
+ 0x0,
+ 0x0,
+ 0x0,
+ };
+ struct zip64_eoc eoc64 = {
+ 0x06064b50,
+ 0x0,
+ 0x0,
+ 0x0403,
+ 0x0,
+ 0x0,
+ 0x0,
+ 0x0,
+ 0x0,
+ 0x0,
+ };
+ struct zip64_eocl eocl = {
+ 0x07064b50,
+ 0x0,
+ 0x0,
+ 0x0,
+ };
+
+ fseek(info->dir, 0, SEEK_SET);
+ zip_write_file_data(info, info->dir);
+ if (info->zip64) {
+ eoc64.zip64esize=sizeof(eoc64)-12;
+ eoc64.zip64enum=info->zipnum;
+ eoc64.zip64ecenn=info->zipnum;
+ eoc64.zip64ecsz=info->dir_size;
+ eoc64.zip64eofst=info->offset;
+ zip_write(info, &eoc64, sizeof(eoc64));
+ eocl.zip64lofst=info->offset+info->dir_size;
+ zip_write(info, &eocl, sizeof(eocl));
+ }
+ eoc.zipenum=info->zipnum;
+ eoc.zipecenn=info->zipnum;
+ eoc.zipecsz=info->dir_size;
+ eoc.zipeofst=info->offset;
+ zip_write(info, &eoc, sizeof(eoc));
+ sig_alrm(0);
#ifndef _WIN32
- alarm(0);
+ alarm(0);
#endif
- return 0;
+ return 0;
}
struct zip_info *
-zip_new(void)
-{
- return g_new0(struct zip_info, 1);
+zip_new(void) {
+ return g_new0(struct zip_info, 1);
}
void
-zip_set_zip64(struct zip_info *info, int on)
-{
- info->zip64=on;
+zip_set_zip64(struct zip_info *info, int on) {
+ info->zip64=on;
}
void
-zip_set_compression_level(struct zip_info *info, int level)
-{
- info->compression_level=level;
+zip_set_compression_level(struct zip_info *info, int level) {
+ info->compression_level=level;
}
void
-zip_set_maxnamelen(struct zip_info *info, int max)
-{
- info->maxnamelen=max;
+zip_set_maxnamelen(struct zip_info *info, int max) {
+ info->maxnamelen=max;
}
int
-zip_get_maxnamelen(struct zip_info *info)
-{
- return info->maxnamelen;
+zip_get_maxnamelen(struct zip_info *info) {
+ return info->maxnamelen;
}
int
-zip_add_member(struct zip_info *info)
-{
- return info->zipnum++;
+zip_add_member(struct zip_info *info) {
+ return info->zipnum++;
}
int
-zip_set_timestamp(struct zip_info *info, char *timestamp)
-{
- int year,month,day,hour,min,sec;
-
- if (sscanf(timestamp,"%d-%d-%dT%d:%d:%d",&year,&month,&day,&hour,&min,&sec) == 6) {
- info->date=day | (month << 5) | ((year-1980) << 9);
- info->time=(sec >> 1) | (min << 5) | (hour << 11);
- return 1;
- }
- return 0;
+zip_set_timestamp(struct zip_info *info, char *timestamp) {
+ int year,month,day,hour,min,sec;
+
+ if (sscanf(timestamp,"%d-%d-%dT%d:%d:%d",&year,&month,&day,&hour,&min,&sec) == 6) {
+ info->date=day | (month << 5) | ((year-1980) << 9);
+ info->time=(sec >> 1) | (min << 5) | (hour << 11);
+ return 1;
+ }
+ return 0;
}
int
-zip_open(struct zip_info *info, char *out, char *dir, char *index)
-{
- info->res2=fopen(out,"wb+");
- if(!info->res2) {
- fprintf(stderr,"Could not open output zip file %s\n", out);
- return 0;
- }
- info->dir=fopen(dir,"wb+");
- if(!info->dir) {
- fprintf(stderr,"Could not open zip directory %s\n", dir);
- return 0;
- }
- info->index=fopen(index,"wb+");
- if(!info->index) {
- fprintf(stderr,"Could not open index %s\n", index);
- return 0;
- }
- return 1;
+zip_open(struct zip_info *info, char *out, char *dir, char *index) {
+ info->res2=fopen(out,"wb+");
+ if(!info->res2) {
+ fprintf(stderr,"Could not open output zip file %s\n", out);
+ return 0;
+ }
+ info->dir=fopen(dir,"wb+");
+ if(!info->dir) {
+ fprintf(stderr,"Could not open zip directory %s\n", dir);
+ return 0;
+ }
+ info->index=fopen(index,"wb+");
+ if(!info->index) {
+ fprintf(stderr,"Could not open index %s\n", index);
+ return 0;
+ }
+ return 1;
}
FILE *
-zip_get_index(struct zip_info *info)
-{
- return info->index;
+zip_get_index(struct zip_info *info) {
+ return info->index;
}
int
-zip_get_zipnum(struct zip_info *info)
-{
- return info->zipnum;
+zip_get_zipnum(struct zip_info *info) {
+ return info->zipnum;
}
void
-zip_set_zipnum(struct zip_info *info, int num)
-{
- info->zipnum=num;
+zip_set_zipnum(struct zip_info *info, int num) {
+ info->zipnum=num;
}
void
-zip_close(struct zip_info *info)
-{
- fclose(info->index);
- fclose(info->dir);
- fclose(info->res2);
+zip_close(struct zip_info *info) {
+ fclose(info->index);
+ fclose(info->dir);
+ fclose(info->res2);
}
void
-zip_destroy(struct zip_info *info)
-{
- g_free(info);
+zip_destroy(struct zip_info *info) {
+ g_free(info);
}