blob: d68e041b738e5ed098312625e2dbb5710d880f78 [file] [log] [blame]
Ben Tyner72feadc2020-04-06 12:57:31 -05001#include <attn/attn_config.hpp>
2
Ben Tyner7212d212020-03-31 09:44:41 -05003#include <algorithm>
4#include <string>
5
6/** @brief Search the command line arguments for an option */
7bool getCliOption(char** i_begin, char** i_end, const std::string& i_option)
8{
9 return (i_end != std::find(i_begin, i_end, i_option));
10}
11
12/** @brief Search the command line arguments for a setting value */
13char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting)
14{
15 char** value = std::find(i_begin, i_end, i_setting);
16 return (value != i_end && ++value != i_end) ? *value : 0;
17}
18
19/** @brief Parse command line for configuration flags */
Ben Tyner72feadc2020-04-06 12:57:31 -050020void parseConfig(char** i_begin, char** i_end, attn::Config* o_config)
Ben Tyner7212d212020-03-31 09:44:41 -050021{
22 char* setting;
23
24 // --all on/off takes precedence over individual settings
25 setting = getCliSetting(i_begin, i_end, "--all");
26 if (nullptr != setting)
27 {
28 if (std::string("off") == setting)
29 {
Ben Tyner72feadc2020-04-06 12:57:31 -050030 o_config->clearFlagAll();
Ben Tyner7212d212020-03-31 09:44:41 -050031 }
32
33 if (std::string("on") == setting)
34 {
Ben Tyner72feadc2020-04-06 12:57:31 -050035 o_config->setFlagAll();
Ben Tyner7212d212020-03-31 09:44:41 -050036 }
37 }
38 // Parse individual options
39 else
40 {
41 setting = getCliSetting(i_begin, i_end, "--vital");
Ben Tynerd3cda742020-05-04 08:00:28 -050042 if (nullptr != setting)
Ben Tyner7212d212020-03-31 09:44:41 -050043 {
Ben Tynerd3cda742020-05-04 08:00:28 -050044 if (std::string("off") == setting)
45 {
46 o_config->clearFlag(attn::enVital);
47 }
48 if (std::string("on") == setting)
49 {
50 o_config->setFlag(attn::enVital);
51 }
Ben Tyner7212d212020-03-31 09:44:41 -050052 }
53
54 setting = getCliSetting(i_begin, i_end, "--checkstop");
Ben Tynerd3cda742020-05-04 08:00:28 -050055 if (nullptr != setting)
Ben Tyner7212d212020-03-31 09:44:41 -050056 {
Ben Tynerd3cda742020-05-04 08:00:28 -050057 if (std::string("off") == setting)
58 {
59 o_config->clearFlag(attn::enCheckstop);
60 }
61 if (std::string("on") == setting)
62 {
63 o_config->setFlag(attn::enCheckstop);
64 }
Ben Tyner7212d212020-03-31 09:44:41 -050065 }
66
67 setting = getCliSetting(i_begin, i_end, "--terminate");
Ben Tynerd3cda742020-05-04 08:00:28 -050068 if (nullptr != setting)
Ben Tyner7212d212020-03-31 09:44:41 -050069 {
Ben Tynerd3cda742020-05-04 08:00:28 -050070 if (std::string("off") == setting)
71 {
72 o_config->clearFlag(attn::enTerminate);
73 }
74 if (std::string("on") == setting)
75 {
76 o_config->setFlag(attn::enTerminate);
77 }
Ben Tyner7212d212020-03-31 09:44:41 -050078 }
79
80 setting = getCliSetting(i_begin, i_end, "--breakpoints");
Ben Tynerd3cda742020-05-04 08:00:28 -050081 if (nullptr != setting)
Ben Tyner7212d212020-03-31 09:44:41 -050082 {
Ben Tynerd3cda742020-05-04 08:00:28 -050083 if (std::string("off") == setting)
84 {
85 o_config->clearFlag(attn::enBreakpoints);
86 }
87 if (std::string("on") == setting)
88 {
89 o_config->setFlag(attn::enBreakpoints);
90 }
Ben Tyner7212d212020-03-31 09:44:41 -050091 }
Ben Tynere4f5dbe2020-10-19 07:19:33 -050092
93 // This option determines whether we service a TI or breakpoint in the
94 // case where we cannot retrieve the TI info succesfully. The default
95 // setting of this is "clear" meaning handle TI by default. This
96 // flag is not affected by the set/clear all command line option.
97 if (true == getCliOption(i_begin, i_end, "--defaultbreakpoint"))
98 {
99 o_config->setFlag(attn::dfltBreakpoint);
100 }
Ben Tyner7212d212020-03-31 09:44:41 -0500101 }
102}