README.md edited online with Bitbucket
[swg-src.git] / tools / ScanScript.pl
blob1a50ed554eb290df93adda55fb9b26b63d9d5ee5
1 #! /usr/bin/perl
2 # ======================================================================
3 # ======================================================================
5 use strict;
6 use warnings;
8 # ======================================================================
9 # Globals
10 # ======================================================================
12 my %str_to_tags;
13 my %str_to_files;
14 my $tmprsp = "a.rsp";
16 my $name = $0;
17 $name =~ s/^(.*)\\//;
19 # ======================================================================
20 # Subroutines
21 # ======================================================================
23 sub usage
25 die "\nTool used to scan through conversation scripts and verify that all .stf files have the appropriate tags\n\n".
26 "\tUsage\n".
27 "\t\t$name <script file>\n\n";
30 sub testfile
32 #p4 fstat //depot/swg/current/data/.../string/en/bartender.stf
33 #echo c:\work\swg\current\data\sku.0\sys.server\built\game\string\en\bartender.stf > a.rsp
34 #WordCountTool.exe -d a.rsp
36 my $file = shift @_;
37 my $path = $file;
38 $path =~ s/\./\//g;
40 my @files;
42 open(P4, "p4 fstat //depot/swg/current/data/.../string/en/${path}.stf | ") or die "Cannot open file: $path\n";
43 while(<P4>)
45 push @files, $1 if(/^\.\.\. clientFile (.+)$/);
47 close(P4);
49 foreach my $elem (@files)
51 print "\t$elem:\n";
53 my %filetags;
54 system("echo $elem > $tmprsp");
55 open(WORDCOUNT, "WordCountTool.exe -d $tmprsp | ");
56 while(<WORDCOUNT>)
58 $filetags{"\"$1\""} = 0 if(/^\t(\S+)\t/);
60 close(WORDCOUNT);
62 my $ref = $str_to_tags{$file};
63 my $missing = 0;
65 foreach my $tag (sort keys %$ref)
67 if(!exists $filetags{$tag})
69 print "\t\tis missing $tag\n";
70 $missing = 1;
74 $missing ? print "\n" : print "\t\tNone missing\n\n";
77 unlink($tmprsp);
80 # ======================================================================
81 # Main
82 # ======================================================================
84 &usage() if(@ARGV != 1);
86 my $scriptfile = shift;
88 print "Scanning script file...\n";
90 open(SCRIPT, "<$scriptfile");
92 while(<SCRIPT>)
94 $str_to_files{$2} = $3 if(/(const)?\s+string\s+([A-Za-z_]+)\s+=\s+"([A-Za-z_\.]+)"/);
95 #if(/(new)?\s+string_id\s*\(\s*([A-Za-z_]+)\s*,\s*"([A-Za-z_]+)"\s*\)/)
96 if(/(new)?\s+string_id\s*\(\s*([A-Za-z_]+)\s*,\s*(.+)\s*\)/)
98 my $string = $2;
99 my $tagline = $3;
101 $str_to_tags{$str_to_files{$string}} = {} if(!exists $str_to_tags{$str_to_files{$string}});
103 if($tagline =~ s/"(.+)"\s*\+\s*rand\s*\(\s*(\d)+\s*,\s*(\d)+\s*\)//)
105 my $tagline = $1;
106 my $num = $2;
107 my $end = $3;
109 while($num <= $end)
111 $str_to_tags{$str_to_files{$string}}->{"\"${tagline}$num\""} = 0;
113 ++$num;
116 else
118 $tagline =~ s/\)//g;
119 $str_to_tags{$str_to_files{$string}}->{$tagline} = 0;
124 close(SCRIPT);
126 foreach my $str (sort keys %str_to_tags)
128 my $hash_ref = $str_to_tags{$str};
129 print "\nFile: '$str' needs to contain\n";
130 foreach my $tag (sort keys %$hash_ref)
132 print "\t$tag\n";
136 print "\nScanning for missing elements of script files...\n";
138 foreach my $filename (sort keys %str_to_tags)
140 testfile($filename);