Ben Tyner | 72feadc | 2020-04-06 12:57:31 -0500 | [diff] [blame] | 1 | #include <attn/attn_config.hpp> |
| 2 | |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 3 | #include <algorithm> |
| 4 | #include <string> |
| 5 | |
| 6 | /** @brief Search the command line arguments for an option */ |
| 7 | bool 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 */ |
| 13 | char* 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 Tyner | 72feadc | 2020-04-06 12:57:31 -0500 | [diff] [blame] | 20 | void parseConfig(char** i_begin, char** i_end, attn::Config* o_config) |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 21 | { |
| 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 Tyner | 72feadc | 2020-04-06 12:57:31 -0500 | [diff] [blame] | 30 | o_config->clearFlagAll(); |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | if (std::string("on") == setting) |
| 34 | { |
Ben Tyner | 72feadc | 2020-04-06 12:57:31 -0500 | [diff] [blame] | 35 | o_config->setFlagAll(); |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | // Parse individual options |
| 39 | else |
| 40 | { |
| 41 | setting = getCliSetting(i_begin, i_end, "--vital"); |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 42 | if (nullptr != setting) |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 43 | { |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 44 | 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 Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | setting = getCliSetting(i_begin, i_end, "--checkstop"); |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 55 | if (nullptr != setting) |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 56 | { |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 57 | 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 Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | setting = getCliSetting(i_begin, i_end, "--terminate"); |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 68 | if (nullptr != setting) |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 69 | { |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 70 | 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 Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | setting = getCliSetting(i_begin, i_end, "--breakpoints"); |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 81 | if (nullptr != setting) |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 82 | { |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 83 | 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 Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | } |