diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-02 10:38:34 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-02 10:39:35 -0700 |
commit | 63c50805610c8d0dd0ec85dc62b3007df4e5dc0b (patch) | |
tree | 7ac298d79f30d4ca92fd70fd326fd9b7513812db /divelist.c | |
parent | e6ec626c9758d30c3f714ddbf6f79195e710e037 (diff) | |
download | subsurface-63c50805610c8d0dd0ec85dc62b3007df4e5dc0b.tar.gz |
Move gas string computation into core logic code
This is now a helper called from the Gtk UI code (and will soon be used by
the Qt UI code).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c index e34f7afeb..58d89d5f6 100644 --- a/divelist.c +++ b/divelist.c @@ -595,6 +595,34 @@ char *get_trip_date_string(timestamp_t when, int nr) { return buffer; } +#define MAX_NITROX_STRING 80 +#define UTF8_ELLIPSIS "\xE2\x80\xA6" + +/* callers needs to free the string */ +char *get_nitrox_string(struct dive *dive) +{ + int o2, he, o2low; + char *buffer = malloc(MAX_NITROX_STRING); + + if (buffer) { + get_dive_gas(dive, &o2, &he, &o2low); + o2 = (o2 + 5) / 10; + he = (he + 5) / 10; + o2low = (o2low + 5) / 10; + + if (he) + snprintf(buffer, sizeof(buffer), "%d/%d", o2, he); + else if (o2) + if (o2 == o2low) + snprintf(buffer, sizeof(buffer), "%d", o2); + else + snprintf(buffer, sizeof(buffer), "%d" UTF8_ELLIPSIS "%d", o2low, o2); + else + strcpy(buffer, _("air")); + } + return buffer; +} + /* * helper functions for dive_trip handling */ |