summaryrefslogtreecommitdiffstats
path: root/info.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-27 12:26:27 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-27 12:26:27 -0800
commit0a91669efe9f3ad217c5cdd220d0d71eba0caf8b (patch)
tree5b6ce95f1b27197b005f9dfdf57f30f143560f45 /info.c
parent1cbffeaaf5a92792beac0e4848082910c82e9498 (diff)
downloadsubsurface-0a91669efe9f3ad217c5cdd220d0d71eba0caf8b.tar.gz
Parse an empty string as "no GPS coordinates"
That's much more intuitive to remove GPS data from a dive than having to type in 0,0 as coordinates. With this change we also skip leading whitespace for WGS84 coordinates. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'info.c')
-rw-r--r--info.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/info.c b/info.c
index 49caf748b..d8a2fdc00 100644
--- a/info.c
+++ b/info.c
@@ -394,6 +394,26 @@ static int get_rating(const char *string)
return rating_val;
}
+static gboolean parse_gps_text(const char *gps_text, double *latitude, double *longitude)
+{
+ const char *text = gps_text;
+
+ while (isspace(*text))
+ text++;
+
+ /* an empty string is interpreted as 0.0,0.0 and therefore "no gps location" */
+ if (!*text) {
+ *latitude = 0.0;
+ *longitude = 0.0;
+ return TRUE;
+ }
+ /* WGS84 style decimal degrees */
+ if (sscanf(text, "%lf,%lf", latitude, longitude) == 2)
+ return TRUE;
+
+ return FALSE;
+}
+
static gboolean gps_changed(struct dive *dive, struct dive *master, const char *gps_text)
{
double latitude, longitude;
@@ -404,8 +424,10 @@ static gboolean gps_changed(struct dive *dive, struct dive *master, const char *
if (master && (master->latitude.udeg != dive->latitude.udeg ||
master->longitude.udeg != dive->longitude.udeg))
return FALSE;
- if (sscanf(gps_text, "%lf,%lf", &latitude, &longitude) != 2)
+
+ if (!parse_gps_text(gps_text, &latitude, &longitude))
return FALSE;
+
latudeg = 1000000 * latitude + 0.5;
longudeg = 1000000 * longitude + 0.5;