#! /usr/bin/perl

# Flags indicating what we are reading
my $control =0;
my $description = 0;

# Contain the package information from debian/control
my $packageName;
my $packageShortDesc;
my $packageLongDesc;


sub printPackageInfo
{
    my ($name, $short, $long) = @_;
    print "$name: $short\n";
    print "$long\n";
}

while (<>)
{
    # Discard lines after debian/control
    last if ($control && m|^---|);

    # Discard lines before debian/control
    next unless ($control || m|^--- .*/debian/control$|);
    $control = 1;

    # Discard the first character of each line
    s/^.//;

    # Get package name
    if (s/^Package:\s*//)
    {
        chomp;
        $packageName = $_;
    }

    # Print package info at the end
    if ($description && /^[^ ]/)
    {
        $description = 0;
        printPackageInfo ($packageName, $packageShortDesc, $packageLongDesc);
    }

    # Get long description lines
    if ($description)
    {
        $packageLongDesc .= $_;
    }

    # Get short package description
    if (s/^Description:\s*//)
    {
        chomp;
        $packageShortDesc = $_;
        $packageLongDesc = "";
        $description = 1;
    }
}

# Print package info at the end of the control file
printPackageInfo ($packageName, $packageShortDesc, $packageLongDesc)
    if ($description == 1);
