#!/usr/local/bin/perl
#
# Split monolithic Foundry MIB into multiple files.
# Net-SNMP doesn't handle multiple modules in a single
# file well (it can do it, but you have to create the
# index yourself instead of letting it do it).
#
# This is a copy of split-extreme tailored for foundry
#
my $filename = undef;
while (<>) {
	if (/^(.*-MIB).*BEGIN/) {
		# Some files end in .mib others don't.  It's too difficult to rename
		# since most users simply untar over last version creating the
		# potential for duplicate modules.
		$filename = uc($1);
		if ($filename =~ /^FOUNDRY/) {
			open(OUT, ">${filename}.mib");
		}
		else {
		    open(OUT, ">${filename}");
		}
	}
	if (!defined($filename)) {
		$between .= $_;
		next;
	}
	print OUT;
	if (/^\s*END\s*$/) {
		$filename = undef;
	}
}
