Merged in Governor-Tarkin/swg-src (pull request #17)
[swg-src.git] / tools / findAssetsUsingCustomization.pl
blobe809507d2f4ab5b67419c6da2cb80f843e92f399
1 #!/bin/perl
2 use strict;
4 # Call with the following args:
5 # -n <newVariableNameFile> -a <assetInfoFile>
7 my $newVariableFileName;
8 my $assetInfoFileName;
9 my $debug = 0;
11 my %targetVariableNames;
13 sub loadTargetVariableNamesFromFile
15 my $filename = shift;
16 my $fileHandle;
18 open($fileHandle, "<$filename") or die "failed to open file [$filename]: $!";
20 while (<$fileHandle>)
22 chomp;
23 if ($_ =~ m/\[(.+)\]/)
25 my $name = $1;
26 $targetVariableNames{$name} = 1;
27 print STDERR "target variable [$name]\n" if $debug;
31 close($fileHandle);
34 sub findVariableNameUsage
36 my $filename = shift;
37 my $fileHandle;
39 print "variableName\treferencing assetName\n";
41 open($fileHandle, "<$filename") or die "failed to open file [$filename]: $!";
42 while (<$fileHandle>)
44 chomp;
45 if (($_ =~ m/^I /) || ($_ =~ m/^P /))
47 # kill code letters.
48 s/..//;
50 # read asset name and variable name.
51 m/([^:]+):([^:]+):/ or die "line [$_] does not match customization variable info data format";
52 my $assetName = $1;
53 my $variableName = $2;
55 # if the variable name is one of the targets, print out the asset.
56 if (exists $targetVariableNames{$variableName})
58 print "$variableName\t$assetName\n";
62 close($fileHandle);
65 # Process args
66 while (@ARGV)
68 my $currentArg = shift @ARGV;
69 if ($currentArg =~ m/-d/)
71 $debug = 1;
72 print STDERR "debugging turned on\n";
74 elsif ($currentArg =~ m/-n/)
76 $newVariableFileName = shift @ARGV;
77 print STDERR "newVariableFileName=[$newVariableFileName]\n" if $debug;
79 elsif ($currentArg =~ m/-a/)
81 $assetInfoFileName = shift @ARGV;
82 print STDERR "assetInfoFileName=[$assetInfoFileName]\n" if $debug;
86 # Load in new variable names
87 loadTargetVariableNamesFromFile($newVariableFileName);
89 # Find asset usage of target names
90 findVariableNameUsage($assetInfoFileName);