{
int l;
l=strlen(buffer)+1;
- while (l % 4)
+ while (l % 4)
buffer[l++]='\0';
a->len=l/4+1;
}
if (! strcmp(k,"foot")) {
level=5;
}
- if (! strcmp(k,"note"))
+ if (! strcmp(k,"note"))
level=5;
if (! strcmp(k,"name")) {
if (in_way) {
sprintf(debug_attr_buffer+strlen(debug_attr_buffer), " %s=%s", k, v);
node_is_tagged=1;
}
- if (level < 6)
+ if (level < 6)
node_is_tagged=1;
if (level >= 5)
return;
- if (in_way)
+ if (in_way)
value_hash=g_hash_table_lookup(way_key_hash, k);
else
value_hash=g_hash_table_lookup(node_key_hash, k);
fprintf(stderr,"realloc of %d bytes failed\n",b->malloced);
exit(1);
}
-
+
}
int nodeid_last;
{
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++)
+ for (i = 0 ; i < count ; i++)
g_hash_table_insert(node_hash, (gpointer)(ni[i].id), (gpointer)i);
}
static void
add_node(int id, double lat, double lon)
{
- if (node_buffer.size + sizeof(struct node_item) > node_buffer.malloced)
+ if (node_buffer.size + sizeof(struct node_item) > node_buffer.malloced)
extend_buffer(&node_buffer);
node_is_tagged=0;
nodeid=id;
node_buffer_to_hash();
}
} else
- if (!g_hash_table_lookup(node_hash, (gpointer)(ni->id)))
+ if (!g_hash_table_lookup(node_hash, (gpointer)(ni->id)))
g_hash_table_insert(node_hash, (gpointer)(ni->id), (gpointer)(ni-(struct node_item *)node_buffer.base));
else {
node_buffer.size-=sizeof(struct node_item);
if (street_name_systematic_attr.len)
alen+=street_name_systematic_attr.len+1;
if (debug_attr.len)
- alen+=debug_attr.len+1;
+ alen+=debug_attr.len+1;
if (flags_attr.len)
- alen+=flags_attr.len+1;
+ alen+=flags_attr.len+1;
item.clen=coord_count*2;
item.len=item.clen+2+alen;
fwrite(&item, sizeof(item), 1, out);
return;
pad_text_attr(&debug_attr, debug_attr_buffer);
if (label_attr.len)
- alen+=label_attr.len+1;
+ alen+=label_attr.len+1;
if (debug_attr.len)
- alen+=debug_attr.len+1;
+ alen+=debug_attr.len+1;
item.clen=2;
item.len=item.clen+2+alen;
fwrite(&item, sizeof(item), 1, out);
} else {
len=strlen(p);
if (len > 0 && p[len-1]=='\n')
- p[len-1]='\0';
+ p[len-1]='\0';
fprintf(stderr,"WARNING: way %d: node %d not found (%s)\n",wayid,ref,p);
}
if (coord_count > 65536) {
static void
save_buffer(char *filename, struct buffer *b)
-{
+{
FILE *f;
f=fopen(filename,"wb+");
fwrite(b->base, b->size, 1, f);
load_buffer(char *filename, struct buffer *b)
{
FILE *f;
- if (b->base)
+ if (b->base)
free(b->base);
b->malloced=0;
f=fopen(filename,"rb");
} else if (!strncmp(p, "<osm ",5)) {
} else if (!strncmp(p, "<bound ",7)) {
} else if (!strncmp(p, "<node ",6)) {
- if (!parse_node(p))
+ if (!parse_node(p))
fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
in_node=1;
processed_nodes++;
} else if (!strncmp(p, "<tag ",5)) {
- if (!parse_tag(p))
+ if (!parse_tag(p))
fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
} else if (!strncmp(p, "<way ",5)) {
in_way=1;
- if (!parse_way(p))
+ 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))
+ if (!parse_nd(p))
fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
} else if (!strncmp(p, "<relation ",10)) {
in_relation=1;
- if (!parse_relation(p))
+ if (!parse_relation(p))
fprintf(stderr,"WARNING: failed to parse %s\n", buffer);
processed_relations++;
} else if (!strncmp(p, "<member ",8)) {
static struct item_bin *
read_item(FILE *in)
{
- struct item_bin *ib=(struct item_bin *) buffer;
+ struct item_bin *ib=(struct item_bin *) buffer;
int r,s;
r=fread(ib, sizeof(*ib), 1, in);
if (r != 1)
if (! count)
return;
r->l=*c;
- r->h=*c;
+ r->h=*c;
while (--count) {
c++;
if (c->x < r->l.x)
strcat(ret,"a");
x0=x2;
y0=y2;
- } else
+ } else
return;
}
}
tile_extend(char *tile, struct item_bin *ib)
{
struct tile_head *th=NULL;
- if (debug_tile(tile))
+ if (debug_tile(tile))
fprintf(stderr,"Tile:Writing %d bytes to '%s' (%p,%p)\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL);
if (tile_hash2)
th=g_hash_table_lookup(tile_hash2, tile);
if (tile_hash2)
g_hash_table_insert(tile_hash2, th->name, th);
processed_tiles++;
- if (debug_tile(tile))
+ if (debug_tile(tile))
fprintf(stderr,"new '%s'\n", tile);
}
th->total_size+=ib->len*4+4;
- if (debug_tile(tile))
+ 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, th->name, th);
}
ths=g_hash_table_lookup(tile_hash, sub);
if (! ths)
return 0;
- if (debug_tile(base) || debug_tile(sub))
+ 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_free(thb->name);
thb->name=g_strdup(base);
g_hash_table_insert(tile_hash, thb->name, thb);
-
+
} else {
thb=realloc(thb, sizeof(*thb)+ths->size+thb->size);
assert(thb != NULL);
if (th) {
if (! th->process)
return;
- if (debug_tile(tile))
+ if (debug_tile(tile))
fprintf(stderr,"Data:Writing %d bytes to '%s' (%p,%p)\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL);
size=(ib->len+1)*4;
if (th->total_size_used+size > th->total_size) {
ii.attr_zipfile_ref.type=attr_zipfile_ref;
ii.zipfile_ref=th->zipnum;
- if (phase == 3)
+ if (phase == 3)
tile_extend(index_tile, (struct item_bin *)&ii);
- else
+ else
write_item(index_tile, (struct item_bin *)&ii);
#if 0
unsigned int *c=(unsigned int *)ⅈ
for (i = 0 ; i < sizeof(ii)/4 ; i++) {
fprintf(stderr,"%08x ", c[i]);
}
- fprintf(stderr,"\n");
+ fprintf(stderr,"\n");
#endif
}
return maxnamelen;
}
-static void
+static void
create_tile_hash_list(GList *list)
{
GList *next;
static void
destroy_tile_hash(void)
-{
+{
g_hash_table_destroy(tile_hash2);
tile_hash2=NULL;
}
last=&tile_head_root;
if (! maxlen) {
while (next) {
- if (strlen(next->data) > maxlen)
+ if (strlen(next->data) > maxlen)
maxlen=strlen(next->data);
next=g_list_next(next);
}
data=th->subtiles;
while (dlen > 0) {
fprintf(out,":%s", data);
- while (*data++)
+ while (*data++)
dlen--;
dlen--;
}
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));
write_tilesdir(phase, maxnamelen, tilesdir_out);
return 0;
-
+
}
static int
size+=th->total_size;
th=th->next;
}
- if (size)
+ if (size)
fprintf(stderr,"Slice %d is of size %d\n", slices, size);
th=tile_head_root;
size=0;
slices++;
}
fseek(dir_out, 0, SEEK_SET);
- cat(dir_out, out);
+ cat(dir_out, out);
eoc.zipenum=zipfiles;
eoc.zipecenn=zipfiles;
eoc.zipecsz=zipdir_size;
fwrite(&eoc, sizeof(eoc), 1, out);
sig_alrm(0);
alarm(0);
- return 0;
+ return 0;
}
static void
fprintf(f,"-e (--end) : end at specified phase\n");
fprintf(f,"-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n\n");
fprintf(f,"-s (--start) : start at specified phase\n");
+ fprintf(f,"-i (--input-file) : specify the input file name (OSM), overrules default stdin\n");
fprintf(f,"-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n");
fprintf(f,"-z (--compression-level) : set the compression level\n");
exit(1);
int process_nodes=1, process_ways=1;
int compression_level=9;
char *result;
+ FILE* input_file = stdin;
+
+
while (1) {
#if 0
int this_option_optind = optind ? optind : 1;
{"keep-tmpfiles", 0, 0, 'k'},
{"nodes-only", 0, 0, 'N'},
{"start", 1, 0, 's'},
+ {"input-file", 1, 0, 'i'},
{"ways-only", 0, 0, 'W'},
{0, 0, 0, 0}
};
case 'w':
dedupe_ways_hash=g_hash_table_new(NULL, NULL);
break;
+ case 'i':
+ input_file = fopen( optarg, "r" );
+ if ( input_file == NULL )
+ {
+ fprintf( stderr, "\nInput file (%s) not found\n", optarg );
+ exit( -1 );
+ }
+ break;
case 'z':
compression_level=atoi(optarg);
break;
break;
default:
fprintf(stderr,"c=%d\n", c);
- }
+ }
}
- if (optind != argc-1)
+ if (optind != argc-1)
usage(stderr);
result=argv[optind];
build_attrmap(map);
nodes=fopen("nodes.tmp","wb+");
phase=1;
fprintf(stderr,"PROGRESS: Phase 1: collecting data\n");
- phase1(stdin,ways,nodes);
+ phase1(input_file,ways,nodes);
if (ways)
fclose(ways);
if (nodes)
fclose(nodes);
}
- if (end == 1 || dump_coordinates)
+ if (end == 1 || dump_coordinates)
save_buffer("coords.tmp",&node_buffer);
if (end == 1)
exit(0);
- if (start == 2)
+ if (start == 2)
load_buffer("coords.tmp",&node_buffer);
if (start <= 2) {
if (process_ways) {
fclose(ways);
if(!keep_tmpfiles)
remove("ways.tmp");
- } else
+ } else
fprintf(stderr,"PROGRESS: Skipping Phase 2\n");
}
free(node_buffer.base);