#!/usr/local/bin/perl -w
# Execute as existing.pl list of directories
#
$irun=0;
$basedir= `pwd`;
chomp($basedir);
while(defined($ARGV[$irun]))	{
	$dirfoilset=$ARGV[$irun];
	++$irun;
	unless( -e $dirfoilset) {
                print "Isnt even a file!\n";
                next;
        }
        if( -l $dirfoilset) {
                print "Unsafe to process link $dirfoilset -- go to correct directory\n";
                next;
        }
	print "Checking Directory ",$dirfoilset,"\n";
	unless(-d $dirfoilset) {
		print "Isnt a directory!\n";
		next;
	}
	unless( (-e $dirfoilset."/processed") || (-e $dirfoilset."/colors") ) {
		print "No Processed or Color File\n";
		next;
	}
#
	$extra = "${dirfoilset}/extrainfo";
	$trypptdir = 'NONE';
	if(-e $extra)	{
		open(EXTRA,'<'. $extra) || die("\nSorry couldnt Open $extra \n");
		my($line);
		while($line=<EXTRA>)	{
			chomp($line);
			if($line =~ m/^([^:]*):(.*)$/ )	{
				my($one,$two);
				$one =$1;
				$two = $2;
				$one =~ s/\s*//g;
				$one =~ tr/A-Z/a-z/;
				if($one eq 'sourcepptdir')	{
					$two =~ s/\s*//g;
					$trypptdir = $two;
				}
			}
		}
		close(EXTRA);
	}
	unless(-e $trypptdir)	{
		print "No powerpoint HTML export file $trypptdir\n";
		next;
	}
	$com = "/home/A11A/gcf/foils/progs/ppttowwwfoil.pl $trypptdir /home/A11A/gcf/foils/$dirfoilset";
	system($com);
	chdir($dirfoilset);
	system('runwwwfoil1');
	chdir($basedir);
#
}
