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

Function ParseLongOption

src/openrct2/command_line/CommandLine.cpp:367–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365 }
366
367 static bool ParseLongOption(
368 const CommandLineOptionDefinition* options, CommandLineArgEnumerator* argEnumerator, const char* argument)
369 {
370 // Get just the option name
371 char optionName[64];
372 const char* equalsCh = strchr(argument, '=');
373 if (equalsCh != nullptr)
374 {
375 String::set(optionName, sizeof(optionName), argument, equalsCh - argument);
376 }
377 else
378 {
379 String::set(optionName, sizeof(optionName), argument);
380 }
381
382 // Find a matching option definition
383 const CommandLineOptionDefinition* option = FindOption(options, optionName);
384 if (option == nullptr)
385 {
386 Console::Error::WriteLine("Unknown option: --%s", optionName);
387 return false;
388 }
389
390 if (equalsCh == nullptr)
391 {
392 if (option->Type == CMDLINE_TYPE_SWITCH)
393 {
394 ParseOptionValue(option, nullptr);
395 }
396 else
397 {
398 const char* valueString = nullptr;
399 if (!argEnumerator->TryPopString(&valueString))
400 {
401 Console::Error::WriteLine("Expected value for option: %s", optionName);
402 return false;
403 }
404
405 if (!ParseOptionValue(option, valueString))
406 {
407 return false;
408 }
409 }
410 }
411 else
412 {
413 if (option->Type == CMDLINE_TYPE_SWITCH)
414 {
415 Console::Error::WriteLine("Option is a switch: %s", optionName);
416 return false;
417 }
418
419 if (!ParseOptionValue(option, equalsCh + 1))
420 {
421 return false;
422 }
423 }
424

Callers 1

ParseOptionsFunction · 0.85

Calls 5

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

Tested by

no test coverage detected