diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-01-27 12:26:27 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-27 12:26:27 -0800 |
commit | 0a91669efe9f3ad217c5cdd220d0d71eba0caf8b (patch) | |
tree | 5b6ce95f1b27197b005f9dfdf57f30f143560f45 /info.c | |
parent | 1cbffeaaf5a92792beac0e4848082910c82e9498 (diff) | |
download | subsurface-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.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -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; |