Annotation of embedaddon/expat/conftools/PrintPath, revision 1.1
1.1 ! misho 1: #!/bin/sh
! 2: # Look for program[s] somewhere in $PATH.
! 3: #
! 4: # Options:
! 5: # -s
! 6: # Do not print out full pathname. (silent)
! 7: # -pPATHNAME
! 8: # Look in PATHNAME instead of $PATH
! 9: #
! 10: # Usage:
! 11: # PrintPath [-s] [-pPATHNAME] program [program ...]
! 12: #
! 13: # Initially written by Jim Jagielski for the Apache configuration mechanism
! 14: # (with kudos to Kernighan/Pike)
! 15: #
! 16: # This script falls under the Apache License.
! 17: # See http://www.apache.org/licenses/LICENSE
! 18:
! 19: ##
! 20: # Some "constants"
! 21: ##
! 22: pathname=$PATH
! 23: echo="yes"
! 24:
! 25: ##
! 26: # Find out what OS we are running for later on
! 27: ##
! 28: os=`(uname) 2>/dev/null`
! 29:
! 30: ##
! 31: # Parse command line
! 32: ##
! 33: for args in $*
! 34: do
! 35: case $args in
! 36: -s ) echo="no" ;;
! 37: -p* ) pathname="`echo $args | sed 's/^..//'`" ;;
! 38: * ) programs="$programs $args" ;;
! 39: esac
! 40: done
! 41:
! 42: ##
! 43: # Now we make the adjustments required for OS/2 and everyone
! 44: # else :)
! 45: #
! 46: # First of all, all OS/2 programs have the '.exe' extension.
! 47: # Next, we adjust PATH (or what was given to us as PATH) to
! 48: # be whitespace separated directories.
! 49: # Finally, we try to determine the best flag to use for
! 50: # test/[] to look for an executable file. OS/2 just has '-r'
! 51: # but with other OSs, we do some funny stuff to check to see
! 52: # if test/[] knows about -x, which is the preferred flag.
! 53: ##
! 54:
! 55: if [ "x$os" = "xOS/2" ]
! 56: then
! 57: ext=".exe"
! 58: pathname=`echo -E $pathname |
! 59: sed 's/^;/.;/
! 60: s/;;/;.;/g
! 61: s/;$/;./
! 62: s/;/ /g
! 63: s/\\\\/\\//g' `
! 64: test_exec_flag="-r"
! 65: else
! 66: ext="" # No default extensions
! 67: pathname=`echo $pathname |
! 68: sed 's/^:/.:/
! 69: s/::/:.:/g
! 70: s/:$/:./
! 71: s/:/ /g' `
! 72: # Here is how we test to see if test/[] can handle -x
! 73: testfile="pp.t.$$"
! 74:
! 75: cat > $testfile <<ENDTEST
! 76: #!/bin/sh
! 77: if [ -x / ] || [ -x /bin ] || [ -x /bin/ls ]; then
! 78: exit 0
! 79: fi
! 80: exit 1
! 81: ENDTEST
! 82:
! 83: if `/bin/sh $testfile 2>/dev/null`; then
! 84: test_exec_flag="-x"
! 85: else
! 86: test_exec_flag="-r"
! 87: fi
! 88: rm -f $testfile
! 89: fi
! 90:
! 91: for program in $programs
! 92: do
! 93: for path in $pathname
! 94: do
! 95: if [ $test_exec_flag $path/${program}${ext} ] && \
! 96: [ ! -d $path/${program}${ext} ]; then
! 97: if [ "x$echo" = "xyes" ]; then
! 98: echo $path/${program}${ext}
! 99: fi
! 100: exit 0
! 101: fi
! 102:
! 103: # Next try without extension (if one was used above)
! 104: if [ "x$ext" != "x" ]; then
! 105: if [ $test_exec_flag $path/${program} ] && \
! 106: [ ! -d $path/${program} ]; then
! 107: if [ "x$echo" = "xyes" ]; then
! 108: echo $path/${program}
! 109: fi
! 110: exit 0
! 111: fi
! 112: fi
! 113: done
! 114: done
! 115: exit 1
! 116:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>