diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-06 17:33:52 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-06 17:33:52 -0700 |
commit | d314b053014bf74b59050d99516527dced75d483 (patch) | |
tree | de5b75a68262a27e17dd2267e707fb0220a6888b /parse-xml.c | |
parent | 4d19f42a4e0aea4c12b9b05af25c7c0f42ca3a48 (diff) | |
download | subsurface-d314b053014bf74b59050d99516527dced75d483.tar.gz |
Minimally parse some UDDF format dives
Dive dates (at least partial parsing), depths and times.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r-- | parse-xml.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/parse-xml.c b/parse-xml.c index d53c9b323..50f85fbfa 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -515,6 +515,14 @@ static int divinglog_fill_sample(struct sample *sample, const char *name, int le 0; } +static int uddf_fill_sample(struct sample *sample, const char *name, int len, char *buf) +{ + return MATCH(".divetime", sampletime, &sample->time) || + MATCH(".depth", depth, &sample->depth) || + MATCH(".temperature", temperature, &sample->temperature) || + 0; +} + /* We're in samples - try to convert the random xml value to something useful */ static void try_to_fill_sample(struct sample *sample, const char *name, char *buf) { @@ -547,6 +555,11 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu return; break; + case UDDF: + if (uddf_fill_sample(sample, name, len, buf)) + return; + break; + default: break; } @@ -781,6 +794,58 @@ static int uemis_dive_match(struct dive *dive, const char *name, int len, char * 0; } +/* + * Uddf specifies ISO 8601 time format. + * + * There are many variations on that. This handles the useful cases. + */ +static void uddf_datetime(char *buffer, void *_when) +{ + char c; + int y,m,d,hh,mm,ss; + time_t *when = _when; + struct tm tm = { 0 }; + int i; + + i = sscanf(buffer, "%d-%d-%d%c%d:%d:%d", &y, &m, &d, &c, &hh, &mm, &ss); + if (i == 7) + goto success; + ss = 0; + if (i == 6) + goto success; + + i = sscanf(buffer, "%04d%02d%02d%c%02d%02d%02d", &y, &m, &d, &c, &hh, &mm, &ss); + if (i == 7) + goto success; + ss = 0; + if (i == 6) + goto success; +bad_date: + printf("Bad date time %s\n", buffer); + free(buffer); + return; + +success: + if (c != 'T' && c != ' ') + goto bad_date; + tm.tm_year = y; + tm.tm_mon = m - 1; + tm.tm_mday = d; + tm.tm_hour = hh; + tm.tm_min = mm; + tm.tm_sec = ss; + *when = utc_mktime(&tm); + free(buffer); +} + +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) || + 0; +} + /* We're in the top-level dive xml. Try to convert whatever value to a dive value */ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf) { @@ -804,6 +869,11 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf) return; break; + case UDDF: + if (uddf_dive_match(dive, name, len, buf)) + return; + break; + default: break; } |