#!/usr/bin/perl -w
# Test that each plugin is reference at least once in each theme directory.
#
# (I can test it's mentioned in each .htm[l] file as there may be a shared
# header file or similar).
#


my @plugins = glob( "../lib/gnump3d/plugins/*.pm" ); 
my @themes  = glob( "../templates/*/" );
my $found   = 0;


foreach my $plugin ( @plugins )
{
    # Plugins which are not mandatory
	next if ( $plugin =~ /info/ );
	next if ( $plugin =~ /bug/ );
	next if ( $plugin =~ /now/ );
	next if ( $plugin =~ /COPYING/ );

   if  ( $plugin =~ /(.*)\/(.*)\.pm$/ )
   {
	   	$plugin = $2;
   }

   foreach my $dir ( @themes )
   {
       next if ( $dir =~ /CVS/ );
	   next if ( $dir =~ /nausicaa/i );
	   next if ( $dir =~ /Thexder/i );
	   next if ( $dir =~ /dotNet/i );

       $found = 0;
       foreach my $file ( glob ( $dir . "/*" ) )
       {
	   open( FILY, "<$file" ) or die "Cannot open $file - $!";
	   my @LINES = <FILY>;
	   close( FILY );
       
	   foreach my $line ( @LINES )
	   {
	       chomp( $line );
	       if ( $line =~ /\"\/$plugin/ )
	       {
		   $found ++;
	       }
	   }
       }

       if ( ! $found )
       {
	   print "Plugin $plugin not found in $dir\n";
	   exit 1;
       }
   }

}

exit 0;
