-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader_make.py
51 lines (37 loc) · 1.23 KB
/
header_make.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
import re
import sys
from pathlib import Path
from os import path
def remove_last_occurrence(string, substring):
return ''.join(string.rsplit(substring, 1))
if len(sys.argv) != 2:
print("Not enough parameters.")
sys.exit(0);
source_file = sys.argv[1];
if ("root" in source_file):
sys.exit(0)
source_file_name = path.basename(source_file);
header_file = Path(f'deps/{source_file_name[:-1]}h')
if not path.isfile(header_file):
with open(header_file, 'w') as f:
pass
source_matches = []
with open(source_file, 'r') as f:
for line in f.readlines():
found = re.findall(r'^[^\(\)\t( )]+ [^\(\)]+ *\(.*\) *{? *$', line)
if found:
source_matches.append(remove_last_occurrence(found[0], '{').rstrip())
with open(header_file, 'r') as f:
contents = f.read()
header_file_contents = contents.split('//refs', 1)[0] + '//refs'
header_file_functions = list(map(lambda x: x[:-1],filter(lambda x: x != '', contents.split('//refs', 1)[1].split('\n'))))
if header_file_functions == source_matches:
sys.exit(0)
print("Making headers for " + source_file)
with open(header_file, 'w') as f:
f.write(header_file_contents)
for func in source_matches:
if "// private" in func:
continue;
#print(f"Adding {func}")
f.write('\n'+func+';')