]> git.tdb.fi Git - ext/subsurface.git/blobdiff - dive.c
Properly merge dive buddies and divemaster information
[ext/subsurface.git] / dive.c
diff --git a/dive.c b/dive.c
index 1b906ee43bd9a7e86db41d08cc5d3f288732a012..1de3759d1bd9b76bc481b13e6f98d4d21cb4c906 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -5,6 +5,31 @@
 
 #include "dive.h"
 
+double get_depth_units(unsigned int mm, int *frac, const char **units)
+{
+       int decimals;
+       double d;
+       const char *unit;
+
+       switch (output_units.length) {
+       case METERS:
+               d = mm / 1000.0;
+               unit = "m";
+               decimals = d < 20;
+               break;
+       case FEET:
+               d = mm_to_feet(mm);
+               unit = "ft";
+               decimals = 0;
+               break;
+       }
+       if (frac)
+               *frac = decimals;
+       if (units)
+               *units = unit;
+       return d;
+}
+
 struct dive *alloc_dive(void)
 {
        const int initial_samples = 5;
@@ -173,6 +198,7 @@ struct dive *fixup_dive(struct dive *dive)
 /* Don't pick a zero for MERGE_MIN() */
 #define MERGE_MAX(res, a, b, n) res->n = MAX(a->n, b->n)
 #define MERGE_MIN(res, a, b, n) res->n = (a->n)?(b->n)?MIN(a->n, b->n):(a->n):(b->n)
+#define MERGE_TXT(res, a, b, n) res->n = merge_text(a->n, b->n)
 
 static struct dive *add_sample(struct sample *sample, int time, struct dive *dive)
 {
@@ -309,8 +335,10 @@ struct dive *try_to_merge(struct dive *a, struct dive *b)
        res = alloc_dive();
 
        res->when = a->when;
-       res->location = merge_text(a->location, b->location);
-       res->notes = merge_text(a->notes, b->notes);
+       MERGE_TXT(res, a, b, location);
+       MERGE_TXT(res, a, b, notes);
+       MERGE_TXT(res, a, b, buddy);
+       MERGE_TXT(res, a, b, divemaster);
        MERGE_MAX(res, a, b, number);
        MERGE_MAX(res, a, b, maxdepth.mm);
        res->meandepth.mm = 0;