From 5f2dff725a923d353222d20cbb9965db7561f6ca Mon Sep 17 00:00:00 2001 From: Josef 'Jeff' Sipek Date: Sun, 10 Jul 2011 17:03:18 -0400 Subject: [PATCH] wrapper for os-independent seq command Signed-off-by: Josef 'Jeff' Sipek --- os.Darwin | 22 ++++++++++++++++++++++ os.Linux | 6 ++++++ regression/scaffold | 26 -------------------------- regression/t-020.sh | 2 +- regression/t-021.sh | 2 +- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/os.Darwin b/os.Darwin index e2cfdcc..470f5fb 100644 --- a/os.Darwin +++ b/os.Darwin @@ -41,3 +41,25 @@ _tac() { sed -e '1!G;h;$!d' } + +_seq() +{ + ( + if [ $# -eq 1 ] + then + /usr/bin/jot $1 + elif [ $# -eq 2 ] + then + n1=$((${2} - ${1} + 1)) + n2=$1 + /usr/bin/jot $n1 $n2 + elif [ $# -eq 3 ] + then + num1=$1 + incr=$2 + num2=$3 + /usr/bin/awk -v n1=$num1 -v n2=$num2 -v add=$incr 'BEGIN{ for(i=n1; i<=n2; i+=add) print i;}' | /usr/bin/sed -E '/e/s/^.+e.+$/0/' + fi + ) + return 0 +} diff --git a/os.Linux b/os.Linux index 0f18045..30b9cb0 100644 --- a/os.Linux +++ b/os.Linux @@ -44,3 +44,9 @@ _tac() { tac } + +_seq() +{ + seq "$@" + return $? +} diff --git a/regression/scaffold b/regression/scaffold index cbbe700..8769058 100644 --- a/regression/scaffold +++ b/regression/scaffold @@ -129,29 +129,3 @@ function setup_repo setup_git_repo setup_guilt_repo } - -function seq() { - if [ $UNAME_S = "Linux" ] - then - `which seq` "$@" - return $? - fi - declare incr n1 n2 num1 num2 - if [[ $# -eq 1 ]] - then - /usr/bin/jot $1 - elif [[ $# -eq 2 ]] - then - n1=$((${2} - ${1} + 1)) - n2=$1 - /usr/bin/jot $n1 $n2 - elif [[ $# -eq 3 ]] - then - num1=${1} - incr=${2} - num2=${3} - # /usr/bin/awk -v n1=${num1} -v n2=${num2} -v add=${incr} 'BEGIN{ for(i=n1; i<=n2; i+=add) print i;}' | /usr/bin/sed 's/.+e.+/0/' - /usr/bin/awk -v n1=${num1} -v n2=${num2} -v add=${incr} 'BEGIN{ for(i=n1; i<=n2; i+=add) print i;}' | /usr/bin/sed -E '/e/s/^.+e.+$/0/' - fi - return 0 -} diff --git a/regression/t-020.sh b/regression/t-020.sh index 761b270..005d4dd 100755 --- a/regression/t-020.sh +++ b/regression/t-020.sh @@ -53,7 +53,7 @@ done cmd guilt-pop --all npatches=`guilt-series | wc -l` -for n in `seq -2 $npatches`; do +for n in `_seq -2 $npatches`; do if [ $n -ge 0 ]; then cmd guilt-push -n $n else diff --git a/regression/t-021.sh b/regression/t-021.sh index 6df9701..8f6eaf9 100755 --- a/regression/t-021.sh +++ b/regression/t-021.sh @@ -57,7 +57,7 @@ done cmd guilt-push --all npatches=`guilt-series | wc -l` -for n in `seq -2 $npatches`; do +for n in `_seq -2 $npatches`; do if [ $n -gt 0 ]; then cmd guilt-pop -n $n else -- 2.11.4.GIT