diff options
-rw-r--r-- | dive.c | 2 | ||||
-rw-r--r-- | dive.h | 12 | ||||
-rw-r--r-- | equipment.c | 18 | ||||
-rw-r--r-- | planner.c | 18 | ||||
-rw-r--r-- | statistics.c | 12 |
5 files changed, 26 insertions, 36 deletions
@@ -546,7 +546,7 @@ void sanitize_gasmix(struct gasmix *mix) if (!o2) return; /* 20.8% to 21% O2 is just air */ - if (is_air(o2, he)) { + if (gasmix_is_air(mix)) { mix->o2.permille = 0; return; } @@ -108,14 +108,11 @@ extern void sanitize_gasmix(struct gasmix *mix); extern int gasmix_distance(const struct gasmix *a, const struct gasmix *b); extern struct gasmix *get_gasmix_from_event(struct event *ev); -static inline bool is_air(int o2, int he) -{ - return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1))); -} - static inline bool gasmix_is_air(const struct gasmix *gasmix) { - return is_air(gasmix->o2.permille, gasmix->he.permille); + int o2 = gasmix->o2.permille; + int he = gasmix->he.permille; + return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1))); } /* in the planner we use a null gasmix to indicate that we keep using the gas as before @@ -140,6 +137,9 @@ static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit) { return depth; } +void get_gas_string(const struct gasmix *gasmix, char *text, int len); +const char *gasname(const struct gasmix *gasmix); + struct sample { duration_t time; depth_t depth; diff --git a/equipment.c b/equipment.c index a67df68a4..1dd3c3f9d 100644 --- a/equipment.c +++ b/equipment.c @@ -97,6 +97,24 @@ bool cylinder_is_used(struct dive *d, cylinder_t *cyl) return false; } +void get_gas_string(const struct gasmix *gasmix, char *text, int len) +{ + if (gasmix_is_air(gasmix)) + snprintf(text, len, "%s", translate("gettextFromC", "air")); + else if (get_he(gasmix) == 0) + snprintf(text, len, translate("gettextFromC", "EAN%d"), (get_o2(gasmix) + 5) / 10); + else + snprintf(text, len, "(%d/%d)", (get_o2(gasmix) + 5) / 10, (get_he(gasmix) + 5) / 10); +} + +/* Returns a static char buffer - only good for immediate use by printf etc */ +const char *gasname(const struct gasmix *gasmix) +{ + static char gas[64]; + get_gas_string(gasmix, gas, sizeof(gas)); + return gas; +} + bool weightsystem_none(void *_data) { weightsystem_t *ws = _data; @@ -93,24 +93,6 @@ int get_gasidx(struct dive *dive, struct gasmix *mix) return -1; } -static void get_gas_string(const struct gasmix *gasmix, char *text, int len) -{ - if (gasmix_is_air(gasmix)) - snprintf(text, len, "%s", translate("gettextFromC", "air")); - else if (get_he(gasmix) == 0) - snprintf(text, len, translate("gettextFromC", "EAN%d"), (get_o2(gasmix) + 5) / 10); - else - snprintf(text, len, "(%d/%d)", (get_o2(gasmix) + 5) / 10, (get_he(gasmix) + 5) / 10); -} - -/* Returns a static char buffer - only good for immediate use by printf etc */ -static const char *gasname(const struct gasmix *gasmix) -{ - static char gas[64]; - get_gas_string(gasmix, gas, sizeof(gas)); - return gas; -} - double interpolate_transition(struct dive *dive, int t0, int t1, int d0, int d1, const struct gasmix *gasmix, int ppo2) { int j; diff --git a/statistics.c b/statistics.c index 71150159c..5da48f225 100644 --- a/statistics.c +++ b/statistics.c @@ -337,7 +337,6 @@ char *get_gaslist(struct dive *dive) { int idx, offset = 0; static char buf[MAXBUF]; - int o2, he; buf[0] = '\0'; for (idx = 0; idx < MAX_CYLINDERS; idx++) { @@ -345,20 +344,11 @@ char *get_gaslist(struct dive *dive) if (!is_gas_used(dive, idx)) continue; cyl = &dive->cylinder[idx]; - o2 = get_o2(&cyl->gasmix); - he = get_he(&cyl->gasmix); if (offset > 0) { strncpy(buf + offset, "\n", MAXBUF - offset); offset = strlen(buf); } - if (is_air(o2, he)) - strncpy(buf + offset, translate("gettextFromC", "air"), MAXBUF - offset); - else if (he == 0) - snprintf(buf + offset, MAXBUF - offset, - translate("gettextFromC", "EAN%d"), (o2 + 5) / 10); - else - snprintf(buf + offset, MAXBUF - offset, - "%d/%d", (o2 + 5) / 10, (he + 5) / 10); + strncpy(buf + offset, gasname(&cyl->gasmix), MAXBUF - offset); offset = strlen(buf); } if (*buf == '\0') |