]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
* config/general.m4sh (sed_double_backslash): New sed expression
authorGary V. Vaughan <gary@gnu.org>
Wed, 20 Oct 2004 20:50:53 +0000 (20:50 +0000)
committerGary V. Vaughan <gary@gnu.org>
Wed, 20 Oct 2004 20:50:53 +0000 (20:50 +0000)
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.

ChangeLog
config/general.m4sh

index b5a21fe5d48a83b686ed63a99e2990ee3739c9e2..64036ce94a96fc8f89d809325d32b4d60ef54416 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,19 @@
+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.
index d03da0dbd3232b0418fc215f2bd9c41dd718613b..efecf7cd6016e0a7050ba30db4badce5bc9e474d 100644 (file)
@@ -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"
 }