| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
;# pwd.pl - keeps track of current working directory in PWD environment var |
|
2
|
|
|
|
|
|
|
;# |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# This library is no longer being maintained, and is included for backward |
|
5
|
|
|
|
|
|
|
# compatibility with Perl 4 programs which may require it. |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# In particular, this should not be used as an example of modern Perl |
|
8
|
|
|
|
|
|
|
# programming techniques. |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# Suggested alternative: Cwd |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
;# $RCSfile: pwd.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:11 $ |
|
13
|
|
|
|
|
|
|
;# |
|
14
|
|
|
|
|
|
|
;# $Log: pwd.pl,v $ |
|
15
|
|
|
|
|
|
|
;# |
|
16
|
|
|
|
|
|
|
;# Usage: |
|
17
|
|
|
|
|
|
|
;# require "pwd.pl"; |
|
18
|
|
|
|
|
|
|
;# &initpwd; |
|
19
|
|
|
|
|
|
|
;# ... |
|
20
|
|
|
|
|
|
|
;# &chdir($newdir); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package pwd; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub main::initpwd { |
|
25
|
0
|
0
|
|
0
|
|
|
if ($ENV{'PWD'}) { |
|
26
|
0
|
|
|
|
|
|
local($dd,$di) = stat('.'); |
|
27
|
0
|
|
|
|
|
|
local($pd,$pi) = stat($ENV{'PWD'}); |
|
28
|
0
|
0
|
0
|
|
|
|
if (!defined $dd or !defined $pd or $di != $pi or $dd != $pd) { |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
chop($ENV{'PWD'} = `pwd`); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
else { |
|
33
|
0
|
|
|
|
|
|
chop($ENV{'PWD'} = `pwd`); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
0
|
0
|
|
|
|
|
if ($ENV{'PWD'} =~ m|(/[^/]+(/[^/]+/[^/]+))(.*)|) { |
|
36
|
0
|
|
|
|
|
|
local($pd,$pi) = stat($2); |
|
37
|
0
|
|
|
|
|
|
local($dd,$di) = stat($1); |
|
38
|
0
|
0
|
0
|
|
|
|
if (defined $pd and defined $dd and $di == $pi and $dd == $pd) { |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$ENV{'PWD'}="$2$3"; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub main::chdir { |
|
45
|
0
|
|
|
0
|
|
|
local($newdir) = shift; |
|
46
|
0
|
|
|
|
|
|
$newdir =~ s|/{2,}|/|g; |
|
47
|
0
|
0
|
|
|
|
|
if (chdir $newdir) { |
|
48
|
0
|
0
|
|
|
|
|
if ($newdir =~ m#^/#) { |
|
49
|
0
|
|
|
|
|
|
$ENV{'PWD'} = $newdir; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
else { |
|
52
|
0
|
|
|
|
|
|
local(@curdir) = split(m#/#,$ENV{'PWD'}); |
|
53
|
0
|
0
|
|
|
|
|
@curdir = '' unless @curdir; |
|
54
|
0
|
|
|
|
|
|
foreach $component (split(m#/#, $newdir)) { |
|
55
|
0
|
0
|
|
|
|
|
next if $component eq '.'; |
|
56
|
0
|
0
|
|
|
|
|
pop(@curdir),next if $component eq '..'; |
|
57
|
0
|
|
|
|
|
|
push(@curdir,$component); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
0
|
|
0
|
|
|
|
$ENV{'PWD'} = join('/',@curdir) || '/'; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
else { |
|
63
|
0
|
|
|
|
|
|
0; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |