diff options
author | 2023-01-05 13:12:20 +0100 | |
---|---|---|
committer | 2023-01-07 15:24:51 +0100 | |
commit | c6880e27d2766bdfed4bb597475d605851c5ff59 (patch) | |
tree | a55404e9f68641f5ff3e8d7d2d697643c07b0358 /src | |
parent | b65d350ab6cdc41d1ef09abbe08b093dfea92057 (diff) | |
download | opendeco-c6880e27d2766bdfed4bb597475d605851c5ff59.tar.gz |
Refactor scan_gas
Diffstat (limited to 'src')
-rw-r--r-- | src/output.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/output.c b/src/output.c index 1d51a08..43ee82a 100644 --- a/src/output.c +++ b/src/output.c @@ -35,29 +35,34 @@ void format_gas(char *buf, size_t buflen, const gas_t *gas) int scan_gas(gas_t *gas, char *str) { - int o2 = -1; - int he = -1; + int o2 = 0; + int he = 0; if (!strcmp(str, "Air")) { - *gas = gas_new(21, 0, MOD_AUTO); - return 0; + o2 = 21; + goto match; } if (!strcmp(str, "Oxygen")) { - *gas = gas_new(100, 0, MOD_AUTO); - return 0; + o2 = 100; + goto match; } - if (!strncmp(str, "EAN", strlen("EAN"))) { - sscanf(str, "EAN%i", &o2); - he = 0; - } else if (!strncmp(str, "Nitrox", strlen("Nitrox"))) { - sscanf(str, "Nitrox %i", &o2); - he = 0; - } else { - sscanf(str, "%i/%i", &o2, &he); - } + if (sscanf(str, "%i/%i", &o2, &he) == 2) + goto match; + + if (sscanf(str, "EAN %i", &o2) == 1) + goto match; + + if (sscanf(str, "Nitrox %i", &o2) == 1) + goto match; + + if (sscanf(str, "%i", &o2) == 1) + goto match; + + return -EINVAL; +match: if (o2 < 0 || he < 0) return -EINVAL; |