summaryrefslogtreecommitdiff
path: root/lib/sbin/ThornList.pl
blob: e9a0221ff93850e362d0bb1ed87175a7f9756cac (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/perl

# use vars qw($arrangements_dir $arrangements $thorns $h $help $thornlist);

#/*@@
#  @file      ThornList.pl 
#  @date      March 2001
#  @author    Ian Kelley
#  @desc 
#      Either creates a stripped down thornlist of all thorns in the arrangments
#      directory, or prints out the full paths to each thorn on a single line
#
#      Used primary by the ThornGuide Makefile
#  @enddesc 
#  @version 
#@@*/

# give help
if ($h || $help) {
   print <<EOC;
--> ThornList.pl <--

Either creates a stripped down thornlist of all thorns in the arrangments directory, or prints out the full paths to each thorn on a single line.  It can also take a combination of arrangements and thorns and will print them all out as a thornlist.

Usage:
\t\$ perl -s ThornList.pl -arrangements_dir=/tmp/Cactus/arrangements > allthorns.th
\t\$ perl -s ThornList.pl -arrangements_dir=/tmp/Cactus/arrangements -thornlist=allthorns.th
\t\$ perl -s ThornList.pl -arrangements_dir=/tmp/Cactus/arrangements -thorns="CactusBase/Boundary CactusBase/IOBasic" -arrangements="CactusTest"
EOC

exit 0;
}

my $start_directory = `pwd`;
chomp ($start_directory);

my @thorns;
my @arrangements;


if (! defined $arrangements_dir) {
   die "\nArrangements directory not defined (-arrangments_dir)";
} elsif ($arrangements_dir !~ /\/$/) {
   $arrangements_dir .= '/';
}


# if we are being passed in the arrangements or thorns manually
if ($arrangements =~ /\w/ || $thorns =~ /\w/) {
   if (defined $arrangements) {
      @arrangements = split/,/, $arrangements;

      foreach my $arrangement (@arrangements) 
      { 
         @thorns = &FindDirectories("$arrangements_dir$arrangement");

         foreach my $thorn (@thorns) {
            print "\n$arrangement/$thorn" if ($thorn ne "doc");
         }
      }
   }

   if (defined $thorns) {
      @thorns = split/,/, $thorns;

      foreach my $thorn (@thorns) {
          print "\n$thorn";
      }
   }

}
# if we are building a thornlist from thorns in $arrangements_dir
elsif (! defined $thornlist) 
{
   @arrangements = &FindDirectories($arrangements_dir);

   foreach my $arrangement (@arrangements) 
   {
      @thorns = &FindDirectories("$arrangements_dir$arrangement");

      foreach my $thorn (@thorns) {
         print "$arrangement/$thorn\n" if ($thorn ne "doc");
      }
   }
} 
# if we are printing all the thorn directories on one line
# for use by the ThornGuide makefile
else 
{
   my $thorn_paths = "";

   open (THORNLIST, "<$thornlist") || die "\nCannot open thornlist ($thornlist): $!";

   while (<THORNLIST>) 
   {
      next if /\s*?\!/;          # bypass any directives
      s/(.*?)#.*/\1/;            # read up to the first "#"
      s/\s+//g;                  # replace any spaces with nothing
      
      next if ! /\w/;            # nothing on this line?

      $thorn_paths .= "$arrangements_dir$_ ";

   }

   close (THORNLIST);

   print $thorn_paths;
}
## END: MAIN ##

#/*@@
#  @routine   FindDirectories
#  @date      Sun Mar  3 01:54:37 CET 2002
#  @author    Ian Kelley
#  @desc 
#     Grabs all directories within a given directory, minus the ones created by CVS
#  @enddesc 
#  @version 
#@@*/

sub FindDirectories 
{
   my $search_dir = shift;
   my @good_directories;
   my $dirhdl;

   opendir ($dirhdl, $search_dir)
            or die "\nCannot open directory $search_dir\n";

   while (defined (my $name = readdir($dirhdl)))
   {
      next if (! -d "$search_dir/$name");

      if (($name ne 'History') && ($name ne 'CVS')
      && !($name =~ /^\./ ) )        # i.e. current, parent & hidden dirs 
      {
         push(@good_directories, $name);
      }
   }
   closedir $dirhdl;

   return @good_directories;
} ## END :Find_Directories: