blob: 4ace713a0fae0e9969a3b26fdff8cce00f53af3b [file] [log] [blame]
Ben Tyner7212d212020-03-31 09:44:41 -05001#include <algorithm>
2#include <string>
3
4/** @brief Search the command line arguments for an option */
5bool getCliOption(char** i_begin, char** i_end, const std::string& i_option)
6{
7 return (i_end != std::find(i_begin, i_end, i_option));
8}
9
10/** @brief Search the command line arguments for a setting value */
11char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting)
12{
13 char** value = std::find(i_begin, i_end, i_setting);
14 return (value != i_end && ++value != i_end) ? *value : 0;
15}
16
17/** @brief Parse command line for configuration flags */
18void parseConfig(char** i_begin, char** i_end, bool& o_vital, bool& o_checkstop,
19 bool& o_terminate, bool& o_breakpoints)
20{
21 char* setting;
22
23 // --all on/off takes precedence over individual settings
24 setting = getCliSetting(i_begin, i_end, "--all");
25 if (nullptr != setting)
26 {
27 if (std::string("off") == setting)
28 {
29 o_vital = false;
30 o_checkstop = false;
31 o_terminate = false;
32 o_breakpoints = false;
33 }
34
35 if (std::string("on") == setting)
36 {
37 o_vital = true;
38 o_checkstop = true;
39 o_terminate = true;
40 o_breakpoints = true;
41 }
42 }
43 // Parse individual options
44 else
45 {
46 setting = getCliSetting(i_begin, i_end, "--vital");
47 if (std::string("off") == setting)
48 {
49 o_vital = false;
50 }
51 if (std::string("on") == setting)
52 {
53 o_vital = true;
54 }
55
56 setting = getCliSetting(i_begin, i_end, "--checkstop");
57 if (std::string("off") == setting)
58 {
59 o_checkstop = false;
60 }
61 if (std::string("on") == setting)
62 {
63 o_checkstop = true;
64 }
65
66 setting = getCliSetting(i_begin, i_end, "--terminate");
67 if (std::string("off") == setting)
68 {
69 o_terminate = false;
70 }
71 if (std::string("on") == setting)
72 {
73 o_terminate = true;
74 }
75
76 setting = getCliSetting(i_begin, i_end, "--breakpoints");
77 if (std::string("off") == setting)
78 {
79 o_breakpoints = false;
80 }
81 if (std::string("on") == setting)
82 {
83 o_breakpoints = true;
84 }
85 }
86}