head 1.31; access; symbols SHTOOL_2_0_8:1.31 SHTOOL_2_0_7:1.30 SHTOOL_2_0_6:1.29 SHTOOL_2_0_5:1.29 SHTOOL_2_0_4:1.29 SHTOOL_2_0_3:1.28 SHTOOL_2_0_2:1.28 SHTOOL_2_0_1:1.27 SHTOOL_2_0_0:1.27 SHTOOL_2_0b3:1.27 SHTOOL_2_0b2:1.27 SHTOOL_2_0b1:1.27 SHTOOL_1_6:1.22.0.2 SHTOOL_1_6_2:1.22 SHTOOL_1_6_1:1.22 SHTOOL_1_6_0:1.21 SHTOOL_1_5:1.18.0.2 SHTOOL_1_5_4:1.18 SHTOOL_1_5_3:1.18 SHTOOL_1_5_2:1.18 SHTOOL_1_5_1:1.16 SHTOOL_1_5_0:1.16 SHTOOL_1_4_9:1.12 SHTOOL_1_4_8:1.11 SHTOOL_1_4_7:1.9 SHTOOL_1_4_6:1.8 SHTOOL_1_4_5:1.8 SHTOOL_1_4_4:1.8 SHTOOL_1_4_3:1.8 SHTOOL_1_4_2:1.7 SHTOOL_1_4_1:1.7 SHTOOL_1_4_0:1.7 SHTOOL_1_3_3:1.7 SHTOOL_1_3_2:1.7 SHTOOL_1_3_1:1.6 SHTOOL_1_3_0:1.6 SHTOOL_1_2_9:1.4 SHTOOL_1_2_8:1.4 SHTOOL_1_2_7:1.4 SHTOOL_1_2_6:1.4 SHTOOL_1_2_5:1.4 SHTOOL_1_2_4:1.3 SHTOOL_1_2_3:1.3 SHTOOL_1_2_2:1.2 SHTOOL_1_2_1:1.1.1.1 SHTOOL_1_2_0:1.1.1.1 SHTOOL_1_1_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @# @; 1.31 date 2008.04.02.20.13.44; author rse; state Exp; branches; next 1.30; commitid eB5Wirx8MdMyDzXs; 1.30 date 2007.05.19.19.09.39; author rse; state Exp; branches; next 1.29; commitid OPUF1UBbllBTwzis; 1.29 date 2006.02.04.09.43.25; author rse; state Exp; branches; next 1.28; commitid oWk7BmnyAitJtfkr; 1.28 date 2005.06.15.08.14.35; author rse; state Exp; branches; next 1.27; 1.27 date 2004.02.12.16.06.27; author rse; state Exp; branches; next 1.26; 1.26 date 2004.01.01.16.54.20; author rse; state Exp; branches; next 1.25; 1.25 date 2003.08.13.14.20.34; author rse; state Exp; branches; next 1.24; 1.24 date 2003.02.11.13.00.50; author rse; state Exp; branches; next 1.23; 1.23 date 2003.02.11.12.56.40; author rse; state Exp; branches; next 1.22; 1.22 date 2002.02.23.09.18.03; author rse; state Exp; branches; next 1.21; 1.21 date 2001.12.31.15.06.04; author rse; state Exp; branches; next 1.20; 1.20 date 2001.09.23.10.58.10; author rse; state Exp; branches; next 1.19; 1.19 date 2001.08.04.15.43.22; author rse; state Exp; branches; next 1.18; 1.18 date 2001.01.17.09.55.11; author rse; state Exp; branches; next 1.17; 1.17 date 2000.11.29.19.58.58; author rse; state Exp; branches; next 1.16; 1.16 date 2000.06.30.16.39.07; author rse; state Exp; branches; next 1.15; 1.15 date 2000.06.30.16.25.34; author rse; state Exp; branches; next 1.14; 1.14 date 2000.06.18.10.48.38; author rse; state Exp; branches; next 1.13; 1.13 date 2000.06.14.18.39.01; author rse; state Exp; branches; next 1.12; 1.12 date 2000.03.24.15.22.51; author rse; state Exp; branches; next 1.11; 1.11 date 2000.03.12.13.28.24; author rse; state Exp; branches; next 1.10; 1.10 date 2000.03.12.11.12.21; author rse; state Exp; branches; next 1.9; 1.9 date 99.12.24.15.11.23; author rse; state Exp; branches; next 1.8; 1.8 date 99.07.11.09.45.42; author rse; state Exp; branches; next 1.7; 1.7 date 99.06.28.15.18.44; author rse; state Exp; branches; next 1.6; 1.6 date 99.06.12.14.46.37; author rse; state Exp; branches; next 1.5; 1.5 date 99.06.12.14.08.49; author rse; state Exp; branches; next 1.4; 1.4 date 99.05.12.15.41.41; author rse; state Exp; branches; next 1.3; 1.3 date 99.05.06.11.10.02; author rse; state Exp; branches; next 1.2; 1.2 date 99.05.05.12.15.52; author rse; state Exp; branches; next 1.1; 1.1 date 99.04.29.11.19.50; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.04.29.11.19.50; author rse; state Exp; branches; next ; desc @@ 1.31 log @adjust copyright for year 2008 @ text @## ## path -- Deal with program paths ## Copyright (c) 1998-2008 Ralf S. Engelschall ## ## 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 . ## str_tool="path" str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path ] [ ...]" gen_tmpfile=yes arg_spec="1+" opt_spec="s.r.d.b.m.p:" opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path" 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:/$::' shtool_exit 0 fi # SPECIAL REQUEST # strip out directory or base name if [ ".$opt_d" = .yes ]; then echo "$namelist" |\ sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' shtool_exit 0 fi if [ ".$opt_b" = .yes ]; then echo "$namelist" |\ sed -e 's;.*/\([^/]*\)$;\1;' shtool_exit 0 fi # MAGIC SITUATION # Perl Interpreter (perl) if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then rm -f $tmpfile >/dev/null 2>&1 touch $tmpfile found=0 pc=99 for dir in $paths; do dir=`echo $dir | sed -e 's;/*$;;'` nc=99 for name in perl perl5 miniperl; do if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then perl="$dir/$name" pv=`$perl -e 'printf("%.3f", $]);'` echo "$pv:$pc:$nc:$perl" >>$tmpfile found=1 fi nc=`expr $nc - 1` done pc=`expr $pc - 1` done if [ $found = 1 ]; then perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`" rm -f $tmpfile >/dev/null 2>&1 echo "$perl" shtool_exit 0 fi rm -f $tmpfile >/dev/null 2>&1 shtool_exit 1 fi # MAGIC SITUATION # C pre-processor (cpp) if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then echo >$tmpfile.c "#include " echo >>$tmpfile.c "Syntax Error" # 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 >/dev/null 2>&1 rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1 if [ ".$cpp" != . ]; then echo "$cpp" shtool_exit 0 fi shtool_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" fi shtool_exit 0 fi done done shtool_exit 1 ## ## manual page ## =pod =head1 NAME B - B command dealing with shell path variables =head1 SYNOPSIS B [B<-s>|B<--suppress>] [B<-r>|B<--reverse>] [B<-d>|B<--dirname>] [B<-b>|B<--basename>] [B<-m>|B<--magic>] [B<-p>|B<--path> I] I [I ...] =head1 DESCRIPTION This command deals with shell C<$PATH> variables. It can find a program through one or more filenames given by one or more I arguments. It prints the absolute filesystem path to the program displayed on C plus an exit code of 0 if it was really found. =head1 OPTIONS The following command line options are available. =over 4 =item B<-s>, B<--suppress> Supress output. Useful to only test whether a program exists with the help of the return code. =item B<-r>, B<--reverse> Transform a forward path to a subdirectory into a reverse path. =item B<-d>, B<--dirname> Output the directory name of I. =item B<-b>, B<--basename> Output the base name of I. =item B<-m>, B<--magic> Enable advanced magic search for "C" and "C". =item B<-p>, B<--path> I Search in I. Default is to search in $PATH. =back =head1 EXAMPLE # shell script awk=`shtool path -p "${PATH}:." gawk nawk awk` perl=`shtool path -m perl` cpp=`shtool path -m cpp` revpath=`shtool path -r path/to/subdir` =head1 HISTORY The B B command was originally written by Ralf S. Engelschall Erse@@engelschall.comE in 1998 for B. It was later taken over into B. =head1 SEE ALSO shtool(1), which(1). =cut @ 1.30 log @Adjust copyright for year 2007. @ text @d3 1 a3 1 ## Copyright (c) 1998-2007 Ralf S. Engelschall @ 1.29 log @Adjust copyright for year 2006 @ text @d3 1 a3 1 ## Copyright (c) 1998-2006 Ralf S. Engelschall @ 1.28 log @Adjust copyright for year 2005 @ text @d3 1 a3 1 ## Copyright (c) 1998-2005 Ralf S. Engelschall @ 1.27 log @Embedded the command documentation from shtool.pod into the individual sh.xxxx scripts and this way split the large shtool(1) manual page into individual manual pages shtool-xxxx(1). Submitted partly by: Thomas Lotterer @ text @d3 1 a3 1 ## Copyright (c) 1998-2004 Ralf S. Engelschall @ 1.26 log @Bump copyright year for 2004 @ text @a3 1 ## Originally written for Apache d167 1 d169 81 @ 1.25 log @Replace "[ x -o/-a x ]" constructs with "[ x ] ||/&& [ x ]" and "egrep"/"fgrep" constructs with compatible "grep" or "case" constructs. This way GNU shtool is now more POSIX 1003.1-2001 compliant. Submitted by: Paul Eggert @ text @d3 1 a3 1 ## Copyright (c) 1998-2003 Ralf S. Engelschall @ 1.24 log @Bump year in copyright messages to cover new year 2003. @ text @d83 1 a83 1 if [ ".$opt_m" = .yes -a ".$namelist" = .perl ]; then d92 1 a92 1 if [ $minusx "$dir/$name" -a ! -d "$dir/$name" ]; then d114 1 a114 1 if [ ".$opt_m" = .yes -a ".$namelist" = .cpp ]; then d130 1 a130 1 if [ $minusx "$path/cpp" -a ! -d "$path/cpp" ]; then d160 1 a160 1 if [ $minusx "$path/$name" -a ! -d "$path/$name" ]; then @ 1.23 log @Fixed error exit in all commands by introducing an "shtool_exit" function (which correctly cleans up temporary files) and replacing all "exit" calls with "shtool_exit". THIS THE FIRST TIME INTRODUCED THE USAGE OF A SHELL FUNCTION TO THE SHTOOL CODE. This is known to break on _very_ anchient and broken Bourne-Shell implementations and is considered to be no longer a real problem in the year 2003. Especially there is no alternative way anyway. @ text @d3 1 a3 1 ## Copyright (c) 1998-2002 Ralf S. Engelschall @ 1.22 log @Port to POSIX 1003.1-2001 (SUSv3) standard: sh.echo, sh.version: "head -1" -> "sed -e 'q'" sh.path: "sort -u | tail -1" -> "sort -r -u | sed -e q" sh.subst: diff -u1 -> diff -U1 Submitted by: Paul Eggert @ text @d65 1 a65 1 exit 0 d73 1 a73 1 exit 0 d78 1 a78 1 exit 0 d106 1 a106 1 exit 0 d109 1 a109 1 exit 1 d149 1 a149 1 exit 0 d151 1 a151 1 exit 1 d164 1 a164 1 exit 0 d168 1 a168 1 exit 1 @ 1.21 log @bump copyright years @ text @d103 1 a103 1 perl="`cat $tmpfile | sort -u | tail -1 | cut -d: -f4`" @ 1.20 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-2001 Ralf S. Engelschall @ 1.19 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="[-s] [-r] [-d] [-b] [-m] [-p] [ ...]" d27 1 @ 1.18 log @*** empty log message *** @ text @d83 1 a83 1 rm -f $tmpfile d103 1 a103 1 rm -f $tmpfile d107 1 d144 2 a145 1 rm -f $tmpfile.c $tmpfile.out @ 1.17 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-2000 Ralf S. Engelschall @ 1.16 log @*** empty log message *** @ text @d82 1 a82 1 if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then d91 1 a91 1 if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then d112 1 a112 1 if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then d128 1 a128 1 if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then d157 1 a157 1 if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then @ 1.15 log @*** empty log message *** @ text @d113 2 a114 4 cat >$tmpfile.c <<'EOT' #include Syntax Error EOT @ 1.14 log @*** empty log message *** @ text @d161 1 a161 1 echo "$path/$name" 2>&1 @ 1.13 log @*** empty log message *** @ text @a84 1 c=0 d86 1 d89 6 a94 8 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 d97 1 d99 1 a99 1 c=`expr $c + 1` d102 1 a102 1 perl="`cat $tmpfile | sort -u | tail -1 | cut '-d ' -f2`" @ 1.12 log @*** empty log message *** @ text @d114 1 a114 1 cat >$tmpfile.c <$tmpfile </dev/null; then a43 1 rm -f $tmpfile @ 1.10 log @*** empty log message *** @ text @d26 6 a31 1 opt_spec="srdbmp:" @ 1.9 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-1999 Ralf S. Engelschall @ 1.8 log @*** empty log message *** @ text @d26 1 a26 1 opt_spec="srdbmp:!" @ 1.7 log @*** empty log message *** @ text @d92 1 a92 1 if [ $minusx "$dir/$perl" ]; then @ 1.6 log @*** empty log message *** @ text @d29 1 a29 1 . sh.common @ 1.5 log @*** empty log message *** @ text @d6 15 @ 1.4 log @*** empty log message *** @ text @a0 1 #!/bin/sh d2 1 a2 1 ## path -- Deal with $PATH variables d4 1 a4 1 ## Usage: path [-s] [-r] [-d] [-b] [-m] [-p ] [ ...] d7 9 a15 25 # # parse argument line # silent=no reverse=no magic=no dirname=no basename=no pathlist="$PATH" namelist="" while [ ".$1" != . ]; do case $1 in -s ) silent=yes ; shift; continue ;; -r ) reverse=yes ; shift; continue ;; -d ) dirname=yes ; shift; continue ;; -b ) basename=yes ; shift; continue ;; -m ) magic=yes ; shift; continue ;; -p ) pathlist="$2"; shift; shift; continue ;; * ) break ;; esac done if [ $# -eq 0 ]; then echo "$0:Usage: path [-s] [-r] [-d] [-b] [-p ] [ ...]" 1>&2 exit 1 fi a17 1 # a18 10 # tmpdir="/tmp" if [ ".$TMPDIR" != . ]; then tmpdir="$TMPDIR" else if [ ".$TEMPDIR" != . ]; then tmpdir="$TEMPDIR" fi fi tmpfile="$tmpdir/shtool.path.tmp.$$" a31 1 # d33 1 a33 2 # paths="`echo $pathlist |\ a38 1 # d41 1 a41 2 # if [ $reverse = yes ]; then a53 1 # d56 1 a56 2 # if [ $dirname = yes ]; then d61 1 a61 1 if [ $basename = yes ]; then a66 1 # d69 1 a69 2 # if [ ".$magic" = .yes ] && [ ".$namelist" = .perl ]; then a97 1 # d100 1 a100 2 # if [ ".$magic" = .yes ] && [ ".$namelist" = .cpp ]; then a140 1 # a142 1 # d148 2 a149 2 if [ "$silent" != "yes" ]; then echo "$path/$name" @ 1.3 log @*** empty log message *** @ text @a17 1 tmpfile="/tmp/path.tmp.$$" d38 9 @ 1.2 log @*** empty log message *** @ text @d103 1 d147 1 d178 1 @ 1.1 log @Initial revision @ text @a39 1 #!/bin/sh d45 1 a45 1 if /bin/sh $tmpfile 2>/dev/null; then @ 1.1.1.1 log @Import of shtool 1.1.0 @ text @@