Newer
Older
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
#!/usr/bin/env python3
import sys
txt = sys.stdin.read()
data = txt.split("\n")
# Check if we're if0
is_comment = False
for l in data:
l_strip = l.strip()
if l_strip:
if l_strip.startswith("#if 0"):
is_comment = True
else:
is_comment = False
break
if is_comment:
pop_a = None
pop_b = None
for i, l in enumerate(data):
l_strip = l.strip()
if pop_a is None:
if l_strip.startswith("#if 0"):
pop_a = i
if l_strip.startswith("#endif"):
pop_b = i
if pop_a is not None and pop_b is not None:
del data[pop_b]
del data[pop_a]
else:
data = ["\n#if 0"] + data + ["#endif\n"]
print("\n".join(data), end="")