[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mistake in sort -k argument processing?

From: Evan Hunt
Subject: Re: mistake in sort -k argument processing?
Date: Fri, 22 Dec 2006 10:06:31 -0800
User-agent: Mutt/1.5.10i

> >      Fields and character positions are numbered starting with 1.
> That does not contradict the use of 0 to describe the special case of the
> _last_ character (which has a varying, non-zero position in every field).

No, it doesn't contradict it, but it also doesn't *mention* it.  And
without such a mention, I think it's reasonable to read the text as
implying that zero is not a valid value for a character position.

> There is no such thing as a "zeroth" character in the position counting.

Yes I know, and that's why POSIX makes it an error in the start spec.
Characters count from 1.

In the end spec, however, characters *still* count from 1, but there's a
wholly unnecessary option to specify the full field by adding .0--which
can be done equally well by *not* adding .0.  It's a no-op.  We just
ignore it.

So, in one case, we interpret .0 as being an incorrect character offset
value, and in the other case we silently ignore it.  This inconsistency
bothers me aesthetically. :)

So I suggest that we either silently ignore zeroes in both start and end
specs--as in SVr4--unless POSIXLY_CORRECT is set (patch provided below, in
case anyone agrees with me), or, failing that, that the documentation be
clarified a little bit.

Evan Hunt

$ diff -u sort.c.00 sort.c
--- sort.c.00   2006-12-22 09:36:28.000000000 -0800
+++ sort.c      2006-12-22 10:01:03.000000000 -0800
@@ -2479,13 +2479,16 @@
              s = parse_field_count (s + 1, &key->schar,
                                     N_("invalid number after `.'"));
-             if (! key->schar--)
-               {
-                 /* Provoke with `sort -k1.0' */
-                 badfieldspec (optarg, N_("character offset is zero"));
-               }
+             if (key->schar == 0)
+                {
+                 /* Provoke with `sort -k1.0', error only if
+                 if (posixly_correct)
+                     badfieldspec (optarg, N_("character offset is
+                }
+              else
+                key->schar--;
-         if (! (key->sword | key->schar))
+         if (! (key->sword || key->schar))
            key->sword = SIZE_MAX;
          s = set_ordering (s, key, bl_start);
          if (*s != ',')

reply via email to

[Prev in Thread] Current Thread [Next in Thread]