blob: 2fbb14b0248ec61598fc3cba46360cccc6112b0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/env python
#coding=utf8
"""
stdin : the original LaTeX log file
stdout : the output filtered log file
"""
from __future__ import print_function
import optparse
import os.path
import re
import sys
import io
def main():
parser = optparse.OptionParser()
(options, args) = parser.parse_args()
display = 0
in_display = 0
start_line = ''
warnerror_re = re.compile(r"^(LaTeX|Package|Class)( (.*))? (Warning:|Error:)")
fullbox_re = re.compile(r"^(Underfull|Overfull) \\[hv]box")
accu = ''
# 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()
|