172feadcfSBen Tyner #include <attn/attn_config.hpp>
272feadcfSBen Tyner
37212d21dSBen Tyner #include <algorithm>
47212d21dSBen Tyner #include <string>
57212d21dSBen Tyner
67212d21dSBen Tyner /** @brief Search the command line arguments for an option */
getCliOption(char ** i_begin,char ** i_end,const std::string & i_option)77212d21dSBen Tyner bool getCliOption(char** i_begin, char** i_end, const std::string& i_option)
87212d21dSBen Tyner {
97212d21dSBen Tyner return (i_end != std::find(i_begin, i_end, i_option));
107212d21dSBen Tyner }
117212d21dSBen Tyner
127212d21dSBen Tyner /** @brief Search the command line arguments for a setting value */
getCliSetting(char ** i_begin,char ** i_end,const std::string & i_setting)137212d21dSBen Tyner char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting)
147212d21dSBen Tyner {
157212d21dSBen Tyner char** value = std::find(i_begin, i_end, i_setting);
167212d21dSBen Tyner return (value != i_end && ++value != i_end) ? *value : 0;
177212d21dSBen Tyner }
187212d21dSBen Tyner
197212d21dSBen Tyner /** @brief Parse command line for configuration flags */
parseConfig(char ** i_begin,char ** i_end,attn::Config * o_config)2072feadcfSBen Tyner void parseConfig(char** i_begin, char** i_end, attn::Config* o_config)
217212d21dSBen Tyner {
227212d21dSBen Tyner char* setting;
237212d21dSBen Tyner
247212d21dSBen Tyner // --all on/off takes precedence over individual settings
257212d21dSBen Tyner setting = getCliSetting(i_begin, i_end, "--all");
267212d21dSBen Tyner if (nullptr != setting)
277212d21dSBen Tyner {
287212d21dSBen Tyner if (std::string("off") == setting)
297212d21dSBen Tyner {
3072feadcfSBen Tyner o_config->clearFlagAll();
317212d21dSBen Tyner }
327212d21dSBen Tyner
337212d21dSBen Tyner if (std::string("on") == setting)
347212d21dSBen Tyner {
3572feadcfSBen Tyner o_config->setFlagAll();
367212d21dSBen Tyner }
377212d21dSBen Tyner }
387212d21dSBen Tyner // Parse individual options
397212d21dSBen Tyner else
407212d21dSBen Tyner {
417212d21dSBen Tyner setting = getCliSetting(i_begin, i_end, "--vital");
42d3cda742SBen Tyner if (nullptr != setting)
43d3cda742SBen Tyner {
447212d21dSBen Tyner if (std::string("off") == setting)
457212d21dSBen Tyner {
4672feadcfSBen Tyner o_config->clearFlag(attn::enVital);
477212d21dSBen Tyner }
487212d21dSBen Tyner if (std::string("on") == setting)
497212d21dSBen Tyner {
5072feadcfSBen Tyner o_config->setFlag(attn::enVital);
517212d21dSBen Tyner }
52d3cda742SBen Tyner }
537212d21dSBen Tyner
547212d21dSBen Tyner setting = getCliSetting(i_begin, i_end, "--checkstop");
55d3cda742SBen Tyner if (nullptr != setting)
56d3cda742SBen Tyner {
577212d21dSBen Tyner if (std::string("off") == setting)
587212d21dSBen Tyner {
5972feadcfSBen Tyner o_config->clearFlag(attn::enCheckstop);
607212d21dSBen Tyner }
617212d21dSBen Tyner if (std::string("on") == setting)
627212d21dSBen Tyner {
6372feadcfSBen Tyner o_config->setFlag(attn::enCheckstop);
647212d21dSBen Tyner }
65d3cda742SBen Tyner }
667212d21dSBen Tyner
677212d21dSBen Tyner setting = getCliSetting(i_begin, i_end, "--terminate");
68d3cda742SBen Tyner if (nullptr != setting)
69d3cda742SBen Tyner {
707212d21dSBen Tyner if (std::string("off") == setting)
717212d21dSBen Tyner {
7272feadcfSBen Tyner o_config->clearFlag(attn::enTerminate);
737212d21dSBen Tyner }
747212d21dSBen Tyner if (std::string("on") == setting)
757212d21dSBen Tyner {
7672feadcfSBen Tyner o_config->setFlag(attn::enTerminate);
777212d21dSBen Tyner }
78d3cda742SBen Tyner }
797212d21dSBen Tyner
807212d21dSBen Tyner setting = getCliSetting(i_begin, i_end, "--breakpoints");
81d3cda742SBen Tyner if (nullptr != setting)
82d3cda742SBen Tyner {
837212d21dSBen Tyner if (std::string("off") == setting)
847212d21dSBen Tyner {
8572feadcfSBen Tyner o_config->clearFlag(attn::enBreakpoints);
867212d21dSBen Tyner }
877212d21dSBen Tyner if (std::string("on") == setting)
887212d21dSBen Tyner {
8972feadcfSBen Tyner o_config->setFlag(attn::enBreakpoints);
907212d21dSBen Tyner }
917212d21dSBen Tyner }
92e4f5dbefSBen Tyner
93e4f5dbefSBen Tyner // This option determines whether we service a TI or breakpoint in the
94fe15649eSBen Tyner // case where TI info is available but not valid. The default setting
95fe15649eSBen Tyner // of this is "clear" meaning we will handle breakpoint by default.
96fe15649eSBen Tyner // This flag is not affected by the set/clear all command line option.
97fe15649eSBen Tyner if (true == getCliOption(i_begin, i_end, "--defaultti"))
98e4f5dbefSBen Tyner {
99fe15649eSBen Tyner o_config->setFlag(attn::dfltTi);
100e4f5dbefSBen Tyner }
101*d28d5f8bSaustinfcui
102*d28d5f8bSaustinfcui setting = getCliSetting(i_begin, i_end, "--clrattnintr");
103*d28d5f8bSaustinfcui if (nullptr != setting)
104*d28d5f8bSaustinfcui {
105*d28d5f8bSaustinfcui if (std::string("off") == setting)
106*d28d5f8bSaustinfcui {
107*d28d5f8bSaustinfcui o_config->clearFlag(attn::enClrAttnIntr);
108*d28d5f8bSaustinfcui }
109*d28d5f8bSaustinfcui if (std::string("on") == setting)
110*d28d5f8bSaustinfcui {
111*d28d5f8bSaustinfcui o_config->setFlag(attn::enClrAttnIntr);
112*d28d5f8bSaustinfcui }
113*d28d5f8bSaustinfcui }
1147212d21dSBen Tyner }
115d3cda742SBen Tyner }
116