-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkwcode.cpp
147 lines (145 loc) · 4.72 KB
/
kwcode.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <bits/stdc++.h>
#include <conio.h>
void usage() {
printf("Usage: kwcode <command> [<args>]\n");
printf("\n");
printf("There are all kwcode command used: \n");
printf(" help help information\n");
printf(" version version information\n");
printf(" clear clear all unnecessary files in this directory\n");
printf(" run compile and run a source code\n");
printf(" compile compile a source code\n");
printf("\n");
printf("Type `kwcode help <command>` for more information.\n");
}
void version() {
printf("KwCode version 0.1.5\n");
printf("Copyright WeKw team.\n");
}
void help(std::string str) {}
void clear() {
system("rm -rf *.in /s");
system("rm -rf *.out /s");
system("rm -rf *.gch /s");
system("rm -rf *.exe /s");
system("rm -rf *.ans /s");
system("rm -rf tmp /s");
system("rm -rf tmp* /s");
system("rm -rf *tmp /s");
system("rm -rf *tmp* /s");
system("rm -rf test /s");
system("rm -rf test* /s");
system("rm -rf *test /s");
system("rm -rf *test* /s");
}
std::pair<std::string, std::string> decFileName(std::string x) {
if (x[x.size() - 1] != '.') {
for (int i = x.size() - 2; ~i; --i) {
if (x[i] == '.') {
return std::make_pair(x.substr(0, i), x.substr(i + 1));
}
}
}
return std::make_pair(x, (std::string)(""));
}
void compile(std::string first, std::string seconed) {
if (seconed == (std::string)("cpp")) {
std::string s = (std::string)("g++ -o \"") + (std::string)(first) +
(std::string)("\" \"") + (std::string)(first) +
(std::string)(".cpp\" -lm -O3");
system(s.data());
} else {
printf("\e[33mError: KwCode doesn't support \"%s\" language.\e[0m\n",
seconed.data());
}
}
void run(std::string first, std::string seconed) {
if (seconed == (std::string)("cpp")) {
std::string s = (std::string)("g++ -o \"") + (std::string)(first) +
(std::string)("\" \"") + (std::string)(first) +
(std::string)(".cpp\" -lm -O3");
system(s.data());
printf("Complie is over.\n");
s = '"' + (std::string)(first) + '"';
int c = clock();
std::cout << s << std::endl;
system(s.data());
printf("The program is over in %dms.\n", clock() - c);
while (_kbhit()) {
getchar();
}
printf("Press any key to continue . . .");
_getch();
} else {
printf("\e[31mError: KwCode doesn't support \"%s\" language.\e[0m\n",
seconed.data());
}
}
int main(int n, char* a[]) {
int f = 0;
if (n == 1) {
usage();
return 0;
}
std::string tmp = a[1];
if (tmp == (std::string)("help")) {
if (n == 2) {
usage();
} else if (n == 3) {
help((std::string)(a[2]));
} else {
printf("\e[33mError: Unknown \"%s\" for command \"help\".\e[0m\n",
a[2]);
}
} else if (tmp == (std::string)("version")) {
if (n == 2) {
version();
} else {
printf(
"\e[33mError: Unknown \"%s\" for command \"version\".\e[0m"
"\n",
a[2]);
}
} else if (tmp == (std::string)("clear")) {
if (n == 2) {
clear();
} else {
printf("\e[33mError: Unknown \"%s\" for command \"clear\".\e[0m\n",
a[2]);
}
} else if (tmp == (std::string)("run")) {
if (n == 2) {
printf("\e[33mError: Miss file name.\003[0m\n");
} else if (n == 3) {
std::pair<std::string, std::string> pair =
decFileName((std::string)(a[2]));
run(pair.first, pair.second);
} else {
printf("\e[33mError: Unknown \"%s\" for command \"run\".\e[0m\n",
a[3]);
}
} else if (tmp == (std::string)("compile")) {
if (n == 2) {
printf("\e[33mError: Miss file name.\e[0m\n");
} else if (n == 3) {
std::pair<std::string, std::string> pair = decFileName(a[2]);
compile(pair.first, pair.second);
} else {
printf(
"\e[33mError: Unknown \"%s\" for command \"compile\".\e[0m"
"\n",
a[3]);
}
} else if (tmp == (std::string)("match")) {
if (n < 5) {
printf("\e[33mError: Miss file name.\e[0m\n");
} else if (n == 5) {
} else {
printf(
"\e[33mError: Unknown \"%s\" for command \"match\".\e[0m"
"\n",
a[5]);
}
}
return 0;
}