+2004-10-20 Gary V. Vaughan <gary@gnu.org>
+
+ * 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 <noah@cs.caltech.edu>,
Gary V. Vaughan <gary@gnu.org>
* 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.
# 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
# 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"
}
# 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"
}