-
Notifications
You must be signed in to change notification settings - Fork 54
/
merge_sfun.py
35 lines (24 loc) · 903 Bytes
/
merge_sfun.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
import os
import re
root = os.path.abspath(__file__)
root = os.path.dirname(root)
internal_include = re.compile(r'#include "(FMI.*|fmi.*)".*')
between_quotes = re.compile(r'"(.*?)"')
included = set()
def open_file(filename):
for folder in ['include', 'src']:
path = os.path.join(root, folder, filename)
if os.path.isfile(path):
return open(path, 'r')
def expand_includes(out, filename):
with open_file(filename) as file:
for line in file.readlines():
if internal_include.match(line):
inc_file = between_quotes.findall(line)[0]
if inc_file not in included:
expand_includes(out, inc_file)
included.add(inc_file)
else:
out.write(line)
with open(os.path.join(root, 'sfun_fmurun.c'), 'w') as sfun:
expand_includes(sfun, 'sfun_fmurun.c')