Re: [hackers] [PATCH][sbase] sort: Don't do top-level sort when -c is used with -k

From: Richard Ipsum <richardipsum_AT_vx21.xyz>
Date: Thu, 2 Jan 2020 12:56:56 +0100

On Wed, Jan 01, 2020 at 09:39:18PM -0800, Michael Forney wrote:
> On 2020-01-01, Richard Ipsum <richardipsum_AT_vx21.xyz> wrote:
[snip]
>
> I think the following diff should cover those cases as well:
>
> diff --git a/sort.c b/sort.c
> index a51997f..fbb1abf 100644
> --- a/sort.c
> +++ b/sort.c
> _AT_@ -385,7 +385,8 @@ main(int argc, char *argv[])
> /* -b shall only apply to custom key definitions */
> if (TAILQ_EMPTY(&kdhead) && global_flags)
> addkeydef("1", global_flags & ~(MOD_STARTB | MOD_ENDB));
> - addkeydef("1", global_flags & MOD_R);
> + if (TAILQ_EMPTY(&kdhead) || (!Cflag && !cflag))
> + addkeydef("1", global_flags & MOD_R);
>
> if (!argc) {
> if (Cflag || cflag) {
>
> I'm still not convinced of the value of this tie-breaker keydef, so
> another option might be to just only add it if no -k flag is
> specified:
>
> diff --git a/sort.c b/sort.c
> index a51997f..adf1d6d 100644
> --- a/sort.c
> +++ b/sort.c
> _AT_@ -383,9 +383,8 @@ main(int argc, char *argv[])
> } ARGEND
>
> /* -b shall only apply to custom key definitions */
> - if (TAILQ_EMPTY(&kdhead) && global_flags)
> + if (TAILQ_EMPTY(&kdhead))
> addkeydef("1", global_flags & ~(MOD_STARTB | MOD_ENDB));
> - addkeydef("1", global_flags & MOD_R);
>
> if (!argc) {
> if (Cflag || cflag) {
>
> I think I will apply the first diff for now to fix the bug, and
> perhaps propose the second as a patch to the list, since it involves
> an unrelated behavior change (order of equal lines according to
> options passed to sort).

First diff looks good, as does the second, personally I don't feel too
strongly either way about the presence of the tie-breaker, I think other
sorts do something like it, so for this reason it may be worth keeping
it.

Thanks,
Richard
Received on Thu Jan 02 2020 - 12:56:56 CET

This archive was generated by hypermail 2.3.0 : Thu Jan 02 2020 - 13:00:23 CET