Ejemplo n.º 1
0
Archivo: misc.c Proyecto: Jalakas/navit
int
phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info)
{
	long long size;
	int slices;
	int zipnum,written_tiles;
	struct tile_head *th,*th2;
	create_tile_hash();

	th=tile_head_root;
	size=0;
	slices=0;
	fprintf(stderr, "Maximum slice size "LONGLONG_FMT"\n", slice_size);
	while (th) {
		if (size + th->total_size > slice_size) {
			fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
			size=0;
			slices++;
		}
		size+=th->total_size;
		th=th->next;
	}
	if (size)
		fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size);
	th=tile_head_root;
	size=0;
	slices=0;
	while (th) {
		th2=tile_head_root;
		while (th2) {
			th2->process=0;
			th2=th2->next;
		}
		size=0;
		while (th && size+th->total_size < slice_size) {
			size+=th->total_size;
			th->process=1;
			th=th->next;
		}
		/* process_slice() modifies zip_info, but need to retain old info */
		zipnum=zip_get_zipnum(zip_info);
		written_tiles=process_slice(in, references, in_count, with_range, size, suffix, zip_info);
		zip_set_zipnum(zip_info, zipnum+written_tiles);
		slices++;
	}
	return 0;
}
Ejemplo n.º 2
0
Archivo: tile.c Proyecto: greg42/navit
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;
}
Ejemplo n.º 3
0
Archivo: ch.c Proyecto: PDXostc/navit
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;
        }
}