Check-in Number:
|
21 | |
Date: |
2000-Jun-13 20:39:01 (local)
2000-Jun-13 18:39:01 (UTC) |
User: | rse |
Branch: | |
Comment: |
*** empty log message *** |
Tickets: |
|
Inspections: |
|
Files: |
|
ossp-pkg/shtool/sh.path -> 1.13
*** /dev/null Sat Nov 23 02:10:02 2024
--- - Sat Nov 23 02:10:02 2024
***************
*** 0 ****
--- 1,169 ----
+ ##
+ ## path -- Deal with program paths
+ ## Copyright (c) 1998-2000 Ralf S. Engelschall <rse@engelschall.com>
+ ## Originally written for Apache
+ ##
+ ## This file is part of shtool and free software; you can redistribute
+ ## it and/or modify it under the terms of the GNU General Public
+ ## License as published by the Free Software Foundation; either version
+ ## 2 of the License, or (at your option) any later version.
+ ##
+ ## This file is distributed in the hope that it will be useful,
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ## General Public License for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License
+ ## along with this program; if not, write to the Free Software
+ ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ ## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
+ ##
+
+ str_tool="path"
+ str_usage="[-s] [-r] [-d] [-b] [-m] [-p<path>] <str> [<str> ...]"
+ gen_tmpfile=yes
+ arg_spec="1+"
+ opt_spec="s.r.d.b.m.p:"
+ opt_s=no
+ opt_r=no
+ opt_d=no
+ opt_b=no
+ opt_m=no
+ opt_p="$PATH"
+
+ . ./sh.common
+
+ namelist="$*"
+
+ # check whether the test command supports the -x option
+ if [ -x /bin/sh ] 2>/dev/null; then
+ minusx="-x"
+ else
+ minusx="-r"
+ fi
+
+ # split path string
+ paths="`echo $opt_p |\
+ sed -e 's/^:/.:/' \
+ -e 's/::/:.:/g' \
+ -e 's/:$/:./' \
+ -e 's/:/ /g'`"
+
+ # SPECIAL REQUEST
+ # translate forward to reverse path
+ if [ ".$opt_r" = .yes ]; then
+ if [ "x$namelist" = "x." ]; then
+ rp='.'
+ else
+ rp=''
+ for pe in `IFS="$IFS/"; echo $namelist`; do
+ rp="../$rp"
+ done
+ fi
+ echo $rp | sed -e 's:/$::'
+ exit 0
+ fi
+
+ # SPECIAL REQUEST
+ # strip out directory or base name
+ if [ ".$opt_d" = .yes ]; then
+ echo "$namelist" |\
+ sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
+ exit 0
+ fi
+ if [ ".$opt_b" = .yes ]; then
+ echo "$namelist" |\
+ sed -e 's;.*/\([^/]*\)$;\1;'
+ exit 0
+ fi
+
+ # MAGIC SITUATION
+ # Perl Interpreter (perl)
+ if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then
+ rm -f $tmpfile
+ touch $tmpfile
+ c=0
+ found=0
+ for dir in $paths; do
+ dir=`echo $dir | sed -e 's;/*$;;'`
+ for perl in perl5 perl miniperl; do
+ if [ $minusx "$dir/$perl" ] && [ ! -d "$dir/$perl" ]; then
+ perl="$dir/$perl"
+ version=`$perl -v | grep version |\
+ sed -e 's/.* version //' -e 's/ built.*//' -e 's/ with.*//'`
+ versionnum="`echo $version | sed -e 's/\.//g' -e 's/_//g'`"
+ versionnum=`expr $versionnum - $c`
+ echo "$versionnum $perl" >>$tmpfile
+ found=1
+ fi
+ done
+ c=`expr $c + 1`
+ done
+ if [ $found = 1 ]; then
+ perl="`cat $tmpfile | sort -u | tail -1 | cut '-d ' -f2`"
+ rm -f $tmpfile
+ echo "$perl"
+ exit 0
+ fi
+ exit 1
+ fi
+
+ # MAGIC SITUATION
+ # C pre-processor (cpp)
+ if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then
+ cat >$tmpfile.c <<'EOT'
+ #include <assert.h>
+ Syntax Error
+ EOT
+ # 1. try the standard cc -E approach
+ cpp="${CC-cc} -E"
+ (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
+ my_error=`grep -v '^ *+' $tmpfile.out`
+ if [ ".$my_error" != . ]; then
+ # 2. try the cc -E approach and GCC's -traditional-ccp option
+ cpp="${CC-cc} -E -traditional-cpp"
+ (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
+ my_error=`grep -v '^ *+' $tmpfile.out`
+ if [ ".$my_error" != . ]; then
+ # 3. try a standalone cpp command in path and lib dirs
+ for path in $paths /lib /usr/lib /usr/local/lib; do
+ path=`echo $path | sed -e 's;/*$;;'`
+ if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
+ cpp="$path/cpp"
+ break
+ fi
+ done
+ if [ ".$cpp" != . ]; then
+ (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
+ my_error=`grep -v '^ *+' $tmpfile.out`
+ if [ ".$my_error" != . ]; then
+ # ok, we gave up...
+ cpp=''
+ fi
+ fi
+ fi
+ fi
+ rm -f $tmpfile.c $tmpfile.out
+ if [ ".$cpp" != . ]; then
+ echo "$cpp"
+ exit 0
+ fi
+ exit 1
+ fi
+
+ # STANDARD SITUATION
+ # iterate over names
+ for name in $namelist; do
+ # iterate over paths
+ for path in $paths; do
+ path=`echo $path | sed -e 's;/*$;;'`
+ if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
+ if [ ".$opt_s" != .yes ]; then
+ echo "$path/$name" 2>&1
+ fi
+ exit 0
+ fi
+ done
+ done
+ exit 1
+
|
|