#!/usr/bin/perl -n
#
# This script is put in the public domain by Henrik Nordström
# <hno@squid-cache.org>. It 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.
#
# If you find this script useful then you are encouraged to send feedback
# to the author, but you have absolutely no obligation to do so.
#
# Author:
#   Henrik Nordström <hno@squid-cache.org>
#   http://hem.passagen.se/hno/
#
# Distribution URL:
#   http://devel.squid-cache.org/CVS.html
#
# Version history:
#   2001-09-25	First public domain release
#
BEGIN { 
    use constant STATE_BEGIN    => 0;
    use constant STATE_HEAD    => 1;
    use constant STATE_BLOCK   => 2;
    use constant STATE_USEFUL  => 3;
    use constant STATE_IGNORE  => 4;
    $state = STATE_BEGIN;

    sub new_block {
	if ($state == STATE_USEFUL) {
	    print $head;
	    $head = "";
	    print $block;
	}
	$block="";
	$state = STATE_BLOCK;
    }
}

next if /^Only in /;

if (0) {
print "------------------------\n";
print "state = $state\n";
print "head = $head\n";
print "block = $block\n";
print "------------------------\n";
}

if ($state != STATE_HEAD && /^[^-+ @]/) {
    new_block;
    $head = "";
    $state = STATE_HEAD;
#   $state = STATE_IGNORE if m%/configure$%;
    $state = STATE_IGNORE if m%/CVS/%;
}

if ($state == STATE_HEAD) {
    $_ = "+++ /dev/null		Thu Jan  1 01:00:00 1970\n" if m%^\+\+\+ /dev/null%;
    $_ = "--- /dev/null		Thu Jan  1 01:00:00 1970\n" if m%^\-\-\- /dev/null%;
}

next if $state == STATE_IGNORE;

&new_block, if /^@@ /;

$head .= $_, next if $state == STATE_HEAD;

$block .= $_;

next if /\$Id[:\$]/;
next if /\$Revision[:$\]/;
next if / Revision: /;
next if / version /;
next if /#line [0-9]+ "configure/;
next if /\bconfigure:[0-9]+: /;

$state = STATE_USEFUL if /^[-+]/;

END { &new_block; }