From b7d3dc2fa389706bde066219b11d3b66832cfa9e Mon Sep 17 00:00:00 2001 From: simonb Date: Thu, 10 Mar 2005 13:53:26 +0000 Subject: fix 'which' program compatibility. Test the capabilities of the one we find, rather than guessing based on the system type --- util/fbsetbg | 42 ++++++++++----------- util/fluxbox-generate_menu.in | 87 +++++++++++++++++++------------------------ 2 files changed, 59 insertions(+), 70 deletions(-) diff --git a/util/fbsetbg b/util/fbsetbg index 3db53da..a75f461 100644 --- a/util/fbsetbg +++ b/util/fbsetbg @@ -130,28 +130,28 @@ Common tips to use with $command: EOF } -# ugly code for solaris compat. -case `uname` in - Linux|*BSD) - find_it() { - which $1 > /dev/null 2>&1 && shift && $* - } - ;; - *) - find_it() { - file=`which $1 2> /dev/null` - if [ -x "$file" ]; then - if [ $# -gt 1 ]; then - shift - $* - fi - return 0 - else - return 1 +# some which's have a reliable return code, some don't +# Lets figure out which which we have. +if which this_program_does_not_exist-no_really-aA1zZ9 >/dev/null 2>/dev/null; then + # can't rely on return value + find_it() { + file=`which $1 2> /dev/null` + if [ -x "$file" ]; then + if [ $# -gt 1 ]; then + shift + $* fi - } - ;; -esac + return 0 + else + return 1 + fi + } +else + # can rely on return value + find_it() { + which $1 > /dev/null 2>&1 && shift && $* + } +fi message() { diff --git a/util/fluxbox-generate_menu.in b/util/fluxbox-generate_menu.in index 5a38247..d77b44b 100755 --- a/util/fluxbox-generate_menu.in +++ b/util/fluxbox-generate_menu.in @@ -123,59 +123,48 @@ fluxbox-generate_menu was brought to you by: EOF } -# ugly code for solaris compat. -UNAME=`uname` -# echo "UNAME=$UNAME" -case "$UNAME" in - Linux|*BSD) - find_it() { - which $1 > /dev/null 2>&1 && shift && $* - } - - find_it_options() { - which $1 > /dev/null 2>&1 - } - ;; - *) - find_it() { - file=`which $1 2> /dev/null` - if [ -x "$file" ]; then - if [ $# -gt 1 ]; then - shift - $* - fi - return 0 - else - return 1 +# some which's have a reliable return code, some don't +# Lets figure out which which we have. +if which this_program_does_not_exist-no_really-aA1zZ9 >/dev/null 2>/dev/null; then + # can't rely on return value + find_it() { + file=`which $1 2> /dev/null` + if [ -x "$file" ]; then + if [ $# -gt 1 ]; then + shift + $* fi - } + return 0 + else + return 1 + fi + } - find_it_options() { - file=`which $1 2> /dev/null` - if [ -x "$file" ]; then - return 0 - else - return 1 - fi - } + find_it_options() { + file=`which $1 2> /dev/null` + if [ -x "$file" ]; then + return 0 + else + return 1 + fi + } - ;; -esac +else + # can rely on return value + find_it() { + which $1 > /dev/null 2>&1 && shift && $* + } -case "$UNAME" in - Linux) - replaceWithinString(){ - #echo "replaceWithinString: $1, $2, $3" >&2 - #echo ${1//$2/$3} # causes error in BSD even though not used - echo $1 | awk "{ gsub(/$2/, \"$3\"); print }" - } - ;; - *BSD) - replaceWithinString(){ - echo $1 | awk "{ gsub(/$2/, \"$3\"); print }" - } - ;; -esac + find_it_options() { + which $1 > /dev/null 2>&1 + } +fi + +#echo "replaceWithinString: $1, $2, $3" >&2 +#echo ${1//$2/$3} # causes error in BSD even though not used +replaceWithinString(){ + echo $1 | awk "{ gsub(/$2/, \"$3\"); print }" +} convertIcon(){ if [ ! -f "$1" ] ; then -- cgit v0.11.2