From c26e922802826dc9e2f044312cc33d5a037f6a10 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 4 Aug 2019 19:17:11 +0200 Subject: Cleanup: return cylinder from add_empty_cylinder() As a convenience, return the cylinder from add_empty_cylinder() to spare the caller from the nasty expression to fetch the last cylinder. Signed-off-by: Berthold Stoeger --- core/dive.c | 4 +--- core/equipment.c | 3 ++- core/equipment.h | 2 +- core/parse.c | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/dive.c b/core/dive.c index 0b68819fa..24fa8780d 100644 --- a/core/dive.c +++ b/core/dive.c @@ -2126,9 +2126,7 @@ static int match_cylinder(const cylinder_t *cyl, const struct dive *dive, const */ static void merge_one_cylinder(struct cylinder_table *t, const cylinder_t *a, const cylinder_t *b) { - cylinder_t *res; - add_empty_cylinder(t); - res = t->cylinders + (t->nr - 1); + cylinder_t *res = add_empty_cylinder(t); res->type.size.mliter = a->type.size.mliter ? a->type.size.mliter : b->type.size.mliter; res->type.workingpressure.mbar = a->type.workingpressure.mbar ? diff --git a/core/equipment.c b/core/equipment.c index 13e4a0486..3a2e6db4b 100644 --- a/core/equipment.c +++ b/core/equipment.c @@ -314,11 +314,12 @@ void copy_cylinder_types(const struct dive *s, struct dive *d) add_cloned_cylinder(&d->cylinders, s->cylinders.cylinders[i]); } -void add_empty_cylinder(struct cylinder_table *t) +cylinder_t *add_empty_cylinder(struct cylinder_table *t) { cylinder_t cyl = { 0 }; cyl.type.description = strdup(""); add_to_cylinder_table(t, t->nr, cyl); + return &t->cylinders[t->nr - 1]; } /* access to cylinders is controlled by two functions: diff --git a/core/equipment.h b/core/equipment.h index ce5683003..86e23f9f8 100644 --- a/core/equipment.h +++ b/core/equipment.h @@ -69,7 +69,7 @@ extern int cylinderuse_from_text(const char *text); extern void copy_weights(const struct weightsystem_table *s, struct weightsystem_table *d); extern void copy_cylinder_types(const struct dive *s, struct dive *d); extern void add_cloned_weightsystem(struct weightsystem_table *t, weightsystem_t ws); -extern void add_empty_cylinder(struct cylinder_table *t); +extern cylinder_t *add_empty_cylinder(struct cylinder_table *t); extern void add_cloned_cylinder(struct cylinder_table *t, cylinder_t cyl); extern cylinder_t *get_cylinder(const struct dive *d, int idx); extern cylinder_t *get_or_create_cylinder(struct dive *d, int idx); diff --git a/core/parse.c b/core/parse.c index 8a07ba818..30d6a8ad5 100644 --- a/core/parse.c +++ b/core/parse.c @@ -289,8 +289,7 @@ void picture_end(struct parser_state *state) cylinder_t *cylinder_start(struct parser_state *state) { - add_empty_cylinder(&state->cur_dive->cylinders); - return &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1]; + return add_empty_cylinder(&state->cur_dive->cylinders); } void cylinder_end(struct parser_state *state) -- cgit v1.2.3-70-g09d2