diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-05-24 14:02:08 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-24 14:03:36 -0700 |
commit | e4b8cf89a1b798a2f266b3dbc01b82155320ea9d (patch) | |
tree | 04ffc21b2e14f6b53419e00afa54cfcb04c6fcd8 /divelist.c | |
parent | 10e567515161f23510874236efd2f105c033ecec (diff) | |
download | subsurface-e4b8cf89a1b798a2f266b3dbc01b82155320ea9d.tar.gz |
Dive list: move trip merging logic into divelist.c
This also fixes a couple of issues with the existing code:
- removes a memory leak
- treats null and "" the same
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c index e600a6cd2..ca2e9827f 100644 --- a/divelist.c +++ b/divelist.c @@ -864,6 +864,25 @@ void select_dives_in_trip(struct dive_trip *trip) select_dive(get_divenr(dive)); } +/* This only gets called with non-NULL trips. + * It does not combine notes or location, just picks the first one + * (or the second one if the first one is empty */ +void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b) +{ + if (same_string(trip_a->location, "") && trip_b->location) { + free(trip_a->location); + trip_a->location = strdup(trip_b->location); + } + if (same_string(trip_a->notes, "") && trip_b->notes) { + free(trip_a->notes); + trip_a->notes = strdup(trip_b->notes); + } + /* this also removes the dives from trip_b and eventually + * calls delete_trip(trip_b) when the last dive has been moved */ + while (trip_b->dives) + add_dive_to_trip(trip_b->dives, trip_a); +} + void mark_divelist_changed(int changed) { dive_list_changed = changed; |