hi all,

I just made a little perl script for sanity check of pathes used in xml files for aircrafts. I've done it to find out what's wrong when fgfs reports failure to open a file at launch.

it must be used from the FGROOT directory.

usage:
tests.pl [relative] aircraft

where:
"relative" is an option for checking relative path, if not given the default is absolute path (this option must be first). Indeed absolute pathes are relative from FGROOT.
"aircraft" is the aircraft name, as used with the fgfs's option --aircraft

if someone find it usefull...

regards.
seb
#!/usr/bin/perl

#GPL licence
#Sébastien MARQUE, Paris (France), 2007

use strict;

my %aircrafts = ();
foreach ( <Aircraft/*> ) {
	if ( -d ) {
		foreach ( <$_/*-set.xml> ) {
			/.+\/(.+)-set.xml$/;
			$aircrafts{$1} = $_;
		}
	} 
}

my $relative = 0;
my $erreur = 0;
my $plane = shift;

if ($plane eq "relative") {
	$relative = 1;
	$plane = shift;
}

sub test ($) {
	my $file = shift;
	$file =~ /(.+\/)[A-Za-z0-9\._-]+$/;
	my $relative_path = $1;
	if (! $relative) { $relative_path = ""; }
	my @pathlist;
	my $line = 0;
	if (!open (FILE, $file)) {
		print "can't open $file\n";
		exit;
	}
	while (<FILE>) {
		$line++;
		if (/>(.+)<\/path>$/) {
			my $path = $1;
			if ( -e "$path" || -e "$relative_path$path" ) {
				if ($path =~ /xml$/) {
					push @pathlist, $path;
				}
			}
			else {
				print "path $path doesn't exist, file $file (line $line)\n";
				$erreur++;
			}
		}
	}
	close (FILE);
	foreach $file (@pathlist) {
		test ("$file");
	}
}

if (! exists $aircrafts{$plane} ) {
	print "aircraft $plane can't be found\n";
	print "please ensure you use this script from FGROOT directory\n\n";
	exit;
}
test ($aircrafts{$plane});
if ($erreur) { print "$erreur errors reported\n\n"; }
else { print "no error found\n\n"; }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to