bin/54594: Apply regexps to the entire variable -- a new variable modifier

Mikhail Teterin mteterin at
Thu Jul 17 14:20:02 PDT 2003

>Number:         54594
>Category:       bin
>Synopsis:       Apply regexps to the entire variable -- a new variable modifier
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 17 14:20:00 PDT 2003
>Originator:     Mikhail Teterin
>Release:        FreeBSD 5.1-CURRENT i386
Virtual Estates, Inc.
System: FreeBSD 5.1-CURRENT FreeBSD 5.1-CURRENT #3: Fri Jul 11 18:12:03 EDT 2003 root at i386


	Writing a Makefile for a Java project, I was unable to easily
	construct a long enough CLASSPATH inside the Makefile without
	resorting to very:long:string or using shell commands.

	The patch below adds another variable modifier, which works
	just like C/pattern/replacement/[1g], but operates on the entire
	value of the variable, rather then on each individual word of it.

	Not only can this be a little faster (as a replacement for the
	C modifier, where possible), it will also allow to operate on
	the very word-separators (blanks) themselves -- such as turning
	sequences of them into CLASSPATH-like colons or whatever:

	JARS=	...
	JARS+=	...
	JARS+=	...


	This is a more general solution than join/split modifiers, one
	could think of.

	I picked 'A' (as in "all") for the new modifier, but that is, of
	course, arbitrary.


cvs server: Diffing .
Index: make.1
RCS file: /home/ncvs/src/usr.bin/make/make.1,v
retrieving revision 1.62
diff -U2 -r1.62 make.1
--- make.1	23 Dec 2002 16:04:51 -0000	1.62
+++ make.1	17 Jul 2003 20:59:02 -0000
@@ -595,4 +595,18 @@
 .Bl -tag -width Cm
 .Sm off
+.It Cm A No \&/ Ar pattern Xo
+.No \&/ Ar replacement
+.No \&/ Op Cm 1g
+.Sm on
+.Cm A
+modifier is just like the
+.Cm C
+modifier (see below) except that the transformation is applied to the whole
+value of the variable at once, rather than to each word of it. This makes it
+possible, for example, to join lists of files or directories together -- such
+as when constructing a Java CLASSPATH.
+.Sm off
 .It Cm C No \&/ Ar pattern Xo
 .No \&/ Ar replacement
Index: var.c
RCS file: /home/ncvs/src/usr.bin/make/var.c,v
retrieving revision 1.42
diff -U2 -r1.42 var.c
--- var.c	15 Jan 2003 22:36:15 -0000	1.42
+++ var.c	17 Jul 2003 20:59:02 -0000
@@ -1372,4 +1372,5 @@
+		case 'A':
 		case 'C':
@@ -1442,6 +1443,18 @@
 		    pattern.matches = emalloc(pattern.nsub *
-		    newStr = VarModify(str, VarRESubstitute,
-				       (void *) &pattern);
+		    if (*tstr == 'C')
+			/* Apply to each word of the string */
+			newStr = VarModify(str, VarRESubstitute,
+				           &pattern);
+		    else {
+			/* Apply to the whole string */
+			Buffer	buf;
+			buf = Buf_Init (0);
+			VarRESubstitute(str, FALSE, buf, &pattern);
+			Buf_AddByte(buf, '\0'); /* XXX Needed? */
+			newStr = Buf_GetAll (buf, (int *)NULL);
+			Buf_Destroy (buf, FALSE);
+		    }

More information about the freebsd-bugs mailing list