From cff819e3c64b19873746fdeb4307d3e6f0a66ff2 Mon Sep 17 00:00:00 2001 From: mstsirkin Date: Wed, 21 Oct 2015 14:19:35 +0000 Subject: Revert: makediff: cleanup using begingroup/endgroup This reverts commit commit ef519a86f046d1be22f82f32d845653a850c21dd Author: mstsirkin Date: Thu Jun 26 16:50:13 2014 +0000 makediff: cleanup using begingroup/endgroup This seemed like a good idea originally: replace perl hacks with tex hacks. However adding \begingroup and \endgroup within macros used by latex-diff breaks its assumption that these are low level tex and can be used in arbitrary situations, e.g. cross the boundaries of environments, use mis-matching begin and end instructions (DIFaddbegin with DIFaddendFL), etc. Let's go back to the original work-around: commit b665b3165b454b98c782617e37a128b53b56c89c Author: mstsirkin Date: Thu Jun 26 12:34:38 2014 +0000 work around xetex bug Too many \color directives produce corrupted output and this warning: WARNING ** Color stack overflow. Just ignore. Use script to reduce # of these directives. Signed-off-by: Michael S. Tsirkin git-svn-id: https://tools.oasis-open.org/version-control/svn/virtio/branches/v1.0@545 0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652 --- fixupdiff.pl | 74 ++++++++++++++---------------------------------------------- 1 file changed, 17 insertions(+), 57 deletions(-) (limited to 'fixupdiff.pl') diff --git a/fixupdiff.pl b/fixupdiff.pl index e557e2b..5c82526 100644 --- a/fixupdiff.pl +++ b/fixupdiff.pl @@ -1,6 +1,7 @@ -my $bufferdiff=""; -my $diff=""; -my $buffer=""; +use strict; + +my $lstlisting=0; + while (<>) { my $line = $_; if (m/%DIFDELCMD\s+<\s+\\begin{lstlisting}/) { @@ -15,60 +16,19 @@ while (<>) { } #print "%FIXED BY RULE 1\n"; } - #In section headings, replace begin/end with begin/endFL, - #but be careful in case some tag spills over to the next - #line - if (m/\\(section|subsection|subsubsection|paragraph)/ and m/DIF/) { - my @list = split(/(\\DIF(?:add|del)(?:begin|end)(?:FL)?)/, $line, -1); - #if there's only one tag, don't touch it: - #matching one is on the other line - if ($#list >= 5) { - #if first tag is end, don't touch it - matching - #begin is on the previous line - if ($list[1] =~ m/begin$/) { - $list[1] .= "FL"; - } - #if last tag is begin, don't touch it - matching - #end is on the next line - if ($list[$#list - 1] =~ m/end$/) { - $list[$#list - 1] .= "FL"; - } - } - for (my $i = 3; $i <= $#list - 3; $i += 2) { - if (not $list[$i] =~ m/FL$/) { - $list[$i] .= "FL"; - } - } - $line = join("", @list); - #print "%FIXED BY RULE 2\n"; - } - #detect where we have DIFbegin/end cross - #enumerate/itemize environments and fix up - if (m/\\DIF(?:add|del)(?:begin|end)/) { - my @list = split(/(\\DIF(?:add|del)(?:begin|end)(?:FL)?)/, $line, -1); - $diff = $list[$#list - 1]; - if ($diff =~ m/begin/) { - $diff =~ s/begin/end/; - } else { - $diff = ""; - } - } - if ($diff ne "" and m/\\(?:begin|end){(?:enumerate|itemize)}$/ and not m/\\DIF/) { - $buffer = $line; - $bufferdiff = $diff; - $line = ""; - #print "%BUFFERED BY RULE 3: $bufferdiff\n"; - } - if ($buffer ne "" and $line ne "") { - if (m/^(\\DIF(?:add|del)end(?:FL)?)/ and $bufferdiff ne $1) { - $line =~ s/^(\\DIF(?:add|del)end(?:FL)?)//; - $buffer =~ s/(\\(?:begin|end){(?:enumerate|itemize)})$/$bufferdiff$1/; - #print "%FIXED BY RULE 3: $bufferdiff\n"; - } - print $buffer; - $buffer = ""; - $bufferdiff = ""; - } + + # Too many \color directives (generated by DIFdel/addbegin/end) + # confuse xetex, producing errors: + # WARNING ** Color stack overflow. Just ignore. + # and resulting in corrupted color in output. + # As a work-around, detect cases where it's safe, and replace \color with + # \textcolor. + # As a result, number of \color directives goes does sufficiently + # enough to avoid the overflow error. + + s/\\DIFdelbegin \\DIFdel{([^}]*)}\\DIFdelend/\\DIFdeltext{$1}/; + s/\\DIFaddbegin \\DIFadd{([^}]*)}\\DIFaddend/\\DIFaddtext{$1}/; + print $line; if (m/%DIFDELCMD\s+<\s+\\end{lstlisting}/) { print "}\n"; -- cgit v1.2.3 From 910b3521ddbe18ed8f63c39dfe4d3e88471ee1a1 Mon Sep 17 00:00:00 2001 From: mstsirkin Date: Tue, 16 Feb 2016 17:11:35 +0000 Subject: fixupdiff: update for latest perl Escape {} in regexes to avoid warnings in latest perl. Signed-off-by: Michael S. Tsirkin git-svn-id: https://tools.oasis-open.org/version-control/svn/virtio/branches/v1.0@560 0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652 --- fixupdiff.pl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'fixupdiff.pl') diff --git a/fixupdiff.pl b/fixupdiff.pl index 5c82526..e274d00 100644 --- a/fixupdiff.pl +++ b/fixupdiff.pl @@ -4,15 +4,15 @@ my $lstlisting=0; while (<>) { my $line = $_; - if (m/%DIFDELCMD\s+<\s+\\begin{lstlisting}/) { + if (m/%DIFDELCMD\s+<\s+\\begin\{lstlisting\}/) { $lstlisting=1; $line =~s/%DIFDELCMD\s+) { # As a result, number of \color directives goes does sufficiently # enough to avoid the overflow error. - s/\\DIFdelbegin \\DIFdel{([^}]*)}\\DIFdelend/\\DIFdeltext{$1}/; - s/\\DIFaddbegin \\DIFadd{([^}]*)}\\DIFaddend/\\DIFaddtext{$1}/; + s/\\DIFdelbegin \\DIFdel\{([^}]*)\}\\DIFdelend/\\DIFdeltext{$1}/; + s/\\DIFaddbegin \\DIFadd\{([^}]*)\}\\DIFaddend/\\DIFaddtext{$1}/; print $line; - if (m/%DIFDELCMD\s+<\s+\\end{lstlisting}/) { + if (m/%DIFDELCMD\s+<\s+\\end\{lstlisting\}/) { print "}\n"; $lstlisting=0; } -- cgit v1.2.3 From caaf1f08c8d3082405de562c1b07c1af40fa2330 Mon Sep 17 00:00:00 2001 From: mstsirkin Date: Tue, 16 Feb 2016 17:12:18 +0000 Subject: fixupdiff: actually apply the DIFadd/DIFdel hack looks like recent changes made it inactive: must change $line, not $_. Signed-off-by: Michael S. Tsirkin git-svn-id: https://tools.oasis-open.org/version-control/svn/virtio/branches/v1.0@562 0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652 --- fixupdiff.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fixupdiff.pl') diff --git a/fixupdiff.pl b/fixupdiff.pl index e274d00..f66eaa3 100644 --- a/fixupdiff.pl +++ b/fixupdiff.pl @@ -26,8 +26,8 @@ while (<>) { # As a result, number of \color directives goes does sufficiently # enough to avoid the overflow error. - s/\\DIFdelbegin \\DIFdel\{([^}]*)\}\\DIFdelend/\\DIFdeltext{$1}/; - s/\\DIFaddbegin \\DIFadd\{([^}]*)\}\\DIFaddend/\\DIFaddtext{$1}/; + $line =~ s/\\DIFdelbegin \\DIFdel\{([^}]*)\}\\DIFdelend/\\DIFdeltext{$1}/; + $line =~ s/\\DIFaddbegin \\DIFadd\{([^}]*)\}\\DIFaddend/\\DIFaddtext{$1}/; print $line; if (m/%DIFDELCMD\s+<\s+\\end\{lstlisting\}/) { -- cgit v1.2.3