#!perl

# Remove USENET headers and leading message lines leaving only the
# Bourne shell contents themselves from all files FOO listed on the
# command line into FOO.sh files.

foreach $in ( @ARGV ){
	open IN, "<", $in or die "Can't open input file '$in': $!";
	my $out = "$in.sh";
	open OUT,">", $out or die "Can't open output file '$out': $!";
	while(<IN>){
		chomp;
		last if m,^#!\s*/bin/sh,;
	}
	print OUT "$_\n";
	my $reallines = 0;
	my $oops = 0;
	while(<IN>){
		print OUT;
		$reallines++;
		$oops++ if m,^#!\s*/bin/sh,;
	}
	close IN;
	close OUT;
	print "WARNING: found #/bin/sh $oops time(s) in body of $in\n" if($oops);
	print "WARNING: no script lines found in $in\n" unless($reallines);
}
