summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/isolated-functions.sh99
1 files changed, 37 insertions, 62 deletions
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 860bc5890..07e7ad67e 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -1,4 +1,4 @@
-# Copyright 1999-2004 Gentoo Technologies, Inc.
+# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header$
@@ -29,15 +29,15 @@ elog() {
esyslog() {
local pri=
local tag=
-
+
if [ -x /usr/bin/logger ]
then
pri="$1"
tag="$2"
-
+
shift 2
[ -z "$*" ] && return 0
-
+
/usr/bin/logger -p "${pri}" -t "${tag}" -- "$*"
fi
@@ -83,7 +83,7 @@ eend() {
echo -e "${ENDCOL} ${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
else
retval="$1"
-
+
if [ "$#" -ge 2 ]
then
shift
@@ -98,107 +98,82 @@ eend() {
}
KV_major() {
- local KV=
-
- [ -z "$1" ] && return 1
-
- KV="$(echo "$1" | \
- awk '{ tmp = $0; gsub(/^[0-9\.]*/, "", tmp); sub(tmp, ""); print }')"
- echo "${KV}" | awk -- 'BEGIN { FS = "." } { print $1 }'
+ [[ -z $1 ]] && return 1
- return 0
+ local KV=$@
+ echo "${KV%%.*}"
}
KV_minor() {
- local KV=
-
- [ -z "$1" ] && return 1
+ [[ -z $1 ]] && return 1
- KV="$(echo "$1" | \
- awk '{ tmp = $0; gsub(/^[0-9\.]*/, "", tmp); sub(tmp, ""); print }')"
- echo "${KV}" | awk -- 'BEGIN { FS = "." } { print $2 }'
-
- return 0
+ local KV=$@
+ KV=${KV#*.}
+ echo "${KV%%.*}"
}
KV_micro() {
- local KV=
-
- [ -z "$1" ] && return 1
-
- KV="$(echo "$1" | \
- awk '{ tmp = $0; gsub(/^[0-9\.]*/, "", tmp); sub(tmp, ""); print }')"
- echo "${KV}" | awk -- 'BEGIN { FS = "." } { print $3 }'
+ [[ -z $1 ]] && return 1
- return 0
+ local KV=$@
+ KV=${KV#*.*.}
+ echo "${KV%%[^[:digit:]]*}"
}
KV_to_int() {
- local KV_MAJOR=
- local KV_MINOR=
- local KV_MICRO=
- local KV_int=
-
- [ -z "$1" ] && return 1
-
- KV_MAJOR="$(KV_major "$1")"
- KV_MINOR="$(KV_minor "$1")"
- KV_MICRO="$(KV_micro "$1")"
- KV_int="$((KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO))"
-
+ [[ -z $1 ]] && return 1
+
+ local KV_MAJOR=$(KV_major "$1")
+ local KV_MINOR=$(KV_minor "$1")
+ local KV_MICRO=$(KV_micro "$1")
+ local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
+
# We make version 2.2.0 the minimum version we will handle as
# a sanity check ... if its less, we fail ...
- if [ "${KV_int}" -ge 131584 ]
- then
+ if [[ ${KV_int} -ge 131584 ]] ; then
echo "${KV_int}"
-
return 0
fi
return 1
-}
+}
+_RC_GET_KV_CACHE=""
get_KV() {
- local KV="$(uname -r)"
+ [[ -z ${_RC_GET_KV_CACHE} ]] \
+ && _RC_GET_KV_CACHE=$(uname -r)
- echo "$(KV_to_int "${KV}")"
+ echo $(KV_to_int "${_RC_GET_KV_CACHE}")
return $?
}
-getcols() {
- echo "$2"
-}
-
unset_colors() {
COLS="25 80"
ENDCOL=
-
+
GOOD=
WARN=
BAD=
NORMAL=
HILITE=
BRACKET=
-
- if [ -n "${EBUILD}" ] && [ "${*/depend}" = "$*" ]; then
- stty cols 80 &>/dev/null
- stty rows 25 &>/dev/null
- fi
}
set_colors() {
- COLS="`stty size 2> /dev/null`"
- COLS="`getcols ${COLS}`"
- COLS=$((${COLS} - 7))
+ COLS=${COLUMNS:-0} # bash's internal COLUMNS variable
+ (( COLS == 0 )) && COLS=$(set -- `stty size 2>/dev/null` ; echo $2)
+ (( COLS > 0 )) || (( COLS = 80 ))
+ COLS=$((${COLS} - 7)) # width of [ ok ] == 7
+
ENDCOL=$'\e[A\e['${COLS}'G' # Now, ${ENDCOL} will move us to the end of the
# column; irregardless of character width
-
+
GOOD=$'\e[32;01m'
WARN=$'\e[33;01m'
BAD=$'\e[31;01m'
- NORMAL=$'\e[0m'
HILITE=$'\e[36;01m'
BRACKET=$'\e[34;01m'
+ NORMAL=$'\e[0m'
}
true