summaryrefslogtreecommitdiffstats
path: root/save-xml.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-03-23 21:07:53 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-03-23 21:07:53 -0700
commit81fddfa67e779c8d378eee4c57fd9f201e15f96f (patch)
tree94fa92476642bcbfbcc334a5a7516cc20fbba4f2 /save-xml.c
parenta738108549371f62a29ef4f4fd005ffcccc84b19 (diff)
parent854bd0269c05adc56caf9667fd68f676520a2941 (diff)
downloadsubsurface-81fddfa67e779c8d378eee4c57fd9f201e15f96f.tar.gz
Merge branch 'weight' of git://subsurface.hohndel.org/subsurface
Pull weight management from Dirk Hohndel: "This is the fifth or sixth version of this code, I'm begining to lose track. I still struggle with the balance between code duplication and unnecessary indirectness and complexity. Maybe I'm just not finding the right level of abstraction. Maybe I'm just trying too hard. The code here is reasonably well tested. Works for me :-) It can import DivingLog xml files with weight systems and correctly parses those. It obviously can read and write weight systems in its own file format. It adds a KG/lbs unit default (and correctly stores that). The thing I still worry about is the code in equipment.c. You'll see that I tried to abstract things in a way that weight systems and cylinders share quite a bit of code - but there's more very similar code that isn't shared as my attempts to do so turned into ugly and hard to read code. It always felt like trying to write C++ in C..." * 'weight' of git://subsurface.hohndel.org/subsurface: Add weight system tracking Fix up some trivial conflicts due to various renaming of globals and simplification in function interfaces.
Diffstat (limited to 'save-xml.c')
-rw-r--r--save-xml.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/save-xml.c b/save-xml.c
index c9085db51..ed55c022d 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -218,6 +218,26 @@ static void save_cylinder_info(FILE *f, struct dive *dive)
}
}
+static void save_weightsystem_info(FILE *f, struct dive *dive)
+{
+ int i;
+
+ for (i = 0; i < MAX_WEIGHTSYSTEMS; 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", "'");
+ if (description && *description)
+ fprintf(f, " description='%s'", description);
+ fprintf(f, " />\n");
+ }
+}
+
static void show_index(FILE *f, int value, const char *pre, const char *post)
{
if (value)
@@ -272,6 +292,7 @@ static void save_dive(FILE *f, struct dive *dive)
FRACTION(dive->duration.seconds, 60));
save_overview(f, dive);
save_cylinder_info(f, dive);
+ save_weightsystem_info(f, dive);
save_events(f, dive->events);
for (i = 0; i < dive->samples; i++)
save_sample(f, dive->sample+i);