diff options
author | Tim Segers <tsegers@pm.me> | 2022-10-04 23:37:18 +0200 |
---|---|---|
committer | Tim Segers <tsegers@pm.me> | 2022-10-04 23:37:18 +0200 |
commit | 5aab2fa8558dc9053eff79a3578854ba44f65b76 (patch) | |
tree | 4c6297ddb13ed1a74cc9ea0685f97a886e8aab15 | |
parent | b6aaf32347e0859fae26f422d66deaac8e63b475 (diff) | |
download | opendeco-5aab2fa8558dc9053eff79a3578854ba44f65b76.tar.gz |
Add scan_gas to mirror format_gas
-rw-r--r-- | output.c | 23 | ||||
-rw-r--r-- | output.h | 2 |
2 files changed, 25 insertions, 0 deletions
@@ -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"); @@ -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 */ |