From: Gary V. Vaughan Date: Wed, 20 Oct 2004 20:50:53 +0000 (+0000) Subject: * config/general.m4sh (sed_double_backslash): New sed expression X-Git-Tag: release-1-9f~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffb70fbe4b27c59d8e80ad2cfe04d14aecdb15c9;p=thirdparty%2Flibtool.git * config/general.m4sh (sed_double_backslash): New sed expression to escape $ properly in combination with double_quote_subst. (func_quote_for_eval): Four space indent margin for functions! (func_quote_for_expand): Use $sed_double_backslash. (func_show_eval): New function that echos an escaped but variable expanded command, and then evaluates it. --- diff --git a/ChangeLog b/ChangeLog index b5a21fe5d..64036ce94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,19 @@ +2004-10-20 Gary V. Vaughan + + * config/general.m4sh (sed_double_backslash): New sed expression + to escape \$ properly in combination with double_quote_subst. + (func_quote_for_eval): Four space indent margin for functions! + (func_quote_for_expand): Use $sed_double_backslash. + (func_show_eval): New function that echos an escaped but variable + expanded command, and then evaluates it. + 2004-10-20 Noah Misch , Gary V. Vaughan * m4/libtool.m4 (sed_quote_subst): Remove superfluous backslashes from the match character set. (double_quote_subst): Ditto. - * lib/general.m4sh (sed_quote_subst): Ditto. + * config/general.m4sh (sed_quote_subst): Ditto. (double_quote_subst): New variable, copied from m4/libtool.m4. Much the same as sed_quote_subst, but variable references are not quoted. diff --git a/config/general.m4sh b/config/general.m4sh index d03da0dbd..efecf7cd6 100644 --- a/config/general.m4sh +++ b/config/general.m4sh @@ -94,6 +94,13 @@ sed_quote_subst='s/\([[`"$\\]]\)/\\\1/g' # Same as above, but do not quote variable references. double_quote_subst='s/\([["`\\]]\)/\\\1/g' +# Save mangling of backslash escaped dollars by the above. Running this +# substitution after double_quote_subst notices and corrects expansion +# of already escaped meta-chars. \$x -> double_quote_subst -> \\$x, +# which doesn't protect $x from expansion. To correct this we do: +# \\$x -> sed_double_backslash -> \\\$x, properly protecting $x. +sed_double_backslash='s/\([[^\\]]\)\\\\$/\1\\\\\\$/g' + # test EBCDIC or ASCII case `$ECHO A|tr A '\301'` in A) # EBCDIC based system @@ -256,20 +263,20 @@ func_mktempdir () # Aesthetically quote ARG to be evaled later. func_quote_for_eval () { - my_arg=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` - - case $my_arg in - # Double-quote args containing shell metacharacters to delay - # word splitting, command substitution and and variable - # expansion for a subsequent eval. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - *[[\@<:@\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]]*|*@:>@*|"") - my_arg="\"$my_arg\"" - ;; - esac - - func_quote_for_eval_result="$my_arg" + my_arg=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` + + case $my_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting, command substitution and and variable + # expansion for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[[\@<:@\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]]*|*@:>@*|"") + my_arg="\"$my_arg\"" + ;; + esac + + func_quote_for_eval_result="$my_arg" } @@ -278,17 +285,36 @@ func_quote_for_eval () # but do not quote variable references. func_quote_for_expand () { - my_arg=`$ECHO "X$1" | $Xsed -e "$double_quote_subst"` - - case $my_arg in - # Double-quote args containing shell metacharacters to delay - # word splitting and command substitution for a subsequent eval. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - *[[\@<:@\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]]*|*@:>@*|"") - my_arg="\"$my_arg\"" - ;; - esac - - func_quote_for_expand_result="$my_arg" + my_arg=`$ECHO "X$1" | $Xsed \ + -e "$double_quote_subst" -e "$sed_double_backslash"` + + case $my_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting and command substitution for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[[\@<:@\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]]*|*@:>@*|"") + my_arg="\"$my_arg\"" + ;; + esac + + func_quote_for_expand_result="$my_arg" +} + + +# func_show_eval cmd [fail_exp] +# Unless opt_silent is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. +func_show_eval () +{ + my_cmd="$1" + my_fail_exp="${2-:}" + + ${opt_silent-false} || { + func_quote_for_expand "$my_cmd" + eval "func_echo $func_quote_for_expand_result" + } + + ${opt_dry_run-false} || eval "$my_cmd" || eval "$my_fail_exp" }