diff options
author | Paul Smith <psmith@gnu.org> | 2004-09-21 04:00:31 +0000 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2004-09-21 04:00:31 +0000 |
commit | 0799ce730d2404d1cd1d03ce2f4ac07cc079c72e (patch) | |
tree | 6b9602199bec0f905f06a7a8f1c7bedb1e65b349 /expand.c | |
parent | 08c8105c5468ff743d2f2ff2fdf3b77a6313b53e (diff) | |
download | gunmake-0799ce730d2404d1cd1d03ce2f4ac07cc079c72e.tar.gz |
Fix some bugs in variable pattern substitution (e.g. $(VAR:A=B)),
reported by Markus Mauhart <qwe123@chello.at>. 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.
Diffstat (limited to 'expand.c')
-rw-r--r-- | expand.c | 80 |
1 files changed, 39 insertions, 41 deletions
@@ -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); } |