diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-23 21:07:53 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-23 21:07:53 -0700 |
commit | 81fddfa67e779c8d378eee4c57fd9f201e15f96f (patch) | |
tree | 94fa92476642bcbfbcc334a5a7516cc20fbba4f2 /parse-xml.c | |
parent | a738108549371f62a29ef4f4fd005ffcccc84b19 (diff) | |
parent | 854bd0269c05adc56caf9667fd68f676520a2941 (diff) | |
download | subsurface-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 'parse-xml.c')
-rw-r--r-- | parse-xml.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/parse-xml.c b/parse-xml.c index 2877e3a99..e920a11f6 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -76,6 +76,7 @@ struct units input_units; * technically the SI unit for pressure is Pascal, but * we default to bar (10^5 pascal), which people * actually use. Similarly, C instead of Kelvin. + * And kg instead of g. */ const struct units SI_units = { .length = METERS, @@ -105,7 +106,7 @@ static struct { const char *name; } cur_event; static struct tm cur_tm; -static int cur_cylinder_index; +static int cur_cylinder_index, cur_ws_index; static enum import_source { UNKNOWN, @@ -298,6 +299,27 @@ static void depth(char *buffer, void *_depth) free(buffer); } +static void weight(char *buffer, void *_weight) +{ + weight_t *weight = _weight; + union int_or_float val; + + switch (integer_or_float(buffer, &val)) { + case FLOAT: + switch (input_units.weight) { + case KG: + weight->grams = val.fp * 1000 + 0.5; + break; + case LBS: + weight->grams = val.fp * 453.6 + 0.5; + break; + } + break; + default: + printf("Strange depth reading %s\n", buffer); + } +} + static void temperature(char *buffer, void *_temperature) { temperature_t *temperature = _temperature; @@ -1036,7 +1058,12 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf) return; if (MATCH(".cylinder.end", pressure, &dive->cylinder[cur_cylinder_index].end)) return; - + if (MATCH(".weightsystem.description", utf8_string, &dive->weightsystem[cur_ws_index].description)) + return; + if (MATCH(".weightsystem.weight", weight, &dive->weightsystem[cur_ws_index].weight)) + return; + if (MATCH("weight", weight, &dive->weightsystem[cur_ws_index].weight)) + return; if (MATCH(".o2", gasmix, &dive->cylinder[cur_cylinder_index].gasmix.o2)) return; if (MATCH(".n2", gasmix_nitrogen, &dive->cylinder[cur_cylinder_index].gasmix)) @@ -1068,6 +1095,7 @@ static void dive_end(void) record_dive(cur_dive); cur_dive = NULL; cur_cylinder_index = 0; + cur_ws_index = 0; } static void event_start(void) @@ -1094,6 +1122,15 @@ static void cylinder_end(void) cur_cylinder_index++; } +static void ws_start(void) +{ +} + +static void ws_end(void) +{ + cur_ws_index++; +} + static void sample_start(void) { cur_sample = prepare_sample(&cur_dive); @@ -1256,6 +1293,7 @@ static struct nesting { { "event", event_start, event_end }, { "gasmix", cylinder_start, cylinder_end }, { "cylinder", cylinder_start, cylinder_end }, + { "weightsystem", ws_start, ws_end }, { "P", sample_start, sample_end }, /* Import type recognition */ |