-
Notifications
You must be signed in to change notification settings - Fork 10
/
tt_list.pl
executable file
·58 lines (43 loc) · 1.11 KB
/
tt_list.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
#! /usr/bin/perl -w
use strict;
use File::Spec::Functions qw(catfile catdir);
use File::Path qw(mkpath);
sub fixtemplate {
my $templateref = shift;
my %seen = ();
while ($$templateref =~ m,\[\% (\S+) \%\],g) {
next if ($1 eq 'END' || $1 eq 'ELSE');
print " $1\n" unless $seen{$1}++ || $1 eq '';
}
return $templateref;
}
sub processDir {
my ($dir,$dirref) = @_;
opendir(DIR,$dir) or die "Cannot open directory $dir\n";
my @subNames = readdir(DIR);
closedir(DIR);
print "\nProcessing $dir\n";
foreach my $file (@subNames) {
next if ($file eq ".");
next if ($file eq "..");
next if ($file eq "CVS");
$file = catfile($dir,$file);
next unless (-d $file || $file =~ /\.(?:htm|js)/i);
print "\n $file\n";
if (-d $file) {
push @$dirref, $file;
} elsif (($file =~ /\.htm/i) || ($file =~ /\.js/i)) {
open(FILE, $file) or die "can't open $file";
my $contents;
read (FILE, $contents, -s FILE);
close FILE;
fixtemplate(\$contents);
}
}
}
my @dirs = ();
my $rootdir = shift @ARGV || '.';
push @dirs, $rootdir;
for (my $i = 0; $i <= $#dirs; $i++) {
processDir($dirs[$i],\@dirs);
}