From 0799ce730d2404d1cd1d03ce2f4ac07cc079c72e Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Tue, 21 Sep 2004 04:00:31 +0000 Subject: Fix some bugs in variable pattern substitution (e.g. $(VAR:A=B)), reported by Markus Mauhart . One was a simple typo; to fix the other we call patsubst_expand() for all instances of variable substitution, even when there is no '%'. We used to call subst_expand() with a special flag set in the latter case, but it didn't work properly in all situations. Easier to just use patsubst_expand() since that's what it is. --- expand.c | 80 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 41 deletions(-) (limited to 'expand.c') diff --git a/expand.c b/expand.c index 2c8b4b6..4440192 100644 --- a/expand.c +++ b/expand.c @@ -304,51 +304,49 @@ variable_expand_string (char *line, char *string, long length) if (v == 0) warn_undefined (beg, colon - beg); + /* If the variable is not empty, perform the + substitution. */ if (v != 0 && *v->value != '\0') { - char *value = (v->recursive ? recursively_expand (v) + char *pattern, *replace, *ppercent, *rpercent; + char *value = (v->recursive + ? recursively_expand (v) : v->value); - char *pattern, *percent; - if (free_beg) - { - *subst_end = '\0'; - pattern = subst_beg; - } - else - { - pattern = (char *) alloca (subst_end - subst_beg - + 1); - bcopy (subst_beg, pattern, subst_end - subst_beg); - pattern[subst_end - subst_beg] = '\0'; - } - percent = find_percent (pattern); - if (percent != 0) - { - char *replace; - if (free_beg) - { - *replace_end = '\0'; - replace = replace_beg; - } - else - { - replace = (char *) alloca (replace_end - - replace_beg - + 1); - bcopy (replace_beg, replace, - replace_end - replace_beg); - replace[replace_end - replace_beg] = '\0'; - } - - o = patsubst_expand (o, value, pattern, replace, - percent, (char *) 0); - } + + /* Copy the pattern and the replacement. Add in an + extra % at the beginning to use in case there + isn't one in the pattern. */ + pattern = (char *) alloca (subst_end - subst_beg + 2); + *(pattern++) = '%'; + bcopy (subst_beg, pattern, subst_end - subst_beg); + pattern[subst_end - subst_beg] = '\0'; + + replace = (char *) alloca (replace_end + - replace_beg + 2); + *(replace++) = '%'; + bcopy (replace_beg, replace, + replace_end - replace_beg); + replace[replace_end - replace_beg] = '\0'; + + /* Look for %. Set the percent pointers properly + based on whether we find one or not. */ + ppercent = find_percent (pattern); + if (ppercent) + { + ++ppercent; + rpercent = 0; + } else - o = subst_expand (o, value, - pattern, replace_beg, - strlen (pattern), - end - replace_beg, - 0, 1); + { + ppercent = pattern; + rpercent = replace; + --pattern; + --replace; + } + + o = patsubst_expand (o, value, pattern, replace, + ppercent, rpercent); + if (v->recursive) free (value); } -- cgit v1.2.3