#!/usr/bin/perl

$outdir = $ARGV[0];
die "usage:\n$0 <output directory>\n" if !$outdir;
die "Output directory: No directory there!\n" if ! -d $outdir;
open(OUTFILE, ">/dev/null") or die "Unable to redirect output to /dev/null\n";

while (<STDIN>) {
	if (/^Index:\s+(.*)/) {
		my $outfile = "patch-$1";
		$outfile =~ s|/|::|g;
		$outfile = "$outdir/$outfile";
		$outfile =~ s|/+|/|g;
		print "Busting to $outfile\n";
		open(OUTFILE, ">$outfile") or
			die "Unable to open \"$outfile\" for output\n";
	}
	print OUTFILE $_;
}
close OUTFILE;
