diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-23 12:42:01 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-29 00:09:31 +0000 |
commit | 68961a169efc37039cd3fda334efb9ad9927444f (patch) | |
tree | 19365422501eacee57b4cc71722a8a5d8a54f323 /core/parse.c | |
parent | 4cea7b49016923e3f9bb00b60976d7635907e038 (diff) | |
download | subsurface-68961a169efc37039cd3fda334efb9ad9927444f.tar.gz |
Dive site: return pointer to dive_site in get_dive_site_*()
As a first step in removing dive-site uuids, change the interface
of the get_dive_site_*() functions to return pointers instead
of uuids. This makes code a bit more complicated in places where
the uuid is extracted afterwards (needed NULL check). Nevertheless,
these places should disappear once pointers instead of uuids are
stored in the dive-structures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/parse.c')
-rw-r--r-- | core/parse.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/core/parse.c b/core/parse.c index bfb46e8a4..c0d127d0b 100644 --- a/core/parse.c +++ b/core/parse.c @@ -417,16 +417,10 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) char *to_free = NULL; int size = trimspace(buffer); if(size) { - uint32_t uuid = dive->dive_site_uuid; - struct dive_site *ds = get_dive_site_by_uuid(uuid); - if (uuid && !ds) { - // that's strange - we have a uuid but it doesn't exist - let's just ignore it - fprintf(stderr, "dive contains a non-existing dive site uuid %x\n", dive->dive_site_uuid); - uuid = 0; - } - if (!uuid) { + struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid); + if (!ds) { // if the dive doesn't have a uuid, check if there's already a dive site by this name - uuid = get_dive_site_uuid_by_name(buffer, &ds); + ds = get_dive_site_by_name(buffer); } if (ds) { // we have a uuid, let's hope there isn't a different name @@ -437,9 +431,9 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) // but wait, we could have gotten this one based on GPS coords and could // have had two different names for the same site... so let's search the other // way around - uint32_t exact_match_uuid = get_dive_site_uuid_by_gps_and_name(buffer, &ds->location); - if (exact_match_uuid) { - dive->dive_site_uuid = exact_match_uuid; + struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location); + if (exact_match) { + dive->dive_site_uuid = exact_match->uuid; } else { dive->dive_site_uuid = create_dive_site(buffer, dive->when); struct dive_site *newds = get_dive_site_by_uuid(dive->dive_site_uuid); @@ -453,7 +447,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) } } else { // add the existing dive site to the current dive - dive->dive_site_uuid = uuid; + dive->dive_site_uuid = ds->uuid; } } else { dive->dive_site_uuid = create_dive_site(buffer, dive->when); |