diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-20 14:12:15 -0400 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-10-21 19:55:09 +0300 |
commit | 28e3413ff66552f392fecee25068d634cdfe59fc (patch) | |
tree | 5fe303d1e7dc1c371e13b534b85c232e29aea884 /core/load-git.c | |
parent | c9869406301ff72f76b399097f0845fc1102ced1 (diff) | |
download | subsurface-28e3413ff66552f392fecee25068d634cdfe59fc.tar.gz |
Add 'location_t' data structure
Instead of having people treat latitude and longitude as separate
things, just add a 'location_t' data structure that contains both.
Almost all cases want to always act on them together.
This is really just prep-work for adding a few more locations that we
track: I want to add a entry/exit location to each dive (independent of
the dive site) because of how the Garmin Descent gives us the
information (and hopefully, some day, other dive computers too).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core/load-git.c')
-rw-r--r-- | core/load-git.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/core/load-git.c b/core/load-git.c index 0abae4239..2040d2f70 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -31,7 +31,7 @@ struct keyword_action { }; #define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0])) -extern degrees_t parse_degrees(char *buf, char **end); +extern void parse_location(char *buf, location_t *); git_blob *git_tree_entry_blob(git_repository *repo, const git_tree_entry *entry); static char *get_utf8(struct membuffer *b) @@ -152,25 +152,24 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive) { UNUSED(str); uint32_t uuid; - degrees_t latitude = parse_degrees(line, &line); - degrees_t longitude = parse_degrees(line, &line); + location_t location; struct dive *dive = _dive; struct dive_site *ds = get_dive_site_for_dive(dive); + + parse_location(line, &location); if (!ds) { - uuid = get_dive_site_uuid_by_gps(latitude, longitude, NULL); + uuid = get_dive_site_uuid_by_gps(&location, NULL); if (!uuid) - uuid = create_dive_site_with_gps("", latitude, longitude, dive->when); + uuid = create_dive_site_with_gps("", &location, dive->when); dive->dive_site_uuid = uuid; } else { - if (dive_site_has_gps_location(ds) && - (ds->latitude.udeg != latitude.udeg || ds->longitude.udeg != longitude.udeg)) { - const char *coords = printGPSCoords(latitude.udeg, longitude.udeg); + if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) { + const char *coords = printGPSCoords(&location); // we have a dive site that already has GPS coordinates ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords); free((void *)coords); } - ds->latitude = latitude; - ds->longitude = longitude; + ds->location = location; } } @@ -274,14 +273,12 @@ static void parse_site_name(char *line, struct membuffer *str, void *_ds) static void parse_site_notes(char *line, struct membuffer *str, void *_ds) { UNUSED(line); struct dive_site *ds = _ds; ds->notes = strdup(mb_cstring(str)); } -extern degrees_t parse_degrees(char *buf, char **end); static void parse_site_gps(char *line, struct membuffer *str, void *_ds) { UNUSED(str); struct dive_site *ds = _ds; - ds->latitude = parse_degrees(line, &line); - ds->longitude = parse_degrees(line, &line); + parse_location(line, &ds->location); } static void parse_site_geo(char *line, struct membuffer *str, void *_ds) @@ -949,8 +946,7 @@ static void parse_picture_gps(char *line, struct membuffer *str, void *_pic) UNUSED(str); struct picture *pic = _pic; - pic->latitude = parse_degrees(line, &line); - pic->longitude = parse_degrees(line, &line); + parse_location(line, &pic->location); } static void parse_picture_hash(char *line, struct membuffer *str, void *_pic) |