Blame view

NKJP/postProcessing/fixForms.py 511 Bytes
Jan Lupa authored
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
import sys

def indent(l: str) -> int:
	i = 0
	while l[i] == '\t': i += 2
	return i / 2

if __name__ == '__main__':
	with open(sys.argv[1]) as i:
		ab = None
		readNext = False
		for l in i:
			outL = l
			if readNext:
				ab = l
				readNext = False
			elif indent(l) == 1:
				readNext = True
			elif indent(l) == 3:
				split = l.split('; ')
				beg = int(split[1])
				end = beg + int(split[2])
				if ab[beg:end] != split[3]:
					split[3] = ab[beg:end]
					outL = '; '.join(split)
			print(outL, end='')