Diff of /trunk/src/gpx.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 7 by harbaum, Thu Jun 25 15:24:24 2009 UTC revision 133 by harbaum, Mon Oct 12 20:27:55 2009 UTC
# Line 155  gpx_dialog_t *gpx_busy_dialog_new(GtkWid Line 155  gpx_dialog_t *gpx_busy_dialog_new(GtkWid
155    gtk_window_set_title(GTK_WINDOW(dialog->dialog), _("Loading"));    gtk_window_set_title(GTK_WINDOW(dialog->dialog), _("Loading"));
156    gtk_window_set_default_size(GTK_WINDOW(dialog->dialog), 300, 10);    gtk_window_set_default_size(GTK_WINDOW(dialog->dialog), 300, 10);
157    
158    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);    gtk_window_set_modal(GTK_WINDOW(dialog->dialog), TRUE);
159    gtk_window_set_transient_for(GTK_WINDOW(dialog->dialog), GTK_WINDOW(parent));    gtk_window_set_transient_for(GTK_WINDOW(dialog->dialog), GTK_WINDOW(parent));
160    
161    dialog->label = gtk_label_new("---");    dialog->label = gtk_label_new("---");
# Line 360  static gboolean skip_element(xmlTextRead Line 360  static gboolean skip_element(xmlTextRead
360    
361  static char *process_text(xmlTextReaderPtr reader) {  static char *process_text(xmlTextReaderPtr reader) {
362    char *text = NULL;    char *text = NULL;
   int depth = xmlTextReaderDepth(reader);  
   int ret = xmlTextReaderRead(reader);  
   while((ret == 1) &&  
         ((xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) ||  
          (xmlTextReaderDepth(reader) != depth))) {  
363    
364      /* found a text fragment */    if(!xmlTextReaderIsEmptyElement(reader)) {
365      if((xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) ||  
366         (xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA)) {      int depth = xmlTextReaderDepth(reader);
367        char *frag = (char*)xmlTextReaderConstValue(reader);      int ret = xmlTextReaderRead(reader);
368        while((ret == 1) &&
369        if(!text) text = strdup(frag);            ((xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) ||
370        else {             (xmlTextReaderDepth(reader) != depth))) {
371          char *old = text;  
372          text = malloc(strlen(old) + strlen(frag) + 1);        /* found a text fragment */
373          strcpy(text, old);        if((xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) ||
374          strcat(text, frag);           (xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA)) {
375          free(old);          char *frag = (char*)xmlTextReaderConstValue(reader);
376    
377            if(!text) text = strdup(frag);
378            else {
379              char *old = text;
380              text = malloc(strlen(old) + strlen(frag) + 1);
381              strcpy(text, old);
382              strcat(text, frag);
383              free(old);
384            }
385        }        }
386          ret = xmlTextReaderRead(reader);
387      }      }
     ret = xmlTextReaderRead(reader);  
388    }    }
389    
390    return text;    return text;
# Line 463  static log_t *process_gpx_wpt_gc_logs_lo Line 467  static log_t *process_gpx_wpt_gc_logs_lo
467      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
468    }    }
469    
470    g_assert(0);    gpx_free_log(log);
471    return log;    return NULL;
472  }  }
473    
474  static log_t *process_gpx_wpt_gc_logs(xmlTextReaderPtr reader) {  static log_t *process_gpx_wpt_gc_logs(xmlTextReaderPtr reader) {
# Line 513  static log_t *process_gpx_wpt_gc_logs(xm Line 517  static log_t *process_gpx_wpt_gc_logs(xm
517      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
518    }    }
519    
520    g_assert(0);    /* free the entire log chain */
521    return log_chain;    while(log_chain) {
522        log_t *next = log_chain->next;
523        gpx_free_log(log_chain);
524        log_chain = next;
525      }
526    
527      return NULL;
528  }  }
529    
530  static tb_t *process_gpx_wpt_gc_tbs_travelbug(xmlTextReaderPtr reader) {  static tb_t *process_gpx_wpt_gc_tbs_travelbug(xmlTextReaderPtr reader) {
# Line 532  static tb_t *process_gpx_wpt_gc_tbs_trav Line 542  static tb_t *process_gpx_wpt_gc_tbs_trav
542    else    else
543      tb->ref = strdup("<NONE>");      tb->ref = strdup("<NONE>");
544    
545      if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "id")))
546        tb->id = atoi(prop);
547    
548    /* process all sub-nodes */    /* process all sub-nodes */
549    int depth = xmlTextReaderDepth(reader);    int depth = xmlTextReaderDepth(reader);
550    int ret = xmlTextReaderRead(reader);    int ret = xmlTextReaderRead(reader);
# Line 563  static tb_t *process_gpx_wpt_gc_tbs_trav Line 576  static tb_t *process_gpx_wpt_gc_tbs_trav
576      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
577    }    }
578    
579    g_assert(0);    gpx_free_tb(tb);
580    return tb;    return NULL;
581  }  }
582    
583  static tb_t *process_gpx_wpt_gc_tbs(xmlTextReaderPtr reader) {  static tb_t *process_gpx_wpt_gc_tbs(xmlTextReaderPtr reader) {
# Line 605  static tb_t *process_gpx_wpt_gc_tbs(xmlT Line 618  static tb_t *process_gpx_wpt_gc_tbs(xmlT
618      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
619    }    }
620    
621    g_assert(0);    while(tb) {
622    return tb;      tb_t *next = tb;
623        gpx_free_tb(tb);
624        tb = next;
625      }
626    
627      return NULL;
628  }  }
629    
630  static void process_gpx_wpt_gc(xmlTextReaderPtr reader, cache_t *cache) {  static void process_gpx_wpt_gc(xmlTextReaderPtr reader, cache_t *cache) {
# Line 653  static void process_gpx_wpt_gc(xmlTextRe Line 671  static void process_gpx_wpt_gc(xmlTextRe
671                    (strcasecmp(name, "hints") == 0))     {                    (strcasecmp(name, "hints") == 0))     {
672            if(!cache->hint) {            if(!cache->hint) {
673              cache->hint = process_text(reader);              cache->hint = process_text(reader);
674    
675              /* often hints aren't more than just a bunch of blanks ... */              /* often hints aren't more than just a bunch of blanks ... */
676              if(cache->hint && all_is_white(cache->hint)) {              if(cache->hint && all_is_white(cache->hint)) {
677                free(cache->hint);                free(cache->hint);
# Line 764  static cache_t *process_gpx_wpt(xmlTextR Line 783  static cache_t *process_gpx_wpt(xmlTextR
783        /* neither geocaching.com GC* nor opencaching.com OC* nor */        /* neither geocaching.com GC* nor opencaching.com OC* nor */
784        /* geocaching australia GA* waypoint */        /* geocaching australia GA* waypoint */
785        if(cache->id &&        if(cache->id &&
786             (strncasecmp(cache->id, "__", 2) != 0) &&
787           (strncasecmp(cache->id, "GC", 2) != 0) &&           (strncasecmp(cache->id, "GC", 2) != 0) &&
788           (strncasecmp(cache->id, "OC", 2) != 0) &&           (strncasecmp(cache->id, "OC", 2) != 0) &&
789           (strncasecmp(cache->id, "GA", 2) != 0)) {           (strncasecmp(cache->id, "GA", 2) != 0)) {
# Line 830  static cache_t *process_gpx_wpt(xmlTextR Line 850  static cache_t *process_gpx_wpt(xmlTextR
850      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
851    }    }
852    
853    g_assert(0);    gpx_free_cache(cache);
854    return cache;    return NULL;
855  }  }
856    
857  static void process_gpx(xmlTextReaderPtr reader, gpx_dialog_t *dialog,  static gboolean process_gpx(xmlTextReaderPtr reader, gpx_dialog_t *dialog,
858                          gpx_t *gpx) {                              gpx_t *gpx) {
859    
860    /* no attributes of interest */    /* no attributes of interest */
861    
# Line 846  static void process_gpx(xmlTextReaderPtr Line 866  static void process_gpx(xmlTextReaderPtr
866    while(*cache) cache = &(*cache)->next;    while(*cache) cache = &(*cache)->next;
867    
868    const xmlChar *name = xmlTextReaderConstName(reader);    const xmlChar *name = xmlTextReaderConstName(reader);
869    g_assert(name);    if(!name) return FALSE;
870    
871    /* read next node */    /* read next node */
872    int ret = xmlTextReaderRead(reader);    int ret = xmlTextReaderRead(reader);
# Line 876  static void process_gpx(xmlTextReaderPtr Line 896  static void process_gpx(xmlTextReaderPtr
896      case XML_READER_TYPE_END_ELEMENT:      case XML_READER_TYPE_END_ELEMENT:
897        /* end element must be for the current element */        /* end element must be for the current element */
898        g_assert(xmlTextReaderDepth(reader) == 0);        g_assert(xmlTextReaderDepth(reader) == 0);
899        return;        return TRUE;
900        break;        break;
901    
902      default:      default:
# Line 885  static void process_gpx(xmlTextReaderPtr Line 905  static void process_gpx(xmlTextReaderPtr
905      ret = xmlTextReaderRead(reader);      ret = xmlTextReaderRead(reader);
906    }    }
907    
908    g_assert(0);    return FALSE;
909  }  }
910    
911  /* parse loc waypoint entry */  /* parse loc waypoint entry */
# Line 1069  static gpx_t *gpx_parse_file(gpx_dialog_ Line 1089  static gpx_t *gpx_parse_file(gpx_dialog_
1089      *dot = 0;      *dot = 0;
1090      snprintf(wpts_name, sizeof(wpts_name), "%s-wpts.gpx", filename);      snprintf(wpts_name, sizeof(wpts_name), "%s-wpts.gpx", filename);
1091      *dot = '.';      *dot = '.';
   
1092      if(g_file_test(wpts_name,  G_FILE_TEST_EXISTS)) {      if(g_file_test(wpts_name,  G_FILE_TEST_EXISTS)) {
   
1093        xmlTextReaderPtr reader = xmlReaderForFile(wpts_name, NULL, 0);        xmlTextReaderPtr reader = xmlReaderForFile(wpts_name, NULL, 0);
1094        if (reader != NULL) {        if (reader != NULL) {
1095          gpx = process_root(reader, dialog, wpts_name, gpx);          gpx = process_root(reader, dialog, wpts_name, gpx);
# Line 1347  float gpx_pos_get_distance(pos_t p1, pos Line 1365  float gpx_pos_get_distance(pos_t p1, pos
1365    
1366  void gpx_pos_get_distance_str(char *str, int len,  void gpx_pos_get_distance_str(char *str, int len,
1367                                pos_t p1, pos_t p2, int mil) {                                pos_t p1, pos_t p2, int mil) {
1368    if(!p1.lat && !p1.lon) {    if(isnan(p1.lat) || isnan(p1.lon)) {
1369      snprintf(str, len, "---");      snprintf(str, len, "---");
1370      return;      return;
1371    }    }
# Line 1356  void gpx_pos_get_distance_str(char *str, Line 1374  void gpx_pos_get_distance_str(char *str,
1374    distance_str(str, len, dist, mil);    distance_str(str, len, dist, mil);
1375  }  }
1376    
 /* http://library.gnome.org/devel/gtk/unstable/GtkRadioButton.html */  
1377  void gpx_sort(gpx_t *gpx, int by, pos_t *refpos) {  void gpx_sort(gpx_t *gpx, int by, pos_t *refpos) {
1378    cache_t **new;    cache_t **new;
1379    cache_t *cur = gpx->cache;    cache_t *cur = gpx->cache;
# Line 1365  void gpx_sort(gpx_t *gpx, int by, pos_t Line 1382  void gpx_sort(gpx_t *gpx, int by, pos_t
1382    
1383    gpx->cache = NULL;  /* detach old chain */    gpx->cache = NULL;  /* detach old chain */
1384    while(cur) {    while(cur) {
1385      float cur_dist = gpx_pos_get_distance(*refpos, gpx_cache_pos(cur), 0);      float cur_dist = -1;
1386      int cur_cnt = 0;      int cur_cnt = 0;
1387    
1388        if(!isnan(cur->pos.lat) && !isnan(cur->pos.lon))
1389          cur_dist = gpx_pos_get_distance(*refpos, gpx_cache_pos(cur), 0);
1390    
1391      new = &(gpx->cache);      new = &(gpx->cache);
1392    
1393      /* search for currect insertion point */      /* search for currect insertion point */

Legend:
Removed from v.7  
changed lines
  Added in v.133