-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_newlinech.py
38 lines (34 loc) · 1.4 KB
/
remove_newlinech.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
'''
1. Find .c file under (test) directory
2. Search lines starting with zassert_
3. Find whether newline character is present at the end of line
4. If yes then remove it
5. No. Then line is split in multiple lines. Look for the line ending with ;
and remove new line character if any.
'''
import re,os,shutil
def finddir():
for path, dirs, files in os.walk('./tests/posix/pthread'):
for names in files:
if names.endswith('.c'):
#for line in open(os.path.join(path, names), "rw"):
with open(os.path.join(path, names), 'r') as f:
lines = f.readlines()
f.close()
f = open(os.path.join(path, names), 'w')
flag = 0
for line in lines:
if (re.findall("zassert_", line) or (flag == 1)):
flag =1
xyz = re.search(r'\\n\"\)\;', line)
if xyz:
line = re.sub(r'\\n\"\)\;', r'");', line)
if re.search(";", line):
flag = 0
f.write(line)
f.close()
def main():
print("Hellow wor")
finddir()
if __name__ == "__main__":
main()