예제 #1
0
bool
CommandLineUserInterface::_RegisterCommand(const BString& name,
	CliCommand* command)
{
	BReference<CliCommand> commandReference(command, true);
	if (name.IsEmpty() || command == NULL)
		return false;

	BString nextName;
	int32 startIndex = 0;
	int32 spaceIndex;
	do {
		spaceIndex = name.FindFirst(' ', startIndex);
		if (spaceIndex == B_ERROR)
			spaceIndex = name.Length();
		name.CopyInto(nextName, startIndex, spaceIndex - startIndex);

		CommandEntry* entry = new(std::nothrow) CommandEntry(nextName,
			command);
		if (entry == NULL || !fCommands.AddItem(entry)) {
			delete entry;
			return false;
		}
		startIndex = spaceIndex + 1;
	} while (startIndex < name.Length());

	return true;
}
예제 #2
0
bool
CommandLineUserInterface::_RegisterCommand(const BString& name,
	CliCommand* command)
{
	BReference<CliCommand> commandReference(command, true);
	if (name.IsEmpty() || command == NULL)
		return false;

	CommandEntry* entry = new(std::nothrow) CommandEntry(name, command);
	if (entry == NULL || !fCommands.AddItem(entry)) {
		delete entry;
		return false;
	}

	return true;
}