@@ -46,13 +46,36 @@ std::pair<std::string, std::string> decFileName(std::string x) {
46
46
}
47
47
void compile (std::string first, std::string seconed) {
48
48
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 ());
50
53
} 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 ());
52
56
}
53
57
}
54
58
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
+ }
56
79
}
57
80
int main (int n, char * a[]) {
58
81
int f = 0 ;
@@ -67,58 +90,44 @@ int main(int n, char* a[]) {
67
90
} else if (n == 3 ) {
68
91
help ((std::string)(a[2 ]));
69
92
} 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 ]);
71
95
}
72
96
} else if (tmp == (std::string)(" version" )) {
73
97
if (n == 2 ) {
74
98
version ();
75
99
} 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 ]);
77
102
}
78
103
} else if (tmp == (std::string)(" clear" )) {
79
104
if (n == 2 ) {
80
105
clear ();
81
106
} 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 ]);
83
109
}
84
110
} else if (tmp == (std::string)(" run" )) {
85
111
if (n == 2 ) {
86
- printf (" \033 [33mError: Miss file name.\003 [0m\n " );
112
+ printf (" \e [33mError: Miss file name.\003 [0m\n " );
87
113
} 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 ]));
89
116
run (pair.first , pair.second );
90
117
} 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 ]);
92
120
}
93
121
} else if (tmp == (std::string)(" compile" )) {
94
122
if (n == 2 ) {
95
- printf (" \033 [33mError: Miss file name.\003 [0m\n " );
123
+ printf (" \e [33mError: Miss file name.\003 [0m\n " );
96
124
} 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 ]));
98
127
compile (pair.first , pair.second );
99
128
} 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 ]);
122
131
}
123
132
}
124
133
return 0 ;
0 commit comments