From 553e011320798af097e8de95a1e2a1d2ed6a1a3e Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 21 Jan 2007 22:47:36 +0000 Subject: 23118: improve sorting to make it work with locales --- Src/builtin.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index 260ba603b..36e829f22 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -617,8 +617,7 @@ bin_set(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) } } if (sort) - qsort(args, arrlen(args), sizeof(char *), - sort > 0 ? strpcmp : invstrpcmp); + strmetasort(args, sort < 0 ? SORTIT_BACKWARDS : 0, NULL); if (array) { /* create an array with the specified elements */ char **a = NULL, **y; @@ -3603,30 +3602,16 @@ bin_print(char *name, char **args, Options ops, int func) } /* -o and -O -- sort the arguments */ - /* - * TODO: this appears to be yet another of the endless - * chunks of code that didn't get fixed up properly - * to reflect the fact that args contains unmetafied - * strings that may contain NULs with the lengths in - * len. - */ - if (OPT_ISSET(ops,'o')) { - if (fmt && !*args) return 0; - if (OPT_ISSET(ops,'i')) - qsort(args, arrlen(args), sizeof(char *), cstrpcmp); - else - qsort(args, arrlen(args), sizeof(char *), strpcmp); - } else if (OPT_ISSET(ops,'O')) { - if (fmt && !*args) return 0; - if (OPT_ISSET(ops,'i')) - qsort(args, arrlen(args), sizeof(char *), invcstrpcmp); - else - qsort(args, arrlen(args), sizeof(char *), invstrpcmp); + if (OPT_ISSET(ops,'o') || OPT_ISSET(ops,'O')) { + int flags; + + if (fmt && !*args) + return 0; + flags = OPT_ISSET(ops,'i') ? SORTIT_IGNORING_CASE : 0; + if (OPT_ISSET(ops,'O')) + flags |= SORTIT_BACKWARDS; + strmetasort(args, flags, len); } - /* after sorting arguments, recalculate lengths */ - if(OPT_ISSET(ops,'o') || OPT_ISSET(ops,'O')) - for(n = 0; n < argc; n++) - len[n] = strlen(args[n]); /* -c -- output in columns */ if (!fmt && (OPT_ISSET(ops,'c') || OPT_ISSET(ops,'C'))) { -- cgit 1.4.1