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=malloc(size); assert(slice_data != NULL); 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); th=tile_head_root; while (th) { if (th->process) { 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 fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info)); } th=th->next; } free(slice_data); return zipfiles; }
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)); }
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; #if 0 dbg(lvl_debug,"%d is "ITEM_ID_FMT"\n",nodeid,ITEM_ID_ARGS(*id2)); #endif g_hash_table_insert(sgr_nodes_hash, GINT_TO_POINTER(nodeid), id2); nodeid++; } th=tile_head_root; while (th) { th->zip_data=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; } }
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) { #if 0 fprintf(stderr,"PROGRESS: collecting tiles with len=%d\n", len); #endif 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--; } 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)); } }