aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-01 20:56:29 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-01 20:57:11 -0700
commit28093ae957548d5fc1e4d373ca0a345cc1be5069 (patch)
treef8899ae3e24033781bf707ceac959636be063917
parentee36bf8bf34013c35120b6c3cc4ae5edcf74b235 (diff)
downloadsubsurface-28093ae957548d5fc1e4d373ca0a345cc1be5069.tar.gz
Remove is_air() and convert its users to gasmix
Also make gasname() and get_gas_string() global functions (which allows us to delete code elsewhere). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c2
-rw-r--r--dive.h12
-rw-r--r--equipment.c18
-rw-r--r--planner.c18
-rw-r--r--statistics.c12
5 files changed, 26 insertions, 36 deletions
diff --git a/dive.c b/dive.c
index aad4b07a5..9cfdfc14a 100644
--- a/dive.c
+++ b/dive.c
@@ -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;
}
diff --git a/dive.h b/dive.h
index 2594f548a..26732df15 100644
--- a/dive.h
+++ b/dive.h
@@ -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;
diff --git a/planner.c b/planner.c
index 370c8d055..cc8e9d908 100644
--- a/planner.c
+++ b/planner.c
@@ -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')