-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.cpp
More file actions
115 lines (97 loc) · 2.76 KB
/
run.cpp
File metadata and controls
115 lines (97 loc) · 2.76 KB
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
#include "inc.h"
#include "utils.h"
#include "macros.h"
ccodes color_codes_rt;
var_struct var_struct_ref_runtime;
controllers controllers_ref_run;
bool silence_arg_control = false;
bool silence_urslt_arg_control = false;
namespace run
{
void execute_directive(const std::string& directive, bool silence_control)
{
int system_res = system(directive.c_str());
// silence control
if (silence_control != true && silence_arg_control != true)
std::cout << color_codes_rt.color_execute_s << str_utils::ltrim(directive)
<< color_codes_rt.color_execute_e << "\n";
// directive result control
if (system_res != 0 && silence_urslt_arg_control == false)
std::cout << color_codes_rt.color_warning_s << RES_ERROR_0 << system_res
<< RES_ERROR_1 << color_codes_rt.color_warning_e << "\n";
}
std::string execute_command_and_return(const char* command)
{
char buffer[256];
FILE* storage;
std::string result;
#ifdef _WIN32
storage = _popen(command, "r");
#else
storage = popen(command, "r");
#endif
while(fgets(buffer, 256, storage) != NULL)
result += buffer;
#ifdef _WIN32
_pclose(storage);
#else
pclose(storage);
#endif
int pos = 0;
while (pos != std::string::npos)
{
pos = result.find('\n', pos);
if (pos == std::string::npos)
break;
result.replace(pos, 1, " ");
pos += 1;
}
return result;
}
bool error_control(const std::string& control_value, const int& error_line, std::string parameter = "")
{
const std::string error_msg_str = color_codes_rt.color_error_s + ERROR_0
+ std::to_string(error_line) + ERROR_1;
const std::string error_msg_end = color_codes_rt.color_error_f + "\n";
if (control_value == ERROR_FILE_NOT_EXISTS)
{
std::cout << error_msg_str << EC000 << error_msg_end;
return true;
}
else if (control_value == ERROR_TARGET_NOT_EXISTS)
{
std::cout << error_msg_str << EC001 << error_msg_end;
std::cout << parameter;
return true;
}
else if (control_value == ERROR_NULL_VAR_NAME)
{
std::cout << error_msg_str << EC00 << error_msg_end;
return true;
}
else if (control_value == ERROR_NULL_VALUE)
{
std::cout << error_msg_str << EC01 << error_msg_end;
return true;
}
else if (control_value == ERROR_VAR_NOT_EXISTS)
{
std::cout << error_msg_str << EC02 << "->" << parameter << error_msg_end;
return true;
}
else if (control_value == ERROR_DEPS_NOT_EXISTS)
{
std::cout << error_msg_str << EC03 << "->" << parameter << error_msg_end;
return true;
}
else if (control_value == ERROR_PATH_O_NOT_EXISTS)
{
std::cout << error_msg_str << EC04 << "->" << parameter << error_msg_end;
return true;
}
else
{
return false;
}
}
}