]> git.street.me.uk Git - andy/viking.git/commitdiff
Locale-independent output for gpsmapper.c and gpspoint.c
authorEvan Battaglia <gtoevan@gmx.net>
Thu, 24 Nov 2005 01:52:06 +0000 (01:52 +0000)
committerEvan Battaglia <gtoevan@gmx.net>
Thu, 24 Nov 2005 01:52:06 +0000 (01:52 +0000)
ChangeLog
TODO
src/coords.c
src/coords.h
src/gpsmapper.c
src/gpspoint.c
src/gpx.c

index bdceff977b7cefba980e576c7415cfb157e5a68e..2290a596dbaf13612e709178a5fdfae077519fda 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2005-11-23  Guilhem BONNEFILLE  <guilhem.bonnefille@gmail.com>
-
        * src/gpx.c (gpx_dtostr): add better GPX export
+Evan Battaglia <gtoevan@gmx.net>:
+       * dtostr -> coords.c; use in gpsmapper.c and gpspoint.c (locale-independent output)
 
 2005-11-21
 Alex Foobarian <foobarian@gmail.com>:
diff --git a/TODO b/TODO
index 5d435d70d0ba7396e376d7d3076c61f297e7d378..8eca1aec7235aecf87a706df310aed42b73f5a93 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,6 +3,7 @@ IMPORTANT STUFF:
        Debugging output shouldn't be printf'd but g_debug'd
        fix KH maps download
        'zoom in too much' line drawing (ruler, tracks) bugs. maybe fix coord-to-screen to clip values (or make vik_viewport_coord_to_screen_clip)?
+       fix SEGFAULT when clicking too far right on elevation diagram
        acquire crashes, sometimes (???)
        google maps download stops (try auto-download), extra processes in background doing nothing
 
index df2391bc31813ccb14d1f13e4d8d19024e23cdfd..390aa52dc57b4e8ea1cb39706a5be12d316d4424 100644 (file)
@@ -6,6 +6,8 @@ I (Evan Battaglia <viking@greentorch.org>) have only made some small changes suc
 renaming functions and defining LatLon and UTM structs.
 2004-02-10 -- I also added a function of my own -- a_coords_utm_diff() -- that I felt belonged in coords.c
 2004-02-21 -- I also added a_coords_utm_equal().
+2005-11-23 -- Added a_coords_dtostr() for lack of a better place.
+
 */
 /* coords.h - include file for coords routines
 **
@@ -44,6 +46,31 @@ renaming functions and defining LatLon and UTM structs.
 #define M_PI 3.14159265358979
 #endif
 
+/**
+ * Convert a double to a string WITHOUT LOCALE.
+ *
+ * Following GPX specifications, decimal values are xsd:decimal
+ * So, they must use the period separator, not the localized one.
+ *
+ * The returned value must be freed by g_free.
+ */
+char *a_coords_dtostr ( double d )
+{
+  /* In order to ignore locale, we do all the stuff manually */
+  double integer, decimal;
+  integer = trunc(d);
+
+  /* 6 decimals are sufficient (~0,1m) */
+  /* Cf. http://www.tbs-sct.gc.ca/rpm-gbi/guides/Latlong_f.asp */
+  decimal = d - integer;
+  decimal = decimal * 1000000;
+  decimal = trunc ( decimal );
+  decimal = fabs ( decimal );
+
+  /* Format */
+  return g_strdup_printf ( "%g.%06g", integer, decimal );
+}
+
 #define PIOVER180 0.01745329252
 
 #define K0 0.9996
index baaf21aa90a5ba7a49dc9039bec125775c34e997..c27878416d059f2752aa052c0957e2d5f81010d7 100644 (file)
@@ -53,5 +53,16 @@ void a_coords_utm_to_latlon ( const struct UTM *utm, struct LatLon *latlon );
 double a_coords_utm_diff( const struct UTM *utm1, const struct UTM *utm2 );
 double a_coords_latlon_diff ( const struct LatLon *ll1, const struct LatLon *ll2 );
 
+/**
+ * Convert a double to a string WITHOUT LOCALE.
+ *
+ * Following GPX specifications, decimal values are xsd:decimal
+ * So, they must use the period separator, not the localized one.
+ *
+ * The returned value must be freed by g_free.
+ */
+char *a_coords_dtostr ( double d );
+
+
 
 #endif
index 54ffd6e00d744184c59aa7aa5d9d4febda51fcca..c64c80c35370e4489eda05c30473ff82d7f08ed4 100644 (file)
@@ -101,8 +101,13 @@ static void write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f )
   guint len = print_rgn_stuff ( wp->comment, f );
   if ( len )
   {
+    gchar *s_lat, *s_lon;
     vik_coord_to_latlon ( &(wp->coord), &ll );
-    fprintf ( f, "Data0=(%f,%f)\n", ll.lat, ll.lon );
+    s_lat = a_coords_dtostr(ll.lat);
+    s_lon = a_coords_dtostr(ll.lon);
+    fprintf ( f, "Data0=(%s,%s)\n", s_lat, s_lon );
+    g_free ( s_lat );
+    g_free ( s_lon );
     fprintf ( f, "[END-%.5s]\n\n", wp->comment+len+1 );
   }
 }
@@ -110,9 +115,13 @@ static void write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f )
 static void write_trackpoint ( VikTrackpoint *tp, FILE *f )
 {
   static struct LatLon ll;
-  vik_coord_to_latlon ( &(tp->coord), &ll );
-
-  fprintf ( f, "(%f,%f),", ll.lat, ll.lon );
+  gchar *s_lat, *s_lon;
+  vik_coord_to_latlon ( &(tp->coord), &ll ); 
+  s_lat = a_coords_dtostr(ll.lat);
+  s_lon = a_coords_dtostr(ll.lon);
+  fprintf ( f, "(%s,%s),", s_lat, s_lon );
+  g_free ( s_lat );
+  g_free ( s_lon );
 }
 
 static void write_track ( const gchar *name, VikTrack *t, FILE *f )
index 00837a7af262b607eb7d65f5821dcfd5b2e01c53..c7f3d381951a4415b80f2cb89c9d876edd1efd56 100644 (file)
@@ -396,10 +396,19 @@ static void gpspoint_process_key_and_value ( const gchar *key, gint key_len, con
 static void a_gpspoint_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f )
 {
   static struct LatLon ll;
+  gchar *s_lat, *s_lon;
   vik_coord_to_latlon ( &(wp->coord), &ll );
-  fprintf ( f, "type=\"waypoint\" latitude=\"%f\" longitude=\"%f\" name=\"%s\"", ll.lat, ll.lon, name );
-  if ( wp->altitude != VIK_DEFAULT_ALTITUDE )
-    fprintf ( f, " altitude=\"%f\"", wp->altitude );
+  s_lat = a_coords_dtostr(ll.lat);
+  s_lon = a_coords_dtostr(ll.lon);
+  fprintf ( f, "type=\"waypoint\" latitude=\"%s\" longitude=\"%s\" name=\"%s\"", s_lat, s_lon, name );
+  g_free ( s_lat ); 
+  g_free ( s_lon );
+
+  if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) {
+    gchar *s_alt = a_coords_dtostr(wp->altitude);
+    fprintf ( f, " altitude=\"%s\"", s_alt );
+    g_free(s_alt);
+  }
   if ( wp->comment )
   {
     gchar *tmp_comment = slashdup(wp->comment);
@@ -424,12 +433,20 @@ static void a_gpspoint_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE
 static void a_gpspoint_write_trackpoint ( VikTrackpoint *tp, FILE *f )
 {
   static struct LatLon ll;
+  gchar *s_lat, *s_lon;
   vik_coord_to_latlon ( &(tp->coord), &ll );
 
-  fprintf ( f, "type=\"trackpoint\" latitude=\"%f\" longitude=\"%f\"", ll.lat, ll.lon );
+  s_lat = a_coords_dtostr(ll.lat);
+  s_lon = a_coords_dtostr(ll.lon);
+  fprintf ( f, "type=\"trackpoint\" latitude=\"%s\" longitude=\"%s\"", s_lat, s_lon );
+  g_free ( s_lat ); 
+  g_free ( s_lon );
 
-  if ( tp->altitude != VIK_DEFAULT_ALTITUDE )
-    fprintf ( f, " altitude=\"%f\"", tp->altitude );
+  if ( tp->altitude != VIK_DEFAULT_ALTITUDE ) {
+    gchar *s_alt = a_coords_dtostr(tp->altitude);
+    fprintf ( f, " altitude=\"%s\"", s_alt );
+    g_free(s_alt);
+  }
   if ( tp->has_timestamp )
     fprintf ( f, " unixtime=\"%ld\"", tp->timestamp );
   if ( tp->newsegment )
index 9a6f79782f721bdd33ef930a63529c79df8031c7..a8fe7a40721e76824e0abcd96b9f69c0c19eac2d 100644 (file)
--- a/src/gpx.c
+++ b/src/gpx.c
@@ -537,39 +537,14 @@ entitize(const char * str)
 
 /* export GPX */
 
-/**
- * Convert a double to a string WITHOUT LOCALE.
- *
- * Following GPX specifications, decimal values are xsd:decimal
- * So, they must use the period separator, not the localized one.
- *
- * The returned value must be freed by g_free.
- */
-static gchar *gpx_dtostr ( double d )
-{
-  /* In order to ignore locale, we do all the stuff manually */
-  double integer, decimal;
-  integer = trunc(d);
-
-  /* 6 decimals are sufficient (~0,1m) */
-  /* Cf. http://www.tbs-sct.gc.ca/rpm-gbi/guides/Latlong_f.asp */
-  decimal = d - integer;
-  decimal = decimal * 1000000;
-  decimal = trunc ( decimal );
-  decimal = fabs ( decimal );
-
-  /* Format */
-  return g_strdup_printf ( "%g.%06g", integer, decimal );
-}
-
 static void gpx_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f ) 
 {
   static struct LatLon ll;
   gchar *s_lat,*s_lon;
   gchar *tmp;
   vik_coord_to_latlon ( &(wp->coord), &ll );
-  s_lat = gpx_dtostr( ll.lat );
-  s_lon = gpx_dtostr( ll.lon );
+  s_lat = a_coords_dtostr( ll.lat );
+  s_lon = a_coords_dtostr( ll.lon );
   fprintf ( f, "<wpt lat=\"%s\" lon=\"%s\"%s>\n",
                s_lat, s_lon, wp->visible ? "" : " hidden=\"hidden\"" );
   g_free ( s_lat );
@@ -581,7 +556,7 @@ static void gpx_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f )
 
   if ( wp->altitude != VIK_DEFAULT_ALTITUDE )
   {
-    tmp = gpx_dtostr ( wp->altitude );
+    tmp = a_coords_dtostr ( wp->altitude );
     fprintf ( f, "  <ele>%s</ele>\n", tmp );
     g_free ( tmp );
   }
@@ -617,15 +592,15 @@ static void gpx_write_trackpoint ( VikTrackpoint *tp, FILE *f )
   if ( tp->newsegment )
     fprintf ( f, "  </trkseg>\n  <trkseg>\n" );
 
-  s_lat = gpx_dtostr( ll.lat );
-  s_lon = gpx_dtostr( ll.lon );
+  s_lat = a_coords_dtostr( ll.lat );
+  s_lon = a_coords_dtostr( ll.lon );
   fprintf ( f, "  <trkpt lat=\"%s\" lon=\"%s\">\n", s_lat, s_lon );
   g_free ( s_lat );
   g_free ( s_lon );
 
   if ( tp->altitude != VIK_DEFAULT_ALTITUDE )
   {
-    s_alt = gpx_dtostr ( tp->altitude );
+    s_alt = a_coords_dtostr ( tp->altitude );
     fprintf ( f, "    <ele>%s</ele>\n", s_alt );
     g_free ( s_alt );
   }