forked from FrankBoesing/Arduino-Teensy-Codec-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixinclude.py
More file actions
executable file
·39 lines (34 loc) · 744 Bytes
/
Copy pathfixinclude.py
File metadata and controls
executable file
·39 lines (34 loc) · 744 Bytes
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
#!/usr/bin/python3
import sys
import re
from pathlib import Path
import os
cfiles = []
hfiles = []
d = Path(sys.argv[1]).resolve()
for path in d.rglob('*.c'):
cfiles += [path]
for path in d.rglob('*.h'):
hfiles += [path]
print(cfiles)
print(hfiles)
for fn in cfiles + hfiles:
print(fn)
pd = fn.parent
lines = open(fn).readlines()
f = open(fn, "w")
for line in lines:
m = re.match('# *include *("|<)([^">]*)("|>)', line)
if m:
hname = Path(m.group(2)).name
found = False
for hf in hfiles:
if hname == hf.name:
assert not found
found = True
print("",os.path.relpath(hf, pd))
f.write('#include "' + os.path.relpath(hf, pd) + '"\n')
if not found:
f.write(line)
else:
f.write(line)