Blame build/PrintPath

Packit 90a5c9
#!/bin/sh
Packit 90a5c9
#
Packit 90a5c9
# Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
# contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
# this work for additional information regarding copyright ownership.
Packit 90a5c9
# The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
# (the "License"); you may not use this file except in compliance with
Packit 90a5c9
# the License.  You may obtain a copy of the License at
Packit 90a5c9
#
Packit 90a5c9
#     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
#
Packit 90a5c9
# Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
# distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
# See the License for the specific language governing permissions and
Packit 90a5c9
# limitations under the License.
Packit 90a5c9
#
Packit 90a5c9
#
Packit 90a5c9
# Look for program[s] somewhere in $PATH.
Packit 90a5c9
#
Packit 90a5c9
# Options:
Packit 90a5c9
#  -s
Packit 90a5c9
#    Do not print out full pathname. (silent)
Packit 90a5c9
#  -pPATHNAME
Packit 90a5c9
#    Look in PATHNAME instead of $PATH
Packit 90a5c9
#
Packit 90a5c9
# Usage:
Packit 90a5c9
#  PrintPath [-s] [-pPATHNAME] program [program ...]
Packit 90a5c9
#
Packit 90a5c9
# Initially written by Jim Jagielski for the Apache configuration mechanism
Packit 90a5c9
#  (with kudos to Kernighan/Pike)
Packit 90a5c9
Packit 90a5c9
##
Packit 90a5c9
# Some "constants"
Packit 90a5c9
##
Packit 90a5c9
pathname=$PATH
Packit 90a5c9
echo="yes"
Packit 90a5c9
Packit 90a5c9
##
Packit 90a5c9
# Find out what OS we are running for later on
Packit 90a5c9
##
Packit 90a5c9
os=`(uname) 2>/dev/null`
Packit 90a5c9
Packit 90a5c9
##
Packit 90a5c9
# Parse command line
Packit 90a5c9
##
Packit 90a5c9
for args in $*
Packit 90a5c9
do
Packit 90a5c9
    case $args in
Packit 90a5c9
	-s  ) echo="no" ;;
Packit 90a5c9
	-p* ) pathname="`echo $args | sed 's/^..//'`" ;;
Packit 90a5c9
	*   ) programs="$programs $args" ;;
Packit 90a5c9
    esac
Packit 90a5c9
done
Packit 90a5c9
Packit 90a5c9
##
Packit 90a5c9
# Now we make the adjustments required for OS/2 and everyone
Packit 90a5c9
# else :)
Packit 90a5c9
#
Packit 90a5c9
# First of all, all OS/2 programs have the '.exe' extension.
Packit 90a5c9
# Next, we adjust PATH (or what was given to us as PATH) to
Packit 90a5c9
# be whitespace separated directories.
Packit 90a5c9
# Finally, we try to determine the best flag to use for
Packit 90a5c9
# test/[] to look for an executable file. OS/2 just has '-r'
Packit 90a5c9
# but with other OSs, we do some funny stuff to check to see
Packit 90a5c9
# if test/[] knows about -x, which is the prefered flag.
Packit 90a5c9
##
Packit 90a5c9
Packit 90a5c9
if [ "x$os" = "xOS/2" ]
Packit 90a5c9
then
Packit 90a5c9
    ext=".exe"
Packit 90a5c9
    pathname=`echo -E $pathname |
Packit 90a5c9
     sed 's/^;/.;/
Packit 90a5c9
	  s/;;/;.;/g
Packit 90a5c9
	  s/;$/;./
Packit 90a5c9
	  s/;/ /g
Packit 90a5c9
	  s/\\\\/\\//g' `
Packit 90a5c9
    test_exec_flag="-r"
Packit 90a5c9
else
Packit 90a5c9
    ext=""	# No default extensions
Packit 90a5c9
    pathname=`echo $pathname |
Packit 90a5c9
     sed 's/^:/.:/
Packit 90a5c9
	  s/::/:.:/g
Packit 90a5c9
	  s/:$/:./
Packit 90a5c9
	  s/:/ /g' `
Packit 90a5c9
    # Here is how we test to see if test/[] can handle -x
Packit 90a5c9
    testfile="pp.t.$$"
Packit 90a5c9
Packit 90a5c9
    cat > $testfile <
Packit 90a5c9
#!/bin/sh
Packit 90a5c9
if [ -x / ] || [ -x /bin ] || [ -x /bin/ls ]; then
Packit 90a5c9
    exit 0
Packit 90a5c9
fi
Packit 90a5c9
exit 1
Packit 90a5c9
ENDTEST
Packit 90a5c9
Packit 90a5c9
    if `/bin/sh $testfile 2>/dev/null`; then
Packit 90a5c9
	test_exec_flag="-x"
Packit 90a5c9
    else
Packit 90a5c9
	test_exec_flag="-r"
Packit 90a5c9
    fi
Packit 90a5c9
    rm -f $testfile
Packit 90a5c9
fi
Packit 90a5c9
Packit 90a5c9
for program in $programs
Packit 90a5c9
do
Packit 90a5c9
    for path in $pathname
Packit 90a5c9
    do
Packit 90a5c9
	if [ $test_exec_flag $path/${program}${ext} ] && \
Packit 90a5c9
	   [ ! -d $path/${program}${ext} ]; then
Packit 90a5c9
	    if [ "x$echo" = "xyes" ]; then
Packit 90a5c9
		echo $path/${program}${ext}
Packit 90a5c9
	    fi
Packit 90a5c9
	    exit 0
Packit 90a5c9
	fi
Packit 90a5c9
Packit 90a5c9
# Next try without extension (if one was used above)
Packit 90a5c9
	if [ "x$ext" != "x" ]; then
Packit 90a5c9
            if [ $test_exec_flag $path/${program} ] && \
Packit 90a5c9
               [ ! -d $path/${program} ]; then
Packit 90a5c9
                if [ "x$echo" = "xyes" ]; then
Packit 90a5c9
                    echo $path/${program}
Packit 90a5c9
                fi
Packit 90a5c9
                exit 0
Packit 90a5c9
            fi
Packit 90a5c9
        fi
Packit 90a5c9
    done
Packit 90a5c9
done
Packit 90a5c9
exit 1
Packit 90a5c9