@rem = '--*-Perl-*--
@echo off

if not "%1" == "" goto Execute
cmd /K setup.bat TkPlot.pl TkPlot
goto EndOfPerl

:Execute
@echo on
rem for perl 5.10

call ppm install Tk
call ppm install Math-Matrix
call ppm install Math-MatrixReal
rem call ppm install Jcode
call cpan Jcode
rem YAML: Version problem for Ver 5.10
call cpan YAML
rem === Clear: SemiconductorParamters.pl Launcher.pl TkEditor.pl

ppm install Math-Amoeba
cpan PDL

rem call ppm install http://www.bribes.org/perl/ppm/OpenGL.ppd 

perl -x -S %0 %*

goto EndOfPerl

#!/usr/bin/perl -w
#line 21

use strict;
use Cwd;

my $BaseDir = cwd();
$BaseDir =~ s/\/[^\/]*$//;
#print "Base directory: $BaseDir\n";
my $BatchDir = $0;
if($BatchDir) {
	$BatchDir =~ s/\\/\//g;
	($BatchDir) = ($BatchDir =~ /^(.*)[\/\\].*?$/);
	if($BatchDir) {
		($BatchDir) = ($BatchDir =~ /^(.*)[\/\\].*?$/);
	}
	#print "Batch directory: $BatchDir\n";
}
my $outfile = "$BaseDir/TkPlot/$ARGV[0]";
if(!-e $outfile and $BatchDir) {
	$BaseDir = $BatchDir;
	$outfile = "$BatchDir/TkPlot/$ARGV[0]";
}
if(-e $outfile) {
	print "Base directory: $BaseDir\n";
	print "Script path: $outfile\n";
}
else {
	print "$ARGV[0] not found.\n";
	exit 1;
}

my $AppDir  = $ARGV[1];
$AppDir = 'TkPlot' unless($AppDir);
unless($outfile) {
	print "Error: Perl Script Name is not specified.\n";
	exit 1;
}
my $infile = $outfile . ".prev";
unlink($infile);
unless(rename($outfile, $infile)) {
	print "Error: Could not rename [$outfile] to [$infile].\n";
	exit 1;
}

open(IN,  "<$infile") or die "Error: $!\n";
open(OUT, ">$outfile") or die "Error: $!\n";
while(<IN>) {
#print "line: $_";
	if(/^#Start:\s*use\s/i) {
#print "Start in\n";
		print OUT;
		print OUT "use lib \"$BaseDir/lib\";\n";
		print OUT "use lib \"$BaseDir/$AppDir\";\n";
		while(<IN>) {
#print "line2: $_";
			if(/^#End:\s*use\s/i) {
#print "End out\n";
				print OUT;
				last;
			}
		}
	}
	else {
		print OUT;
	}
}
close(OUT);
close(IN);

print "$outfile updated.\n";

exit;

__END__

:EndOfPerl
