#!/usr/bin/perl -w

use strict;

my %people = ();
my $addr = "";
my @cur = ();
my @sorted = ();

sub append_item() {
	if (!$addr) { return; }
	if (!$people{$addr}) { @{$people{$addr}} = (); }
	push @{$people{$addr}}, [@cur];

	@cur = ();
}

while (<>) {
	# Match address
	if (/^\s*<([^>]+)>/) {
		# Add old item (if any) before beginning new
		append_item();
		$addr = $1;
	} elsif ($addr) {
		# Add line to patch
		# s/^\s*(.*)\s*$/$1/;
		s/^(.*)\s*$/$1/;
		push @cur, "$_\n";
	} else {
		# Header information
		print;
	}
}

sub print_terse_items($) {
	my @items = @{$people{$_[0]}};
	# Vain attempt to sort patches from one address
	@items = sort @items;
	while ($_ = shift @items) {
		# Insert a bullet
		my $line; $line = @$_[0];
		$line =~ s/^(\s*)(.*)$/$1o  $2/;
		print "$line";
	}
}

sub print_items($) {
	my @items = @{$people{$_[0]}};
	# Vain attempt to sort patches from one address
	@items = sort @items;
	while ($_ = shift @items) {
		# Item separator
		print "\t--------------------------------------------------------------\n";
		my $line; foreach $line (@$_) { print "$line"; }
	}
}

append_item();
@sorted = sort keys %people;
print "-- Terse ChangeLog starts here --\n\n";
foreach $addr (@sorted) {
	print "<$addr>\n";
	print_terse_items($addr);
	print "\n";
}
print "-- Full ChangeLog starts here --\n\n";
foreach $addr (@sorted) {
	print "<$addr>\n";
	print_items($addr);
	print "\n";
}

