summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c102
1 files changed, 52 insertions, 50 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 6aa063467..ba5ca1e50 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -234,26 +234,16 @@ enum number_type {
static enum number_type integer_or_float(char *buffer, union int_or_float *res)
{
char *end;
- long val;
double fp;
- /* Integer or floating point? */
- val = strtol(buffer, &end, 10);
- if (val < 0 || end == buffer)
- return NEITHER;
-
- /* Looks like it might be floating point? */
- if (*end == '.') {
- errno = 0;
- fp = g_ascii_strtod(buffer, &end);
- if (!errno) {
- res->fp = fp;
- return FLOAT;
- }
+ errno = 0;
+ fp = g_ascii_strtod(buffer, &end);
+ if (!errno && end != buffer) {
+ res->fp = fp;
+ return FLOAT;
}
- res->fp = val;
- return FLOAT;
+ return NEITHER;
}
static void pressure(char *buffer, void *_press)
@@ -353,10 +343,6 @@ static void temperature(char *buffer, void *_temperature)
switch (integer_or_float(buffer, &val)) {
case FLOAT:
- /* Ignore zero. It means "none" */
- if (!val.fp)
- break;
- /* Celsius */
switch (xml_parsing_units.temperature) {
case KELVIN:
temperature->mkelvin = val.fp * 1000;
@@ -657,6 +643,40 @@ static struct divecomputer *get_dc(void)
return cur_dc ? : &cur_dive->dc;
}
+static int match_dc_data_fields(struct divecomputer *dc, const char *name, int len, char *buf)
+{
+ if (MATCH(".maxdepth", depth, &dc->maxdepth))
+ return 1;
+ if (MATCH(".meandepth", depth, &dc->meandepth))
+ return 1;
+ if (MATCH(".depth.max", depth, &dc->maxdepth))
+ return 1;
+ if (MATCH(".depth.mean", depth, &dc->meandepth))
+ return 1;
+ if (MATCH(".duration", duration, &dc->duration))
+ return 1;
+ if (MATCH(".divetime", duration, &dc->duration))
+ return 1;
+ if (MATCH(".divetimesec", duration, &dc->duration))
+ return 1;
+ if (MATCH(".surfacetime", duration, &dc->surfacetime))
+ return 1;
+ if (MATCH(".airtemp", temperature, &dc->airtemp))
+ return 1;
+ if (MATCH(".watertemp", temperature, &dc->watertemp))
+ return 1;
+ if (MATCH(".temperature.air", temperature, &dc->airtemp))
+ return 1;
+ if (MATCH(".temperature.water", temperature, &dc->watertemp))
+ return 1;
+ if (MATCH(".surface.pressure", pressure, &dc->surface_pressure))
+ return 1;
+ if (MATCH(".water.salinity", salinity, &dc->salinity))
+ return 1;
+
+ return 0;
+}
+
/* We're in the top-level dive xml. Try to convert whatever value to a dive value */
static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf)
{
@@ -675,6 +695,9 @@ static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf)
if (MATCH(".diveid", hex_value, &dc->diveid))
return;
+ if (match_dc_data_fields(dc, name, len, buf))
+ return;
+
nonmatch("divecomputer", name, buf);
}
@@ -797,7 +820,7 @@ static int divinglog_dive_match(struct dive *dive, const char *name, int len, ch
{
return MATCH(".divedate", divedate, &dive->when) ||
MATCH(".entrytime", divetime, &dive->when) ||
- MATCH(".depth", depth, &dive->maxdepth) ||
+ MATCH(".depth", depth, &dive->dc.maxdepth) ||
MATCH(".tanktype", utf8_string, &dive->cylinder[0].type.description) ||
MATCH(".tanksize", cylindersize, &dive->cylinder[0].type.size) ||
MATCH(".presw", pressure, &dive->cylinder[0].type.workingpressure) ||
@@ -856,8 +879,8 @@ success:
static int uddf_dive_match(struct dive *dive, const char *name, int len, char *buf)
{
return MATCH(".datetime", uddf_datetime, &dive->when) ||
- MATCH(".diveduration", duration, &dive->duration) ||
- MATCH(".greatestdepth", depth, &dive->maxdepth) ||
+ MATCH(".diveduration", duration, &dive->dc.duration) ||
+ MATCH(".greatestdepth", depth, &dive->dc.maxdepth) ||
0;
}
@@ -966,34 +989,13 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
return;
if (MATCH(".datetime", divedatetime, &dive->when))
return;
- if (MATCH(".maxdepth", depth, &dive->maxdepth))
- return;
- if (MATCH(".meandepth", depth, &dive->meandepth))
- return;
- if (MATCH(".depth.max", depth, &dive->maxdepth))
- return;
- if (MATCH(".depth.mean", depth, &dive->meandepth))
- return;
- if (MATCH(".duration", duration, &dive->duration))
- return;
- if (MATCH(".divetime", duration, &dive->duration))
- return;
- if (MATCH(".divetimesec", duration, &dive->duration))
- return;
- if (MATCH(".surfacetime", duration, &dive->surfacetime))
- return;
- if (MATCH(".airtemp", temperature, &dive->airtemp))
- return;
- if (MATCH(".watertemp", temperature, &dive->watertemp))
- return;
- if (MATCH(".temperature.air", temperature, &dive->airtemp))
- return;
- if (MATCH(".temperature.water", temperature, &dive->watertemp))
- return;
- if (MATCH(".surface.pressure", pressure, &dive->surface_pressure))
- return;
- if (MATCH(".water.salinity", salinity, &dive->salinity))
+ /*
+ * Legacy format note: per-dive depths and duration get saved
+ * in the first dive computer entry
+ */
+ if (match_dc_data_fields(&dive->dc, name, len, buf))
return;
+
if (MATCH(".cylinderstartpressure", pressure, &dive->cylinder[0].start))
return;
if (MATCH(".cylinderendpressure", pressure, &dive->cylinder[0].end))