#!/usr/bin/perl
#----------------------------->  Perl - script  <-----------------------------#
#- Copyright (C) 199x by International Computer Science Institute            -#
#- This file is part of the GNU Sather package. It is free software; you may -#
#- redistribute  and/or modify it under the terms of the  GNU General Public -#
#- License (GPL)  as  published  by the  Free  Software  Foundation;  either -#
#- version 3 of the license, or (at your option) any later version.          -#
#- This  program  is distributed  in the  hope that it will  be  useful, but -#
#- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY -#
#- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/GPL for more details.        -#
#- The license text is also available from:  Free Software Foundation, Inc., -#
#- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     -#
#------------->  Please email comments to <bug-sather@gnu.org>  <-------------#

# Runs the test in all directories it finds a DESC file. You either
# have to pass the compiler as an argument, or it
# will pick the first one it finds at the following
# positions: $SATHER_HOME/Bin/sacomp  $SATHER_HOME/Compiler/sacomp
# SATHER_HOME/Boot/sacomp
#
# It assumes that the SATHER_HOME variable is set
# to the correct directory
#

require "$ENV{'SATHER_HOME'}/Test/TestPrg/PROG/exectest.prl";
$SH=$ENV{'SATHER_HOME'};
$P='STD';
$PS=0;
if($ARGV[0] =~ /^(QUICK)|(STD)|(EXT)$/) { 
	$P=$ARGV[0];
	shift;
} 
if($ARGV[0] =~ /^(PSATHER)$/) { 
	$PS=1;
	shift;
} 
if(@ARGV==0) { 
	if(-x "$SH/Compiler/sacomp") { 
		$CS="$SH/Compiler/sacomp";
		print "Using the Compiler $CS\n";
	} elsif(-x "$SH/Bin/sacomp") { 
		$CS="SH/Bin/sacomp";
		print "Using the Standard Compiler $CS\n";
	} elsif(-x "$SH/Boot/sacomp") { 
		$CS="SH/Boot/sacom";
		print "Using the Boot Compiler in $CS\n";
	} else {
		die "I cannot find a compiler to use for this test.\n";
	} 
} else {
	$CS=$ARGV[0];
	if(! -x $CS) {
		die "The supplied Compiler $CS does not exist.\n";
	} 
	shift;
} 
if(@ARGV==1) {
	open(STDOUT,"| tee -a $ARGV[0]") || die "cannot open '| tee -a $ARGV[0]', $!\n";
	open(STDERR,">&STDOUT") || die "cannot redirect STDERR, $!\n";
	select(STDOUT);
}
opendir(DIR,".") || die "cannot open the directory '.'., $!\n";
foreach $a (readdir(DIR)) { 
	if($a ne '.' && $a ne '..' && -e "$a/DESC") { 
		&exec_test($a,$CS,$P,$PS);
	} 
}
close(DIR);
exit(0);
