DragonFly BSD
DragonFly submit List (threaded) for 2004-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

usr.bin/make Patch to Implement the O modifier


From: Max Okumoto <okumoto@xxxxxxxx>
Date: Wed, 24 Nov 2004 04:35:10 -0800

Patch sent to correct mailing list. Time to go to sleep.

Max



PatchSet 320 Date: 2003/09/18 04:15:57 Author: marcel
        o Implement the O modifier. The O modifier sorts the words
          in a variable. The implementation is based upon the patch
          sent to arch@, but modified to be compatible with NetBSD.
          The modifier that does a reverse sort has been dropped
          for now, but the ability to add one later has been
          preserved.

PatchSet 321 Date: 2003/10/02 19:38:23 Author: ru
        o Document the recently added `O' modifier.


---------------------
PatchSet 320
Date: 2003/09/18 04:15:57
Author: marcel
Log:
Implement the O modifier. The O modifier sorts the words in a
variable. The implementation is based upon the patch sent to
arch@, but modified to be compatible with NetBSD. The modifier
that does a reverse sort has been dropped for now, but the
ability to add one later has been preserved.

Members: 
	var.c:1.42->1.43 

Index: var.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/var.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- var.c	15 Jan 2003 22:36:15 -0000	1.42
+++ var.c	18 Sep 2003 03:15:57 -0000	1.43
@@ -608,6 +608,48 @@
 
 /*-
  *-----------------------------------------------------------------------
+ * VarSortWords --
+ *	Sort the words in the string.
+ *
+ * Input:
+ *	str		String whose words should be sorted
+ *	cmp		A comparison function to control the ordering
+ *
+ * Results:
+ *	A string containing the words sorted
+ *
+ * Side Effects:
+ *	None.
+ *
+ *-----------------------------------------------------------------------
+ */
+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(*(const char* const*)l, *(const char* const*)r));
+}
+
+/*-
+ *-----------------------------------------------------------------------
  * VarGetPattern --
  *	Pass through the tstr looking for 1) escaped delimiters,
  *	'$'s and backslashes (place the escaped character in
@@ -1114,7 +1156,7 @@
 
 	    DEBUGF(VAR, ("Applying :%c to \"%s\"\n", *tstr, str));
 	    switch (*tstr) {
-	        case 'U':
+		case 'U':
 			if (tstr[1] == endc || tstr[1] == ':') {
 				Buffer buf;
 				buf = Buf_Init(MAKE_BSIZE);
@@ -1448,6 +1490,14 @@
 		    free(pattern.matches);
 		    break;
 		}
+		case 'O':
+		    if (tstr[1] == endc || tstr[1] == ':') {
+			newStr = VarSortWords(str, SortIncreasing);
+			cp = tstr + 1;
+			termc = *cp;
+			break;
+		    }
+		    /* FALLTHROUGH */
 		case 'Q':
 		    if (tstr[1] == endc || tstr[1] == ':') {
 			newStr = VarQuote (str);
---------------------
PatchSet 321
Date: 2003/10/02 19:38:23
Author: ru
Log:
Document the recently added `O' modifier.

Members: 
	make.1:1.63->1.64 

Index: make.1
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/make.1,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- make.1	14 Sep 2003 12:31:33 -0000	1.63
+++ make.1	2 Oct 2003 18:38:23 -0000	1.64
@@ -652,6 +652,8 @@
 .Cm M ,
 but selects all words which do not match
 the rest of the modifier.
+.It Cm O
+Order every word in the variable alphabetically.
 .It Cm Q
 Quotes every shell meta-character in the variable, so that it can be passed
 safely through recursive invocations of


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