Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Sep 2003 23:51:27 -0700
From:      Marcel Moolenaar <marcel@xcllnt.net>
To:        arch@FreeBSD.org
Subject:   make(1): adding sort modifiers
Message-ID:  <20030917065127.GB4261@athlon.pn.xcllnt.net>

next in thread | raw e-mail | index | archive | help

--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Gang,

Attached a patch that adds the functionality to make(1) to sort
the words in a variable. With this functionality and a small
change to bsd.subdir.mk (also attached), we automaticly have
sorted subdirectory recursion, even though it's impossible or
hard to do it in the makesfiles themselves. Is this too evil?

-- 
 Marcel Moolenaar	  USPA: A-39004		 marcel@xcllnt.net

--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="make.diff"

Index: var.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/var.c,v
retrieving revision 1.42
diff -u -r1.42 var.c
--- var.c	15 Jan 2003 22:36:15 -0000	1.42
+++ var.c	17 Sep 2003 06:30:11 -0000
@@ -606,7 +606,38 @@
     return (str);
 }
 
+static char *
+VarSortWords(char *str, int (*cmp)(const void *, const void *))
+{
+	Buffer buf;
+	char **av;
+	int ac, i;
+
+	buf = Buf_Init(0);
+	av = brk_string(str, &ac, FALSE);
+	qsort((void*)(av + 1), ac - 1, sizeof(char*), cmp);
+	for (i = 1; i < ac; i++) {
+		Buf_AddBytes(buf, strlen(av[i]), (Byte *)av[i]);
+		Buf_AddByte(buf, (Byte)((i < ac - 1) ? ' ' : '\0'));
+	}
+	str = (char *)Buf_GetAll(buf, (int *)NULL);
+	Buf_Destroy(buf, FALSE);
+	return (str);
+}
+
+static int
+SortIncreasing(const void *l, const void *r)
+{
+	return (strcmp(*(char**)l, *(char**)r));
+}
+
+static int
+SortDecreasing(const void *l, const void *r)
+{
+	return (-strcmp(*(char**)l, *(char**)r));
+}
+
 /*-
  *-----------------------------------------------------------------------
  * VarGetPattern --
@@ -1448,6 +1479,22 @@
 		    free(pattern.matches);
 		    break;
 		}
+		case '<':
+		    if (tstr[1] == endc || tstr[1] == ':') {
+			newStr = VarSortWords(str, SortIncreasing);
+			cp = tstr + 1;
+			termc = *cp;
+			break;
+		    }
+		    /* FALLTHROUGH */
+		case '>':
+		    if (tstr[1] == endc || tstr[1] == ':') {
+			newStr = VarSortWords(str, SortDecreasing);
+			cp = tstr + 1;
+			termc = *cp;
+			break;
+		    }
+		    /* FALLTHROUGH */
 		case 'Q':
 		    if (tstr[1] == endc || tstr[1] == ':') {
 			newStr = VarQuote (str);

--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="subdir.diff"

Index: bsd.subdir.mk
===================================================================
RCS file: /home/ncvs/src/share/mk/bsd.subdir.mk,v
retrieving revision 1.44
diff -u -r1.44 bsd.subdir.mk
--- bsd.subdir.mk	12 Jul 2002 15:09:35 -0000	1.44
+++ bsd.subdir.mk	17 Sep 2003 06:46:57 -0000
@@ -42,7 +42,7 @@
 
 _SUBDIR: .USE
 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
-	@for entry in ${SUBDIR}; do \
+	@for entry in ${SUBDIR:<}; do \
 		if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
 			${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH}"; \
 			edir=$${entry}.${MACHINE_ARCH}; \

--HcAYCG3uE/tztfnV--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030917065127.GB4261>