From c804c4e02e0530889697fab524cba294a55ffeeb Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 19 Sep 2012 23:42:11 -0400 Subject: Partial rewrite of the dive trip code This introduces a new data structure for dive trips - reuseing the struct dive just got way too messy. The dive_trip_t datastructure now allows the code to remember if the trip was auto generated or if its time stamp changed when dives where added to the trip during auto generation. The algorithm also distinguishes between dives that were intentionally added to a trip (either in an XML file or by adding them to trip in the UI) and dives that were added to trips via autogen. Saving dives that were added to trips via autogen makes that assignment "intentional". With this partial rewrite several of the oddities of the old code should be resolved - especially turning autogen on and off again should get the divelist back to the previous stage. Also, when dives are merged during file open or import we now try to pick the correct tripflag (instead of just ignoring the tripflag completely and resetting it to TF_NONE by mistake). Finally, the dive trip debugging code got more verbose and is trying harder to detect issues at the earliest time possible. Signed-off-by: Dirk Hohndel --- parse-xml.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'parse-xml.c') diff --git a/parse-xml.c b/parse-xml.c index 2a10792f8..4950d5d96 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -156,7 +156,8 @@ const struct units IMPERIAL_units = { /* * Dive info as it is being built up.. */ -static struct dive *cur_dive, *cur_trip = NULL; +static struct dive *cur_dive; +static dive_trip_t *cur_trip = NULL; static struct sample *cur_sample; static struct { int active; @@ -542,8 +543,10 @@ static void get_tripflag(char *buffer, void *_tf) *tf = TF_NONE; for (i = NO_TRIP; i < NUM_TRIPFLAGS; i++) - if(! strcmp(buffer, tripflag_names[i])) + if(! strcmp(buffer, tripflag_names[i])) { *tf = i; + break; + } } static void centibar(char *buffer, void *_pressure) @@ -1152,21 +1155,23 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf) } /* We're in the top-level trip xml. Try to convert whatever value to a trip value */ -static void try_to_fill_trip(struct dive **divep, const char *name, char *buf) +static void try_to_fill_trip(dive_trip_t **dive_trip_p, const char *name, char *buf) { int len = strlen(name); start_match("trip", name, buf); - struct dive *dive = *divep; + dive_trip_t *dive_trip = *dive_trip_p; - if (MATCH(".date", divedate, &dive->when)) + if (MATCH(".date", divedate, &dive_trip->when)) return; - if (MATCH(".time", divetime, &dive->when)) + if (MATCH(".time", divetime, &dive_trip->when)) { + dive_trip->when_from_file = dive_trip->when; return; - if (MATCH(".location", utf8_string, &dive->location)) + } + if (MATCH(".location", utf8_string, &dive_trip->location)) return; - if (MATCH(".notes", utf8_string, &dive->notes)) + if (MATCH(".notes", utf8_string, &dive_trip->notes)) return; nonmatch("trip", name, buf); @@ -1212,7 +1217,7 @@ static void trip_start(void) { if (cur_trip) return; - cur_trip = alloc_dive(); + cur_trip = calloc(sizeof(dive_trip_t),1); memset(&cur_tm, 0, sizeof(cur_tm)); } -- cgit v1.2.3-70-g09d2