summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-12-12 00:00:22 +0000
committerJim Meyering <jim@meyering.net>1994-12-12 00:00:22 +0000
commit88442ad88504354756c189531a259ae6f859494a (patch)
tree6212116c71a753e50b7495d63465dabfc03fdc0d /src
parentf46511eb69737feea7e4db989ae9371dc19257f6 (diff)
downloadcoreutils-88442ad88504354756c189531a259ae6f859494a.tar.xz
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 <faith@cs.unc.edu>.
Diffstat (limited to 'src')
-rw-r--r--src/sort.c8
1 files changed, 7 insertions, 1 deletions
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;