blob: 8129821807e28bc7ac41324ba7cd55f3fca981d6 [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
Ben Tynerfe156492021-04-08 07:28:13 -050094 // case where TI info is available but not valid. The default setting
95 // of this is "clear" meaning we will handle breakpoint by default.
96 // This flag is not affected by the set/clear all command line option.
97 if (true == getCliOption(i_begin, i_end, "--defaultti"))
Ben Tynere4f5dbe2020-10-19 07:19:33 -050098 {
Ben Tynerfe156492021-04-08 07:28:13 -050099 o_config->setFlag(attn::dfltTi);
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500100 }
austinfcuid28d5f82022-04-28 16:20:39 -0500101
102 setting = getCliSetting(i_begin, i_end, "--clrattnintr");
103 if (nullptr != setting)
104 {
105 if (std::string("off") == setting)
106 {
107 o_config->clearFlag(attn::enClrAttnIntr);
108 }
109 if (std::string("on") == setting)
110 {
111 o_config->setFlag(attn::enClrAttnIntr);
112 }
113 }
Ben Tyner7212d212020-03-31 09:44:41 -0500114 }
115}