#!/usr/bin/perl -w
# Small script to pipe commit messages through
# that will (hopefully) return a given ports
# COMMENT line.
# $Id: fetch_info.pl,v 1.3 2005/07/22 12:08:23 mich Exp $

my $port;
my $info;

while (<>) {
    if (m/^Subject: cvs commit: ports\/[a-z]+\/[a-z0-9\W]+/) {
        ($port) = /(ports\/[a-z]+\/[-\.a-z0-9]+)/i;
        $port = "/usr/" . $port . "/Makefile";
        if ( ( -e $port ) && ( -r $port ) ) {
            open( FD, $port ) or die("Could not open: $port: $!\n");
            foreach $line (<FD>) {
                chomp($line);
                if ( $line =~ m/COMMENT/ ) {
                    $line =~ s/^COMMENT\?=\s+//g;
                    $line =~ s/^COMMENT=\s+//g;
                    $info = $line;
                }
            }
            close(FD);
        }
        else {
            $info = "No such file";
        }
    }
}
$info = "No comment available." if ( !defined($info) );

print $info. "\n";
