From: Jim Meyering Date: Mon, 12 Dec 1994 00:00:22 +0000 (+0000) Subject: sort.c (main): Fix interpretation of field offsets when specified X-Git-Tag: textutils-1_12_1~393 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88442ad88504354756c189531a259ae6f859494a;p=thirdparty%2Fcoreutils.git sort.c (main): Fix interpretation of field offsets when specified via -k option. They were being interpreted as zero-indexed. POSIX says they are 1-based indices. (keycompare): Don't ignore characters at the end of words when otherwise they compare equal. Both from Rik Faith . --- diff --git a/src/sort.c b/src/sort.c index 87d6533479..94c9408dba 100644 --- a/src/sort.c +++ b/src/sort.c @@ -861,6 +861,8 @@ keycompare (a, b) diff = translate[UCHAR (*--texta)] - translate[UCHAR (*--textb)]; break; } + else if (texta == lima && textb < limb) diff = -1; + else if (texta < lima && textb == limb) diff = 1; } else if (ignore) while (texta < lima && textb < limb) @@ -874,6 +876,8 @@ keycompare (a, b) diff = *--texta - *--textb; break; } + else if (texta == lima && textb < limb) diff = -1; + else if (texta < lima && textb == limb) diff = 1; } else if (translate) while (texta < lima && textb < limb) @@ -1624,13 +1628,15 @@ main (argc, argv) /* Get POS2. */ for (t = 0; digits[UCHAR (*s)]; ++s) t = t * 10 + *s - '0'; + if (t) + t--; t2 = 0; if (*s == '.') { for (++s; digits[UCHAR (*s)]; ++s) t2 = t2 * 10 + *s - '0'; if (t2) - t--; + t2--; } key->eword = t; key->echar = t2;