2010-02-23 08:43:04 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
# Test annotation of sort keys
|
|
|
|
|
|
2011-01-01 11:37:32 +01:00
|
|
|
# Copyright (C) 2010-2011 Free Software Foundation, Inc.
|
2010-02-23 08:43:04 +00:00
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2010-11-14 11:05:05 +01:00
|
|
|
. "${srcdir=.}/init.sh"; path_prepend_ ../src
|
2010-11-17 21:35:31 +01:00
|
|
|
print_ver_ sort
|
2010-02-23 08:43:04 +00:00
|
|
|
|
|
|
|
|
number() { cat -n | sed 's/^ *//'; }
|
|
|
|
|
|
|
|
|
|
cat <<\EOF > exp
|
|
|
|
|
1
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
44
|
|
|
|
|
^ no match for key
|
|
|
|
|
33
|
|
|
|
|
^ no match for key
|
|
|
|
|
2
|
|
|
|
|
^ no match for key
|
|
|
|
|
1
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
44
|
|
|
|
|
^ no match for key
|
|
|
|
|
33
|
|
|
|
|
^ no match for key
|
|
|
|
|
2
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
2
|
|
|
|
|
_
|
|
|
|
|
33
|
|
|
|
|
__
|
|
|
|
|
44
|
|
|
|
|
__
|
|
|
|
|
2>
|
|
|
|
|
^ no match for key
|
|
|
|
|
3>1
|
|
|
|
|
_
|
|
|
|
|
1>2
|
|
|
|
|
_
|
|
|
|
|
1
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
44
|
|
|
|
|
^ no match for key
|
|
|
|
|
33
|
|
|
|
|
^ no match for key
|
|
|
|
|
2
|
|
|
|
|
^ no match for key
|
|
|
|
|
1
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
44
|
|
|
|
|
^ no match for key
|
|
|
|
|
33
|
|
|
|
|
^ no match for key
|
|
|
|
|
2
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
2
|
|
|
|
|
_
|
|
|
|
|
33
|
|
|
|
|
__
|
|
|
|
|
44
|
|
|
|
|
__
|
|
|
|
|
2>
|
|
|
|
|
^ no match for key
|
|
|
|
|
3>1
|
|
|
|
|
_
|
|
|
|
|
1>2
|
|
|
|
|
_
|
|
|
|
|
1
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
44
|
|
|
|
|
^ no match for key
|
|
|
|
|
33
|
|
|
|
|
^ no match for key
|
|
|
|
|
2
|
|
|
|
|
^ no match for key
|
|
|
|
|
1
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
44
|
|
|
|
|
^ no match for key
|
|
|
|
|
33
|
|
|
|
|
^ no match for key
|
|
|
|
|
2
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
2
|
|
|
|
|
_
|
|
|
|
|
33
|
|
|
|
|
__
|
|
|
|
|
44
|
|
|
|
|
__
|
|
|
|
|
2>
|
|
|
|
|
^ no match for key
|
|
|
|
|
3>1
|
|
|
|
|
_
|
|
|
|
|
1>2
|
|
|
|
|
_
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
JAN
|
|
|
|
|
___
|
|
|
|
|
FEB
|
|
|
|
|
___
|
|
|
|
|
FEB
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
JAN
|
|
|
|
|
^ no match for key
|
|
|
|
|
JAZZ
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
JAN
|
|
|
|
|
___
|
|
|
|
|
FEB
|
|
|
|
|
___
|
|
|
|
|
2>JAZZ
|
|
|
|
|
^ no match for key
|
|
|
|
|
3>
|
|
|
|
|
^ no match for key
|
|
|
|
|
4>JAN
|
|
|
|
|
___
|
|
|
|
|
1>FEB
|
|
|
|
|
___
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
JANZ
|
|
|
|
|
___
|
|
|
|
|
JAN
|
|
|
|
|
___
|
|
|
|
|
FEB
|
|
|
|
|
___
|
|
|
|
|
3>
|
|
|
|
|
^ no match for key
|
|
|
|
|
2>JANZ
|
|
|
|
|
___
|
|
|
|
|
4>JAN
|
|
|
|
|
___
|
|
|
|
|
1>FEB
|
|
|
|
|
___
|
|
|
|
|
1.2ignore
|
|
|
|
|
___
|
|
|
|
|
1.1e4ignore
|
|
|
|
|
_____
|
|
|
|
|
>>a
|
|
|
|
|
___
|
|
|
|
|
>b
|
|
|
|
|
__
|
|
|
|
|
a
|
|
|
|
|
^ no match for key
|
|
|
|
|
|
|
|
|
|
^ no match for key
|
|
|
|
|
a
|
|
|
|
|
_
|
|
|
|
|
b
|
|
|
|
|
_
|
|
|
|
|
-3
|
|
|
|
|
__
|
|
|
|
|
-2
|
|
|
|
|
__
|
|
|
|
|
-0
|
|
|
|
|
__
|
|
|
|
|
--Mi-1
|
sort: tune and refactor --debug code, and fix minor underlining bug
Formerly, the 'compare' function and some of its subroutines had a
debugging flag, which caused them to output underlines. This
change refactors the code so that debugging output is
more-separated from the actual sorting. In the process, the
change fixes a minor error in the debugging output. The change
shortens the source code and executable size a tad, and improves
CPU performance by 2.4% on my platform with a simple benchmark (C
locale, line sorting, no debug).
* src/sort.c (long_double, strtold): Move back to prelude, since
they're now used by multiple functions again.
(unit_order): Move to file scope, since it's now used by two functions.
(find_unit_order, human_numcompare, numcompare, general_numcompare):
Remove endptr parameter. All callers changed.
(human_numcompare): Args are now const pointers.
(getmonth): Endptr is now non-const.
(key_numeric): Move up, since it's needed earlier.
(debug_key): Take a line and a key as argument, instead of having
the caller figure out where the field is.
(debug_line): New function.
(keycompare, compare): Omit debug parameter; debug output now done
elsewhere. All callers changed.
(write_line): Renamed from write_bytes; all callers changed.
Use debug_line (not 'compare') to output debug info.
Use a slightly faster check for whether output file is stdout.
(check): Don't do debugging output; it's not that useful here,
and it confuses the code.
(main): Check for incompatibility between -c and --debug.
Use standard diagnostic for incompatible options.
* tests/misc/sort-debug-keys: Fix test case: "--Mi-1" is not
a number, so its first character should not be underlined when
debugging a numeric sort.
2010-08-05 13:28:35 -07:00
|
|
|
^ no match for key
|
2010-02-23 08:43:04 +00:00
|
|
|
-0
|
|
|
|
|
__
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
__
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
_
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
1
|
|
|
|
|
__
|
|
|
|
|
1
|
|
|
|
|
_
|
|
|
|
|
2,5
|
|
|
|
|
_
|
|
|
|
|
2.4
|
|
|
|
|
___
|
|
|
|
|
2.,,3
|
2010-07-30 01:52:59 -06:00
|
|
|
__
|
2010-02-23 08:43:04 +00:00
|
|
|
2.4
|
|
|
|
|
___
|
|
|
|
|
2,,3
|
|
|
|
|
_
|
|
|
|
|
2.4
|
|
|
|
|
___
|
|
|
|
|
1a
|
|
|
|
|
_
|
|
|
|
|
2b
|
|
|
|
|
_
|
2010-08-03 10:24:11 -07:00
|
|
|
>a
|
|
|
|
|
_
|
2011-02-02 23:08:42 +00:00
|
|
|
A>chr10
|
|
|
|
|
^ no match for key
|
|
|
|
|
B>chr1
|
|
|
|
|
^ no match for key
|
2010-02-23 08:43:04 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
(
|
|
|
|
|
for type in n h g; do
|
2010-09-20 15:23:20 +01:00
|
|
|
printf '1\n\n44\n33\n2\n' | sort -s -k2$type --debug
|
|
|
|
|
printf '1\n\n44\n33\n2\n' | sort -s -k1.3$type --debug
|
|
|
|
|
printf '1\n\n44\n33\n2\n' | sort -s -k1$type --debug
|
|
|
|
|
printf '2\n\n1\n' | number | sort -s -k2g --debug
|
2010-02-23 08:43:04 +00:00
|
|
|
done
|
|
|
|
|
|
2010-09-20 15:23:20 +01:00
|
|
|
printf 'FEB\n\nJAN\n' | sort -s -k1M --debug
|
|
|
|
|
printf 'FEB\n\nJAN\n' | sort -s -k2,2M --debug
|
|
|
|
|
printf 'FEB\nJAZZ\n\nJAN\n' | sort -s -k1M --debug
|
|
|
|
|
printf 'FEB\nJAZZ\n\nJAN\n' | number | sort -s -k2,2M --debug
|
|
|
|
|
printf 'FEB\nJANZ\n\nJAN\n' | sort -s -k1M --debug
|
|
|
|
|
printf 'FEB\nJANZ\n\nJAN\n' | number | sort -s -k2,2M --debug
|
2010-02-23 08:43:04 +00:00
|
|
|
|
2010-09-20 15:23:20 +01:00
|
|
|
printf ' 1.2ignore\n 1.1e4ignore\n' | sort -s -g --debug
|
2010-02-23 08:43:04 +00:00
|
|
|
|
2010-09-20 15:23:20 +01:00
|
|
|
printf '\tb\n\t\ta\n' | sort -s -d --debug # ignore = 1
|
2010-02-23 08:43:04 +00:00
|
|
|
|
2010-09-20 15:23:20 +01:00
|
|
|
printf 'a\n\n' | sort -s -k2,2 --debug #lena = 0
|
2010-02-23 08:43:04 +00:00
|
|
|
|
2010-09-20 15:23:20 +01:00
|
|
|
printf 'b\na\n' | sort -s -k1 --debug #otherwise key compare
|
2010-02-23 08:43:04 +00:00
|
|
|
|
2010-09-20 15:23:20 +01:00
|
|
|
printf -- '-0\n1\n-2\n--Mi-1\n-3\n-0\n' | sort -s --debug -k1,1h
|
2010-02-23 08:43:04 +00:00
|
|
|
|
2010-09-20 15:23:20 +01:00
|
|
|
printf ' 1\n1\n' | sort -b --debug
|
|
|
|
|
printf ' 1\n1\n' | sort -sb --debug
|
|
|
|
|
printf ' 1\n1\n' | sort --debug
|
2010-02-23 08:43:04 +00:00
|
|
|
|
|
|
|
|
# strnumcmp is a bit weird, so we don't match exactly
|
2010-09-20 15:23:20 +01:00
|
|
|
printf '2,5\n2.4\n' | sort -s -k1n --debug
|
|
|
|
|
printf '2.,,3\n2.4\n' | sort -s -k1n --debug
|
|
|
|
|
printf '2,,3\n2.4\n' | sort -s -k1n --debug
|
2010-02-23 08:43:04 +00:00
|
|
|
|
|
|
|
|
# -z means we convert \0 to \n
|
2010-09-20 15:23:20 +01:00
|
|
|
env printf '1a\x002b\x00' | sort -s -n -z --debug
|
2010-08-03 10:24:11 -07:00
|
|
|
|
|
|
|
|
# Check that \0 and \t intermix.
|
2010-09-20 15:23:20 +01:00
|
|
|
printf '\0\ta\n' | sort -s -k2b,2 --debug | tr -d '\0'
|
2011-02-02 23:08:42 +00:00
|
|
|
|
|
|
|
|
# Check that key end before key start is not underlined
|
|
|
|
|
printf 'A\tchr10\nB\tchr1\n' | sort -s -k2.4b,2.3n --debug
|
2010-02-23 08:43:04 +00:00
|
|
|
) > out
|
|
|
|
|
|
|
|
|
|
compare out exp || fail=1
|
|
|
|
|
|
|
|
|
|
cat <<\EOF > exp
|
|
|
|
|
1²---++3 1,234 Mi
|
|
|
|
|
_
|
|
|
|
|
_________
|
|
|
|
|
________________________
|
|
|
|
|
1²---++3 1,234 Mi
|
|
|
|
|
_____
|
|
|
|
|
________
|
|
|
|
|
_______________________
|
|
|
|
|
+1234 1234Gi 1,234M
|
|
|
|
|
^ no match for key
|
|
|
|
|
_____
|
|
|
|
|
^ no match for key
|
|
|
|
|
____
|
|
|
|
|
____
|
sort: revert recent -h changes and use a more-conservative approach
* NEWS: Document changes to sort -h, which are now minor with
respect to the pre-July-30th version.
* doc/coreutils.texi (sort invocation): Likewise. The
documentation now describes how -h comparison is done rather than
being vague with border cases.
* src/sort.c (long_double, strtold): Move back to general_numcompare.
(LD, compute_human): Remove.
(find_unit_order): Remove THOU_SEP parameter, since thousands
separators are now allowed by all callers. Revert to previous
behavior of sorting by suffix, and returning the order rather than
2 * order + binary, since we no longer care whether binary powers
are being used. However, treat all zeros the same, instead of
sorting 0M before 0G; this is more consistent with the desired
behavior of sorting -1G before -1M.
* tests/misc/sort (h1, h3, h6): Adjust to match mostly-reverted
behavior. However, check that all zeros sort together.
* tests/misc/sort-debug-keys: Omit a "_", since the trailing "i"
in "1234Gi" is no longer part of the key.
2010-08-02 19:18:01 -07:00
|
|
|
_____
|
2010-02-23 08:43:04 +00:00
|
|
|
_____
|
|
|
|
|
_____
|
|
|
|
|
______
|
|
|
|
|
___________________
|
|
|
|
|
EOF
|
|
|
|
|
|
2011-06-17 20:30:10 +02:00
|
|
|
unset LC_ALL
|
|
|
|
|
f=$LOCALE_FR_UTF8
|
|
|
|
|
|
2010-05-18 23:42:36 +01:00
|
|
|
: ${LOCALE_FR_UTF8=none}
|
|
|
|
|
if test "$LOCALE_FR_UTF8" != "none"; then
|
2010-05-12 14:47:30 +01:00
|
|
|
(
|
2010-09-20 15:23:20 +01:00
|
|
|
echo ' 1²---++3 1,234 Mi' |
|
2010-02-23 08:43:04 +00:00
|
|
|
LC_ALL=C sort --debug -k2g -k1b,1
|
2010-09-20 15:23:20 +01:00
|
|
|
echo ' 1²---++3 1,234 Mi' |
|
2011-06-17 20:30:10 +02:00
|
|
|
LC_COLLATE=$f LC_CTYPE=$f LC_NUMERIC=$f LC_MESSAGES=C \
|
|
|
|
|
sort --debug -k2g -k1b,1
|
2010-09-20 15:23:20 +01:00
|
|
|
echo '+1234 1234Gi 1,234M' |
|
2011-06-17 20:30:10 +02:00
|
|
|
LC_COLLATE=$f LC_CTYPE=$f LC_NUMERIC=$f LC_MESSAGES=C \
|
|
|
|
|
sort --debug -k1,1n -k1,1g \
|
|
|
|
|
-k1,1h -k2,2n -k2,2g -k2,2h -k3,3n -k3,3g -k3,3h
|
2010-05-12 14:47:30 +01:00
|
|
|
) > out
|
|
|
|
|
compare out exp || fail=1
|
2010-02-23 08:43:04 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
Exit $fail
|