while (*s == ' ') {
s++;
}
- if (!strncmp(str, "0x", 2) || !strncmp(str,"-0x", 3)) {
- args=sscanf(str, "%x %x%n",&c.x, &c.y, &ret);
+ if (!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3)) {
+ args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret);
if (args < 2)
goto out;
dbg(1,"str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret);
return ret;
}
+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 ),
+ sign_x, x,
+ sign_y, y );
+ return;
+}
+
/** @} */
#ifndef NAVIT_COORD_H
#define NAVIT_COORD_H
+#include <stdio.h>
#include "projection.h"
/*! A integer mercator coordinate */
struct coord * coord_new(int x, int y);
void coord_destroy(struct coord *c);
int coord_parse(const char *c_str, enum projection pro, struct coord *c_ret);
+void coord_print(enum projection pro, struct coord *c, FILE *out);
struct coord_rect * coord_rect_new(struct coord *lu, struct coord *rl);
void coord_rect_destroy(struct coord_rect *r);
int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2);
navit_set_destination_from_file(this_, "bookmark.txt", 1, (int)offset_p);
}
+static void
+navit_set_center_from_file(struct navit *this_, char *file)
+{
+ FILE *f;
+ char *line = NULL;
+
+ size_t line_size = 0;
+ enum projection pro;
+ struct coord *center;
+
+ file = g_strjoin(NULL, get_home_directory(), "/.navit/", file, NULL);
+ if (!file_exists(file)) {
+ g_free(file);
+ return;
+ }
+ f = fopen(file, "r");
+ getline(&line, &line_size, f);
+ fclose(f);
+ g_free(file);
+ if (line) {
+ center = transform_center(this_->trans);
+ pro = transform_get_projection(this_->trans);
+ coord_parse(g_strchomp(line), pro, center);
+ free(line);
+ }
+ return;
+}
+
+static void
+navit_write_center_to_file(struct navit *this_, char *file)
+{
+ FILE *f;
+ enum projection pro;
+ struct coord *center;
+ char *directory;
+
+ directory = g_strjoin(NULL, get_home_directory(), "/.navit/", NULL);
+ if (!file_exists(directory)) {
+ if (mkdir(directory,
+ S_IRUSR|S_IWUSR|S_IXUSR|
+ S_IRGRP|S_IXGRP|
+ S_IROTH|S_IXOTH) == -1) {
+ perror(directory);
+ g_free(directory);
+ return;
+ }
+ }
+
+ file = g_strjoin(NULL, directory, file, NULL);
+ g_free(directory);
+ f = fopen(file, "w+");
+ if (f) {
+ center = transform_center(this_->trans);
+ pro = transform_get_projection(this_->trans);
+ coord_print(pro, center, f);
+ fclose(f);
+ } else {
+ perror(file);
+ }
+ g_free(file);
+ return;
+}
+
+
/**
* Start the route computing to a given set of coordinates
*
this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
}
+ navit_set_center_from_file(this_, "center.txt");
#if 0
if (this_->menubar) {
men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
{
/* TODO: destroy objects contained in this_ */
main_remove_navit(this_);
+ navit_write_center_to_file(this_, "center.txt");
g_free(this_);
}