ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/2] ant git commit: latest iteration of Jeff Adamson's script fixes
Date Wed, 26 Oct 2016 13:44:35 GMT
Repository: ant
Updated Branches:
  refs/heads/master fea1cfe23 -> d48317a4b


latest iteration of Jeff Adamson's script fixes

known to not completely break in Solaris


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/61e1cccf
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/61e1cccf
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/61e1cccf

Branch: refs/heads/master
Commit: 61e1cccf303dd7b1c42026e9544c3733031a3249
Parents: c385fc6
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Wed Oct 26 15:43:10 2016 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Wed Oct 26 15:43:10 2016 +0200

----------------------------------------------------------------------
 src/script/ant | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/61e1cccf/src/script/ant
----------------------------------------------------------------------
diff --git a/src/script/ant b/src/script/ant
index 8cc8f8e..0f83e18 100644
--- a/src/script/ant
+++ b/src/script/ant
@@ -24,6 +24,15 @@ show_help=false
 
 esc_tool=sed
 
+# if awk esc_tool is chosen, use nawk when available
+if [ "$esc_tool" = "awk" ]
+then
+  awk_exec=awk
+  # Solaris_awk does not support gsub, but Solaris_nawk does
+  # `command -v` behavior is part of posix spec
+  command -v nawk >/dev/null && awk_exec=nawk
+fi
+
 for arg in "$@" ; do
   if [ "$arg" = "--noconfig" ] ; then
     no_config=true
@@ -40,19 +49,21 @@ for arg in "$@" ; do
     fi
 
     # wrap all arguments as "" strings, escape any internal back-slash, double-quote, $,
or back-tick characters
-    #  use printf to avoid echo modification behaviors such as escape and line continuation
-    #  pad the value with leading/trailing X to protect trailing newlines and whitespace
from awk and sed
+    #  use printf to avoid echo interpretation behaviors such as escapes and line continuation
+    #  pad the value with leading/trailing X to protect whitespace
     esc_arg="X${arg}X"
     case "$esc_tool" in
       'sed')
-        #  mac sed does not support group-0, so pattern uses group-1
-        esc_arg="$(printf '%s' "$esc_arg" | sed -e 's@\([$"\\`]\)@\\\1@g')"
+        # Mac bsd_sed does not support group-0, so pattern uses group-1
+        # Solaris sed only proceses lines with trailing newline, passing in an extra newline
+        # sed will consume the trailing newline
+        esc_arg="$(printf '%s\n' "$esc_arg" | sed -e 's@\([$"\\`]\)@\\\1@g')"
         ;;
       'awk')
-        esc_arg="$(printf '%s' "$esc_arg" | awk '{ gsub(/\\/, "\\\\"); print }' )"
-        esc_arg="$(printf '%s' "$esc_arg" | awk '{ gsub(/\$/, "\\$");  print }' )"
-        esc_arg="$(printf '%s' "$esc_arg" | awk '{ gsub(/\"/, "\\\""); print }' )"
-        esc_arg="$(printf '%s' "$esc_arg" | awk '{ gsub(/`/,  "\\`");  print }' )"
+        esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\\/, "\\\\"); print }' )"
+        esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\$/, "\\$");  print }' )"
+        esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\"/, "\\\""); print }' )"
+        esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/`/,  "\\`");  print }' )"
         ;;
 #      'bash')
 #        # does not depend upon `sed` or `echo` quirks


Mime
View raw message