#!/usr/bin/perl

my $key = shift or die "Usage: $0 key pattern file";
my $pattern=shift or die "Usage: $0 key pattern file";
my $file=shift or die "Usage: $0 key pattern file";

open(FP, $file) or die "Unable to open $file $@";
while (<FP>) {
    if ($_ =~ /BEGIN-$key/) {
        print "\% Autogenerated by $0 $key $pattern $file\n";
        print "\% Do not modify directly this file, modify $file instead\n";
        $p=1;
        
    } elsif ($_ =~ /END-$key/) {
        exit 0;
    }

    $_ =~ s/Main:/$pattern:/;

    if ($p) {
        print $_;
    }
}
close(FP);
