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

Function FindCommandFor

src/openrct2/command_line/CommandLine.cpp:286–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284 }
285
286 static const CommandLineCommand* FindCommandFor(const CommandLineCommand* commands, CommandLineArgEnumerator* argEnumerator)
287 {
288 // Check if end of arguments or options have started
289 const char* firstArgument;
290 if (!argEnumerator->TryPopString(&firstArgument))
291 {
292 return commands;
293 }
294 if (firstArgument[0] == '-')
295 {
296 argEnumerator->Backtrack();
297 return commands;
298 }
299
300 // Search through defined commands for one that matches
301 const CommandLineCommand* fallback = nullptr;
302 const CommandLineCommand* command = commands;
303 for (; command->Name != nullptr; command++)
304 {
305 if (command->Name[0] == '\0')
306 {
307 // If we don't find a command, this should be used
308 fallback = command;
309 }
310 else if (String::equals(command->Name, firstArgument))
311 {
312 if (command->SubCommands == nullptr)
313 {
314 // Found matching command
315 return command;
316 }
317
318 // Recurse for the sub command table
319 return FindCommandFor(command->SubCommands, argEnumerator);
320 }
321 }
322
323 argEnumerator->Backtrack();
324 return fallback;
325 }
326
327 static bool ParseOptions(const CommandLineOptionDefinition* options, CommandLineArgEnumerator* argEnumerator)
328 {

Callers 1

CommandLineRunFunction · 0.85

Calls 3

equalsFunction · 0.85
TryPopStringMethod · 0.80
BacktrackMethod · 0.80

Tested by

no test coverage detected