Diff of /trunk/src/gpx.c

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

revision 13 by harbaum, Sat Jun 27 11:09:19 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 1345  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    }    }

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