Ticket #980: navi-stopped.diff

File navi-stopped.diff, 4.2 KB (added by sleske, 11 years ago)

Patch to remember if navigation was stopped.

  • navit/navit/map/textfile/textfile.c

    commit 4a5cb227d8ad95e40672e73d77c1229ab348cc08
    Author: Sebastian Leske <Sebastian.Leske@sleske.name>
    Date:   Thu Dec 22 16:47:58 2011 +0100
    
        Mark destination as stopped in destination.txt.
        
        Mark destination as stopped in destination.txt. Avoids restarting a
        stopped navigation when Navit is restarted.
    
    diff --git a/navit/navit/map/textfile/textfile.c b/navit/navit/map/textfile/textfile.c
    index cbcef07..b617f1d 100644
    a b  
    3939static int map_id;
    4040
    4141static void
     42remove_comment_line(char* line){
     43        if (line==TEXTFILE_COMMENT_CHAR){
     44                line='\0';
     45        }
     46}
     47
     48static void
    4249get_line(struct map_rect_priv *mr)
    4350{
    4451        if(mr->f) {
    get_line(struct map_rect_priv *mr) 
    4754                else
    4855                        mr->pos+=mr->lastlen;
    4956                fgets(mr->line, SIZE, mr->f);
     57                dbg(1,"read textfile line: %s\n", mr->line);
     58                remove_comment_line(mr->line);
    5059                mr->lastlen=strlen(mr->line)+1;
    5160                if (strlen(mr->line) >= SIZE-1)
    5261                        printf("line too long\n");
    53                 dbg(1,"read textfile line: %s\n", mr->line);
    5462        }
    5563}
    5664
  • navit/navit/map/textfile/textfile.h

    diff --git a/navit/navit/map/textfile/textfile.h b/navit/navit/map/textfile/textfile.h
    index 05e4769..36524d6 100644
    a b  
    2020#include <stdio.h>
    2121#include "attr.h"
    2222#include "coord.h"
     23
     24#define TEXTFILE_COMMENT_CHAR '#'
     25#define TEXTFILE_COMMENT_NAVI_STOPPED "# navigation stopped\n"
     26
    2327struct map_priv {
    2428        int id;
    2529        char *filename;
  • navit/navit/navit.c

    diff --git a/navit/navit/navit.c b/navit/navit/navit.c
    index 99b5da6..4be58f9 100644
    a b  
    2323#include <unistd.h>
    2424#endif
    2525#include <stdio.h>
     26#include <errno.h>
    2627#include <stdlib.h>
    2728#include <signal.h>
    2829#include <string.h>
     
    6667#include "vehicleprofile.h"
    6768#include "sunriset.h"
    6869#include "bookmarks.h"
     70#include "map/textfile/textfile.h"
    6971#ifdef HAVE_API_WIN32_BASE
    7072#include <windows.h>
    7173#include "util.h"
    navit_projection_set(struct navit *this_, enum projection pro, int draw) 
    14581460                navit_draw(this_);
    14591461}
    14601462
     1463static void
     1464navit_mark_navigation_stopped(char *former_destination_file){
     1465        FILE *f;
     1466        f=fopen(former_destination_file, "a");
     1467        if (f) {
     1468                fprintf(f,"%s", TEXTFILE_COMMENT_NAVI_STOPPED);
     1469                fclose(f);
     1470        }else{
     1471                dbg(0, "Error setting mark in destination file %s: %s\n", former_destination_file, strerror(errno));
     1472        }
     1473}
     1474
    14611475/**
    14621476 * Start the route computing to a given set of coordinates
    14631477 *
    void 
    14701484navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
    14711485{
    14721486        char *destination_file;
     1487        destination_file = bookmarks_get_destination_file(TRUE);
    14731488        if (c) {
    14741489                this_->destination=*c;
    14751490                this_->destination_valid=1;
    14761491
    14771492                dbg(1, "c=(%i,%i)\n", c->x,c->y);
    1478                 destination_file = bookmarks_get_destination_file(TRUE);
    14791493                bookmarks_append_coord(this_->former_destination, destination_file, c, type_former_destination, description, this_->recentdest_count);
    1480                 g_free(destination_file);
    1481         } else
     1494        } else {
    14821495                this_->destination_valid=0;
     1496                navit_mark_navigation_stopped(destination_file);
     1497        }
     1498        g_free(destination_file);
    14831499        callback_list_call_attr_0(this_->attr_cbl, attr_destination);
    14841500        if (this_->route) {
    14851501                route_set_destination(this_->route, c, async);
    navit_check_route(struct navit *this_) 
    15401556static int
    15411557navit_former_destinations_active(struct navit *this_)
    15421558{
    1543         char *destination_file = bookmarks_get_destination_file(FALSE);
    1544         FILE *f;
     1559        char *destination_file_name = bookmarks_get_destination_file(FALSE);
     1560        FILE *destination_file;
    15451561        int active=0;
    1546         char buffer[3];
    1547         f=fopen(destination_file,"r");
    1548         if (f) {
    1549                 if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n'))
     1562        char lastline[100];
     1563        destination_file=fopen(destination_file_name,"r");
     1564        if (destination_file) {
     1565                while(fgets(lastline, sizeof(lastline), destination_file));
     1566                fclose(destination_file);
     1567                if ((lastline != NULL) && (strcmp(lastline, TEXTFILE_COMMENT_NAVI_STOPPED))){
    15501568                        active=1;
    1551                 fclose(f);
     1569                }
    15521570        }
    1553         g_free(destination_file);
     1571        g_free(destination_file_name);
    15541572        return active;
    15551573}
    15561574