#!/usr/bin/perl -w
# Quick & dirty script to find booboos in FlightGear animation files # May 2004 Joshua Babcock [EMAIL PROTECTED]
use strict;
if ( $#ARGV != 1 ) { print "Usage: $0 <xml file> <ac3d file>\n"; exit; }
my %Objects; my %References; my $Key; my $Object; my $Num; my $First; my $ObjCount=0; my $CheckForm=1;
# Put whatever you want in here to check for poorly formatted object names. sub CheckForm { my $Bad=0; $Object=$_[0]; $Object !~ /^[A-Z].*/ && ($Bad=1); $Object =~ /\W/ && ($Bad=1); $Object =~ /\s/ && ($Bad=1); $Object =~ /\./ && ($Bad=1); print "$Object poorly formatted\n" if $Bad; }
# Make a hash of all the object names in the AC3D file. open (AC3D, $ARGV[1]) or die "Could not open $ARGV[1]"; while (<AC3D>) { /^name \"(\w*)\"/ && ($Objects{$1}+=1); } close AC3D;
# Check for duplicates and proper format. foreach $Key (keys %Objects) { print "$Objects{$Key} instances of $1\n" if ($Objects{$Key}>1); &CheckForm($Key) if $CheckForm; ++$ObjCount; } print "$ObjCount objects found.\n\n";
# Make a hash of objects in the XML file that do not reference an object in the AC3D file.
open (XML, $ARGV[0]) or die "Could not open $ARGV[0]";
while (<XML>) {
m|<object-name>(.*)</object-name>|;
$1 ? ($Object=$1) : ($Object='');
if (! exists($Objects{$Object})) {
# voodoo, "Perl Cookbook", p140
push( @{$References{$Object}}, $.);
}
}
close XML;
# List all the bad referencees. foreach $Key (keys %References) { $First=1; print "Non-existant object $Key at line"; print "s" if (scalar( @{$References{$Key}}) > 1); print ":"; foreach $Num (@{$References{$Key}}) { print "," if not $First; print " $Num" } print "\n"; }
exit 0;
_______________________________________________ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel