[PATCH 3/2] Don't ignore surface events in xml parsing

Linus Torvalds torvalds at linux-foundation.org
Tue May 31 11:43:21 PDT 2016


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Tue, 31 May 2016 11:38:47 -0700
Subject: [PATCH 3/2] Don't ignore surface events in xml parsing

I missed the fact that not only did we skip importing surface events
from the dive computer, we had also made our xml parser ignore them when
loading an xml file.  All part of our historical "let's ignore surface
events because dive computers are being very annoying about it".

Signed-off-by: Linus Torvalds <torvalds at linux-foundtion.org>
---

I was wondering why I didn't see any surface events even after importing 
all the dives from my Vyper Air. This was the silly reason...

Anyway, with this, I see a few rather annoying surface events (like at the 
beginning of most dives). So now I have a test-case at least for soem 
cases that should just be suppressed.

 core/parse-xml.c | 58 +++++++++++++++++++++++++++-----------------------------
 1 file changed, 28 insertions(+), 30 deletions(-)

diff --git a/core/parse-xml.c b/core/parse-xml.c
index 87e2e6acd094..c79d7a9fcac2 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -1642,38 +1642,36 @@ static void event_start(void)
 static void event_end(void)
 {
 	struct divecomputer *dc = get_dc();
-	if (strcmp(cur_event.name, "surface") != 0) {			/* 123 is a magic event that we used for a while to encode images in dives */
-		if (cur_event.type == 123) {
-			struct picture *pic = alloc_picture();
-			pic->filename = strdup(cur_event.name);
-			/* theoretically this could fail - but we didn't support multi year offsets */
-			pic->offset.seconds = cur_event.time.seconds;
-			dive_add_picture(cur_dive, pic);
-		} else {
-			struct event *ev;
-			/* At some point gas change events did not have any type. Thus we need to add
-			 * one on import, if we encounter the type one missing.
-			 */
-			if (cur_event.type == 0 && strcmp(cur_event.name, "gaschange") == 0)
-				cur_event.type = cur_event.value >> 16 > 0 ? SAMPLE_EVENT_GASCHANGE2 : SAMPLE_EVENT_GASCHANGE;
-			ev = add_event(dc, cur_event.time.seconds,
-				       cur_event.type, cur_event.flags,
-				       cur_event.value, cur_event.name);
+	if (cur_event.type == 123) {
+		struct picture *pic = alloc_picture();
+		pic->filename = strdup(cur_event.name);
+		/* theoretically this could fail - but we didn't support multi year offsets */
+		pic->offset.seconds = cur_event.time.seconds;
+		dive_add_picture(cur_dive, pic);
+	} else {
+		struct event *ev;
+		/* At some point gas change events did not have any type. Thus we need to add
+		 * one on import, if we encounter the type one missing.
+		 */
+		if (cur_event.type == 0 && strcmp(cur_event.name, "gaschange") == 0)
+			cur_event.type = cur_event.value >> 16 > 0 ? SAMPLE_EVENT_GASCHANGE2 : SAMPLE_EVENT_GASCHANGE;
+		ev = add_event(dc, cur_event.time.seconds,
+			       cur_event.type, cur_event.flags,
+			       cur_event.value, cur_event.name);
 
-			/*
-			 * Older logs might mark the dive to be CCR by having an "SP change" event at time 0:00. Better
-			 * to mark them being CCR on import so no need for special treatments elsewhere on the code.
-			 */
-			if (ev && cur_event.time.seconds == 0 && cur_event.type == SAMPLE_EVENT_PO2 && dc->divemode==OC) {
-				dc->divemode = CCR;
-			}
+		/*
+		 * Older logs might mark the dive to be CCR by having an "SP change" event at time 0:00. Better
+		 * to mark them being CCR on import so no need for special treatments elsewhere on the code.
+		 */
+		if (ev && cur_event.time.seconds == 0 && cur_event.type == SAMPLE_EVENT_PO2 && dc->divemode==OC) {
+			dc->divemode = CCR;
+		}
 
-			if (ev && event_is_gaschange(ev)) {
-				/* See try_to_fill_event() on why the filled-in index is one too big */
-				ev->gas.index = cur_event.gas.index-1;
-				if (cur_event.gas.mix.o2.permille || cur_event.gas.mix.he.permille)
-					ev->gas.mix = cur_event.gas.mix;
-			}
+		if (ev && event_is_gaschange(ev)) {
+			/* See try_to_fill_event() on why the filled-in index is one too big */
+			ev->gas.index = cur_event.gas.index-1;
+			if (cur_event.gas.mix.o2.permille || cur_event.gas.mix.he.permille)
+				ev->gas.mix = cur_event.gas.mix;
 		}
 	}
 	cur_event.deleted = 1;	/* No longer active */
-- 
2.9.0.rc0.21.g7777322



More information about the subsurface mailing list