|
1
|
1 #include "stdafx.h"
|
|
|
2 #include "commandline_parser.h"
|
|
|
3
|
|
|
4 commandline_parser::commandline_parser() {
|
|
|
5 init(pfc::stringcvt::string_utf8_from_os(GetCommandLine()));
|
|
|
6 }
|
|
|
7
|
|
|
8 void commandline_parser::init(const char * cmd)
|
|
|
9 {
|
|
|
10 pfc::string8_fastalloc temp;
|
|
|
11 pfc::chain_list_v2_t<pfc::string8> out;
|
|
|
12 while(*cmd)
|
|
|
13 {
|
|
|
14 temp.reset();
|
|
|
15 while(*cmd && *cmd!=' ')
|
|
|
16 {
|
|
|
17 if (*cmd=='\"')
|
|
|
18 {
|
|
|
19 cmd++;
|
|
|
20 while(*cmd && *cmd!='\"') temp.add_byte(*(cmd++));
|
|
|
21 if (*cmd == '\"') cmd++;
|
|
|
22 }
|
|
|
23 else temp.add_byte(*(cmd++));
|
|
|
24 }
|
|
|
25 out.insert_last(temp);
|
|
|
26 while(*cmd==' ') cmd++;
|
|
|
27 }
|
|
|
28 pfc::list_to_array(m_data,out);
|
|
|
29 }
|
|
|
30
|
|
|
31 size_t commandline_parser::find_param(const char * ptr) const {
|
|
|
32 for(size_t n=1;n<m_data.get_size();n++)
|
|
|
33 {
|
|
|
34 const char * cmd = m_data[n];
|
|
|
35 if (cmd[0]=='/') {
|
|
|
36 if (!strcmp(cmd+1,ptr)) return n;
|
|
|
37 }
|
|
|
38 }
|
|
|
39 return SIZE_MAX;
|
|
|
40 }
|
|
|
41 bool commandline_parser::check_param(const char * ptr) const
|
|
|
42 {
|
|
|
43 return find_param(ptr) != SIZE_MAX;
|
|
|
44 }
|
|
|
45
|
|
|
46 void commandline_parser::build_string(pfc::string_base & out)
|
|
|
47 {
|
|
|
48 out.reset();
|
|
|
49 unsigned n;
|
|
|
50 for(n=0;n<m_data.get_size();n++)
|
|
|
51 {
|
|
|
52 const char * cmd = m_data[n];
|
|
|
53 if (!out.is_empty()) out += " ";
|
|
|
54 if (strchr(cmd,' '))
|
|
|
55 {
|
|
|
56 out += "\"";
|
|
|
57 out += cmd;
|
|
|
58 out += "\"";
|
|
|
59 }
|
|
|
60 else
|
|
|
61 {
|
|
|
62 out += cmd;
|
|
|
63 }
|
|
|
64 }
|
|
|
65 }
|