diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-03-05 22:58:47 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | e2df38d868324f2a767d2109cdd8727acb866ca2 (patch) | |
tree | 614b560431d2c61f3f2b1e2f986c7806bd175ae9 /core/parse.c | |
parent | c22fd9f4fd6699333629b8acb1e9c135a9783082 (diff) | |
download | subsurface-e2df38d868324f2a767d2109cdd8727acb866ca2.tar.gz |
Dive site: add dive site ref-counting
Instead of setting dive->dive_site directly, call the
add_dive_to_dive_site() and unregister_dive_from_dive_site()
functions. In the parser this turned out to be a bit tricky.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/parse.c')
-rw-r--r-- | core/parse.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/core/parse.c b/core/parse.c index 87d2b8ea3..b40d2ce90 100644 --- a/core/parse.c +++ b/core/parse.c @@ -415,14 +415,14 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) char *buffer = ds_name; char *to_free = NULL; int size = trimspace(buffer); - if(size) { + if (size) { struct dive_site *ds = dive->dive_site; if (!ds) { - // if the dive doesn't have a uuid, check if there's already a dive site by this name + // if the dive doesn't have a dive site, check if there's already a dive site by this name ds = get_dive_site_by_name(buffer, state->sites); } if (ds) { - // we have a uuid, let's hope there isn't a different name + // we have a dive site, let's hope there isn't a different name if (empty_string(ds->name)) { ds->name = copy_string(buffer); } else if (!same_string(ds->name, buffer)) { @@ -432,10 +432,12 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) // way around struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location, state->sites); if (exact_match) { - dive->dive_site = exact_match; + unregister_dive_from_dive_site(dive); + add_dive_to_dive_site(dive, exact_match); } else { struct dive_site *newds = create_dive_site(buffer, state->sites); - dive->dive_site = newds; + unregister_dive_from_dive_site(dive); + add_dive_to_dive_site(dive, newds); if (has_location(&state->cur_location)) { // we started this uuid with GPS data, so lets use those newds->location = state->cur_location; @@ -444,12 +446,13 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) } newds->notes = add_to_string(newds->notes, translate("gettextFromC", "additional name for site: %s\n"), ds->name); } - } else { + } else if (dive->dive_site != ds) { // add the existing dive site to the current dive - dive->dive_site = ds; + unregister_dive_from_dive_site(dive); + add_dive_to_dive_site(dive, ds); } } else { - dive->dive_site = create_dive_site(buffer, state->sites); + add_dive_to_dive_site(dive, create_dive_site(buffer, state->sites)); } } free(to_free); |