From abd040180e210e74448c42f094aab1769ca6c636 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 30 Jul 2010 01:52:59 -0600 Subject: sort: -h now handles comparisons such as 6000K vs 5M and 5MiB vs 5MB * NEWS: Document changes to sort -h. * doc/coreutils.texi (sort invocation): Likewise. * src/sort.c (long_double, strtold): Move to prelude, since they're now used by multiple functions. (LD): New macro. (struct keyfield.iec_present): Remove this member. All uses removed. (check_mixed_SI_IEC): Remove. This code was busted in the presence of multiple threads, as it had a race condition. (find_unit_order): Remove arg KEY; add arg THOU_SEP; arg ENDPTR is now char ** rather than char const **. Return an integer that distinguishes decimal from binary powers. Parse the number consistently with the intersection of strtold and strnumcmp. Set *ENDPTR unconditionally. (compute_human): New static function. (human_numcompare): Remove arg KEY. Remove 'const' from other args. Use strnumcmp if possible, but fall back on floating point if not. (numcompare, general_numcompare): Arg EA is now char ** rather than char const **. (numcompare): Adjust to new find_unit_order signature and behavior. (keycompare): Adjus to new human_numcompare signature. * tests/misc/sort (h1, h3, h4, h6): Adjust to new behavior. * tests/misc/sort-debug-keys: Likewise. --- tests/misc/sort | 16 ++++++++-------- tests/misc/sort-debug-keys | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/misc/sort b/tests/misc/sort index de189ddb9..12222e19b 100755 --- a/tests/misc/sort +++ b/tests/misc/sort @@ -55,17 +55,17 @@ my @Tests = ["n11b", '-s -n -k1,1', {IN=>".010\n.01a\n"}, {OUT=>".010\n.01a\n"}], # human readable suffixes -["h1", '-h', {IN=>"Y\nZ\nE\nP\nT\nG\nM\nK\n"}, - {OUT=>"K\nM\nG\nT\nP\nE\nZ\nY\n"}], +["h1", '-h', {IN=>"1Y\n1Z\n1E\n1P\n1T\n1G\n1M\n1K\n02\n1\n"}, + {OUT=>"1\n02\n1K\n1M\n1G\n1T\n1P\n1E\n1Z\n1Y\n"}], ["h2", '-h', {IN=>"1M\n-2G\n-3K"}, {OUT=>"-2G\n-3K\n1M\n"}], -["h3", '-h', {IN=>"1Mi\n1M\n"}, {OUT=>""}, {EXIT=>2}, - {ERR=>"$prog: both SI and IEC prefixes present on units\n"}], -# decimal at end => ignore suffix -["h4", '-h', {IN=>"1.E\n2.M\n"}, {OUT=>"1.E\n2.M\n"}], +# check that powers of 1024 beat powers of 1000 +["h3", '-k 2,2h -k 1,1', {IN=>"a 1Mi\nb 1M\n"}, {OUT=>"b 1M\na 1Mi\n"}], +# decimal at end => allowed +["h4", '-h', {IN=>"1.E\n2.M\n"}, {OUT=>"2.M\n1.E\n"}], # double decimal => ignore suffix ["h5", '-h', {IN=>"1..2E\n2..2M\n"}, {OUT=>"1..2E\n2..2M\n"}], -# illustrate misordering of ambiguous abbreviations -["h6", '-h', {IN=>"1GiB\n1030MiB\n"}, {OUT=>"1030MiB\n1GiB\n"}], +# handle inconsistent use of multiplers +["h6", '-h', {IN=>"1GiB\n1030MiB\n"}, {OUT=>"1GiB\n1030MiB\n"}], # check option incompatibility ["h7", '-hn', {IN=>""}, {OUT=>""}, {EXIT=>2}, {ERR=>"$prog: options `-hn' are incompatible\n"}], diff --git a/tests/misc/sort-debug-keys b/tests/misc/sort-debug-keys index 6714a4741..89f8b9b7d 100755 --- a/tests/misc/sort-debug-keys +++ b/tests/misc/sort-debug-keys @@ -225,7 +225,7 @@ _ 2.4 ___ 2.,,3 -_ +__ 2.4 ___ 2,,3 -- cgit v1.2.3-70-g09d2