#! /usr/bin/perl

@newlog = ();
$k = 0;

#Read in the changelog
open (FILE, "<CHANGELOG");
while (<FILE>)
{
	$log[$k] = $_;
	$k++;
}
$k=0;
close (FILE);
$length = @log;
$stop = $length;
$first = 0;
print "$length\n";
for ($i=$length-1; $i>=0; $i--)
{
	($trash, $rest) = split (/\*/, $log[$i], 2);
	($date, $trash) = split (/:/, $rest, 2);
	($rest, $trash) = split (/\./, $date, 2);
	($date, $trash) = split (/\(/, $rest, 2);
	($rest, $trash) = split (/\)/, $date, 2); 

	$_ = $rest;
        if (/^\ [1-9]/)
        {
                $first = 1;
        }
        if ($first == 1)
        {
		invert();
	}
}

#write out the new file
open (FILE, ">CL");
for ($j=0; $j<$k; $j++)
{
	print FILE "$newlog[$j]";
}
close (FILE);

sub invert
{
	print "$i -> ";
	for ($j=$i; $j<$stop; $j++)
	{
		$newlog[$k] = $log[$j];
		$k++;
	}
	$first = 0;
	$stop = $i;
		
}
