Cleanup: detangle unregister_dive() and delete_single_dive()

These two functions were called in different contexts:
- unregister_dive(): from the undo-commands to remove the dive
  from the global dive table, but not delete it. The dive was
  already removed from its trip.
- delete_single_dive(): from non-undo code. Most of it not in
  use and removed in a sibling-commit. Here, the dive is supposed
  to be removed from its trip and a new selection is calculated.

delete_single_dive() calls unregister_dive(), which removes the
dive from its trip. Move remove_dive_from_trip() from the former
to the latter and make both functions independent. Instead
of deleting the dive explicitly in delete_single_dive(), call
the delete_dive_from_table() function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-12-09 13:01:10 +01:00 committed by Dirk Hohndel
parent dfd7f98129
commit c64c9c923b

View file

@ -1075,16 +1075,15 @@ void delete_dive_from_table(struct dive_table *table, int idx)
unregister_dive_from_table(table, idx);
}
/* this removes a dive from the dive table and trip-list but doesn't
* free the resources associated with the dive. It returns a pointer
* to the unregistered dive. The returned dive has the selection-
* and hidden-flags cleared. */
/* This removes a dive from the global dive table but doesn't free the
* resources associated with the dive. The caller must removed the dive
* from the trip-list. Returns a pointer to the unregistered dive.
* The unregistered dive has the selection- and hidden-flags cleared. */
struct dive *unregister_dive(int idx)
{
struct dive *dive = get_dive(idx);
if (!dive)
return NULL; /* this should never happen */
remove_dive_from_trip(dive, false);
unregister_dive_from_table(&dive_table, idx);
if (dive->selected)
amount_selected--;
@ -1092,8 +1091,8 @@ struct dive *unregister_dive(int idx)
return dive;
}
/* this implements the mechanics of removing the dive from the table,
* but doesn't deal with updating dive trips, etc */
/* this implements the mechanics of removing the dive from the global
* dive table and the trip, but doesn't deal with updating dive trips, etc */
void delete_single_dive(int idx)
{
struct dive *dive = get_dive(idx);
@ -1101,8 +1100,8 @@ void delete_single_dive(int idx)
return; /* this should never happen */
if (dive->selected)
deselect_dive(dive);
dive = unregister_dive(idx);
free_dive(dive);
remove_dive_from_trip(dive, false);
delete_dive_from_table(&dive_table, idx);
}
struct dive **grow_dive_table(struct dive_table *table)