#!/usr/bin/perl -w

my $indent;
my $f = shift;
open (FILE, $f) or die "Can't open file $f: $!\n";

LINE: while (<FILE>)
{
	chomp;
	s/\x0d//; # I had ^M here, but lots of things didn't like it
	next LINE if /^\x1a/; #^Z = deleted line
	if (/^\.HEAD (\d) ([+-])  (.+)/g)
	{
		if ($2 eq "-") 
		{
			$indent = "\t" x ($1 - 1);
			printf $indent . "| ";
		}
		else
		{
			$indent = "\t" x $1;
			printf $indent;
		}
		print $3 . "\n";
	}
	else
	{
		print $indent . "| " . $_ ."\n";
	}
}
