-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_dir_dot.pl
executable file
·109 lines (93 loc) · 2.23 KB
/
make_dir_dot.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
#!/usr/bin/perl -w
#
# Author: Floyd Moore (floyd.moore\@hp.com)
# $Header:$
# Description:
#
# "make_dir_dot.pl" created by red
# make a 'dot' diagram input file that describes the layout
# of a directory.
#
# $Log:$
#
use strict;
use vars qw ($opt_V $opt_c $opt_x $opt_v $opt_F @Dirs);
use Getopt::Std;
sub show_usage
{
print "$0 [-xVv]\n";
print " Options:\n";
print " -v: Verbose mode\n";
print " -V: Report Version and quit.\n";
print " -x: Debug mode\n";
print " -c: Just create a simple CSV file of the dir structure\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('VvxcF')) {
&show_usage();
exit(1);
}
}
sub traverse_dir
{
my $top = shift;
opendir (DIR, "$top") || die "Cannot opendir $top";
while ($_ = readdir(DIR)){
/^\.$/ && do { next; };
/^\.\.$/ && do { next; };
/obsolete/ && do { next; };
if (defined($opt_F)){
/RCS/ && do { next; };
}
my $fullpath = $top . "/" . $_;
#print " dir entry = $fullpath\n";
if (-d "$fullpath"){
my $fullpath = $top . "/" . $_;
push @Dirs, $fullpath;
print " directory = $fullpath\n";
if (defined($opt_c)){
print " CSV: \"$top\" -> \"$fullpath\"\n";
} else {
print DOT " \"$top\" -> \"$fullpath\"\n";
}
}
elsif (-l "$fullpath"){
print " sym-link = $fullpath\n";
} else {
; #print "file=$fullpath\n";
}
}
closedir DIR;
}
######################################
# Main Program #####################
######################################
parse_options;
my $depth=0;
my $top_dir=shift;
$top_dir = "." unless defined($top_dir);
if ( ! -d "$top_dir" ){
die "Cannot find top directory: '$top_dir'\n";
}
if (!defined($opt_c)){
my $dotfile = "/tmp/dotfile";
open (DOT, ">$dotfile") ||
die "Cannot open dot output file: $dotfile\n";
}
push @Dirs, $top_dir;
while (scalar @Dirs > 0){
my $dir = shift @Dirs;
traverse_dir($dir);
print " $dir ... depth=$#Dirs\n";
}
unless(defined($opt_c)){
close DOT;
}