mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
1cbffeaaf5
commit
0a91669efe
1 changed files with 23 additions and 1 deletions
24
info.c
24
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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue