summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-01-28 21:07:52 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-28 21:43:43 -0800
commitd322f6762a4916e91b8be3b5118e1310f97c8b68 (patch)
tree9ba8b8628c3370ad58a2230956b3f78f387d0194 /parse-xml.c
parent37282176d5b3348beacda3622ca4726c4d1f41d7 (diff)
downloadsubsurface-d322f6762a4916e91b8be3b5118e1310f97c8b68.tar.gz
Be even more permissive in our date parsing logic
Not that we aren't already insanely permissive in parsing just about any random noise that could _possibly_ be construed as xml and turn it into a dive, this makes us even laxer. If somebody wants to have a <date> tag with both date and time, why the heck not? It's fine. And if it has just the date, that's fine too. And the date can be in any of several formats. We really don't care, the more permissive, the better. We strive to always write beautiful xml, but let's face it, not everybody else does. If we can turn random line noise into a dive, we should do so. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 5061227e3..e2f84f073 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -168,25 +168,26 @@ static enum import_source {
static void divedate(char *buffer, void *_when)
{
int d,m,y;
+ int hh,mm,ss;
timestamp_t *when = _when;
- int success;
- success = cur_tm.tm_sec | cur_tm.tm_min | cur_tm.tm_hour;
- if (sscanf(buffer, "%d.%d.%d", &d, &m, &y) == 3) {
- cur_tm.tm_year = y;
- cur_tm.tm_mon = m-1;
- cur_tm.tm_mday = d;
- } else if (sscanf(buffer, "%d-%d-%d", &y, &m, &d) == 3) {
- cur_tm.tm_year = y;
- cur_tm.tm_mon = m-1;
- cur_tm.tm_mday = d;
+ hh = 0; mm = 0; ss = 0;
+ if (sscanf(buffer, "%d.%d.%d %d:%d:%d", &d, &m, &y, &hh, &mm, &ss) >= 3) {
+ /* This is ok, and we got at least the date */
+ } else if (sscanf(buffer, "%d-%d-%d %d:%d:%d", &y, &m, &d, &hh, &mm, &ss) >= 3) {
+ /* This is also ok */
} else {
fprintf(stderr, "Unable to parse date '%s'\n", buffer);
- success = 0;
+ return;
}
+ cur_tm.tm_year = y;
+ cur_tm.tm_mon = m-1;
+ cur_tm.tm_mday = d;
+ cur_tm.tm_hour = hh;
+ cur_tm.tm_min = mm;
+ cur_tm.tm_sec = ss;
- if (success)
- *when = utc_mktime(&cur_tm);
+ *when = utc_mktime(&cur_tm);
}
static void divetime(char *buffer, void *_when)
@@ -198,8 +199,7 @@ static void divetime(char *buffer, void *_when)
cur_tm.tm_hour = h;
cur_tm.tm_min = m;
cur_tm.tm_sec = s;
- if (cur_tm.tm_year)
- *when = utc_mktime(&cur_tm);
+ *when = utc_mktime(&cur_tm);
}
}