#!/opt/local/bin/perl

$pre = 0;

while (<>) {
    if (!$pre) {
	if (m#<pre>\s*$#) {
	    $pre = 1;
	}
	    print $_;
    } else {
	if (m#</pre>#) {
	    print $_;
	    $pre = 0;
	} else {
	    chomp;
	    $pref = '  ';
	    $head = undef;
	    $tail = $_;
	    
	    while ($tail) {
		if ($tail =~ m#^(.{1,70}\s*)(\&lt;[^/].*)?$#)
		{
		    $ws = '';
		    $head = $1;
		    $tail = $2;
		}
		elsif ($tail =~ m#^(.{1,70}\&gt;\s*)(.*)?$#)
		{
		    $ws = '';
		    $head = $1;
		    $tail = $2;
		}
		elsif ($tail =~ m#^(\s*)(.{1,70}\s*)(\s.*)?$#)
		{
		    $ws = $1;
		    $head = $2;
		    $tail = $3;
		}
		elsif ($tail =~ m#^(.+?(\&gt;\s*|\s+))(.*)?$#)
		{
		    $ws = '';
		    $head = $1;
		    $tail = $3;
		}
		else
		{
		    $ws = '';
		    $head = $tail;
		    $tail = '';
		}
		
		if ($tail) {
		    print $pref, $ws, $head, "\\\n";
		} else {
		    print $pref, $ws, $head, "\n";
		}
		$pref = "+ "
	    }
	}
    }
}
