#!/usr/bin/perl

# ----------------------------------------------------------------
# John Kerl
# kerl at emtek dot com
# 1996/03
#
# A simple grep operating on paragraphs, not lines.
# ----------------------------------------------------------------

$case="";

while (@ARGV) {
	last unless ($ARGV[0] =~ m/^-/);

	if ($ARGV[0] eq "-i") {
		$case="i";
	}
	else {
		last;
	}
	shift @ARGV;
}

#print "case: $case\n";
#for my $arg (@ARGV) {
#	print "arg: <<$arg>>\n";
#}

die "Usage: $0 {pat} [file names ...]\n" unless @ARGV;

$pat=$ARGV[0];
shift @ARGV;

$/="";
if ($case eq "i") {
	while ($para=<>) {
		if ($para =~ m/$pat/i) {
			print $para;
		}
	}
}
else {
	while ($para=<>) {
		if ($para =~ m/$pat/) {
			print $para;
		}
	}
}
