mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: add remove_event_from_dc() function
We have a remove_event() function that 1) frees the event 2) works on the current divecomputer 3) compares the events because the profile has copies of events However, for undo commands 1) we want to keep the event so that we can readd it later 2) we have to work on arbitrary divecomputers 3) we don't work with copies of events Therefore, create a new remove_event_from_dc() function that does all that. Moreover, make the event argument to remove_event() const to (slightly) point out the difference in the API. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
2417a54675
commit
3aa1bb5bfa
2 changed files with 17 additions and 2 deletions
16
core/dive.c
16
core/dive.c
|
|
@ -205,7 +205,21 @@ static int same_event(const struct event *a, const struct event *b)
|
|||
return !strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
void remove_event(struct event *event)
|
||||
/* Remove given event from dive computer. Does *not* free the event. */
|
||||
void remove_event_from_dc(struct divecomputer *dc, struct event *event)
|
||||
{
|
||||
for (struct event **ep = &dc->events; *ep; ep = &(*ep)->next) {
|
||||
if (*ep == event) {
|
||||
*ep = event->next;
|
||||
event->next = NULL; // For good measure.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove an event from current dive computer that is identical to the passed in event.
|
||||
* Frees the event. */
|
||||
void remove_event(const struct event *event)
|
||||
{
|
||||
struct event **ep = ¤t_dc->events;
|
||||
while (ep && !same_event(*ep, event))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue