Ejemplo n.º 1
0
// React to a shell-issued command line directive.
int CXtApp::ProcessShellCommand( int argc, TCHAR *argv[] )
{
	if ( m_pCmdLineParser == NULL )
	{
		return FUN_RET_OK;
	}

	int nRet = FUN_RET_OK;

	const TCHAR *cszOpt = NULL;
	const TCHAR *cszParam = NULL;
	BOOL bBriefOpt = FALSE;

	int nCurArg = 1;

	while( nCurArg < argc )
	{
		cszOpt = NULL;
		cszParam = NULL;
		bBriefOpt = GetShellCommand( argc-nCurArg, &argv[nCurArg], &cszOpt, &cszParam );
		if ( cszOpt && cszParam )
		{
			nCurArg += 2;
		}
		else
		{
			++nCurArg;
		}

		nRet = m_pCmdLineParser->ParseCommand( cszOpt, cszParam, bBriefOpt );
	}

	return FUN_RET_OK;
}
Ejemplo n.º 2
0
BT_ERROR BT_ShellCommand(char *input) {

	BT_u32 ulArguments = 0;
	BT_u32 bIsArg = BT_FALSE;

	char *copy = BT_kMalloc(strlen(input)+1);
	if(!copy) {
		return BT_ERR_NO_MEMORY;
	}

	strcpy(copy, input);

	input = copy;

	while(isspace((int)*input)) {
		input++;	// Eat up prefixed whitespace.
	}

	bIsArg = BT_TRUE;

	char *line = input;

	while(*input) {
		if(bIsArg) {
			if(isspace((int)*input)) {
				ulArguments += 1;
				bIsArg = BT_FALSE;
			}
		} else {
			if(!isspace((int)*input)) {
				bIsArg = BT_TRUE;
			}
		}
		input++;
	}

	if(bIsArg) {
		ulArguments += 1;
	}

	char **pargs = BT_kMalloc(sizeof(char *) * ulArguments);
	if(!pargs) {
		return BT_ERR_NO_MEMORY;
	}

	input = line;
	while(!*input);

	bIsArg = BT_FALSE;

	BT_u32 i = 0;

	while(*input) {
		if(!bIsArg) {
			if(!isspace((int)*input)) {
				bIsArg = BT_TRUE;
				pargs[i++] = input;
			}
		} else {
			if(isspace((int)*input)) {
				*input = '\0';
				bIsArg = BT_FALSE;
			}
		}
		input++;
	}

	const BT_SHELL_COMMAND *pCommand = GetShellCommand(pargs[0]);
	if(!pCommand) {
		BT_kFree(pargs);
		BT_kFree(copy);
		return BT_ERR_NONE;
	}

	pCommand->pfnCommand(ulArguments, pargs);

	BT_kFree(pargs);
	BT_kFree(copy);

	return BT_ERR_NONE;
}