From 88442ad88504354756c189531a259ae6f859494a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 12 Dec 1994 00:00:22 +0000 Subject: 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 . --- src/sort.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/sort.c') diff --git a/src/sort.c b/src/sort.c index 87d653347..94c9408db 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; -- cgit v1.2.3-70-g09d2