mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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.
This commit is contained in:
commit
81fddfa67e
5 changed files with 648 additions and 47 deletions
42
parse-xml.c
42
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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue