bug-coreutils
[Top][All Lists]
Advanced

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

bug#6176: [PATCH 2/2] sort: --debug: output data independent key warning


From: Pádraig Brady
Subject: bug#6176: [PATCH 2/2] sort: --debug: output data independent key warnings
Date: Sat, 15 May 2010 01:26:21 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3

On 14/05/10 22:47, Pádraig Brady wrote:
> On 14/05/10 22:23, Paul Eggert wrote:

>> Something like the following diagnostic would be far more helpful for
>> users who are not 'sort' experts:
>>
>>   sort: obsolescent key `+2 -4' used; consider `-k 3,4' instead
>>
>> Can you please arrange for that?

I did that using this chunk.
Note that it doesn't reproduce char offsets or flags
on the old or new formats, but they're the same on
both formats, so it's not worth the complexity I think.

if (key->obsolete_used)
  {
    /* obsolescent syntax +A.x -B.y is equivalent to:
         -k A+1.x+1,B.y   (when y = 0)
         -k A+1.x+1,B+1.y (when y > 0)  */
    char obuf[INT_BUFSIZE_BOUND (size_t) * 2 + 4]; /* +# -#  */
    char nbuf[INT_BUFSIZE_BOUND (size_t) * 2 + 5]; /* -k #,#  */

    char *po = obuf;
    char *pn = nbuf;

    size_t sword = key->sword;
    size_t eword = key->eword;
    if (sword == SIZE_MAX)
      sword++;

    po += sprintf (po, "+%" PRIuMAX, (uintmax_t) sword);
    pn += sprintf (pn, "-k %" PRIuMAX, (uintmax_t) sword + 1);
    if (key->eword != SIZE_MAX)
      {
        po += sprintf (po, " -%" PRIuMAX, (uintmax_t) eword + 1);
        pn += sprintf (pn, ",%" PRIuMAX,
                       (uintmax_t) eword + 1 + (key->echar == SIZE_MAX));
      }
    error (0, 0, _("obsolescent key `%s' used; consider `%s' instead"),
           obuf, nbuf);
  }

That latest patch is at http://url.ie/660o

cheers,
Pádraig.





reply via email to

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