-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectCPP2OneFile.py
49 lines (40 loc) · 970 Bytes
/
projectCPP2OneFile.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
import sys
import os
import re
if len(sys.argv) != 2:
print('Erreur : nombre d\'arguments incorrect', file=sys.stderr)
quit()
filesIncluded = []
def getNameIncludedFile(line):
line = str(line)
i = 10
l = []
while line[i] != "\"" :
l.append(line[i])
i += 1
return "".join(l)
def printFile(nomFile):
#Ouverture
nomFile = os.path.abspath(nomFile)
if nomFile in filesIncluded:
return
#print(nomFile)
filesIncluded.append(nomFile)
file = open(nomFile,"r")
#On se place dans le répertoire du fichier
os.chdir(os.path.dirname(nomFile))
content = file.read().split('\n')
for line in content:
if line.strip() == "#pragma once":
continue
#line = line.strip()
if re.match(r"\#include \".+\"",line.strip()) != None:
includedFile = getNameIncludedFile(line)
printFile(os.path.abspath(includedFile))
os.chdir(os.path.dirname(nomFile))
print("")
continue
print(line)
#Fermeture du fichier
file.close()
printFile(sys.argv[1])