Use common helper function for the "no cylinder info" case

Miika fixed the statistics code that didn't properly check for the "no
cylinder info" case - this cleans it up and just uses the helper
function in equipment.c.

Rename the helper to be slightly better named while at it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2011-12-09 09:52:59 -08:00
parent fe532a585c
commit 9b1ea2ae6d
3 changed files with 5 additions and 6 deletions

2
dive.h
View file

@ -87,6 +87,8 @@ typedef struct {
pressure_t start, end, sample_start, sample_end; pressure_t start, end, sample_start, sample_end;
} cylinder_t; } cylinder_t;
extern int cylinder_none(cylinder_t *cyl);
extern int get_pressure_units(unsigned int mb, const char **units); extern int get_pressure_units(unsigned int mb, const char **units);
extern double get_depth_units(unsigned int mm, int *frac, const char **units); extern double get_depth_units(unsigned int mm, int *frac, const char **units);
extern double get_volume_units(unsigned int mm, int *frac, const char **units); extern double get_volume_units(unsigned int mm, int *frac, const char **units);

View file

@ -286,7 +286,7 @@ static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2); gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2);
} }
static int cyl_nothing(cylinder_t *cyl) int cylinder_none(cylinder_t *cyl)
{ {
return !cyl->type.size.mliter && return !cyl->type.size.mliter &&
!cyl->type.workingpressure.mbar && !cyl->type.workingpressure.mbar &&
@ -328,7 +328,7 @@ void show_dive_equipment(struct dive *dive)
do { do {
cylinder_t *cyl = &dive->cylinder[max-1]; cylinder_t *cyl = &dive->cylinder[max-1];
if (!cyl_nothing(cyl)) if (!cylinder_none(cyl))
break; break;
} while (--max); } while (--max);

View file

@ -169,10 +169,7 @@ void show_dive_stats(struct dive *dive)
start = cyl->start.mbar ? : cyl->sample_start.mbar; start = cyl->start.mbar ? : cyl->sample_start.mbar;
end = cyl->end.mbar ? : cyl->sample_end.mbar; end = cyl->end.mbar ? : cyl->sample_end.mbar;
/* we assume that every valid cylinder has either a working pressure if (!cylinder_none(cyl)) {
* or a size; but for good measure let's also accept cylinders with
* a starting or ending pressure*/
if (cyl->type.workingpressure.mbar || cyl->type.size.mliter || cyl->gasmix.o2.permille || start || end) {
/* 0% O2 strangely means air, so 21% - I don't like that at all */ /* 0% O2 strangely means air, so 21% - I don't like that at all */
int o2 = cyl->gasmix.o2.permille ? : 209; int o2 = cyl->gasmix.o2.permille ? : 209;
if (offset > 0) { if (offset > 0) {