| 412 | } |
| 413 | |
| 414 | bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::string& error) |
| 415 | { |
| 416 | LOCK(cs_args); |
| 417 | m_override_args.clear(); |
| 418 | |
| 419 | for (int i = 1; i < argc; i++) { |
| 420 | std::string key(argv[i]); |
| 421 | std::string val; |
| 422 | size_t is_index = key.find('='); |
| 423 | if (is_index != std::string::npos) { |
| 424 | val = key.substr(is_index + 1); |
| 425 | key.erase(is_index); |
| 426 | } |
| 427 | #ifdef WIN32 |
| 428 | std::transform(key.begin(), key.end(), key.begin(), ::tolower); |
| 429 | if (key[0] == '/') |
| 430 | key[0] = '-'; |
| 431 | #endif |
| 432 | |
| 433 | if (key[0] != '-') |
| 434 | break; |
| 435 | |
| 436 | // Transform --foo to -foo |
| 437 | if (key.length() > 1 && key[1] == '-') |
| 438 | key.erase(0, 1); |
| 439 | |
| 440 | // Check for -nofoo |
| 441 | if (InterpretNegatedOption(key, val)) { |
| 442 | m_override_args[key].clear(); |
| 443 | } else { |
| 444 | m_override_args[key].push_back(val); |
| 445 | } |
| 446 | |
| 447 | // Check that the arg is known |
| 448 | if (!(IsSwitchChar(key[0]) && key.size() == 1)) { |
| 449 | if (!IsArgKnown(key)) { |
| 450 | error = strprintf("Invalid parameter %s", key.c_str()); |
| 451 | return false; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | // we do not allow -includeconf from command line, so we clear it here |
| 457 | auto it = m_override_args.find("-includeconf"); |
| 458 | if (it != m_override_args.end()) { |
| 459 | if (it->second.size() > 0) { |
| 460 | for (const auto& ic : it->second) { |
| 461 | error += "-includeconf cannot be used from commandline; -includeconf=" + ic + "\n"; |
| 462 | } |
| 463 | return false; |
| 464 | } |
| 465 | } |
| 466 | return true; |
| 467 | } |
| 468 | |
| 469 | bool ArgsManager::IsArgKnown(const std::string& key) const |
| 470 | { |