diff options
Diffstat (limited to 'dive.c')
-rw-r--r-- | dive.c | 47 |
1 files changed, 41 insertions, 6 deletions
@@ -19,6 +19,26 @@ static const char *default_tags[] = { QT_TRANSLATE_NOOP("gettextFromC", "deco") }; +void make_first_dc() +{ + struct divecomputer *dc = ¤t_dive->dc; + struct divecomputer *newdc = malloc(sizeof(*newdc)); + struct divecomputer *cur_dc = current_dc; /* needs to be in a local variable so the macro isn't re-executed */ + + /* skip the current DC in the linked list */ + while (dc && dc->next != cur_dc) + dc = dc->next; + if (!dc) { + fprintf(stderr, "data inconsistent: can't find the current DC"); + return; + } + dc->next = cur_dc->next; + *newdc = current_dive->dc; + current_dive->dc = *cur_dc; + current_dive->dc.next = newdc; + free(cur_dc); +} + void add_event(struct divecomputer *dc, int time, int type, int flags, int value, const char *name) { struct event *ev, **p; @@ -45,6 +65,17 @@ void add_event(struct divecomputer *dc, int time, int type, int flags, int value remember_event(name); } +void remove_event(struct event* event) +{ + struct event **ep = ¤t_dc->events; + while (ep && *ep != event) + ep = &(*ep)->next; + if (ep) { + *ep = event->next; + free(event); + } +} + int get_pressure_units(unsigned int mb, const char **units) { int pressure; @@ -221,6 +252,7 @@ struct dive *alloc_dive(void) if (!dive) exit(1); memset(dive, 0, sizeof(*dive)); + dive->id = dive_getUniqID(dive); return dive; } @@ -955,7 +987,10 @@ struct dive *fixup_dive(struct dive *dive) weightsystem_t *ws = dive->weightsystem + i; add_weightsystem_description(ws); } - dive->id = dive_getUniqID(dive); + /* we should always have a uniq ID as that gets assigned during alloc_dive(), + * but we want to make sure... */ + if (!dive->id) + dive->id = dive_getUniqID(dive); return dive; } @@ -1296,11 +1331,8 @@ static void dc_cylinder_renumber(struct dive *dive, struct divecomputer *dc, int static void cylinder_renumber(struct dive *dive, int mapping[]) { struct divecomputer *dc; - - dc = &dive->dc; - do { + for_each_dc(dive, dc) dc_cylinder_renumber(dive, dc, mapping); - } while ((dc = dc->next) != NULL); } /* @@ -1905,6 +1937,9 @@ static void interleave_dive_computers(struct divecomputer *res, if (match) { merge_events(res, a, match, offset); merge_samples(res, a, match, offset); + /* Use the diveid of the later dive! */ + if (offset > 0) + res->diveid = match->diveid; } else { res->sample = a->sample; res->samples = a->samples; @@ -2135,7 +2170,7 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer if (dl) { /* If we prefer downloaded, do those first, and get rid of "might be same" computers */ join_dive_computers(&res->dc, &dl->dc, &a->dc, 1); - } else if (offset) + } else if (offset && might_be_same_device(&a->dc, &b->dc)) interleave_dive_computers(&res->dc, &a->dc, &b->dc, offset); else join_dive_computers(&res->dc, &a->dc, &b->dc, 0); |