Repository navigation
Expand file tree
/
Copy pathcli.cpp
More file actions
63 lines (54 loc) · 1.68 KB
/
Copy pathcli.cpp
File metadata and controls
63 lines (54 loc) · 1.68 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
/*
Dimension
(c) LifesMinder
Module name:
cli.cpp
Purpose:
Command-line commands management file
*/
#include "dimension.h"
extern map<int, wchar_t> flags;
extern map<wstring, any> options;
void CLI() {
int argc;
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
int realArgc = argc - 1;
if (argv != NULL && realArgc > 0) {
// Attach the console
FILE* f;
if (!AttachConsole(ATTACH_PARENT_PROCESS))
AllocConsole();
freopen_s(&f, "CONOUT$", "w", stdout);
// Traverse through the arguments.
// argv[0] is executable, real args start at 1
for (int i = 1; i < argc; i++) {
int index = i - 1;
wstring arg = argv[i];
if (arg[0] == L'-') {
if (arg.size() > 1 && arg[1] == L'-') {
wstring key = arg.substr(2);
options.emplace(key, L"");
}
else if (arg.size() > 1) {
flags.emplace(index, arg[1]);
}
}
else if (arg[0] == L'/') {
size_t colon = arg.find(L":");
wstring key = arg.substr(1, colon - 1), value = L"";
if (colon != wstring::npos) {
value = arg.substr(colon + 1);
}
options.emplace(key, value);
}
}
// Work with options. To-Do: separate this exact logic
if (options.find(L"debug") != options.end()) {
cout << endl;
cout << "[Dimension] Debug mode is on" << endl;
}
FreeConsole();
LocalFree(argv);
fclose(f);
}
}