-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcmdline.cpp
More file actions
95 lines (75 loc) · 2.08 KB
/
cmdline.cpp
File metadata and controls
95 lines (75 loc) · 2.08 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
#include "cmdline.h"
#include "getopt.h"
typedef struct
{
struct option_w option;
LPCWSTR description;
} OPTIONW;
static OPTIONW s_options[] =
{
{{ L"help", ARG_NONE, NULL, L'h' }, L"打印帮助信息\n"},
{{ L"html", ARG_REQ, NULL, L'x' }, L"设置要打开的HTML文件"},
{{ L"transparent", ARG_OPT, 0, L't' }, L"支持使用分层窗口透明"},
{{ NULL, ARG_NULL, 0, 0 }, NULL}
};
void ParseOptions(int argc, LPWSTR* argv, CommandOptions* options)
{
struct option_w longOptions[100] = { 0 };
WCHAR shortOptions[100] = { 0 };
WCHAR val[2] = { 0 };
OPTIONW* opt = s_options;
int i = 0;
do
{
longOptions[i++] = opt->option;
val[0] = opt->option.val;
wcscat_s(shortOptions, 99, val);
if (opt->option.has_arg)
wcscat_s(shortOptions, 99, L":");
++ opt;
}
while (opt->description);
do
{
int option = getopt_long_w(argc, argv, shortOptions, longOptions, NULL);
if (option == -1)
break;
switch (option)
{
case L'h':
options->showHelp = TRUE;
break;
case L'x':
wcscpy_s(options->htmlFile, MAX_PATH, optarg_w);
break;
case L't':
if (!optarg_w ||
_wcsicmp(optarg_w, L"yes") == 0 ||
_wcsicmp(optarg_w, L"true") == 0)
{
options->transparent = TRUE;
}
else
{
options->transparent = FALSE;
}
break;
}
}
while (1);
}
void PrintHelp()
{
WCHAR helpString[1024] = { 0 };
int helpLength = 0;
OPTIONW* opt = s_options;
do
{
WCHAR* buffer = (LPWSTR)helpString + helpLength;
int capacity = 1024 - helpLength;
helpLength += swprintf_s(buffer, capacity, L"--%-15s%s\n", opt->option.name, opt->description);
++ opt;
}
while (opt->description);
MessageBoxW(NULL, helpString, L"wkexe", MB_OK|MB_ICONINFORMATION);
}