/*! * \brief Return the activation state of an item with a specified name. */ bool CNutConfDoc::IsOptionActive(char *name) { NUTCOMPONENTOPTION *opt = FindOptionByName(m_root->nc_child, name); if (opt && opt->nco_active) { return true; } return false; }
bool CommandLineParser::HandleOption (bool is_long_name_option, char const *token, char const *const next_token) { assert(token != NULL); assert(*token != '\0'); // next_token may be NULL // a short-name option must be solitary (e.g. "-a" and not "-ab") if (!is_long_name_option && *(token+1) != '\0') throw string("invalid short option: -") + token; CommandLineOption const *option = FindOptionByName(is_long_name_option, token); if (option == NULL) { if (is_long_name_option) throw string("no such long option: --") + token; else throw string("no such short option: -") + token; } if (option->m_handler_method_with_argument != NULL) // argument required { if (next_token == NULL) { if (is_long_name_option) throw string("option --") + option->m_long_name + " requires an argument"; else throw string("option -") + option->m_short_name + " requires an argument"; } (this->*(option->m_handler_method_with_argument))(string(next_token)); return true; // next_token was used up. } else if (option->m_handler_method_with_optional_argument != NULL) // optional argument { // if the next token is not present, or it's an option ("-" and "--" // are not considered options), call the handler without the argument. if (next_token == NULL || (*next_token == '-' && next_token != string("-") && next_token != string("--"))) { (this->*(option->m_handler_method_with_optional_argument))(false, string()); return false; // next_token was NOT used up. } else { (this->*(option->m_handler_method_with_optional_argument))(true, string(next_token)); return true; // next_token was used up. } } else // no argument { assert(option->m_handler_method_without_argument != NULL); (this->*(option->m_handler_method_without_argument))(); return false; // next_token was NOT used up. } }
void CNutConfDoc::DeactivateOptionList(NUTCOMPONENT *compo, char **exlist) { if (exlist) { if (compo == NULL) { compo = m_root->nc_child; } for (int i = 0; exlist[i]; i++) { NUTCOMPONENTOPTION *opt = FindOptionByName(compo, exlist[i]); if (opt) { opt->nco_active = 0; } } } }
/*! * \brief Find NUTCOMPONENTOPTION by name. */ NUTCOMPONENTOPTION *CNutConfDoc::FindOptionByName(NUTCOMPONENT * compo, char *name) { if (compo == NULL && m_root) { compo = m_root->nc_child; } while (compo) { NUTCOMPONENTOPTION *opts = compo->nc_opts; while (opts) { if (strcmp(opts->nco_name, name) == 0) { return opts; } opts = opts->nco_nxt; } if (compo->nc_child && (opts = FindOptionByName(compo->nc_child, name)) != NULL) { return opts; } compo = compo->nc_nxt; } return NULL; }