Skip to content

Commit a486da4

Browse files
committed
update
1 parent 9356f94 commit a486da4

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

KwCode.exe

1.78 MB
Binary file not shown.

kwcode.cpp

+42-33
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,36 @@ std::pair<std::string, std::string> decFileName(std::string x) {
4646
}
4747
void compile(std::string first, std::string seconed) {
4848
if (seconed == (std::string)("cpp")) {
49-
49+
std::string s = (std::string)("g++ -o \"") + (std::string)(first) +
50+
(std::string)("\" \"") + (std::string)(first) +
51+
(std::string)(".cpp\" -lm -O3");
52+
system(s.data());
5053
} else {
51-
printf("\033[33mError: KwCode doesn't support \"%s\" language.\033[0m\n", seconed);
54+
printf("\e[33mError: KwCode doesn't support \"%s\" language.\e[0m\n",
55+
seconed.data());
5256
}
5357
}
5458
void run(std::string first, std::string seconed) {
55-
59+
if (seconed == (std::string)("cpp")) {
60+
std::string s = (std::string)("g++ -o \"") + (std::string)(first) +
61+
(std::string)("\" \"") + (std::string)(first) +
62+
(std::string)(".cpp\" -lm -O3");
63+
system(s.data());
64+
printf("Complie is over.\n");
65+
s = '"' + (std::string)(first) + '"';
66+
int c = clock();
67+
std::cout << s << std::endl;
68+
system(s.data());
69+
printf("The program is over in %dms.\n", clock() - c);
70+
while (_kbhit()) {
71+
getchar();
72+
}
73+
printf("Press any key to continue . . .");
74+
_getch();
75+
} else {
76+
printf("\e[31mError: KwCode doesn't support \"%s\" language.\e[0m\n",
77+
seconed.data());
78+
}
5679
}
5780
int main(int n, char* a[]) {
5881
int f = 0;
@@ -67,58 +90,44 @@ int main(int n, char* a[]) {
6790
} else if (n == 3) {
6891
help((std::string)(a[2]));
6992
} else {
70-
printf("\033[33mError: Unknown \"%s\" for command \"help\".\033[0m\n", a[2]);
93+
printf("\e[33mError: Unknown \"%s\" for command \"help\".\e[0m\n",
94+
a[2]);
7195
}
7296
} else if (tmp == (std::string)("version")) {
7397
if (n == 2) {
7498
version();
7599
} else {
76-
printf("\033[33mError: Unknown \"%s\" for command \"version\".\033[0m\n", a[2]);
100+
printf("\e[33mError: Unknown \"%s\" for command \"version\".\e[0m"
101+
"\n", a[2]);
77102
}
78103
} else if (tmp == (std::string)("clear")) {
79104
if (n == 2) {
80105
clear();
81106
} else {
82-
printf("\033[33mError: Unknown \"%s\" for command \"clear\".\033[0m\n", a[2]);
107+
printf("\e[33mError: Unknown \"%s\" for command \"clear\".\e[0m\n",
108+
a[2]);
83109
}
84110
} else if (tmp == (std::string)("run")) {
85111
if (n == 2) {
86-
printf("\033[33mError: Miss file name.\003[0m\n");
112+
printf("\e[33mError: Miss file name.\003[0m\n");
87113
} else if (n == 3) {
88-
std::pair<std::string, std::string> pair = decFileName((std::string)(a[2]));
114+
std::pair<std::string, std::string> pair = decFileName((std::string)
115+
(a[2]));
89116
run(pair.first, pair.second);
90117
} else {
91-
printf("\033[33mError: Unknown \"%s\" for command \"run\".\033[0m\n", a[3]);
118+
printf("\e[33mError: Unknown \"%s\" for command \"run\".\e[0m\n",
119+
a[3]);
92120
}
93121
} else if (tmp == (std::string)("compile")) {
94122
if (n == 2) {
95-
printf("\033[33mError: Miss file name.\003[0m\n");
123+
printf("\e[33mError: Miss file name.\003[0m\n");
96124
} else if (n == 3) {
97-
std::pair<std::string, std::string> pair = decFileName((std::string)(a[2]));
125+
std::pair<std::string, std::string> pair =
126+
decFileName((std::string)(a[2]));
98127
compile(pair.first, pair.second);
99128
} else {
100-
printf("\033[33mError: Unknown \"%s\" for command \"compile\".\033[0m\n", a[3]);
101-
}
102-
}
103-
else if (n == 3) {
104-
if (op(a[1], (char*)"run")) {
105-
std::string s = (std::string)"g++ -o " + (std::string)a[2] + (std::string)" " + (std::string)a[2] + (std::string)".cpp -lm -O3";
106-
system(s.data());
107-
printf("Complie is over.\n");
108-
s = (std::string)a[2];
109-
int c = clock();
110-
system(s.data());
111-
printf("The program is over in %dms.\n", clock() - c);
112-
while (_kbhit()) {
113-
getchar();
114-
}
115-
printf("Press any key to continue . . .");
116-
_getch();
117-
return 0;
118-
} else if (op(a[1], (char*)"compile")) {
119-
std::string s = (std::string)"g++ -o " + (std::string)a[2] + (std::string)" " + (std::string)a[2] + (std::string)".cpp -lm -O3";
120-
system(s.data());
121-
return 0;
129+
printf("\e[33mError: Unknown \"%s\" for command \"compile\".\e[0m"
130+
"\n", a[3]);
122131
}
123132
}
124133
return 0;

0 commit comments

Comments
 (0)