-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathoptions-parser.cpp
92 lines (83 loc) · 2.22 KB
/
options-parser.cpp
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
#include "options-parser.h"
#include "helpers/formatter.h"
OptionsParser::GenOptions OptionsParser::GetOptions(int argc, char** argv)
{
using onepair_t = std::pair<std::string, std::string>;
std::vector<onepair_t> temppairs{};
onepair_t pair{};
GenOptions retpairs{};
// collect arguments/values to vector
for (int i = 0; i < argc; i++)
{
// key found (must start with '-' (e.g. '-dbc'))
if (argv[i][0] == '-')
{
pair.first = std::string(argv[i]);
pair.second.clear();
size_t valindex = i + 1;
if ((valindex < argc) && (argv[valindex][0] != '-'))
{
// key param
pair.second = std::string(argv[valindex]);
// shift position to next key
++i;
}
temppairs.push_back(pair);
}
}
for (size_t i = 0; i < temppairs.size(); i++)
{
if (temppairs[i].first.compare("-dbc") == 0)
{
retpairs.dbc.first = temppairs[i].second;
retpairs.dbc.second = true;
}
else if (temppairs[i].first.compare("-out") == 0)
{
retpairs.outdir.first = temppairs[i].second;
retpairs.outdir.second = true;
}
else if (temppairs[i].first.compare("-drvname") == 0)
{
retpairs.drvname.first = make_c_name(temppairs[i].second);
retpairs.drvname.second = true;
if (retpairs.drvname.first.length() == 0)
{
retpairs.drvname.second = false;
}
}
else if (temppairs[i].first.compare("-rw") == 0)
{
retpairs.is_rewrite = true;
}
else if (temppairs[i].first.compare("-nodeutils") == 0)
{
retpairs.is_nodeutils = true;
}
else if (temppairs[i].first.compare("-help") == 0)
{
retpairs.is_help = true;
}
else if (temppairs[i].first.compare("-noinc") == 0)
{
retpairs.is_nocanmon = true;
}
else if (temppairs[i].first.compare("-noconfig") == 0)
{
retpairs.is_noconfig = true;
}
else if (temppairs[i].first.compare("-nofmon") == 0)
{
retpairs.is_nofmon = true;
}
else if (temppairs[i].first.compare("-driverdir") == 0)
{
retpairs.is_driver_dir = true;
}
else if (temppairs[i].first.compare("-gendate") == 0)
{
retpairs.add_gen_date = true;
}
}
return retpairs;
}