diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-11-06 10:34:19 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-07 12:59:15 -0800 |
commit | d6b410940975c7ccaf63c3509eda4ff25d16190f (patch) | |
tree | 5542de55997a256c1d168a404aaa231853715210 /parse-xml.c | |
parent | 9aefaa1ec87aff88bb1170bd6a79b76d351f804f (diff) | |
download | subsurface-d6b410940975c7ccaf63c3509eda4ff25d16190f.tar.gz |
Load and save extra data in Subsurface XML format
Includes test dive to test missing attributes and the overall syntax.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r-- | parse-xml.c | 19 |
1 files changed, 18 insertions, 1 deletions
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 }, |