#!/usr/bin/perl

use Text::Wrap qw(wrap $columns);

$columns=80;

$skip=1;
while(<>){
    if(/^\s+/){
	$comment .= $_ unless $skip;
    }
    else{
	if($file){
	    do_print();
	    $comment="";
	}
	if(/ R (date-stamp|BUGS),/){
	    $skip=1;
	    $file="";
	}
	else{
	    if(/^(.* UTC \d{4}) (.*) (\S+)$/){
		$date = $1;
		$file = $2;
		$author = $3;
		$skip=0;
	    }
	}
    }
}
## Clean up at end:
do_print();


sub do_print {

    $comment =~ s/[\s]*$//s;
    $comment =~ s/\n\s*/\n/sg;
    $file =~ s/\n\s*/\n/sg;

    if($oldcomment eq $comment){
	print wrap("  ", "  ","$file\n");
    }
    else{
	print "\n$date, $author\n";
	print wrap("", "  ", "$comment\n$file\n");
	$oldcomment=$comment;
    }
}