-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolve_includes.py
More file actions
38 lines (24 loc) · 845 Bytes
/
solve_includes.py
File metadata and controls
38 lines (24 loc) · 845 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
import argparse
import os
parser = argparse.ArgumentParser(description='Include solver')
parser.add_argument("-i", action='store', required=True , help="input file")
parser.add_argument("-o", action='store', required=True , help="output file")
args = parser.parse_args()
in_file = args.i
out_file = args.o
print("Input : ",in_file)
print("Output : ",out_file)
def process(in_file):
buf = ""
ifile = open(in_file ,'r')
for l in ifile.readlines():
if l.startswith("#include"):
path_inc = l.split()[1]
resolved_path = os.path.join(os.path.dirname(in_file), path_inc)
print("include file : ", resolved_path )
buf += process(resolved_path) + "\n"
else:
buf += l
return buf
ofile = open(out_file ,'w')
ofile.write(process(in_file))