From ae4bd802afac9723da27f2bcc3d402effd636ffc Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Mon, 18 Mar 2013 15:22:14 +0100 Subject: Take only used gases into account when showing gas in divelist Here is a patch that restricts the gases listed in the divelist to those that are actually used. I seem to have the indentation now under control but I am not sure about the logic: 1) First gas (with index 0) is always used. 2) If there is a gas switch event, the new gas is also used (determined by walking the list of dive computers and then the list of events). Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- divelist.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/divelist.c b/divelist.c index ac81d9daa..aa29c72ed 100644 --- a/divelist.c +++ b/divelist.c @@ -459,11 +459,39 @@ static void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p) int i; int maxo2 = -1, maxhe = -1, mino2 = 1000; + for (i = 0; i < MAX_CYLINDERS; i++) { cylinder_t *cyl = dive->cylinder + i; struct gasmix *mix = &cyl->gasmix; int o2 = mix->o2.permille; int he = mix->he.permille; + struct divecomputer *dc = &dive->dc; + int used = !i; /* The first gas is always used */ + + while (dc){ + struct event *event = dc->events; + while(event){ + if (event->value) { + if (event->name && !strcmp(event->name, "gaschange")) { + unsigned int event_he = event->value >> 16; + unsigned int event_o2 = event->value & 0xffff; + + if (is_air(o2, he)){ + if (is_air(event_o2 * 10, event_he * 10)) + used = 1; + } + else { + if (he == event_he*10 && o2 == event_o2*10) + used = 1; + } + } + } + event = event->next; + } + dc = dc->next; + } + if (!used) + continue; if (cylinder_none(cyl)) continue; -- cgit v1.2.3-70-g09d2