#!/usr/bin/perl -w

use strict;
my $debug = 0;
my $noout = 0;

sub out {
    return if($noout);
    my $s = shift;
    if   ($debug) { print $s; }
    else          { print F2 $s; }
}

$/ = "=head1";

foreach my $file (@ARGV) {
    my $flag = 0;
    open F, $file or die $file;
    unless ($debug) { open F2, ">$file.n" or die; }
    while (<F>) {
        m/ *(.*)$/m;
        my $chapter = $1;
        if ( $chapter eq 'BUG REPORT' ) {
            out ' BUG REPORT

Use OW2 system to report bug or ask for features:
L<http://jira.ow2.org>

=head1';
        }
        elsif ( $chapter eq 'DOWNLOAD' ) {
            out ' DOWNLOAD

Lemonldap::NG is available at
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>

=head1';
        }
        elsif ( $chapter eq 'SEE ALSO' ) {
            s/(\n|, *)(?!L<)(https?:\/\/\S+|\w+(?:::\w+)*)(?<!>)(?= *\n|, +)/$1L<$2>/sg;
            out $_;
        }
        else {
            out $_;
        }
    }
    close F;
    unless($debug) {
    close F2;
    unlink($file);
    rename( "$file.n", $file );
    }
}

