From owner-freebsd-current Sun Apr 7 3:44:24 2002 Delivered-To: freebsd-current@freebsd.org Received: from treetop.robbins.dropbear.id.au (170.d.003.mel.iprimus.net.au [210.50.34.170]) by hub.freebsd.org (Postfix) with ESMTP id 409AE37B41D for ; Sun, 7 Apr 2002 03:44:12 -0700 (PDT) Received: from treetop.robbins.dropbear.id.au (localhost [127.0.0.1]) by treetop.robbins.dropbear.id.au (8.12.2/8.12.2) with ESMTP id g37AeFSu020715; Sun, 7 Apr 2002 20:40:15 +1000 (EST) (envelope-from tim@treetop.robbins.dropbear.id.au) Received: (from tim@localhost) by treetop.robbins.dropbear.id.au (8.12.2/8.12.2/Submit) id g37AeDe7020714; Sun, 7 Apr 2002 20:40:13 +1000 (EST) Date: Sun, 7 Apr 2002 20:40:13 +1000 From: "Tim J. Robbins" To: freebsd-current@FreeBSD.ORG Cc: "Andrey A. Chernov" Subject: Re: NetBSD sort l10n: I give up! Message-ID: <20020407204013.A20639@treetop.robbins.dropbear.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5.1i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Here is a patch to make NetBSD's sort(1) sort by the locale's collating order. The table should not be called ascii[] anymore, but I can't think of a better one, and supplying a patch to change the name would be pointless. It works. It assumes the string strxfrm() outputs is the same length as its input, which is always possible, and true on FreeBSD. $ env LC_COLLATE=fr_FR.ISO8859-1 sort +#include #include static void insertcol __P((struct field *)); @@ -291,8 +292,7 @@ * Note: when sorting in forward order, to encode character zero in a key, * use \001\001; character 1 becomes \001\002. In this case, character 0 * is reserved for the field delimiter. Analagously for -r (fld_d = 255). - * Note: this is only good for ASCII sorting. For different LC 's, - * all bets are off. See also num_init in number.c + * See also num_init in number.c */ void settables(gflags) @@ -300,8 +300,20 @@ { u_char *wts; int i, incr; + static int warned; + char abuf[2], xbuf[8]; + + abuf[1] = '\0'; for (i=0; i < 256; i++) { - ascii[i] = i; + if (i != 0) { + *abuf = i; + if (strxfrm(xbuf, abuf, sizeof(xbuf)) > 1 && !warned) { + warnx("collating order too complicated"); + warned = 1; + } + ascii[i] = *xbuf; + } else + ascii[i] = 0; if (i > REC_D && i < 255 - REC_D+1) Rascii[i] = 255 - i + 1; else To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message