eval '(exit $?0)' && eval '[ -f /usr/local/bin/perl ] && exec /usr/local/bin/perl -S $0 ${1+"$@"}; exec perl -S $0 ${1+"$@"};'
& eval 'if ( -f /usr/local/bin/perl ) exec /usr/local/bin/perl -S $0 $argv:q ; exec perl -S $0 $argv:q'
     if 0;

#  Gerald Pani
#
#
#  installHeader.pl
#
# $Id: hgInstallHeader,v 1.1 1995/11/28 13:18:50 root Exp $
#
# $Log: hgInstallHeader,v $
# Revision 1.1  1995/11/28 13:18:50  root
# Initial revision
#
#

$path = '';
$src = '';
$dst  = '';

{
    local($arg);
    while ($arg = shift) {
	if ($arg =~ /^-p$/) {
	    if (($arg = shift) && (!($arg =~ /^-/))) {
		$path = $arg;
		next;
	    }
	    else {
		die &Usage();
	    }
	}
	elsif ($arg =~ /^-s$/) {
	    if (($arg = shift) && (!($arg =~ /^-/))) {
		$src = $arg;
		next;
	    }
	    else {
		die &Usage();
	    }
	}
	elsif ($arg =~ /^-d$/) {
	    if (($arg = shift) && (!($arg =~ /^-/))) {
		$dst = $arg;
		next;
	    }
	    else {
		die &Usage();
	    }
	}
	die &Usage();
    }
}

die &Usage() if (!$path || !$dst || !$src);

$stime = (stat($src))[9];
$dtime = (stat($dst))[9];

exit(0) if ($stime <= $dtime);

open(SRC, "< $src") || die "open $src:$!\n";

rename($dst, "$dst.old");

open(DST, "> $dst") || die "create $dst:$!\n";


while(<SRC>) {
    /^(\#\s*include\s+)\"([^\/]\S+)\"(.*)/ && (print(DST "$1<$path/$2>$3\n"), next);
    print DST;
}

close(SRC);
close(DST);

chmod( 0444, $dst) || die "chmod $dst:$!\n";

exit(0);
