summaryrefslogtreecommitdiff
path: root/fixupdiff.pl
diff options
context:
space:
mode:
authormstsirkin <mstsirkin@0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652>2016-07-22 21:40:05 +0000
committermstsirkin <mstsirkin@0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652>2016-07-22 21:40:05 +0000
commit713d75d585f3b8c23d7e17202ccf4f3c572e313a (patch)
treeb8b0122e0161d589722ff9b230cd2024427f0494 /fixupdiff.pl
parent87b53c42fc247805e839f14a9afbfab4ad08f894 (diff)
parent2aa7268d2808a2fddd3fd81a1f1ff2abb62d37c7 (diff)
Merge remote-tracking branch 'origin/v1.0'
git-svn-id: https://tools.oasis-open.org/version-control/svn/virtio/trunk@572 0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652
Diffstat (limited to 'fixupdiff.pl')
-rw-r--r--fixupdiff.pl82
1 files changed, 21 insertions, 61 deletions
diff --git a/fixupdiff.pl b/fixupdiff.pl
index e557e2b..f66eaa3 100644
--- a/fixupdiff.pl
+++ b/fixupdiff.pl
@@ -1,76 +1,36 @@
-my $bufferdiff="";
-my $diff="";
-my $buffer="";
+use strict;
+
+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+</{\\lstset{escapechar=\\\$} /;
}
if ($lstlisting) {
$line =~ s/%DIFDELCMD\s+< //;
- if (not $line =~ m/\\(?:begin|end){lstlisting}/) {
+ if (not $line =~ m/\\(?:begin|end)\{lstlisting\}/) {
$line =~ s/([#&{} ])/\\$1/g;
- $line =~ s/(.*)/\$\\DIFdel{$1}\$/;
+ $line =~ s/(.*)/\$\\DIFdel\{$1\}\$/;
}
#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.
+
+ $line =~ s/\\DIFdelbegin \\DIFdel\{([^}]*)\}\\DIFdelend/\\DIFdeltext{$1}/;
+ $line =~ 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;
}