Пример #1
0
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);
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
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;
}