aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Tim Segers <tsegers@pm.me>2022-10-04 23:37:18 +0200
committerGravatar Tim Segers <tsegers@pm.me>2022-10-04 23:37:18 +0200
commit5aab2fa8558dc9053eff79a3578854ba44f65b76 (patch)
tree4c6297ddb13ed1a74cc9ea0685f97a886e8aab15
parentb6aaf32347e0859fae26f422d66deaac8e63b475 (diff)
downloadopendeco-5aab2fa8558dc9053eff79a3578854ba44f65b76.tar.gz
Add scan_gas to mirror format_gas
-rw-r--r--output.c23
-rw-r--r--output.h2
2 files changed, 25 insertions, 0 deletions
diff --git a/output.c b/output.c
index 3d8a597..589c811 100644
--- a/output.c
+++ b/output.c
@@ -2,6 +2,7 @@
#include <math.h>
#include <stdio.h>
+#include <string.h>
#include "output.h"
@@ -31,6 +32,28 @@ void format_gas(char *buf, const size_t buflen, const gas_t *gas)
snprintf(buf, buflen, "%i/%i", gas_o2(gas), gas_he(gas));
}
+void scan_gas(gas_t *gas, char *str)
+{
+ int o2 = 0;
+ int he = 0;
+
+ if (!strcmp(str, "Air")) {
+ *gas = gas_new(21, 0, MOD_AUTO);
+ return;
+ } else if (!strcmp(str, "Oxygen")) {
+ *gas = gas_new(100, 0, MOD_AUTO);
+ return;
+ } else if (!strncmp(str, "EAN", strlen("EAN"))) {
+ sscanf(str, "EAN%i", &o2);
+ } else if (!strncmp(str, "Nitrox", strlen("Nitrox"))) {
+ sscanf(str, "Nitrox %i", &o2);
+ } else {
+ sscanf(str, "%i/%i", &o2, &he);
+ }
+
+ *gas = gas_new(o2, he, MOD_AUTO);
+}
+
void print_planhead()
{
wprintf(L"DIVE PLAN\n\n");
diff --git a/output.h b/output.h
index 0cedcc7..829e23a 100644
--- a/output.h
+++ b/output.h
@@ -16,4 +16,6 @@ void print_planhead();
void print_planline(const wchar_t sign, const double depth, const double time, const double runtime, const gas_t *gas);
void print_planfoot(const decostate_t *ds);
+void scan_gas(gas_t *gas, char *str);
+
#endif /* end of include guard: OUTPUT_H */