Fix:Core:Mark destination as stopped in destination.txt, closes ticket #980.
authorsleske <sleske@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 25 Dec 2011 21:07:15 +0000 (21:07 +0000)
committersleske <sleske@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 25 Dec 2011 21:07:15 +0000 (21:07 +0000)
Avoids restarting a stopped navigation when Navit is restarted.

git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4871 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/map/textfile/textfile.c
navit/navit/map/textfile/textfile.h
navit/navit/navit.c

index cbcef07..b617f1d 100644 (file)
 static int map_id;
 
 static void
+remove_comment_line(char* line){
+       if (line==TEXTFILE_COMMENT_CHAR){
+               line='\0';
+       }
+}
+
+static void
 get_line(struct map_rect_priv *mr)
 {
        if(mr->f) {
@@ -47,10 +54,11 @@ get_line(struct map_rect_priv *mr)
                else
                        mr->pos+=mr->lastlen;
                fgets(mr->line, SIZE, mr->f);
+               dbg(1,"read textfile line: %s\n", mr->line);
+               remove_comment_line(mr->line);
                mr->lastlen=strlen(mr->line)+1;
                if (strlen(mr->line) >= SIZE-1) 
                        printf("line too long\n");
-               dbg(1,"read textfile line: %s\n", mr->line);
        }
 }
 
index 05e4769..36524d6 100644 (file)
 #include <stdio.h>
 #include "attr.h"
 #include "coord.h"
+
+#define TEXTFILE_COMMENT_CHAR '#'
+#define TEXTFILE_COMMENT_NAVI_STOPPED "# navigation stopped\n"
+
 struct map_priv {
        int id;
        char *filename;
index 99b5da6..4be58f9 100644 (file)
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #endif
 #include <stdio.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <string.h>
@@ -66,6 +67,7 @@
 #include "vehicleprofile.h"
 #include "sunriset.h"
 #include "bookmarks.h"
+#include "map/textfile/textfile.h"
 #ifdef HAVE_API_WIN32_BASE
 #include <windows.h>
 #include "util.h"
@@ -1458,6 +1460,18 @@ navit_projection_set(struct navit *this_, enum projection pro, int draw)
                navit_draw(this_);
 }
 
+static void
+navit_mark_navigation_stopped(char *former_destination_file){
+        FILE *f;
+       f=fopen(former_destination_file, "a");
+       if (f) {
+               fprintf(f,"%s", TEXTFILE_COMMENT_NAVI_STOPPED);
+               fclose(f);
+       }else{
+               dbg(0, "Error setting mark in destination file %s: %s\n", former_destination_file, strerror(errno));
+       }
+}
+
 /**
  * Start the route computing to a given set of coordinates
  *
@@ -1470,16 +1484,18 @@ void
 navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
 {
        char *destination_file;
+       destination_file = bookmarks_get_destination_file(TRUE);
        if (c) {
                this_->destination=*c;
                this_->destination_valid=1;
 
                dbg(1, "c=(%i,%i)\n", c->x,c->y);
-               destination_file = bookmarks_get_destination_file(TRUE);
                bookmarks_append_coord(this_->former_destination, destination_file, c, type_former_destination, description, this_->recentdest_count);
-               g_free(destination_file);
-       } else
+       } else {
                this_->destination_valid=0;
+               navit_mark_navigation_stopped(destination_file);
+       }
+       g_free(destination_file);
        callback_list_call_attr_0(this_->attr_cbl, attr_destination);
        if (this_->route) {
                route_set_destination(this_->route, c, async);
@@ -1540,17 +1556,19 @@ navit_check_route(struct navit *this_)
 static int
 navit_former_destinations_active(struct navit *this_)
 {
-       char *destination_file = bookmarks_get_destination_file(FALSE);
-       FILE *f;
+       char *destination_file_name = bookmarks_get_destination_file(FALSE);
+       FILE *destination_file;
        int active=0;
-       char buffer[3];
-       f=fopen(destination_file,"r");
-       if (f) {
-               if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n')) 
+       char lastline[100];
+       destination_file=fopen(destination_file_name,"r");
+       if (destination_file) {
+               while(fgets(lastline, sizeof(lastline), destination_file));
+               fclose(destination_file);
+               if ((lastline != NULL) && (strcmp(lastline, TEXTFILE_COMMENT_NAVI_STOPPED))){
                        active=1;
-               fclose(f);
+               }
        }
-       g_free(destination_file);
+       g_free(destination_file_name);
        return active;
 }