summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dives/test38.xml13
-rw-r--r--parse-xml.c19
-rw-r--r--save-xml.c15
3 files changed, 45 insertions, 2 deletions
diff --git a/dives/test38.xml b/dives/test38.xml
new file mode 100644
index 000000000..1f895adc8
--- /dev/null
+++ b/dives/test38.xml
@@ -0,0 +1,13 @@
+<divelog program='subsurface' version='2'>
+<settings>
+</settings>
+<dives>
+<dive number='1' date='2014-03-08' time='09:00:00' duration='30:00 min'>
+ <notes>test dive with dive computer extra data</notes>
+ <divecomputer model='Ficticious Perfect' deviceid='00abcdef' diveid='12345678'>
+ <depth max='30.0 m' mean='15.0 m' />
+ <extradata key='some key' value='some value' />
+ </divecomputer>
+</dive>
+</dives>
+</divelog>
diff --git a/parse-xml.c b/parse-xml.c
index fb5533708..3e8c55bfd 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -120,6 +120,7 @@ static struct tm cur_tm;
static int cur_cylinder_index, cur_ws_index;
static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco;
static int lastcylinderindex, lastsensor;
+static struct extra_data cur_extra_data;
/*
* If we don't have an explicit dive computer,
@@ -348,6 +349,18 @@ static void depth(char *buffer, depth_t *depth)
}
}
+static void extra_data_start(void)
+{
+ memset(&cur_extra_data, 0, sizeof(struct extra_data));
+}
+
+static void extra_data_end(void)
+{
+ // don't save partial structures - we must have both key and value
+ if (cur_extra_data.key && cur_extra_data.value)
+ add_extra_data(cur_dc, cur_extra_data.key, cur_extra_data.value);
+}
+
static void weight(char *buffer, weight_t *weight)
{
union int_or_float val;
@@ -821,7 +834,10 @@ static int match_dc_data_fields(struct divecomputer *dc, const char *name, char
return 1;
if (MATCH("salinity.water", salinity, &dc->salinity))
return 1;
-
+ if (MATCH("key.extradata", utf8_string, &cur_extra_data.key))
+ return 1;
+ if (MATCH("value.extradata", utf8_string, &cur_extra_data.value))
+ return 1;
return 0;
}
@@ -1643,6 +1659,7 @@ static struct nesting {
{ "P", sample_start, sample_end },
{ "userid", userid_start, userid_stop},
{ "picture", picture_start, picture_end },
+ { "extradata", extra_data_start, extra_data_end },
/* Import type recognition */
{ "Divinglog", DivingLog_importer },
diff --git a/save-xml.c b/save-xml.c
index dc85d328b..a128cf04d 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -301,6 +301,19 @@ static void save_tags(struct membuffer *b, struct tag_entry *entry)
}
}
+static void save_extra_data(struct membuffer *b, struct extra_data *ed)
+{
+ while (ed) {
+ if (ed->key && ed->value) {
+ put_string(b, " <extradata");
+ show_utf8(b, ed->key, " key='", "'", 1);
+ show_utf8(b, ed->value, " value='", "'", 1);
+ put_string(b, " />\n");
+ }
+ ed = ed->next;
+ }
+}
+
static void show_date(struct membuffer *b, timestamp_t when)
{
struct tm tm;
@@ -341,7 +354,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
save_airpressure(b, dc);
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_samples(b, dc->samples, dc->sample);