diff options
author | wm4 <wm4@nowhere> | 2019-06-07 13:36:46 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2019-09-19 20:37:05 +0200 |
commit | b45c17e5a91476bf8a7293343fca3c8dc4761481 (patch) | |
tree | 0481f39875adcda75a740ad1ac235ff96bb0c5ca /options | |
parent | 46247df6e55bf9a93588c5adfdc553c1d189b2fc (diff) | |
download | mpv-b45c17e5a91476bf8a7293343fca3c8dc4761481.tar.bz2 mpv-b45c17e5a91476bf8a7293343fca3c8dc4761481.tar.xz |
m_option: add "B" suffix to human-readable byte numbers
The conversion to string as the pretty printer returns it is
sometimes used on OSD. I think it's pretty odd that quantities below 1
KB are shown as number without suffix. So use "B" for them.
For orthogonality, allow the same for parsing. (Although strictly
speaking, this is not a requirement of the option API. Option parsers
don't need to accept pretty-printed strings.)
Diffstat (limited to 'options')
-rw-r--r-- | options/m_option.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/options/m_option.c b/options/m_option.c index 1fde03cccd..7bb43ad399 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -403,7 +403,9 @@ static int parse_byte_size(struct mp_log *log, const m_option_t *opt, long long tmp_int = bstrtoll(param, &r, 0); int64_t unit = 1; if (r.len) { - if (bstrcasecmp0(r, "kib") == 0 || bstrcasecmp0(r, "k") == 0) { + if (bstrcasecmp0(r, "b") == 0) { + unit = 1; + } else if (bstrcasecmp0(r, "kib") == 0 || bstrcasecmp0(r, "k") == 0) { unit = 1024; } else if (bstrcasecmp0(r, "mib") == 0 || bstrcasecmp0(r, "m") == 0) { unit = 1024 * 1024; @@ -415,7 +417,7 @@ static int parse_byte_size(struct mp_log *log, const m_option_t *opt, mp_err(log, "The %.*s option must be an integer: %.*s\n", BSTR_P(name), BSTR_P(param)); mp_err(log, "The following suffixes are also allowed: " - "KiB, MiB, GiB, TiB, K, M, G, T.\n"); + "KiB, MiB, GiB, TiB, B, K, M, G, T.\n"); return M_OPT_INVALID; } } @@ -456,7 +458,7 @@ char *format_file_size(int64_t size) { double s = size; if (size < 1024) - return talloc_asprintf(NULL, "%.0f", s); + return talloc_asprintf(NULL, "%.0f B", s); if (size < (1024 * 1024)) return talloc_asprintf(NULL, "%.3f KiB", s / (1024.0)); |