#! /usr/bin/perl
use warnings;
use strict;
use integer;
use FindBin;
use lib $FindBin::RealBin;
use Def;
use Alpha;

# This helper script sorts and checks the maint.txt file.  It acts as a
# filter, accepting the old maint.txt on stdin, printing the new
# maint.txt on stdout.

my $pat_mnstd = qr/^.{1,${Def::n_init}} .{1,${Def::n_last}}$/;

$/ = '';
my %mnlong; # long-form maintainer names
my %mnstd ; # debram-standard short-form maintainer names
while ( <> ) {
    my @c = grep { /\S/ } split '\n';
    my $mnstd = shift @c;
    $mnstd =~ $pat_mnstd or die "$0: bad std maint name $mnstd\n";
    $mnstd{$mnstd} and die "$0: std maint name $mnstd given twice\n";
    for ( @c ) {
        defined $mnlong{$_}
            and die "$0: long maint name $_ given twice\n";
        $mnlong{$_} = $mnstd;
    }
    $mnstd{$mnstd} = [ sort @c ];
} <>;
for my $mnstd ( sort { Alpha::cmp_std_mn $a, $b } keys %mnstd ) {
    print "$mnstd\n";
    print "$_\n" for @{ $mnstd{$mnstd} };
    print "\n";
}

