-
Notifications
You must be signed in to change notification settings - Fork 1
/
cxlc.py
100 lines (78 loc) · 2.02 KB
/
cxlc.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
import os
import sys
import re
import random
argv = sys.argv
libd = os.environ['HOME'] + "/cxl"
if (len(argv) == 1):
print(argv[0] + ": \033[1;37mError:\033[1;31m No input file passed\033[0m")
sys.exit(1)
filename = re.sub("\\..*", "", argv[1])
code = []
tp_file = []
if (argv[1] != "--moo"):
with open(argv[1], 'r') as f:
str_w = f.readlines()
else:
with open(libd + '/lib/cow/config.txt', 'r') as f:
ch = f.readlines()
item = random.choice(ch)
print(item)
print(" \\ ^__^\n \\ (oo)\\_______\n (__)\\ )N\n ||----w |\n || ||\n")
sys.exit(0)
for i in str_w:
if (i.startswith("use")):
module = i.replace("use@", "")
f_module = module.replace("\n", "")
tp_file.append(i.replace(f_module, "").replace("use@", "#include \"" + f_module + ".cxlbund/" + f_module + ".h").replace("\n", "\"\n"))
else:
code.append(i)
with open(argv[1], 'w') as f:
for i in tp_file:
f.write(i)
for i in code:
f.write(i)
compre = "g++ "
whatf = []
for i in str_w:
if (i.startswith("use")):
module = i.replace("use@", "")
whatf.append(module.strip())
"""
move
"""
for i in whatf:
os.system("cp -r " + libd + "/lib/" + i + ".cxlbund .")
compre += "-x c++ " + i + ".cxlbund/" + i + ".c* "
compre += "-x c++ " + argv[1] + " -o " + filename
print(compre)
os.system(compre + " -std=c++17")
"""
change back
"""
includes = []
includes_rep = []
code_w = []
incs_raw = []
with open(argv[1], 'r') as f:
w_ph = f.readlines()
for i in w_ph:
if (i.startswith("#include")):
inc_ = i.replace("#include \"", "").replace("\"", "")
inc = re.sub(".cxlbund.*", "", inc_)
includes.append("use@" + inc)
incs_raw.append(inc.strip())
else:
code_w.append(i)
with open(argv[1], 'w') as f:
for i in includes:
f.write(i)
for i in code_w:
f.write(i)
"""
destroy local cxlbunds
"""
for i in incs_raw:
os.system("chmod -R +w " + i + ".cxlbund")
os.system("rm -r " + i + ".cxlbund")