summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2010-04-20 16:25:55 +0100
committerPádraig Brady <P@draigBrady.com>2010-04-20 22:37:18 +0100
commit8fc12909f649fbe75eb84c48ace554ae3e4e6c06 (patch)
tree34cadaffde2978c7033fae2ce54355330d7b1159 /src
parent1777d0dfe34dc4d8c148a34a96eb92c6036ff7bd (diff)
downloadcoreutils-8fc12909f649fbe75eb84c48ace554ae3e4e6c06.tar.xz
sort: fix parsing of end field in obsolescent key formats
This regression was introduced in commit 224a69b5, 2009-02-24, "sort: Fix two bugs with determining the end of field". The specific regression being that we include 1 field too many when an end field is specified using obsolescent key syntax (+POS -POS). * src/sort.c (struct keyfield): Clarify the description of the eword member, as suggested by Alan Curry. (main): When processing obsolescent format key specifications, normalize eword to a zero based count when no specific end char is given for an end field. This matches what's done when keys are specified with -k. * tests/misc/sort: Add a few more tests for the obsolescent key formats, with test 07i being the particular failure addressed by this change. * THANKS: Add Alan Curry who precisely identified the issue. * NEWS: Mention the fix. Reported by Santiago Rodríguez
Diffstat (limited to 'src')
-rw-r--r--src/sort.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/sort.c b/src/sort.c
index d619c60d5..6d47b794b 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -167,7 +167,7 @@ struct keyfield
{
size_t sword; /* Zero-origin 'word' to start at. */
size_t schar; /* Additional characters to skip. */
- size_t eword; /* Zero-origin first word after field. */
+ size_t eword; /* Zero-origin last 'word' of key. */
size_t echar; /* Additional characters in field. */
bool const *ignore; /* Boolean array of characters to ignore. */
char const *translate; /* Translation applied to characters. */
@@ -3389,6 +3389,16 @@ main (int argc, char **argv)
if (*s == '.')
s = parse_field_count (s + 1, &key->echar,
N_("invalid number after `.'"));
+ if (!key->echar && key->eword)
+ {
+ /* obsolescent syntax +A.x -B.y is equivalent to:
+ -k A+1.x+1,B.y (when y = 0)
+ -k A+1.x+1,B+1.y (when y > 0)
+ So eword is decremented as in the -k case
+ only when the end field (B) is specified and
+ echar (y) is 0. */
+ key->eword--;
+ }
if (*set_ordering (s, key, bl_end))
badfieldspec (optarg1,
N_("stray character in field spec"));