コード例 #1
0
ファイル: coord.c プロジェクト: justinzane/navit
void
coord_print(enum projection pro, struct coord *c, FILE *out) {
	unsigned int x;
	unsigned int y;
	char *sign_x = "";
	char *sign_y = "";
	
	if ( c->x < 0 ) {
		x = -c->x;
		sign_x = "-";
	} else {
		x = c->x;
	}
	if ( c->y < 0 ) {
		y = -c->y;
		sign_y = "-";
	} else {
		y = c->y;
	}
	fprintf( out, "%s: %s0x%x %s0x%x\n",
		 projection_to_name( pro , NULL),
		 sign_x, x,
		 sign_y, y );
	return;
}
コード例 #2
0
ファイル: bookmarks.c プロジェクト: nutellarlz/Navination
/**
 * @param limit Limits the number of entries in the "backlog". Set to 0 for "infinite"
 */
void
bookmarks_append_coord(struct bookmarks *this_, char *file, struct pcoord *c, int count, const char *type, const char *description, GHashTable *h, int limit)
{
	FILE *f;
	const char *prostr;

	if (limit != 0 && (f=fopen(file, "r"))) {
		int *offsets=g_alloca(sizeof(int)*limit);
		int offset_pos=0;
		int offset;
		char buffer[4096];
		memset(offsets, 0, sizeof(int)*limit);
		for (;;) {
			offset=ftell(f);
			if (!fgets(buffer, sizeof(buffer), f))
				break;
			if (strstr(buffer,"type=")) {
				offsets[offset_pos]=offset;
				offset_pos=(offset_pos+1)%limit;
			}
		}
		fclose(f);
		bookmarks_shrink(file, offsets[offset_pos]);
	}
	f=fopen(file, "a");
	if (f) {
		if (c) {
			int i;
			if (description) 
				fprintf(f,"type=%s label=\"%s\"\n", type, description);
			else
				fprintf(f,"type=%s\n", type);
			for (i = 0 ; i < count ; i++) {
				prostr = projection_to_name(c[i].pro,NULL);
				fprintf(f,"%s%s%s0x%x %s0x%x\n",
				 prostr, *prostr ? ":" : "",
				 c[i].x >= 0 ? "":"-", c[i].x >= 0 ? c[i].x : -c[i].x,
				 c[i].y >= 0 ? "":"-", c[i].y >= 0 ? c[i].y : -c[i].y);
			}
		} else
			fprintf(f,"\n");
	}
	fclose(f);
}
コード例 #3
0
ファイル: bookmarks.c プロジェクト: nutellarlz/Navination
static int
bookmarks_store_bookmarks_to_file(struct bookmarks *this_,  int limit,int replace) {
	FILE *f;
	struct bookmark_item_priv *item,*parent_item;
	char *fullname;
	const char *prostr;
	int result;
	GHashTable *dedup=g_hash_table_new_full(g_str_hash,g_str_equal,g_free_func,NULL);

	f=fopen(this_->working_file, replace ? "w+" : "a+");
	if (f==NULL) {
		navit_add_message(this_->parent->u.navit,"Failed to write bookmarks file");
		return FALSE;
	}

	this_->bookmarks_list=g_list_first(this_->bookmarks_list);
	while (this_->bookmarks_list) {
		item=(struct bookmark_item_priv*)this_->bookmarks_list->data;

		parent_item=item;
		fullname=g_strdup(item->label);
		while ((parent_item=parent_item->parent)) {
			char *pathHelper;
			if (parent_item->label) {
				pathHelper=g_strconcat(parent_item->label,"/",fullname,NULL);
				g_free(fullname);
				fullname=g_strdup(pathHelper);
				g_free(pathHelper);
				dbg(1,"full name: %s\n",fullname);
			}
		}

		if (!g_hash_table_lookup(dedup,fullname)) {
			g_hash_table_insert(dedup,fullname,fullname);
			if (item->type == type_bookmark) {
				prostr = projection_to_name(projection_mg,NULL);
				if (fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\" path=\"%s\"\n",
					 prostr, *prostr ? ":" : "",
					 item->c.x >= 0 ? "":"-", item->c.x >= 0 ? item->c.x : -item->c.x,
					 item->c.y >= 0 ? "":"-", item->c.y >= 0 ? item->c.y : -item->c.y,
					 "bookmark", item->label,fullname)<1) {
					g_free(fullname);
					break;
				}
			}
			if (item->type == type_bookmark_folder) {
				prostr = projection_to_name(projection_mg,NULL);
				if (fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\" path=\"%s\"\n",
					 prostr, *prostr ? ":" : "",
					 "", 0,
					 "", 0,
					 "bookmark_folder", item->label,fullname)<1) {
					g_free(fullname);
					break;
				}
			}
		}

 		/* Limit could be zero, so we start decrementing it from zero and never reach 1
 		 or it was bigger and we decreased it earlier. So when this counter becomes 1, we know
		 that we have enough entries in bookmarks file */
		if (limit==1) {
			break;
		}
		limit--;

		this_->bookmarks_list=g_list_next(this_->bookmarks_list);
	}

	fclose(f);

    g_hash_table_destroy(dedup);

    if (this_->mr) {
        map_rect_destroy(this_->mr);
        this_->mr = 0;
    }

    unlink(this_->bookmark_file);
	result=(rename(this_->working_file,this_->bookmark_file)==0);
	if (!result) 
	{
		navit_add_message(this_->parent->u.navit,"Failed to write bookmarks file");
	}
	return result;
}