MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ParseShortOption

Function ParseShortOption

src/openrct2/command_line/CommandLine.cpp:428–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426 }
427
428 static bool ParseShortOption(
429 const CommandLineOptionDefinition* options, CommandLineArgEnumerator* argEnumerator, const char* argument)
430 {
431 const CommandLineOptionDefinition* option = nullptr;
432
433 const char* shortOption = &argument[1];
434 for (; *shortOption != '\0'; shortOption++)
435 {
436 option = FindOption(options, shortOption[0]);
437 if (option == nullptr)
438 {
439 Console::Error::WriteLine("Unknown option: -%c", shortOption[0]);
440 return false;
441 }
442 if (option->Type == CMDLINE_TYPE_SWITCH)
443 {
444 if (!ParseOptionValue(option, nullptr))
445 {
446 return false;
447 }
448 }
449 else if (shortOption[1] != '\0')
450 {
451 return ParseOptionValue(option, &shortOption[1]);
452 }
453 }
454
455 if (option != nullptr && option->Type != CMDLINE_TYPE_SWITCH)
456 {
457 const char* valueString = nullptr;
458 if (!argEnumerator->TryPopString(&valueString))
459 {
460 Console::Error::WriteLine("Expected value for option: %c", option->ShortName);
461 return false;
462 }
463
464 if (!ParseOptionValue(option, valueString))
465 {
466 return false;
467 }
468 }
469
470 return true;
471 }
472
473 static bool ParseOptionValue(const CommandLineOptionDefinition* option, const char* valueString)
474 {

Callers 1

ParseOptionsFunction · 0.85

Calls 4

FindOptionFunction · 0.85
WriteLineFunction · 0.85
ParseOptionValueFunction · 0.85
TryPopStringMethod · 0.80

Tested by

no test coverage detected