]> git.street.me.uk Git - andy/viking.git/blobdiff - src/degrees_converters.c
Remove not very helpful debug message since it can generate large volumes of messages.
[andy/viking.git] / src / degrees_converters.c
index fbf433fd1057a2bf609b8e35621a231db7ad00d2..c34ed9a6256ba6033da1642f15faa693cbeb8344 100644 (file)
@@ -25,8 +25,8 @@
 #ifdef HAVE_MATH_H
 #include <math.h>
 #endif
-#include <glib.h>
 #include <string.h>
+#include "degrees_converters.h"
 
 #define DEGREE_SYMBOL "\302\260"
 
@@ -138,7 +138,7 @@ static gchar *convert_dec_to_dms(gdouble dec, gchar pos_c, gchar neg_c)
   val_s = (tmp - val_m) * 60;
 
   /* Format */
-  result = g_strdup_printf ( "%c%d" DEGREE_SYMBOL "%d'%f\"",
+  result = g_strdup_printf ( "%c%d" DEGREE_SYMBOL "%d'%.4f\"",
                              sign_c, val_d, val_m, val_s );
   return result;
 }
@@ -178,8 +178,13 @@ gdouble convert_dms_to_dec(const gchar *dms)
                        gdouble value;
                        ptr = strpbrk (endptr, "0123456789,.");
                        if (ptr != NULL) {
-                         value = g_strtod((const gchar *)ptr, (gchar **)&endptr);
-                       nbFloat++;
+                               const gchar *tmpptr = endptr;
+                               value = g_strtod((const gchar *)ptr, (gchar **)&endptr);
+                               // Detect when endptr hasn't changed (which may occur if no conversion took place)
+                               //  particularly if the last character is a ',' or there are multiple '.'s like '5.5.'
+                               if ( endptr == tmpptr )
+                                       break;
+                               nbFloat++;
                switch(nbFloat) {
                        case 1:
                                d = value;
@@ -190,6 +195,7 @@ gdouble convert_dms_to_dec(const gchar *dms)
                        case 3:
                                s = value;
                                break;
+                       default: break;
                }
                        }
                } while (ptr != NULL && endptr != NULL);