summaryrefslogtreecommitdiffstats
path: root/core/dive.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-07-27 09:00:37 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-09 19:19:04 +0100
commit860807bf922f6fa08260def906df4d864353c90f (patch)
tree9b573173b9275f1caacf87ee2bd60ba757b0a23b /core/dive.c
parentf2bcc240c4d63c8e18d963ddb917e76fd3b939ec (diff)
downloadsubsurface-860807bf922f6fa08260def906df4d864353c90f.tar.gz
Core: create copy_cylinder_type() function
Move the loop body of copy_cylinder_types() into its own function. When using variable sized arrays, this loop will have to treat two cases (overwrite cylinder and add new cylinder), so that makes things more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/dive.c')
-rw-r--r--core/dive.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/core/dive.c b/core/dive.c
index 1a1b598ea..241125f61 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -517,6 +517,17 @@ int nr_weightsystems(const struct dive *dive)
return dive->weightsystems.nr;
}
+static void copy_cylinder_type(const cylinder_t *s, cylinder_t *d)
+{
+ free(d->type.description);
+ d->type = s->type;
+ d->type.description = s->type.description ? strdup(s->type.description) : NULL;
+ d->gasmix = s->gasmix;
+ d->depth = s->depth;
+ d->cylinder_use = s->cylinder_use;
+ d->manually_added = true;
+}
+
/* copy the equipment data part of the cylinders but keep pressures */
static void copy_cylinder_types(const struct dive *s, struct dive *d)
{
@@ -524,16 +535,8 @@ static void copy_cylinder_types(const struct dive *s, struct dive *d)
if (!s || !d)
return;
- for (i = 0; i < MAX_CYLINDERS; i++) {
- free((void *)d->cylinder[i].type.description);
- d->cylinder[i].type = s->cylinder[i].type;
- d->cylinder[i].type.description = s->cylinder[i].type.description ?
- strdup(s->cylinder[i].type.description) : NULL;
- d->cylinder[i].gasmix = s->cylinder[i].gasmix;
- d->cylinder[i].depth = s->cylinder[i].depth;
- d->cylinder[i].cylinder_use = s->cylinder[i].cylinder_use;
- d->cylinder[i].manually_added = true;
- }
+ for (i = 0; i < MAX_CYLINDERS; i++)
+ copy_cylinder_type(s->cylinder + i, d->cylinder + i);
}
void copy_cylinders(const struct dive *s, struct dive *d, bool used_only)