From 659eafddd5964820ce8bdc0d90f5fcf7df04b5b7 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 16 Mar 2006 04:18:53 +0000 Subject: cleanup bash code in use*() and has*() functions with the help of agriffis svn path=/main/trunk/; revision=2903 --- bin/ebuild.sh | 56 +++++++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/bin/ebuild.sh b/bin/ebuild.sh index 26bd235e8..3f3e14343 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -103,10 +103,7 @@ esyslog() { use() { - if useq ${1}; then - return 0 - fi - return 1 + useq ${1} } usev() { @@ -118,64 +115,41 @@ usev() { } useq() { - local u="${1}" - local neg=0 - if [ "${u:0:1}" == "!" ]; then - u="${u:1}" - neg=1 + local u=$1 + local found=0 + + # if we got something like '!flag', then invert the return value + if [[ ${u:0:1} == "!" ]] ; then + u=${u:1} + found=1 fi - local x # Make sure we have this USE flag in IUSE if ! hasq "${u}" ${IUSE} ${E_IUSE} && ! hasq "${u}" ${PORTAGE_ARCHLIST} selinux; then echo "QA Notice: USE Flag '${u}' not in IUSE for ${CATEGORY}/${PF}" >&2 fi - for x in ${USE}; do - if [ "${x}" == "${u}" ]; then - if [ ${neg} -eq 1 ]; then - return 1 - else - return 0 - fi - fi - done - if [ ${neg} -eq 1 ]; then - return 0 + if [[ " ${USE} " == *" ${u} "* ]] ; then + return ${found} else - return 1 + return $((!found)) fi } has() { - if hasq "$@"; then - return 0 - fi - return 1 + hasq "$@" } hasv() { - if hasq "$@"; then - echo "${1}" + if hasq "$@" ; then + echo "$1" return 0 fi return 1 } hasq() { - local x - - local me=$1 - shift - - # All the TTY checks really only help out depend. Which is nice. - # Logging kills all this anyway. Everything becomes a pipe. --NJ - for x in "$@"; do - if [ "${x}" == "${me}" ]; then - return 0 - fi - done - return 1 + [[ " ${*:2} " == *" $1 "* ]] } has_version() { -- cgit v1.2.3-1-g7c22