]> git.mxchange.org Git - flightgear.git/blob - utils/Modeller/animcheck.pl
initial commit for a python based terrasync client
[flightgear.git] / utils / Modeller / animcheck.pl
1 #!/usr/bin/perl -w
2
3 # Quick & dirty script to find booboos in FlightGear animation files
4 # May 2004 Joshua Babcock jbabcock@atlantech.net
5
6 use strict;
7
8 if ( $#ARGV != 1 ) {
9     print "Usage: $0 <xml file> <ac3d file>\n";
10     exit;
11 }
12
13 my %Objects;
14 my %References;
15 my $Key;
16 my $Num;
17 my $First;
18 my $ObjCount=0;
19 my $CheckForm=1;
20
21 # Put whatever you want in here to check for poorly formatted object names.
22 sub CheckForm {
23     my $Bad=0;
24     $_[0] !~ /^[A-Z].*/ && ($Bad=1);
25     $_[0] =~ /\W/ && ($Bad=1);
26     print "$_[0] poorly formatted\n" if $Bad;
27 }
28
29 # Make a hash of all the object names in the AC3D file.
30 open (AC3D, $ARGV[1]) or die "Could not open $ARGV[1]";
31 while (<AC3D>) {
32     /^name \"(.*)\"/ && ($Objects{$1}+=1);
33 }
34 close AC3D;
35
36 # Check for duplicates and proper format.
37 foreach $Key (keys %Objects) {
38     print "$Objects{$Key} instances of $1\n" if ($Objects{$Key}>1);
39     &CheckForm($Key) if $CheckForm;
40     ++$ObjCount;
41 }
42 print "$ObjCount objects found.\n\n";
43
44 # Make a hash of objects in the XML file that do not reference an object in the AC3D file.
45 open (XML, $ARGV[0]) or die "Could not open $ARGV[0]";
46 while (<XML>) {
47     if (m|<object-name>(.*)</object-name>| && ! exists($Objects{$1})) {
48         # voodoo, "Perl Cookbook", p140
49         push( @{$References{$1}}, $.);
50     }
51 }
52 close XML;
53
54 # List all the bad referencees.
55 foreach $Key (keys %References) {
56     $First=1;
57     print "Non-existant object $Key at line";
58     print "s" if (scalar( @{$References{$Key}}) > 1);
59     print ":";
60     foreach $Num (@{$References{$Key}}) {
61         $First ? ($First=0) : (print ",");
62         print " $Num"
63     }
64     print "\n";
65 }
66
67 exit 0;
68