]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort.c (main): Fix interpretation of field offsets when specified
authorJim Meyering <jim@meyering.net>
Mon, 12 Dec 1994 00:00:22 +0000 (00:00 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 12 Dec 1994 00:00:22 +0000 (00:00 +0000)
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>.

src/sort.c

index 87d653347958faf86ab7142d94cb0d093c5c9ac2..94c9408dbaf35551166befb7185c532c9de23838 100644 (file)
@@ -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;