#!/usr/local/bin/perl -w
#
$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);
	}
	else	{
		$sourcedir = '/usr/local/archives/public/users/gcf/03/rawfoils';
		$trypptdir = $sourcedir .'/'.$dirfoilset;
		unless( -e $trypptdir )	{
			$sourcedir = '/usr/local/archives/public/users/gcf/02/rawfoils';	
			$trypptdir = $sourcedir .'/'.$dirfoilset;
		}
	}
	unless(-e $trypptdir)	{
		$sourcedir = '/usr/local/archives/public/users/gcf/03/rawfoils';
		$trypptdir = $sourcedir .'/'.$dirfoilset;
		unless( -e $trypptdir )	{
			$sourcedir = '/usr/local/archives/public/users/gcf/05/rawfoils';	
			$trypptdir = $sourcedir .'/'.$dirfoilset;
		}
	}
	unless(-e $trypptdir)	{
		print "No powerpoint HTML export file $trypptdir\n";
		next;
	}
#
	($grab) = <$dirfoilset/seporgimagedir/001*>;
	if(defined($grab))	{
		if(-l $grab)	{
			print "File Already Processed $grab\n";
			&doextra();
			next;
		}
	}
	else	{
		print "No file defined $dirfoilset/seporgimagedir/001*\n";
	}
#
	$com = "/home/A11A/gcf/foils/progs/ppttowwwfoil.pl $trypptdir /home/A11A/gcf/foils/$dirfoilset";
	system($com);
	chdir($dirfoilset);
	system('runwwwfoil1');
	chdir($basedir);
	unless(-e $extra)   {
		open(EXTRA,'>'. $extra) || die("\nSorry couldnt Open $extra \n");
		print EXTRA "sourcepptdir:$trypptdir\n";
		close(EXTRA);
	}
#
}
sub doextra	{
#
	$extra = "${dirfoilset}/extrainfo";
	return if(-e $extra);
	unless(-e $trypptdir)   {
                print "No powerpoint HTML export file $trypptdir\n";
                return;
        }
	open(EXTRA,'>'. $extra) || die("\nSorry couldnt Open $extra \n");
        print EXTRA "sourcepptdir:$trypptdir\n";
        close(EXTRA);
	return;
}


