#!/usr/bin/perl -w

#
# podprune
# $Id: podprune,v 1.2 1999/09/14 04:29:50 johnh Exp $
#
# Copyright (C) 1999 by John Heidemann
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#



sub usage {
    print STDERR <<END;
usage: $0 [-k] sections

Omit (or keep with -k) the given sections of a pod file
which is read from standard input.
END
    exit 1;
}

use strict;

use Getopt::Long;
&usage if ($#ARGV >= 0 && $ARGV[0] eq '-?');
my(%opts);
&GetOptions(\%opts, qw(k));
&usage if ($#ARGV < 0);

my(%omit, %keep);
my($default_status) = !defined($opts{'k'});
my($section, $kept) = ("", "");

foreach (@ARGV) {
    if ($default_status) {
	$omit{lc($_)} = 1;
    } else {
	$keep{lc($_)} = 1;
    };
};

sub handle {
    if (defined($keep{$section}) || (!defined($omit{$section}) && $default_status)) {
	print $kept;
    };
}

while (<STDIN>) {
    if (/^=head1\s+(.*)$/) {
	&handle;
	$section = lc($1);
	$kept = $_;
    } else {
	$kept .= $_;
    };
};

&handle;

exit 0;

