#!@@PERL@@ -n
#
#	This script is part of rtfdtohtml.
#	Copyright (c) 1996  Elmar Ludwig - Universitaet Osnabrueck
#
#	Avoid bugs in rtftohtml-2.7.5 (\b...\i...\i0...\b0 does not work).
#	Note: This may become obsolete one day.

$out = '';

while (/\\(pard|b[01]?|i[01]?|up[01]?|dn[01]?|nosupersub)(\W)/)
{
    $tag = $1;

    if (substr($`, -1) ne '\\')
    {
	if ($tag eq 'nosupersub')
	{
	    $tag = 'up0';
	}
	elsif ($tag eq 'b' || $tag eq 'b1')
	{
	    $b = 'YES';
	}
	elsif ($tag eq 'b0')
	{
	    $b = '';
	}
	elsif ($tag eq 'i' || $tag eq 'i1')
	{
	    $i = 'YES';
	}
	elsif ($tag eq 'i0')
	{
	    $i = '';
	    $b && ($tag .= '\\b0\\b');
	}
	elsif ($tag eq 'up' || $tag eq 'up1')
	{
	    $up = 'YES';
	}
	elsif ($tag eq 'up0')
	{
	    $up = '';
	    $i && ($tag .= '\\i0\\i');
	    $b && ($tag .= '\\b0\\b');
	}
	elsif ($tag eq 'dn' || $tag eq 'dn1')
	{
	    $dn = 'YES';
	}
	elsif ($tag eq 'dn0')
	{
	    $dn = '';
	    $i && ($tag .= '\\i0\\i');
	    $b && ($tag .= '\\b0\\b');
	}
	else
	{
	    $i && ($tag .= '\\i0\\i');
	    $b && ($tag .= '\\b0\\b');
	}
    }
    $out .= "$`\\$tag";
    $_ = $2 . $';
}

print $out . $_;
