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; }
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=malloc(at->size); assert(buffer != NULL); f=fopen(at->filename,"rb"); assert(f != NULL); fread(buffer, at->size, 1, f); fclose(f); write_zipmember(zip_info, at->name, zip_get_maxnamelen(zip_info), buffer, at->size); free(buffer); count++; l=g_list_next(l); zip_add_member(zip_info); } return count; }
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; } }