-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.py
96 lines (73 loc) · 2.39 KB
/
process.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# !/usr/bin/python3
# -*- coding: utf-8 -*-
# > Author : lunar
# > Email : lunar_ubuntu@qq.com
# > Created Time : Wed 08 Dec 2021 04:17:10 PM CST
# > Location : Shanghai
# > Copyright@ https://github.com/xiaoqixian
def rm_win32(path, output_path):
f = open(path, "r")
out = open(output_path, "w")
enter = False
count = 0
lin_num = 1
line = f.readline()
while len(line) != 0:
if line.startswith("#ifdef _WIN32"):
enter = True
count += 1
elif enter and line.startswith("#ifdef"):
count += 1
elif enter and line.startswith("#if"):
count += 1
elif enter and line.startswith("#else"):
if count == 1:
enter = False
elif count > 0 and line.startswith("#endif"):
if enter and count > 1:
count -= 1
elif count == 1:
count -= 1
enter = False
assert count >= 0, "invalid count: %d" % lin_num
elif not enter:
out.write(line)
line = f.readline()
# print("%d lines" % lin_num)
lin_num += 1
def add_space(path, output_path):
f = open(path, 'r')
out = open(output_path, 'w')
line = f.readline()
while len(line) != 0:
if line.startswith("#ifdef") or line.startswith("#ifndef"):
out.write("\n" + line)
elif line.startswith("#endif") or line.startswith("#else"):
out.write(line + "\n")
else:
out.write(line)
line = f.readline()
def add_comment(path, output_path):
f = open(path, 'r')
out = open(output_path, 'w')
stack = []
count = 1
line = f.readline()
while len(line) != 0:
if line.startswith("#ifdef") or line.startswith("#ifndef") or line.startswith("#if"):
out.write(line)
temp = line.split(" ")
temp[-1] = temp[-1][:-1]
stack.append(temp[1:])
elif line.startswith("#else"):
out.write(line[:-1] + " /*" + " ".join(stack[-1]) + "*/\n")
elif line.startswith("#endif"):
out.write(line[:-1] + " /*" + " ".join(stack[-1]) + "*/\n")
stack.pop()
else:
out.write(line)
print("%d lines" % count)
line = f.readline()
count += 1
if __name__ == "__main__":
rm_win32("mdb.c", "mdb_cp3.c")