
undef $/;
while (@ARGV) {
	$filename = shift @ARGV;
	($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
	 $atime,$mtime,$ctime,$blksize,$blocks)
		= stat($filename);

	$bakfile = $filename . ".bak";

	unless (open(IN,$filename)) {
		warn "$0: cannot open $bakfile for reading, $!\n";
		next;
	}
	
	$inputFile=<IN>; #Slurp!

	close IN;

	$_=$inputFile;
#Convert to new legend class location
	s!com.klg.jclass.chart.JCLegend!com.klg.jclass.util.legend.JCLegend!mg;
	s!com.klg.jclass.chart.JCLegendItem!com.klg.jclass.util.legend.JCLegendItem!mg;
	s!com.klg.jclass.chart.JCGridLegend!com.klg.jclass.util.legend.JCGridLegend!mg;
	s!com.klg.jclass.chart.JCMultiColLegend!com.klg.jclass.util.legend.JCMultiColLegend!mg;
#If importing all chart classes, add an import for all legend classes
	s!import com.klg.jclass.chart.\*;!import com.klg.jclass.chart.\*;\nimport com.klg.jclass.util.legend.\*;!mg;

	if($inputFile ne $_) {
		print "File $filename changed, writing to disk\n";
		unless (rename $filename, $bakfile) {
			warn "$0: cannot rename $filename to $bakfile, $!\n";
			next;
		}
		unless (open(OUT,">$filename")) {
			warn "$0: cannot open $filename for writing, $!\n";
			next;
		}
		
		print OUT $_;
		
		close OUT;
		
		chmod 0644,$bakfile;
		system("rm $bakfile");
		chmod $mode,$filename;
		
	}

}

