#!perl -w

$In = 0;
while(<>)
{
	chomp;

	if(/^\s*$/o)
	{
		# Blank line.  No op.
	}
	elsif(/^\@\@\s*/o)
	{
		# New quote.  Print "header" (aqf - Alan's Quote File)
		print "\naqf,";
		$In = 0;
	}
	elsif(/^\@PARA:/o)
	{
		if($In == 1)	{ print "\\n\\n"; }
		else			{ $In = 1; }

		s/^\@PARA://o;	# Remove paragraph marks
		print DoLine($_);
	}
	elsif(/^\@ATTR:/o)
	{
		print '\n\n';
		s/^\@ATTR:/ -- /o;	# Remove Attribution marks
		print DoLine($_);
	}
	else
	{
		print ' ';
		print DoLine($_);
	}
}

sub DoLine($)
{
	$_ = $_[0];

	s/<DT>/\\n\\n/go;
	s/<DD>/\\n\\n/go;
	s/<P>/\\n\\n/go;	# <P> to blank line
	s/<BR>/\\n/go;	# turn <BR> into carriage return
	s/<[^>]+>//go;	# Strip all remaining HTML
	s/\s+$//go;		# Strip trailing whitespace
	s/&nbsp;/ /go;	# &nbsp; -> ' '
	s/&otilde;/o/go; # otilde -> o

	return $_;
}
