#!/usr/bin/perl

$current_file = "";
$current_log_msg = "";
$date = "";
%LOGS = ();
%FILES = ();
%AUTHOR = ();

# 0 = cruising through garbage
# 1 = accumulating log message
$state = 0;

while ( <> ) {
    if ( m/^RCS file: / ) {
        # snag current file name
        chomp;
        $current_file = $_;
        $current_file =~ s/^RCS file: //;
        $current_file =~ s/,v$//;
        $state = 0;
        # print "$current_file\n";
    } elsif ( m/total revisions:/ && m/selected revisions:/ ) {
        # snag number of revisions (log messages)
        ($junk, $junk, $junk, $junk, $junk, $revs ) = split();
        # print "revisions = $revs\n";
    } elsif ( m/^----------------------------$/ ) {
        # if there are log messages, parse/save them
        &store_log_msg();

        $state = 1;

        $revnum = <>;
        # print "1 $revnum";
        $dateline = <>;
        # print "2 $dateline";
        ($junk, $year, $time, $junk, $junk, $author) = split(/\s+/, $dateline);
        $date = "$year\_$time";
        $author =~ s/\;$//;
        # print "3 $date\n";
    } elsif ( m/^=============================================================================$/ ) {
        # end of information for this file
        &store_log_msg();
        $state = 0;
    } elsif ( $state == 1 ) {
        # accumulate log message
        $current_log_msg .= $_;
    }

}


# dump log messages.
foreach $key (sort (keys %LOGS)) {
    print "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
    print "$key (" . $AUTHOR{$key} . ")\n";
    print "$FILES{$key}";
    print "\n";
    print "$LOGS{$key}";
    print "\n\n";
}

print "2f585eeea02e2c79d7b1d8c4963bae2d\n";


# store individual log messages in a hash by date
sub store_log_msg {
    if ( $date ne "" ) {
        # print "=-=-=-=\n";
        # print "$current_log_msg";
        # print "=-=-=-=\n";
        $LOGS{"$date"} = $current_log_msg;
        $FILES{"$date"} .= "$current_file\n";
        $AUTHOR{"$date"} = $author;
        $date = "";
        $current_log_msg = "";
    }
}

