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=realloc(thb, sizeof(struct tile_head)+( ths->num_subtiles+thb->num_subtiles ) * sizeof( char*) ); assert(thb != NULL); 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 int add_tile_hash(struct tile_head *th) { int idx,len,maxnamelen=0; char **data; #if 0 g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th); #endif for( idx = 0; idx < th->num_subtiles; 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); } g_hash_table_insert(tile_hash2, *data, th); len = strlen( *data ); if (len > maxnamelen) { maxnamelen=len; } } return maxnamelen; }
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=malloc(sizeof(struct tile_head)+ sizeof( char* ) ); assert(th != NULL); // 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); }
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=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); #if 0 printf("tile '%s' %d\n",tile,size); #endif while (fscanf(in,":%[^:\n]",subtile) == 1) { #if 0 printf("subtile '%s'\n",subtile); #endif th=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) { #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)); } }