$err=0 if (! defined $err);
$path="";
if ($mode eq "e") {
$mode="de";
} elsif ($mode eq "r") {
$mode="derx";
} elsif ($mode eq "w") {
$mode="derwx";
}
foreach (@dir) {
# Expand path
if ($full) {
$_=FullFilePath($_);
} else {
$_=ExpandTilde($_);
}
if (! $_) {
return "" if ($err);
next;
}
# Check mode
if (! $mode or CheckFilePath($_,$mode)) {
$path .= $Cnf{"PathSep"} . $_;
} else {
return "" if ($err);
}
}
$path =~ s/^$Cnf{"PathSep"}//;
return $path;
}
#&&
# $File=SearchPath($file,$path [,$mode] [,@suffixes]);
# Searches through directories in $path for a file named $file. The
# full path is returned if one is found, or an empty string otherwise.
# The file may exist with one of the @suffixes. The mode is checked
# similar to CheckFilePath.
#
# The first full path that matches the name and mode is returned. If none
# is found, an empty string is returned.
sub SearchPath {
my($file,$path,$mode,@suff)=@_;
my($f,$s,$d,@dir,$fs)=();
$path=FixPath($path,1,"r");
@dir=split(/$Cnf{"PathSep"}/,$path);
foreach $d (@dir) {
$f="$d/$file";
$f=~ s|//|/|g;
return $f if (CheckFilePath($f,$mode));
foreach $s (@suff) {
$fs="$f.$s";
return $fs if (CheckFilePath($fs,$mode));
}
}
return "";
}
# @list=ReturnList($str);
# This takes a string which should be a comma separated list of integers
# or ranges (5-7). It returns a sorted list of all integers referred to
# by the string, or () if there is an invalid element.
#
# Negative integers are also handled. "-2--1" is equivalent to "-2,-1".
sub ReturnList {
my($str)=@_;
my(@ret,@str,$from,$to,$tmp)=();
@str=split(/,/,$str);
foreach $str (@str) {
if ($str =~ /^[-+]?\d+$/) {
push(@ret,$str);
} elsif ($str =~ /^([-+]?\d+)-([-+]?\d+)$/) {
($from,$to)=($1,$2);
if ($from>$to) {
$tmp=$from;
$from=$to;
$to=$tmp;
}
push(@ret,$from..$to);
} else {
return ();
}
}
@ret;
}
1;
# Local Variables:
# mode: cperl
# indent-tabs-mode: nil
# cperl-indent-level: 3
# cperl-continued-statement-offset: 2
# cperl-continued-brace-offset: 0
# cperl-brace-offset: 0
# cperl-brace-imaginary-offset: 0
# cperl-label-offset: -2
# End:
=76=
THE END |