#!/usr/local/bin/perl -w 

# Scans file for lines like:
# +++ cityhand.c  1999/01/08 00:45:26
# and replaces filename (here cityhand.c) with the name from
# the previous line like:
# Index: server/cityhand.c

# Filters stdin to stdout (maybe should use -p instead?)
# Filenames should not contain spaces!

$index = undef;

while(<>) {
    if( /^Index: (.*)/ ) {
	$index = $1;
	#print STDERR "index $index\n";
    } elsif( /^\+\+\+ \S+\s/ ) {
	#print STDERR "found";
	if( !defined($index) ) {
	    warn "+++ line before Index line?";
	} else {
	    s/^(\+\+\+ )(\S+)/$1$index/;
	}
    }
    print;
}
