-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.cpp
115 lines (104 loc) · 3.35 KB
/
cli.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <attn/attn_config.hpp>
#include <algorithm>
#include <string>
/** @brief Search the command line arguments for an option */
bool getCliOption(char** i_begin, char** i_end, const std::string& i_option)
{
return (i_end != std::find(i_begin, i_end, i_option));
}
/** @brief Search the command line arguments for a setting value */
char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting)
{
char** value = std::find(i_begin, i_end, i_setting);
return (value != i_end && ++value != i_end) ? *value : 0;
}
/** @brief Parse command line for configuration flags */
void parseConfig(char** i_begin, char** i_end, attn::Config* o_config)
{
char* setting;
// --all on/off takes precedence over individual settings
setting = getCliSetting(i_begin, i_end, "--all");
if (nullptr != setting)
{
if (std::string("off") == setting)
{
o_config->clearFlagAll();
}
if (std::string("on") == setting)
{
o_config->setFlagAll();
}
}
// Parse individual options
else
{
setting = getCliSetting(i_begin, i_end, "--vital");
if (nullptr != setting)
{
if (std::string("off") == setting)
{
o_config->clearFlag(attn::enVital);
}
if (std::string("on") == setting)
{
o_config->setFlag(attn::enVital);
}
}
setting = getCliSetting(i_begin, i_end, "--checkstop");
if (nullptr != setting)
{
if (std::string("off") == setting)
{
o_config->clearFlag(attn::enCheckstop);
}
if (std::string("on") == setting)
{
o_config->setFlag(attn::enCheckstop);
}
}
setting = getCliSetting(i_begin, i_end, "--terminate");
if (nullptr != setting)
{
if (std::string("off") == setting)
{
o_config->clearFlag(attn::enTerminate);
}
if (std::string("on") == setting)
{
o_config->setFlag(attn::enTerminate);
}
}
setting = getCliSetting(i_begin, i_end, "--breakpoints");
if (nullptr != setting)
{
if (std::string("off") == setting)
{
o_config->clearFlag(attn::enBreakpoints);
}
if (std::string("on") == setting)
{
o_config->setFlag(attn::enBreakpoints);
}
}
// This option determines whether we service a TI or breakpoint in the
// case where TI info is available but not valid. The default setting
// of this is "clear" meaning we will handle breakpoint by default.
// This flag is not affected by the set/clear all command line option.
if (true == getCliOption(i_begin, i_end, "--defaultti"))
{
o_config->setFlag(attn::dfltTi);
}
setting = getCliSetting(i_begin, i_end, "--clrattnintr");
if (nullptr != setting)
{
if (std::string("off") == setting)
{
o_config->clearFlag(attn::enClrAttnIntr);
}
if (std::string("on") == setting)
{
o_config->setFlag(attn::enClrAttnIntr);
}
}
}
}