($in) = @ARGV;
die "Missing input file name.\n" unless $in;
open(IN, "< $in") or die "can't open $in: $!\n";
$EXT=".DDS
";
$EXT2=".TXT";
binmode(IN);
$Indexes = $in.$EXT2;
open(IND, "> $Indexes") or die("Couldn't open $Indexes\n") ;
binmode(IND);
$MyFileLength = (-s IN);
read (IN,$b,$MyFileLength,0) or die "can't read $MyFileLength bytes.\n";
$check = 1;
while ($check > 0)
{

$check = index($b, DDS,$offset);
($Size1, $Blank1, $Size2, $Blank2)= unpack "SSSS", substr $b, $check + 12,255;
$DDS = (128 + ($Size1 * $Size2));
print IND "Offset = $check \n";
print IND "Size1 = $Size1\n";
print IND "Size2 = $Size2\n";
print IND "FileSize = $DDS\n";
close(IN);
open(IN, "< $in") or die "can't open $in: $!\n";
binmode(IN);
seek IN, $check, SEEK_SET or die "can't seek to $check.\n";
read (IN,$c,$DDS,0) or die "can't read $MyFileLength bytes.\n";
$offset = ($check + 1);
$NewFile= $check.$EXT;
open(OUT, "> $NewFile") or die "can't open $NewFile: $!\n";
binmode(OUT);
print OUT $c;
} 

close(IN);
close(OUT);
close(IND); 
