summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/dive.c6
-rw-r--r--core/save-git.c24
-rw-r--r--core/save-xml.c24
3 files changed, 33 insertions, 21 deletions
diff --git a/core/dive.c b/core/dive.c
index 915a04fe5..ecddda6b9 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -159,8 +159,12 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
struct gasmix *get_gasmix_from_event(struct dive *dive, struct event *ev)
{
static struct gasmix dummy;
- if (ev && event_is_gaschange(ev))
+ if (ev && event_is_gaschange(ev)) {
+ int index = ev->gas.index;
+ if (index >= 0 && index <= MAX_CYLINDERS)
+ return &dive->cylinder[index].gasmix;
return &ev->gas.mix;
+ }
return &dummy;
}
diff --git a/core/save-git.c b/core/save-git.c
index ed91debf4..f2803c315 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -220,10 +220,15 @@ static void show_date(struct membuffer *b, timestamp_t when)
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
+static void show_integer(struct membuffer *b, int value, const char *pre, const char *post)
+{
+ put_format(b, " %s%d%s", pre, value, post);
+}
+
static void show_index(struct membuffer *b, int value, const char *pre, const char *post)
{
if (value)
- put_format(b, " %s%d%s", pre, value, post);
+ show_integer(b, value, pre, post);
}
/*
@@ -314,7 +319,7 @@ static void save_samples(struct membuffer *b, int nr, struct sample *s)
}
}
-static void save_one_event(struct membuffer *b, struct event *ev)
+static void save_one_event(struct membuffer *b, struct dive *dive, struct event *ev)
{
put_format(b, "event %d:%02d", FRACTION(ev->time.seconds, 60));
show_index(b, ev->type, "type=", "");
@@ -322,19 +327,18 @@ static void save_one_event(struct membuffer *b, struct event *ev)
show_index(b, ev->value, "value=", "");
show_utf8(b, " name=", ev->name, "");
if (event_is_gaschange(ev)) {
- if (ev->gas.index >= 0) {
- show_index(b, ev->gas.index, "cylinder=", "");
- put_gasmix(b, &ev->gas.mix);
- } else
- put_gasmix(b, &ev->gas.mix);
+ struct gasmix *mix = get_gasmix_from_event(dive, ev);
+ if (ev->gas.index >= 0)
+ show_integer(b, ev->gas.index, "cylinder=", "");
+ put_gasmix(b, mix);
}
put_string(b, "\n");
}
-static void save_events(struct membuffer *b, struct event *ev)
+static void save_events(struct membuffer *b, struct dive *dive, struct event *ev)
{
while (ev) {
- save_one_event(b, ev);
+ save_one_event(b, dive, ev);
ev = ev->next;
}
}
@@ -362,7 +366,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
put_duration(b, dc->surfacetime, "surfacetime ", "min\n");
save_extra_data(b, dc->extra_data);
- save_events(b, dc->events);
+ save_events(b, dive, dc->events);
save_samples(b, dc->samples, dc->sample);
}
diff --git a/core/save-xml.c b/core/save-xml.c
index 045e47c55..80dda63b8 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -178,10 +178,15 @@ static void save_weightsystem_info(struct membuffer *b, struct dive *dive)
}
}
+static void show_integer(struct membuffer *b, int value, const char *pre, const char *post)
+{
+ put_format(b, " %s%d%s", pre, value, post);
+}
+
static void show_index(struct membuffer *b, int value, const char *pre, const char *post)
{
if (value)
- put_format(b, " %s%d%s", pre, value, post);
+ show_integer(b, value, pre, post);
}
static void save_sample(struct membuffer *b, struct sample *sample, struct sample *old)
@@ -258,7 +263,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
put_format(b, " />\n");
}
-static void save_one_event(struct membuffer *b, struct event *ev)
+static void save_one_event(struct membuffer *b, struct dive *dive, struct event *ev)
{
put_format(b, " <event time='%d:%02d min'", FRACTION(ev->time.seconds, 60));
show_index(b, ev->type, "type='", "'");
@@ -266,20 +271,19 @@ static void save_one_event(struct membuffer *b, struct event *ev)
show_index(b, ev->value, "value='", "'");
show_utf8(b, ev->name, " name='", "'", 1);
if (event_is_gaschange(ev)) {
- if (ev->gas.index >= 0) {
- show_index(b, ev->gas.index, "cylinder='", "'");
- put_gasmix(b, &ev->gas.mix);
- } else
- put_gasmix(b, &ev->gas.mix);
+ struct gasmix *mix = get_gasmix_from_event(dive, ev);
+ if (ev->gas.index >= 0)
+ show_integer(b, ev->gas.index, "cylinder='", "'");
+ put_gasmix(b, mix);
}
put_format(b, " />\n");
}
-static void save_events(struct membuffer *b, struct event *ev)
+static void save_events(struct membuffer *b, struct dive *dive, struct event *ev)
{
while (ev) {
- save_one_event(b, ev);
+ save_one_event(b, dive, ev);
ev = ev->next;
}
}
@@ -360,7 +364,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
save_salinity(b, dc);
put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n");
save_extra_data(b, dc->extra_data);
- save_events(b, dc->events);
+ save_events(b, dive, dc->events);
save_samples(b, dc->samples, dc->sample);
put_format(b, " </divecomputer>\n");