Subject: make: allow setting variable mods in variable?
To: None <tech-toolchain@netbsd.org>
From: Simon J. Gerraty <sjg@crufty.net>
List: tech-toolchain
Date: 01/20/2006 17:10:28
I occasionally have a complex set of variable mods that I want to use
in multiple places and it would be handy to specify these in variable
as in (trivial example I know):
MODS=S,A,a,
V=Abc
all:
@echo V=${V:${MODS}}
it would be nice if this printed 'abc' rather than an error about $
being an unknown modifier. The patch below does this (and all the
unit tests still pass), but I'm not convinced it is right wrt cleanup.
I'd appreciate a 2nd opinion.
Thanks
--sjg
--- var.c.~1~ Sat Sep 3 15:15:09 2005
+++ var.c Fri Jan 20 16:58:52 2006
@@ -1890,6 +1890,7 @@ Var_Parse(const char *str, GNode *ctxt,
Boolean *freePtr)
{
const char *tstr; /* Pointer into str */
+ const char *tstr2; /* Secondary tstr if we need to recurse */
Var *v; /* Variable in invocation */
const char *cp; /* Secondary pointer into str (place marker
* for tstr) */
@@ -1915,6 +1916,7 @@ Var_Parse(const char *str, GNode *ctxt,
start = str;
parsestate.oneBigWord = FALSE;
parsestate.varSpace = ' '; /* word separator */
+ tstr2 = NULL;
if (str[1] != PROPEN && str[1] != BROPEN) {
/*
@@ -2257,6 +2259,9 @@ Var_Parse(const char *str, GNode *ctxt,
tstr++;
delim = '\0';
+ if (*tstr == '$') {
+ tstr = tstr2 = Var_Subst(NULL, tstr, ctxt, err);
+ }
while (*tstr && *tstr != endc) {
char *newStr; /* New value to return */
char termc; /* Character which terminated scan */
@@ -3235,6 +3240,8 @@ cleanup:
*lengthPtr = cp - start + 1;
if (*freePtr)
free(nstr);
+ if (tstr2)
+ free(tstr2);
if (delim != '\0')
Error("Unclosed substitution for %s (%c missing)",
v->name, delim);