summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latex-make/figdepth.py
blob: 264af1bb9570452ab5ea655b03a0f375e3bfcaaa (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
#!/usr/bin/env python3
#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 sys

def main():
    parser = optparse.OptionParser()
    (options, args) = parser.parse_args()

    depths_to_keep = set()
    for arg in args:
        depths_to_keep.add(arg)

    comment = ''
    display = True
    def show(depth, line):
        if depth in depths_to_keep:
            print(comment+line, end='')
            return True
        else:
            return False
    for line in sys.stdin:
        if line[0] == '#':
            comment += line
            continue
        if line[0] in "\t ":
            if display:
                print(line, end='')
        else:
            Fld = line.split(' ', 9999)
            if not Fld[0] or Fld[0] not in ('1', '2', '3', '4', '5'):
                print(comment+line, end='')
                display = True
            elif Fld[0] == '4':
                display = show(Fld[3], line)
            else:
                display = show(Fld[6], line)
            comment = ''

if __name__ == "__main__":
    main()