index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Eli Schwartz <eschwartz@archlinux.org> | 2019-11-06 00:05:22 -0500 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2019-11-06 15:52:21 +1000 |
commit | 8c7043390f80d93445f2817ae5419b06fc72983a (patch) | |
tree | fab602cc728790a41c63d91332419f2cc9e6b218 /scripts/library/human_to_size.sh | |
parent | 2dd7725f2a0cccd0a248531551c9fbea4ef35f1f (diff) |
-rw-r--r-- | scripts/library/human_to_size.sh | 51 |
diff --git a/scripts/library/human_to_size.sh b/scripts/library/human_to_size.sh deleted file mode 100644 index 11613207..00000000 --- a/scripts/library/human_to_size.sh +++ /dev/null @@ -1,51 +0,0 @@ -human_to_size() { - awk -v human="$1" ' - function trim(s) { - gsub(/^[[:space:]]+|[[:space:]]+$/, "", s) - return s - } - - function parse_units(units) { - if (!units || units == "B") - return 1 - if (match(units, /^.iB$/)) - return 1024 - if (match(units, /^.B$/)) - return 1000 - if (length(units) == 1) - return 1024 - - # parse failure: invalid base - return -1 - } - - function parse_scale(s) { - return index("BKMGTPE", s) - 1 - } - - function isnumeric(string) { - return match(string, /^[-+]?[[:digit:]]*(\.[[:digit:]]*)?/) - } - - BEGIN { - # peel off the leading number as the size, fail on invalid number - human = trim(human) - if (isnumeric(human)) - size = substr(human, RSTART, RLENGTH) - else - exit 1 - - # the trimmed remainder is assumed to be the units - units = trim(substr(human, RLENGTH + 1)) - - base = parse_units(units) - if (base < 0) - exit 1 - - scale = parse_scale(substr(units, 1, 1)) - if (scale < 0) - exit 1 - - printf "%d\n", size * base^scale + (size + 0 > 0 ? 0.5 : -0.5) - }' -} |