From 5aab2fa8558dc9053eff79a3578854ba44f65b76 Mon Sep 17 00:00:00 2001 From: Tim Segers Date: Tue, 4 Oct 2022 23:37:18 +0200 Subject: Add scan_gas to mirror format_gas --- output.c | 23 +++++++++++++++++++++++ output.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/output.c b/output.c index 3d8a597..589c811 100644 --- a/output.c +++ b/output.c @@ -2,6 +2,7 @@ #include #include +#include #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 */ -- cgit v1.2.3-70-g09d2