summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latex-make/latexfilter.py
blob: 1e94870125d698f3779af58da94301c15f72b0c1 (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
#!/usr/bin/env python
#coding=utf8

"""

stdin : the original xfig file
stdout : the output xfig file
args : all depths we want to keep

"""

from __future__ import print_function
import optparse
import os.path
import re
import sys

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 = ''
    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

if __name__ == "__main__":
    main()