Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make: add :Or for reverse sort
details: https://anonhg.NetBSD.org/src/rev/8c01fc847ea4
branches: trunk
changeset: 1010771:8c01fc847ea4
user: sjg <sjg%NetBSD.org@localhost>
date: Fri Jun 05 19:20:46 2020 +0000
description:
make: add :Or for reverse sort
:Or is more efficient than :O:[-1..1]
Reviewed by: christos
diffstat:
usr.bin/make/make.1 | 15 +++++++++------
usr.bin/make/var.c | 18 ++++++++++++++----
2 files changed, 23 insertions(+), 10 deletions(-)
diffs (102 lines):
diff -r 4c62748f45f8 -r 8c01fc847ea4 usr.bin/make/make.1
--- a/usr.bin/make/make.1 Fri Jun 05 18:03:59 2020 +0000
+++ b/usr.bin/make/make.1 Fri Jun 05 19:20:46 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: make.1,v 1.280 2020/04/27 20:03:08 christos Exp $
+.\" $NetBSD: make.1,v 1.281 2020/06/05 19:20:46 sjg Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\"
-.Dd April 27, 2020
+.Dd June 5, 2020
.Dt MAKE 1
.Os
.Sh NAME
@@ -1195,10 +1195,8 @@
.Ar pattern .
.It Cm \&:O
Order every word in variable alphabetically.
-To sort words in
-reverse order use the
-.Ql Cm \&:O:[-1..1]
-combination of modifiers.
+.It Cm \&:Or
+Order every word in variable in reverse alphabetical order.
.It Cm \&:Ox
Randomize words in variable.
The results will be different each time you are referring to the
@@ -1613,6 +1611,11 @@
For example,
.Ql Cm \&:[-1..1]
selects all the words from last to first.
+If the list is already ordered, then this effectively reverses
+the list, but it is more efficient to use
+.Ql Cm \&:Or
+instead of
+.Ql Cm \&:O:[-1..1] .
.\" :[*]
.It Cm \&*
Causes subsequent modifiers to treat the value as a single word
diff -r 4c62748f45f8 -r 8c01fc847ea4 usr.bin/make/var.c
--- a/usr.bin/make/var.c Fri Jun 05 18:03:59 2020 +0000
+++ b/usr.bin/make/var.c Fri Jun 05 19:20:46 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $ */
+/* $NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $");
+__RCSID("$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -2028,6 +2028,13 @@
return r;
}
+static int
+VarWordCompareReverse(const void *a, const void *b)
+{
+ int r = strcmp(*(const char * const *)b, *(const char * const *)a);
+ return r;
+}
+
/*-
*-----------------------------------------------------------------------
* VarOrder --
@@ -2059,6 +2066,9 @@
if (ac > 0)
switch (otype) {
+ case 'r': /* reverse sort alphabetically */
+ qsort(av, ac, sizeof(char *), VarWordCompareReverse);
+ break;
case 's': /* sort alphabetically */
qsort(av, ac, sizeof(char *), VarWordCompare);
break;
@@ -3563,7 +3573,7 @@
if (tstr[1] == endc || tstr[1] == ':') {
otype = 's';
termc = *cp;
- } else if ( (tstr[1] == 'x') &&
+ } else if ( (tstr[1] == 'r' || tstr[1] == 'x') &&
(tstr[2] == endc || tstr[2] == ':') ) {
otype = tstr[1];
cp = tstr + 2;
Home |
Main Index |
Thread Index |
Old Index