#!/usr/local/bin/perl -w
# Execute as runconv.pl list of directories
#
$irun=0;
$basedir= `pwd`;
chomp($basedir);
while(defined($ARGV[$irun]))    {
        $dirfoilset=$ARGV[$irun];
        ++$irun;
        unless( -e $dirfoilset) {
                print "$dirfoilset Isnt even a file!\n";
                next;
        }
        unless(-d $dirfoilset) {
                print "$dirfoilset Isnt a directory!\n";
                next;
        }
	unless( -e $dirfoilset."/extrainfo" )	{
		print "No source information in $dirfoilset\n";
		next;
	}
	$original = '';
	$originalimage = '';
	$originalindex = '';
	open(SOURCE,"<${dirfoilset}/extrainfo")|| die("\nSorry couldn't open ${dirfoilset}/extrainfo\n");
	while( $line=<SOURCE>)	{
		if( $line =~ m%^source:(.*)$%i )	{
			$original = $1; }
		if( $line =~ m%^sourceindex:(.*)$%i )	{
			$originalindex = $1; }
		if( $line =~ m%^sourceimage:(.*)$%i )	{
			$originalimage = $1; }
	}
	close(SOURCE);
	if( $original )	{
		$originalindex = $original unless($originalindex);
		$originalimage = $original unless($originalimage);
	}
	unless($originalindex && $originalimage)	{
		print "No source information in $dirfoilset\n";
	}
	$image=$dirfoilset."/seporgimagedir";
	unless(-e $image)	{
		mkdir($image,0755);
	}
	$com = "cp masterbasic/* $dirfoilset";
	system($com);
	$com = "/home/A7E/gcf/foils3/hitachi/convphoto.pl $originalimage $originalindex $dirfoilset";
	if( system($com) )	{
		die "Creating $dirfoilset from $original fails\n";
	}
	chdir $dirfoilset;
	system("rm seporgimagedir/*");
	system("runwwwfoil1");
	chdir $basedir;
	system("master.pl $dirfoilset");
	print "$dirfoilset Processed\n";
}
#
