summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-12 12:49:25 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-12 12:49:25 -0800
commit7fb35c98d3657407287e6674e7d20ff2525ef152 (patch)
treeb7c0c094dc01dfc72a8cc84a3df9f7dabbeba3af
parent0ce215e0d90e8d7612917b75f73bb703b9ada9ae (diff)
downloadsubsurface-7fb35c98d3657407287e6674e7d20ff2525ef152.tar.gz
Get trip location from dive's dive site
This adds another useful helper function as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h8
-rw-r--r--divelist.c7
2 files changed, 11 insertions, 4 deletions
diff --git a/dive.h b/dive.h
index 42cec6224..76ea4b597 100644
--- a/dive.h
+++ b/dive.h
@@ -512,6 +512,14 @@ static inline struct dive_site *get_dive_site_for_dive(struct dive *dive)
return NULL;
}
+static inline char *get_dive_location(struct dive *dive)
+{
+ struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
+ if (ds && ds->name)
+ return ds->name;
+ return NULL;
+}
+
static inline unsigned int number_of_computers(struct dive *dive)
{
unsigned int total_number = 0;
diff --git a/divelist.c b/divelist.c
index f1dd7006c..a6f6332e1 100644
--- a/divelist.c
+++ b/divelist.c
@@ -678,9 +678,9 @@ void add_dive_to_trip(struct dive *dive, dive_trip_t *trip)
dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive)
{
dive_trip_t *dive_trip = calloc(1, sizeof(dive_trip_t));
+
dive_trip->when = dive->when;
- if (dive->location)
- dive_trip->location = strdup(dive->location);
+ dive_trip->location = copy_string(get_dive_location(dive));
insert_trip(&dive_trip);
dive->tripflag = IN_TRIP;
@@ -714,7 +714,7 @@ void autogroup_dives(void)
dive_trip_t *trip = lastdive->divetrip;
add_dive_to_trip(dive, trip);
if (dive->location && !trip->location)
- trip->location = strdup(dive->location);
+ trip->location = copy_string(get_dive_location(dive));
lastdive = dive;
continue;
}
@@ -745,7 +745,6 @@ void delete_single_dive(int idx)
dive_table.dives[--dive_table.nr] = NULL;
/* free all allocations */
free(dive->dc.sample);
- free((void *)dive->location);
free((void *)dive->notes);
free((void *)dive->divemaster);
free((void *)dive->buddy);