-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeInfo.pl
executable file
·124 lines (104 loc) · 2.77 KB
/
TreeInfo.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/perl -w
#
# Author: Floyd Moore (floyd.moore\@hp.com)
# $Header:$
# Description:
#
# "TreeInfo" created by red
#
# $Log:$
#
use strict;
use subs qw(handler show_usage parse_options get_dir file_mtime round);
use POSIX qw/strftime/;
use Data::Dumper;
local $Data::Dumper::Indent=1;
use Filesys::Tree qw/tree/;
use vars qw($mgc_home $opt_v $opt_x $opt_V);
use vars qw($ProgName $RunDate $Rev $DirName);
$RunDate = strftime '%Y/%m/%d %H:%M:%S', localtime;
$Rev = (split(' ', '$Revision: 2 $', 3))[1];
$0 =~ m!(.*)/!; $ProgName = $'; $DirName = $1; $DirName = '.' unless $DirName;
$SIG{'HUP'} = \&handler;
$SIG{'INT'} = \&handler;
$SIG{'QUIT'} = \&handler;
$SIG{'TERM'} = \&handler;
use Getopt::Std;
sub show_usage
{
print "$ProgName $Rev\t\t$RunDate\n";
print "$ProgName [-xVv]\n";
print " Options:\n";
print " -v: Verbose mode\n";
print " -V: Report Version and quit.\n";
print " -x: Debug mode\n";
print "\n";
exit 0;
}
# my options parser
sub parse_options
{
if ( $#ARGV > 0 && $ARGV[0] =~ "-help"){
&show_usage();
exit(1);
}
unless (&Getopt::Std::getopts('Vvx')) {
&show_usage();
exit(1);
}
if ($opt_V) { die "$ProgName $Rev\n"; };
}
######################################
# Main Program #####################
######################################
my $depth=0;
my $parent;
parse_options;
$opt_v && print "# $ProgName $Rev\t\t$RunDate\n\n";
my $top_dir = shift;
unless(defined($top_dir)){
print "You need to specify a directory to dump\n";
usage();
}
unless (-d "$top_dir"){
die "$top_dir is not a directory!\n";
}
my $tree = tree({ 'directories-only' => 1, 'exclude-pattern' => q/obsolete/ }, $top_dir);
sub fillspace {
my $count=shift;
my $spaces="";
for (my $i=0; $i<3*$count; $i++){
$spaces .= " ";
}
return $spaces;
}
sub walkdir {
my $hashref=shift;
my %dir = %$hashref;
for my $key (keys %dir){
if ($key =~ /RCS/ ) { next; }
if ($key =~ /debussyLog/ ) { next; }
if ($key =~ /obsolete/ ) { next; }
if ($key =~ /svdb/ ) { next; }
#print " ... walk $key at depth=$depth...\n";
unless (exists ($dir{$key}->{contents})){
die "Bad directory tree for $hashref\n";
}
my $contents = $dir{$key}->{contents};
if (scalar(keys %{$contents}) > 0 ){
# contents is another directory
print fillspace($depth) . "$key\/\n";
if ($key =~ /LIB_\w+/ ) { next; }
if ($key =~ /work_\w+/ ) { next; }
++$depth;
walkdir($contents);
--$depth;
} else {
# contents is a simple leaf in the tree
#print " ... ... leaf $key\n";
print fillspace($depth) . "$key\n";
}
}
}
walkdir($tree);
#print Data::Dumper->Dump([\$tree], ["*tree"]);