summaryrefslogtreecommitdiffstats
path: root/save-xml.c
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2013-11-27 22:59:17 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-27 14:13:47 -0800
commit57fb878b41bb803aa9418f84e82aa489b5d542d3 (patch)
treeb254b6a9750c06411168a83ab0bcebc5e82029f3 /save-xml.c
parentab4115791bb3b867f2bc0bbfd583238fd5210054 (diff)
downloadsubsurface-57fb878b41bb803aa9418f84e82aa489b5d542d3.tar.gz
Show/save weights up to and including last valid
Previous show and save code would have aborted at the first invalid weight system. This makes sure we save and show all weight systems up until and including the last valid. If we had: integrated: 1kg belt: 2kg ankle: 3kg And changed belt to 0 kg, we would have only saved integrated 1kg, and nothing about the belt or the ankle weights. This will save all of them, and show all of them. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-xml.c')
-rw-r--r--save-xml.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/save-xml.c b/save-xml.c
index d16b16daf..0b83a0235 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -301,18 +301,29 @@ static void save_cylinder_info(FILE *f, struct dive *dive)
}
}
+static int nr_weightsystems(struct dive *dive)
+{
+ int nr;
+
+ for (nr = MAX_WEIGHTSYSTEMS; nr; --nr) {
+ weightsystem_t *ws = dive->weightsystem+nr-1;
+ if (!weightsystem_none(ws))
+ break;
+ }
+ return nr;
+}
+
static void save_weightsystem_info(FILE *f, struct dive *dive)
{
- int i;
+ int i, nr;
- for (i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
+ nr = nr_weightsystems(dive);
+
+ for (i = 0; i < nr; i++) {
weightsystem_t *ws = dive->weightsystem+i;
int grams = ws->weight.grams;
const char *description = ws->description;
- /* No weight information at all? */
- if (grams == 0)
- return;
fprintf(f, " <weightsystem");
show_milli(f, " weight='", grams, " kg", "'");
show_utf8(f, description, " description='", "'", 1);