| 292 | } |
| 293 | |
| 294 | bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::string& error) |
| 295 | { |
| 296 | LOCK(cs_args); |
| 297 | m_settings.command_line_options.clear(); |
| 298 | |
| 299 | for (int i = 1; i < argc; i++) { |
| 300 | std::string key(argv[i]); |
| 301 | |
| 302 | #ifdef MAC_OSX |
| 303 | // At the first time when a user gets the "App downloaded from the |
| 304 | // internet" warning, and clicks the Open button, macOS passes |
| 305 | // a unique process serial number (PSN) as -psn_... command-line |
| 306 | // argument, which we filter out. |
| 307 | if (key.substr(0, 5) == "-psn_") continue; |
| 308 | #endif |
| 309 | |
| 310 | if (key == "-") break; //bitcoin-tx using stdin |
| 311 | std::string val; |
| 312 | size_t is_index = key.find('='); |
| 313 | if (is_index != std::string::npos) { |
| 314 | val = key.substr(is_index + 1); |
| 315 | key.erase(is_index); |
| 316 | } |
| 317 | #ifdef WIN32 |
| 318 | key = ToLower(key); |
| 319 | if (key[0] == '/') |
| 320 | key[0] = '-'; |
| 321 | #endif |
| 322 | |
| 323 | if (key[0] != '-') { |
| 324 | if (!m_accept_any_command && m_command.empty()) { |
| 325 | // The first non-dash arg is a registered command |
| 326 | std::optional<unsigned int> flags = GetArgFlags(key); |
| 327 | if (!flags || !(*flags & ArgsManager::COMMAND)) { |
| 328 | error = strprintf("Invalid command '%s'", argv[i]); |
| 329 | return false; |
| 330 | } |
| 331 | } |
| 332 | m_command.push_back(key); |
| 333 | while (++i < argc) { |
| 334 | // The remaining args are command args |
| 335 | m_command.push_back(argv[i]); |
| 336 | } |
| 337 | break; |
| 338 | } |
| 339 | |
| 340 | // Transform --foo to -foo |
| 341 | if (key.length() > 1 && key[1] == '-') |
| 342 | key.erase(0, 1); |
| 343 | |
| 344 | // Transform -foo to foo |
| 345 | key.erase(0, 1); |
| 346 | KeyInfo keyinfo = InterpretKey(key); |
| 347 | std::optional<unsigned int> flags = GetArgFlags('-' + keyinfo.name); |
| 348 | |
| 349 | // Unknown command line options and command line options with dot |
| 350 | // characters (which are returned from InterpretKey with nonempty |
| 351 | // section strings) are not valid. |