summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/dive.c20
-rw-r--r--core/dive.h3
2 files changed, 22 insertions, 1 deletions
diff --git a/core/dive.c b/core/dive.c
index 3ec9b1a82..6d2645cef 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -166,6 +166,11 @@ struct event *create_event(unsigned int time, int type, int flags, int value, co
return ev;
}
+struct event *clone_event_rename(const struct event *ev, const char *name)
+{
+ return create_event(ev->time.seconds, ev->type, ev->flags, ev->value, name);
+}
+
void add_event_to_dc(struct divecomputer *dc, struct event *ev)
{
struct event **p;
@@ -192,7 +197,20 @@ struct event *add_event(struct divecomputer *dc, unsigned int time, int type, in
return ev;
}
-static int same_event(const struct event *a, const struct event *b)
+/* Substitutes an event in a divecomputer for another. No reordering is performed! */
+void swap_event(struct divecomputer *dc, struct event *from, struct event *to)
+{
+ for (struct event **ep = &dc->events; *ep; ep = &(*ep)->next) {
+ if (*ep == from) {
+ to->next = from->next;
+ *ep = to;
+ from->next = NULL; // For good measure.
+ break;
+ }
+ }
+}
+
+bool same_event(const struct event *a, const struct event *b)
{
if (a->time.seconds != b->time.seconds)
return 0;
diff --git a/core/dive.h b/core/dive.h
index 1de68f4ff..727d4bbff 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -378,7 +378,10 @@ extern bool is_cylinder_used(const struct dive *dive, int idx);
extern bool is_cylinder_prot(const struct dive *dive, int idx);
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
extern struct event *create_event(unsigned int time, int type, int flags, int value, const char *name);
+extern struct event *clone_event_rename(const struct event *ev, const char *name);
extern void add_event_to_dc(struct divecomputer *dc, struct event *ev);
+extern void swap_event(struct divecomputer *dc, struct event *from, struct event *to);
+extern bool same_event(const struct event *a, const struct event *b);
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name);
extern void remove_event_from_dc(struct divecomputer *dc, struct event *event);
extern void remove_event(const struct event *event);