[oe-commits] Chris Larson : bin/{cp,sed}: simplify, consolidate

git version control git at git.openembedded.org
Thu Nov 4 18:27:03 UTC 2010


Module: openembedded.git
Branch: master
Commit: c35b4a0846ea9867ed1eeea94a465019a22b6b6c
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=c35b4a0846ea9867ed1eeea94a465019a22b6b6c

Author: Chris Larson <chris_larson at mentor.com>
Date:   Thu Nov  4 11:21:38 2010 -0700

bin/{cp,sed}: simplify, consolidate

Signed-off-by: Chris Larson <chris_larson at mentor.com>

---

 bin/cp         |   37 ++-----------------------------------
 bin/sed        |   43 ++++---------------------------------------
 bin/wrapper.sh |   29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 74 deletions(-)

diff --git a/bin/cp b/bin/cp
index 81fdbe8..0a523b7 100755
--- a/bin/cp
+++ b/bin/cp
@@ -6,40 +6,8 @@
 # - We allow -a as shorthand for -RpP
 # - Otherwise, we stick to what SuSv3 defines
 
-realbin() {
-     _script=`basename $0`
-     found=
-     for bin in `which -a $_script`; do
-          if ! cmp -s $bin $0; then
-                found=$bin
-                break
-          fi
-     done
-     if [ -n "$found" ]; then
-          echo "$found"
-     else
-          return 1
-     fi
-}
 
-quote(){
-    /usr/bin/sed -e "s,','\\\\'',g; 1s,^,',; \$s,\$,',;" << EOF
-$1
-EOF
-}
-
-save () {
-    case "$1" in
-    # when a string contains a "'" we have to escape it
-    *\'*)
-        saved="$saved `quote "$1"`"
-        ;;
-    # otherwise just quote the variable
-    *)
-        saved="$saved '$1'"
-        ;;
-    esac
-}
+source $(dirname $0)/wrapper.sh
 
 saved=""
 while getopts fpaRHLP opt; do
@@ -58,5 +26,4 @@ for arg; do
     save "$arg"
 done
 
-eval set -- "$saved"
-exec `realbin` "$@"
+exec_real
diff --git a/bin/sed b/bin/sed
index 520c5bd..2200bd1 100755
--- a/bin/sed
+++ b/bin/sed
@@ -21,40 +21,7 @@
 # to reimplement -i internally in this script on some platforms.
 
 
-realbin() {
-     _script=`basename $0`
-     found=
-     for bin in `which -a $_script`; do
-          if ! cmp -s $bin $0; then
-                found=$bin
-                break
-          fi
-     done
-     if [ -n "$found" ]; then
-          echo "$found"
-     else
-          return 1
-     fi
-}
-
-quote(){
-    /usr/bin/sed -e "s,','\\\\'',g; 1s,^,',; \$s,\$,',;" << EOF
-$1
-EOF
-}
-
-save () {
-    case "$1" in
-    # when a string contains a "'" we have to escape it
-    *\'*)
-        saved="$saved `quote "$1"`"
-        ;;
-    # otherwise just quote the variable
-    *)
-        saved="$saved '$1'"
-        ;;
-    esac
-}
+source $(dirname $0)/wrapper.sh
 
 case `uname -s` in
     Darwin)
@@ -80,15 +47,14 @@ while getopts ne:f:$getopt_os opt; do
             save "$OPTARG"
             ;;
         i)
-            saved="$saved $inplace_arg"
+            save "$inplace_arg"
             continue
             ;;
         r)
-            saved="$saved $extended_re_arg"
+            save "$extended_re_arg"
             continue
             ;;
         \?)
-            echo >&2 "Unsupported argument: $OPTARG"
             exit 1
             ;;
     esac
@@ -98,5 +64,4 @@ for arg; do
     save "$arg"
 done
 
-eval set -- "$saved"
-exec `realbin` "$@"
+exec_real
diff --git a/bin/wrapper.sh b/bin/wrapper.sh
new file mode 100644
index 0000000..3a93475
--- /dev/null
+++ b/bin/wrapper.sh
@@ -0,0 +1,29 @@
+path_remove () {
+    echo $PATH | tr ':' '\n' | grep -v "^$1\$" | tr '\n' ':'
+}
+
+quote(){
+    sed -e "s,','\\\\'',g; 1s,^,',; \$s,\$,',;" << EOF
+$1
+EOF
+}
+
+save () {
+    case "$1" in
+    # when a string contains a "'" we have to escape it
+    *\'*)
+        saved="$saved $(quote "$1")"
+        ;;
+    # otherwise just quote the variable
+    *)
+        saved="$saved '$1'"
+        ;;
+    esac
+}
+
+exec_real () {
+    eval set -- "$saved"
+    scriptdir="$(dirname $0)"
+    PATH="$(path_remove $scriptdir)"
+    exec "$(basename $0)" "$@"
+}





More information about the Openembedded-commits mailing list