From 86bc2422851681264fcb90ee7b12a8abbb06cb70 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 3 Jan 2021 22:32:40 +0000 Subject: latex-make (3jan21) git-svn-id: svn://tug.org/texlive/trunk@57317 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/scripts/latex-make/latexfilter.py | 68 ++++++++++++---------- 1 file changed, 37 insertions(+), 31 deletions(-) (limited to 'Master/texmf-dist/scripts') diff --git a/Master/texmf-dist/scripts/latex-make/latexfilter.py b/Master/texmf-dist/scripts/latex-make/latexfilter.py index 1e94870125d..2fbb14b0248 100755 --- a/Master/texmf-dist/scripts/latex-make/latexfilter.py +++ b/Master/texmf-dist/scripts/latex-make/latexfilter.py @@ -3,9 +3,8 @@ """ -stdin : the original xfig file -stdout : the output xfig file -args : all depths we want to keep +stdin : the original LaTeX log file +stdout : the output filtered log file """ @@ -14,6 +13,7 @@ import optparse import os.path import re import sys +import io def main(): parser = optparse.OptionParser() @@ -25,34 +25,40 @@ def main(): warnerror_re = re.compile(r"^(LaTeX|Package|Class)( (.*))? (Warning:|Error:)") fullbox_re = re.compile(r"^(Underfull|Overfull) \\[hv]box") accu = '' - for line in sys.stdin: - if display > 0: - display -= 1 - if line[0:4].lower() in ('info', 'warn') or line[0:5].lower() == 'error': - display = 0 - line_groups = warnerror_re.match(line) - if line_groups: - start_line = line_groups.group(3) - if not start_line: - start_line = '' - if line_groups.group(2): - start_line = "(" + start_line + ")" - display = 1 - in_display = 1 - elif (start_line != '') and (line[0:len(start_line)] == start_line): - display = 1 - elif line == "\n": - in_display = 0 - elif line[0:4] == 'Chap': - display = 1 - elif fullbox_re.match(line): - display = 2 - if display: - print(accu, end="") - accu = line - elif in_display: - print(accu[0:-1], end="") - accu = line + # PDFLaTeX log file is not really in latin-1 (in T1 more exactly) + # but all bytes are corrects in latin-1, so python won't stop + # while parsing log. + # Without specifying this encoding (ie using default utf-8), we + # can get decode errors (UnicodeDecodeError: 'utf-8' codec can't decode byte...) + with io.open(sys.stdin.fileno(),'r',encoding='latin-1') as sin: + for line in sin: + if display > 0: + display -= 1 + if line[0:4].lower() in ('info', 'warn') or line[0:5].lower() == 'error': + display = 0 + line_groups = warnerror_re.match(line) + if line_groups: + start_line = line_groups.group(3) + if not start_line: + start_line = '' + if line_groups.group(2): + start_line = "(" + start_line + ")" + display = 1 + in_display = 1 + elif (start_line != '') and (line[0:len(start_line)] == start_line): + display = 1 + elif line == "\n": + in_display = 0 + elif line[0:4] == 'Chap': + display = 1 + elif fullbox_re.match(line): + display = 2 + if display: + print(accu, end="") + accu = line + elif in_display: + print(accu[0:-1], end="") + accu = line if __name__ == "__main__": main() -- cgit v1.2.3