X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=parse-xml.c;fp=parse-xml.c;h=e920a11f6f0d798b18900ccb23317c95c8ec5162;hb=81fddfa67e779c8d378eee4c57fd9f201e15f96f;hp=2877e3a9966781f368d009564cb6700570c3e670;hpb=a738108549371f62a29ef4f4fd005ffcccc84b19;p=ext%2Fsubsurface.git diff --git a/parse-xml.c b/parse-xml.c index 2877e3a..e920a11 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 */