Fix:map_textfile:Fixed pipe mode
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 25 Jun 2009 15:08:18 +0000 (15:08 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 25 Jun 2009 15:08:18 +0000 (15:08 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2373 ffa7fe5e-494d-0410-b361-a75ebd5db220

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

index 67d5858..2bdf07d 100644 (file)
@@ -95,8 +95,12 @@ static void
 get_line(struct map_rect_priv *mr)
 {
        if(mr->f) {
-               mr->pos=ftell(mr->f);
+               if (!mr->m->is_pipe) 
+                       mr->pos=ftell(mr->f);
+               else
+                       mr->pos+=mr->lastlen;
                fgets(mr->line, SIZE, mr->f);
+               mr->lastlen=strlen(mr->line)+1;
                if (strlen(mr->line) >= SIZE-1) 
                        printf("line too long\n");
        }
@@ -235,6 +239,8 @@ map_rect_new_textfile(struct map_priv *map, struct map_selection *sel)
                dbg(1,"popen args %s\n", args);
                mr->args=args;
                mr->f=popen(mr->args, "r");
+               mr->pos=0;
+               mr->lastlen=0;
        } else {
                mr->f=fopen(map->filename, "r");
        }
@@ -280,6 +286,8 @@ map_rect_get_item_textfile(struct map_rect_priv *mr)
                        if (mr->m->is_pipe) {
                                pclose(mr->f);
                                mr->f=popen(mr->args, "r");
+                               mr->pos=0;
+                               mr->lastlen=0;
                        } else
                                fseek(mr->f, 0, SEEK_SET);
                        get_line(mr);
@@ -333,6 +341,8 @@ map_rect_get_item_byid_textfile(struct map_rect_priv *mr, int id_hi, int id_lo)
        if (mr->m->is_pipe) {
                pclose(mr->f);
                mr->f=popen(mr->args, "r");
+               mr->pos=0;
+               mr->lastlen=0;
        } else
                fseek(mr->f, id_lo, SEEK_SET);
        get_line(mr);
index b7a77be..ef97e33 100644 (file)
@@ -46,5 +46,6 @@ struct map_rect_priv {
        struct map_priv *m;
        struct item item;
        char *args;
+       int lastlen;
 };