bug-coreutils
[Top][All Lists]
Advanced

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

sort and LC_COLLATE: suggestions for improvement (with patch)


From: Jean-Pierre Vial
Subject: sort and LC_COLLATE: suggestions for improvement (with patch)
Date: Fri, 18 May 2007 15:47:56 +0200
User-agent: Thunderbird 1.5.0.9 (X11/20060911)

When one wants to sort a file in which letters are just codes,
not meaningfull words, the sort order obtained through LC_COLLATE
is very often inadequate.
The help suggest to set LC_ALL="C", but this is often inadequate as well
in complcated shell scripts.

I attach a small patch, which adds a global command-line option: -A
and s sub-option for use in individual keys : a
These options force the same ordering as LC_ALL="C", without tempering
any environment variable.
Numeric sorts, monthes etc. are not modified.

I hope that it may be useful for others.
You are free to use the patch as you want.

-- 
Jean-Pierre Vial
47a48
> 
120a122,125
> 
> /* Nonzero if we use  hard_LC_COLLATE*/
> static bool Use_local_collate=1;
> 
126a132
> 
175a182,183
>   bool use_local_collate;         /* =1 use the current collate function
>                                  =0 sort by ascii code, even if >128 */
325a334,336
>       fputs("  -A, --all-ascii             sort by ascii numeric code (all 
> textual keys)\n",stdout);
>       fputs("  a,  sort this key by ascii numeric code (option letter for one 
> key)\n",stdout);
>       fputs("      Caution for accented letters etc. the order depends  on 
> the encoding\n      in use at file creation\n",stdout);
398c409
< static char const short_options[] = "-bcCdfgik:mMno:rRsS:t:T:uy:z";
---
> static char const short_options[] = "aA-bcCdfgik:mMno:rRsS:t:T:uy:z";
412a424,425
>   {"ascii-sort",no_argument,NULL,'a'},
>   {"all-ascii",no_argument,NULL,'A'},
1693d1705
< 
1717d1728
< 
1744c1755
<       else if (hard_LC_COLLATE)
---
>       else if (hard_LC_COLLATE && Use_local_collate && key->use_local_collate)
1905c1916
<   else if (hard_LC_COLLATE)
---
>   else if (hard_LC_COLLATE && Use_local_collate)
2670a2682,2684
>       case 'a':
>         key->use_local_collate=0;
>         break;
2716a2731
>   key->use_local_collate=1;
2902c2917,2920
< 
---
>       case 'A':
>         Use_local_collate=0;
>         break;
>       case 'a':
2905a2924
>       case 'F':

reply via email to

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