From: Gerhard Sittig Date: Sun, 4 Feb 2018 18:50:25 +0000 (+0100) Subject: strutil: support tera/peta/exa suffixes in symbolic size specs X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=751ba4c8ed3ec40c85e497fde5bf58185f1d9490;hp=57a88297dd0c57eb9eab2d79bdf681ddcca29f00;p=libsigrok.git strutil: support tera/peta/exa suffixes in symbolic size specs Synchronize sr_parse_sizestring() with sr_si_string_u64() capabilities. Add support for the T/P/E suffixes. Since this conversion helper deals with integer values exclusively, there is no issue with case insensitive matches. The value cannot be pico. Neither is there an ambiguity with the 10e6 notation. This addresses bug #763. Fix a style nit while we are here. Put braces around both arms of a complex conditional. --- diff --git a/src/strutil.c b/src/strutil.c index 30e992b8..3fe59551 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -477,7 +477,8 @@ SR_API char *sr_voltage_string(uint64_t v_p, uint64_t v_q) */ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) { - int multiplier, done; + uint64_t multiplier; + int done; double frac_part; char *s; @@ -504,6 +505,18 @@ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) case 'G': multiplier = SR_GHZ(1); break; + case 't': + case 'T': + multiplier = SR_GHZ(1000); + break; + case 'p': + case 'P': + multiplier = SR_GHZ(1000 * 1000); + break; + case 'e': + case 'E': + multiplier = SR_GHZ(1000 * 1000 * 1000); + break; default: done = TRUE; s--; @@ -513,8 +526,9 @@ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) if (multiplier > 0) { *size *= multiplier; *size += frac_part * multiplier; - } else + } else { *size += frac_part; + } if (s && *s && g_ascii_strcasecmp(s, "Hz")) return SR_ERR;