#! perl -w
die unless defined $ARGV[0];

while(<STDIN>){
    next if /^\s*--/;
    next if /^\s*$/;
    s/^\s*constraints:/ /;
    s/,$//;
    next if /^\s+(\S+)\s+installed\s*$/;
    die unless /^\s+(\S+)\s+==(\S+)\s*$/;
    die if defined$z{$1}; # repeat
    $z{$1}=$2;
}

if($ARGV[0]eq'rest') {
    for(sort keys%z){
        &outpackage($_);
    }
} elsif($ARGV[0]eq'config'){
    for(sort keys%z){
        print "constraint: $_ == $z{$_}\n"
    }
} else {
    die;
}
sub outpackage {
    my $p=shift;
    print "$p-$z{$p}\n";
}
