#!/pro/bin/perl

use strict;
use warnings;

my %key;

my $section = "";
open my $ini, "<", "Merijn-850.ini" or die "$!\n";
while (<$ini>) {
    m/^\s*([;#]|\s+$)/	and next;

    if (m/^\[(.*)\]\s*$/) {
	$section = $1;
	next;
	}

    m/^(.*?)\s*=\s*(.*)/ or next;

    my ($desc, $base, @mods) = ($2, split m/\s+/, $1);
    push @{$key{lc $base}}, [ $base, lc "@mods", $section, $desc ];
    }

my $letter = lc shift or die "usage: $0 letter [mod]\n";
my $modif  = lc shift // "";

my @kb = @{$key{$letter}} or exit;
foreach my $k (sort { $a->[2] cmp $b->[2]
		   || $a->[0] cmp $b->[0]
                   || $a->[1] cmp $b->[1]
                   } @kb) {
    my ($base, $mods, $sect, $desc) = @$k;
    printf "%-25s = [ %-14s ] %s\n", "$base $mods", $sect, $desc;
    }
