diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-04-14 15:37:19 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-15 10:24:31 +1200 |
commit | 88dc32fdfcb7cb63b0e47280d1f38395077df757 (patch) | |
tree | d3d733d5da8923a5081a90cd87387216888e0df7 /core | |
parent | 5729f93e1f512aa9e68b0e01743152aaee2b7c12 (diff) | |
download | subsurface-88dc32fdfcb7cb63b0e47280d1f38395077df757.tar.gz |
Core: turn add_single_dive() to append_dive()
The only external caller of add_single_dive() used it to append a
dive to the global dive list. Rename the function accordingly and
remove the index parameter.
The internal caller can use the local insert_dive() function, which
doesn't consider selection. That shouldn't be a problem, as the
caller is doing import.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divelist.c | 31 | ||||
-rw-r--r-- | core/divelist.h | 2 |
2 files changed, 14 insertions, 19 deletions
diff --git a/core/divelist.c b/core/divelist.c index be0d95852..010ef244a 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -845,6 +845,12 @@ MAKE_SORT(trip_table, struct dive_trip *, trips, comp_trips) MAKE_REMOVE(dive_table, struct dive *, dive) MAKE_REMOVE(trip_table, struct dive_trip *, trip) +static void insert_dive(struct dive_table *table, struct dive *d) +{ + int idx = dive_table_get_insertion_index(table, d); + add_to_dive_table(table, idx, d); +} + /* remove a dive from the trip it's associated to, but don't delete the * trip if this was the last dive in the trip. the caller is responsible * for removing the trip, if the trip->dives.nr went to 0. @@ -878,13 +884,11 @@ void remove_dive_from_trip(struct dive *dive, struct trip_table *trip_table_arg) * from trip beforehand. */ void add_dive_to_trip(struct dive *dive, dive_trip_t *trip) { - int idx; if (dive->divetrip == trip) return; if (dive->divetrip) fprintf(stderr, "Warning: adding dive to trip that has trip set\n"); - idx = dive_table_get_insertion_index(&trip->dives, dive); - add_to_dive_table(&trip->dives, idx, dive); + insert_dive(&trip->dives, dive); dive->divetrip = trip; } @@ -1085,12 +1089,11 @@ void delete_single_dive(int idx) delete_dive_from_table(&dive_table, idx); } -/* add a dive at the given index in the global dive table and keep track - * of the number of selected dives. if the index is negative, the dive will - * be added according to dive_less_than() order */ -void add_single_dive(int idx, struct dive *dive) +/* add a dive at the end of the global dive table and keep track + * of the number of selected dives. */ +void append_dive(struct dive *dive) { - add_to_dive_table(&dive_table, idx, dive); + add_to_dive_table(&dive_table, dive_table.nr, dive); if (dive->selected) amount_selected++; } @@ -1279,12 +1282,6 @@ static void merge_imported_dives(struct dive_table *table) } } -static void insert_dive(struct dive_table *table, struct dive *d) -{ - int idx = dive_table_get_insertion_index(table, d); - add_to_dive_table(table, idx, d); -} - /* * Clear a dive_table, trip_table and dive_site_table. Think about generating these with macros. */ @@ -1471,10 +1468,8 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo dives_to_remove.nr = 0; /* Add new dives */ - for (i = 0; i < dives_to_add.nr; i++) { - idx = dive_table_get_insertion_index(&dive_table, dives_to_add.dives[i]); - add_single_dive(idx, dives_to_add.dives[i]); - } + for (i = 0; i < dives_to_add.nr; i++) + insert_dive(&dive_table, dives_to_add.dives[i]); dives_to_add.nr = 0; /* Add new trips */ diff --git a/core/divelist.h b/core/divelist.h index c09b8651a..ae71040c4 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -34,7 +34,7 @@ extern char *get_dive_gas_string(const struct dive *dive); extern struct dive **grow_dive_table(struct dive_table *table); extern int dive_table_get_insertion_index(struct dive_table *table, struct dive *dive); extern void add_to_dive_table(struct dive_table *table, int idx, struct dive *dive); -extern void add_single_dive(int idx, struct dive *dive); +extern void append_dive(struct dive *dive); extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p); extern int get_divenr(const struct dive *dive); extern struct dive_trip *unregister_dive_from_trip(struct dive *dive); |