From 7236dbfeb785534f8aede7f8b3c93b8a2d1f263b Mon Sep 17 00:00:00 2001 From: Reinhard Kotucha Date: Sun, 20 Jan 2008 22:12:10 +0000 Subject: TLUtils.pm: dirname, basename: replace '\' by '/' when on Windows. git-svn-id: svn://tug.org/texlive/trunk@6337 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/TeXLive/TLUtils.pm | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm index ac661311c73..be36b02ef70 100644 --- a/Master/tlpkg/TeXLive/TLUtils.pm +++ b/Master/tlpkg/TeXLive/TLUtils.pm @@ -270,7 +270,7 @@ sub getenv { my $var=$ENV{"$envvar"}; return 0 unless (defined $var); if (&win32) { - $var=~s@\\@/@g; # change \ -> / (required by Perl) + $var=~s!\\!/!g; # change \ -> / (required by Perl) } return "$var"; } @@ -360,8 +360,12 @@ Return C<$path> with its trailing C removed. =cut sub dirname { - if ($_[0] =~ m!/!) { # dirname("foo/bar/baz") -> "foo/bar" - $_[0] =~ m!(.*)/.*!; + my $path=shift; + if (win32) { + $path=~s!\\!/!g; + } + if ($path=~m!/!) { # dirname("foo/bar/baz") -> "foo/bar" + $path=~m!(.*)/.*!; return $1; } else { # dirname("ignore") -> "." return "."; @@ -376,10 +380,14 @@ Return C<$path> with any leading directory components removed. =cut sub basename { - if ($_[0] =~ m!/!) { # basename("foo/bar") -> "bar" - $_[0] =~ m!.*/(.*)!; + my $path=shift; + if (win32) { + $path=~s!\\!/!g; + } + if ($path=~m!/!) { # basename("foo/bar") -> "bar" + $path=~m!.*/(.*)!; return $1; - } else { # basename("ignore") -> "ignore" + } else { # basename("ignore") -> "ignore" return $_[0]; } } @@ -394,8 +402,12 @@ Return both C and C. Example: =cut sub dirname_and_basename { - $_[0]=~/(.*)\/(.*)/; - return ("$1", "$2"); + my $path=shift; + if (win32) { + $path=~s!\\!/!g; + } + $path=~/(.*)\/(.*)/; + return ("$1", "$2"); } =pod -- cgit v1.2.3