mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
9aefaa1ec8
commit
d6b4109409
3 changed files with 45 additions and 2 deletions
13
dives/test38.xml
Normal file
13
dives/test38.xml
Normal file
|
@ -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>
|
19
parse-xml.c
19
parse-xml.c
|
@ -120,6 +120,7 @@ static struct tm cur_tm;
|
||||||
static int cur_cylinder_index, cur_ws_index;
|
static int cur_cylinder_index, cur_ws_index;
|
||||||
static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco;
|
static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco;
|
||||||
static int lastcylinderindex, lastsensor;
|
static int lastcylinderindex, lastsensor;
|
||||||
|
static struct extra_data cur_extra_data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we don't have an explicit dive computer,
|
* 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)
|
static void weight(char *buffer, weight_t *weight)
|
||||||
{
|
{
|
||||||
union int_or_float val;
|
union int_or_float val;
|
||||||
|
@ -821,7 +834,10 @@ static int match_dc_data_fields(struct divecomputer *dc, const char *name, char
|
||||||
return 1;
|
return 1;
|
||||||
if (MATCH("salinity.water", salinity, &dc->salinity))
|
if (MATCH("salinity.water", salinity, &dc->salinity))
|
||||||
return 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1643,6 +1659,7 @@ static struct nesting {
|
||||||
{ "P", sample_start, sample_end },
|
{ "P", sample_start, sample_end },
|
||||||
{ "userid", userid_start, userid_stop},
|
{ "userid", userid_start, userid_stop},
|
||||||
{ "picture", picture_start, picture_end },
|
{ "picture", picture_start, picture_end },
|
||||||
|
{ "extradata", extra_data_start, extra_data_end },
|
||||||
|
|
||||||
/* Import type recognition */
|
/* Import type recognition */
|
||||||
{ "Divinglog", DivingLog_importer },
|
{ "Divinglog", DivingLog_importer },
|
||||||
|
|
15
save-xml.c
15
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)
|
static void show_date(struct membuffer *b, timestamp_t when)
|
||||||
{
|
{
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
@ -341,7 +354,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
|
||||||
save_airpressure(b, dc);
|
save_airpressure(b, dc);
|
||||||
save_salinity(b, dc);
|
save_salinity(b, dc);
|
||||||
put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n");
|
put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n");
|
||||||
|
save_extra_data(b, dc->extra_data);
|
||||||
save_events(b, dc->events);
|
save_events(b, dc->events);
|
||||||
save_samples(b, dc->samples, dc->sample);
|
save_samples(b, dc->samples, dc->sample);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue