-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
191 lines (180 loc) · 5.92 KB
/
utils.h
File metadata and controls
191 lines (180 loc) · 5.92 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <windows.h>
#include <direct.h> // _getcwd
#include <processthreadsapi.h> // PROCESS_INFORMATION
#include <handleapi.h> // CloseHandle
#include <bits/stdc++.h>
using namespace std;
string trim(const string &s)
{
auto start = s.begin();
while (start != s.end() && isspace(*start))
{
start++;
}
auto end = s.end();
do
{
end--;
}
while (distance(start, end) > 0 && isspace(*end));
return string(start, end + 1);
}
vector<string> getArg(string line)
{
const string TOKEN_DELIMETERS = " \t";
vector<string> tokens;
size_t position = 0;
bool in_quotes = false;
string current_token = "";
while (position != string::npos)
{
position = line.find_first_not_of(TOKEN_DELIMETERS, position);
if (position != string::npos)
{
if (line[position] == '\"')
{
in_quotes = true;
position++;
}
size_t end;
if (in_quotes)
{
end = line.find_first_of('\"', position);
}
else
{
end = line.find_first_of(TOKEN_DELIMETERS, position);
}
if (end == string::npos)
{
end = line.length();
}
string token = line.substr(position, end - position);
if (in_quotes)
{
current_token += token;
if (line[end - 1] == '\"')
{
tokens.push_back(current_token);
current_token = "";
in_quotes = false;
}
else
{
current_token += " ";
}
}
else
{
tokens.push_back(token);
}
position = end;
}
}
return tokens;
}
void INFO_SHELL()
{
cout << "Tiny Shell [Version 1.3.10]" << endl;
cout << "Developed by Pham Vu Tuan Dat 20210158; Le Tuan Dat 20215340\n" << endl;
}
void COMMAND_NOT_FOUND(string command)
{
cout << "The command '" + command + "' was not recognized.\n";
}
void CANNOT_HAVE_PARAMETER(string command)
{
cout << "The command " + command + " cannot have parameters.\n";
}
void CANNOT_HAVE_OUTPUT(string command)
{
cout << "The command '" + command + "' cannot have an output.\n";
}
void help()
{
cout << "=========================================== GUIDE TO USING TINY SHELL ===========================================\n\n";
cout.width(38);
cout << left << "1. help"
<< "Provide Help information for commands\n";
cout.width(38);
cout << left << "2. cd .."
<< "Change to the parrent directory of the current directory\n";
cout.width(38);
cout << left << "3. cd <path>"
<< "Change current directory to this path.\n";
cout.width(38);
cout << left << "" << "Noted: Using <\"path\"> for path have space character. Ex: cd \"Folder name\"\n";
cout.width(38);
cout << left << "4. dir | ls"
<< "Display list of files in parent directory.\n";
cout.width(38);
cout << left << "5. mkdir <name>"
<< "Create a new folder in current directory.\n";
cout.width(38);
cout << left << "6. rmdir <name>"
<< "Delete a folder in current directory.\n";
cout.width(38);
cout << left << "7. date"
<< "Display date\n";
cout.width(38);
cout << left << "8. time"
<< "Display time\n";
cout.width(38);
cout << left << "9. run mspaint -f|bg"
<< "Open MS paint with foreground or background mode.\n";
cout.width(38);
cout << left << "" << "Example in foreground mode: run mspaint -f; run mspaint --foreground\n";
cout.width(38);
cout << left << "" << "Example in background mode: run mspaint -bg; run mspaint --background\n";
cout.width(38);
cout << left << "10. run notepad -f|bg"
<< "Open system notepad with foreground or background mode.\n";
cout.width(38);
cout << left << "" << "Example in foreground mode: run notepad -f; run notepad --foreground\n";
cout.width(38);
cout << left << "" << "Example in background mode: run notepad -bg; run notepad --background\n";
cout.width(38);
cout << left << "11. run [*.exe] -f|bg"
<< "Open an application in current directory with foreground or background mode.\n";
cout.width(38);
cout << left << "" << "Example in foreground mode: run [*.exe] -f; run [*.exe] --foreground\n";
cout.width(38);
cout << left << "" << "Example in background mode: run [*.exe] -bg; run [*.exe] --background\n";
cout.width(38);
cout << left << "12. list"
<< "Display list of processes\n";
cout.width(38);
cout << left << "13. stop 'ID'"
<< "Stop a running process\n";
cout.width(38);
cout << left << "14. resume 'ID'"
<< "Resume a stopping process\n";
cout.width(38);
cout << left << "15. kill 'ID'"
<< "Kill a running process\n";
cout.width(38);
cout << left << "16. kill -a"
<< "Kill all running processes\n";
cout.width(38);
cout << left << "17. run [*.bat]"
<< "Read *.bat file and run list of command lines\n";
cout.width(38);
cout << left << "18. env"
<< "Display all the environment variables and their values\n";
cout.width(38);
cout << left << "19. env <name>"
<< "Display the value of the environment variable <name>. Ex: env PYTHON\n";
cout.width(38);
cout << left << "20. addenv -n <name> -v <value env>"
<< "Add the environment variable <name> with value is <value env>\n";
cout.width(38);
cout << left << "21. delenv <name>"
<< "Delete the environment variable <name>\n";
cout.width(38);
cout << left << "22. clear|cls"
<< "Clear tiny shell\n";
cout.width(38);
cout << left << "23. exit"
<< "Exit process\n";
cout << endl;
}