Esempio n. 1
0
//++ ------------------------------------------------------------------------------------
// Details: Parse the command's argument options string and try to extract the value *this
//          argument is looking for.
// Type:    Overridden.
// Args:    vwArgContext    - (R) The command's argument options string.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool
CMICmdArgValConsume::Validate(CMICmdArgContext &vwArgContext)
{
    if (vwArgContext.IsEmpty())
        return MIstatus::success;

    // Consume the optional file, line, linenum arguments till the mode '--' argument
    const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs());
    CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
    while (it != vecOptions.end())
    {
        const CMIUtilString & rTxt( *it );
        
	if ( rTxt.compare( "--" ) == 0 )
        {
            m_bFound = true;
            m_bValid = true;
	    return MIstatus::success;
	}
	
	if ( !vwArgContext.RemoveArg( rTxt ) )
	    return MIstatus::failure;

        // Next
        ++it;
    }

    return MIstatus::failure;
}
//++
// Details: Parse the command's argument options string and try to extract the
// long
//          argument *this argument type is looking for.
// Type:    Overridden.
// Args:    vwArgContext    - (RW) The command's argument options string.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool CMICmdArgValOptionLong::Validate(CMICmdArgContext &vwArgContext) {
  if (vwArgContext.IsEmpty())
    return m_bMandatory ? MIstatus::failure : MIstatus::success;

  if (vwArgContext.GetNumberArgsPresent() == 1) {
    const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
    if (IsArgLongOption(rArg) && ArgNameMatch(rArg)) {
      m_bFound = true;

      if (!vwArgContext.RemoveArg(rArg))
        return MIstatus::failure;

      if (m_nExpectingNOptions == 0) {
        m_bValid = true;
        return MIstatus::success;
      }

      m_bIsMissingOptions = true;
      return MIstatus::failure;
    } else
      return MIstatus::failure;
  }

  // More than one option...
  MIuint nArgIndex = 0;
  const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs());
  CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
  while (it != vecOptions.end()) {
    const CMIUtilString &rArg(*it);
    if (IsArgOptionCorrect(rArg) && ArgNameMatch(rArg)) {
      m_bFound = true;

      if (!vwArgContext.RemoveArg(rArg))
        return MIstatus::failure;

      if (m_nExpectingNOptions != 0) {
        if (ExtractExpectedOptions(vwArgContext, nArgIndex)) {
          m_bValid = true;
          return MIstatus::success;
        }

        m_bIsMissingOptions = true;
        return MIstatus::failure;
      } else {
        m_bValid = true;
        return MIstatus::success;
      }
    }

    // Next
    ++it;
    ++nArgIndex;
  }

  return MIstatus::failure;
}
Esempio n. 3
0
//++ ------------------------------------------------------------------------------------
// Details:	Parse the command's argument options string and try to extract the value *this
//			argument is looking for.
// Type:	Overridden.
// Args:	vrwArgContext	- (RW) The command's argument options string.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMICmdArgValString::Validate( CMICmdArgContext & vrwArgContext )
{
	if( vrwArgContext.IsEmpty() )
		return MIstatus::success;

	if( m_bHandleQuotedString )
		return ValidateQuotedText( vrwArgContext );

	return ValidateSingleText( vrwArgContext );
}
Esempio n. 4
0
//++ ------------------------------------------------------------------------------------
// Details: Parse the command's argument options string and try to extract the value *this
//          argument is looking for.
// Type:    Overridden.
// Args:    vwArgContext    - (R) The command's argument options string.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool
CMICmdArgValFile::Validate(CMICmdArgContext &vwArgContext)
{
    if (vwArgContext.IsEmpty())
        return m_bMandatory ? MIstatus::failure : MIstatus::success;

    // The GDB/MI spec suggests there is only parameter

    if (vwArgContext.GetNumberArgsPresent() == 1)
    {
        const CMIUtilString &rFile(vwArgContext.GetArgsLeftToParse());
        if (IsFilePath(rFile))
        {
            m_bFound = true;
            m_bValid = true;
            m_argValue = rFile.Trim('"');
            vwArgContext.RemoveArg(rFile);
            return MIstatus::success;
        }
        else
            return MIstatus::failure;
    }

    // In reality there are more than one option,  if so the file option
    // is the last one (don't handle that here - find the best looking one)
    const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs());
    CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
    while (it != vecOptions.end())
    {
        const CMIUtilString &rTxt(*it);
        if (IsFilePath(rTxt))
        {
            m_bFound = true;

            if (vwArgContext.RemoveArg(rTxt))
            {
                m_bValid = true;
                m_argValue = rTxt.Trim('"');
                return MIstatus::success;
            }
            else
                return MIstatus::success;
        }

        // Next
        ++it;
    }

    return MIstatus::failure;
}
//++
// Details: Parse the command's argument options string and try to extract the
// value *this
//          argument is looking for.
// Type:    Overridden.
// Args:    vwArgContext    - (RW) The command's argument options string.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool CMICmdArgValPrintValues::Validate(CMICmdArgContext &vwArgContext) {
  if (vwArgContext.IsEmpty())
    return m_bMandatory ? MIstatus::failure : MIstatus::success;

  const CMIUtilString strArg(vwArgContext.GetArgs()[0]);
  if (IsArgPrintValues(strArg) && ExtractPrintValues(strArg)) {
    m_bFound = true;
    m_bValid = true;
    m_argValue = GetPrintValues();
    vwArgContext.RemoveArg(strArg);
    return MIstatus::success;
  }

  return MIstatus::failure;
}
Esempio n. 6
0
//++ ------------------------------------------------------------------------------------
// Details: Parse the command's argument options string and try to extract the value *this
//          argument is looking for.
// Type:    Overridden.
// Args:    vwArgContext    - (RW) The command's argument options string.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool
CMICmdArgValThreadGrp::Validate(CMICmdArgContext &vwArgContext)
{
    if (vwArgContext.IsEmpty())
        return m_bMandatory ? MIstatus::failure : MIstatus::success;

    if (vwArgContext.GetNumberArgsPresent() == 1)
    {
        const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
        if (IsArgThreadGrp(rArg) && ExtractNumber(rArg))
        {
            m_bFound = true;
            m_bValid = true;
            m_argValue = GetNumber();
            vwArgContext.RemoveArg(rArg);
            return MIstatus::success;
        }
        else
            return MIstatus::failure;
    }

    // More than one option...
    const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs());
    CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
    while (it != vecOptions.end())
    {
        const CMIUtilString &rArg(*it);
        if (IsArgThreadGrp(rArg) && ExtractNumber(rArg))
        {
            m_bFound = true;

            if (vwArgContext.RemoveArg(rArg))
            {
                m_bValid = true;
                m_argValue = GetNumber();
                return MIstatus::success;
            }
            else
                return MIstatus::failure;
        }

        // Next
        ++it;
    }

    return MIstatus::failure;
}
Esempio n. 7
0
//++ ------------------------------------------------------------------------------------
// Details:	Parse the command's argument options string and try to extract the list of
//			arguments based on the argument object type to look for.
// Type:	Overridden.
// Args:	vwArgContext	- (RW) The command's argument options string.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMICmdArgValListOfN::Validate( CMICmdArgContext & vwArgContext )
{
	if( m_eArgType >= eArgValType_count )
	{
		m_eArgType = eArgValType_invalid;
		return MIstatus::failure;
	}

	if( vwArgContext.IsEmpty() )
		return MIstatus::success;

	const CMIUtilString & rArg( vwArgContext.GetArgsLeftToParse() ); 
	if( IsListOfN( rArg ) && CreateList( rArg ) )
	{
		m_bFound = true;
		m_bValid = true;
		vwArgContext.RemoveArg( rArg );
		return MIstatus::success;
	}
	else
		return MIstatus::failure;
}
Esempio n. 8
0
//++ ------------------------------------------------------------------------------------
// Details:	Given a set of command argument objects parse the context option string to
//			find those argument and retrieve their value. If the function fails call
//			GetArgsThatAreMissing() to see which commands that were mandatory were 
//			missing or failed to parse.
// Type:	Method.
// Args:	vStrMiCmd		- (R)  Command's name.
//			vCmdArgsText	- (RW) A command's options or argument.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMICmdArgSet::Validate( const CMIUtilString & vStrMiCmd, CMICmdArgContext & vwCmdArgsText )
{
	m_cmdArgContext = vwCmdArgsText;

	// Iterate all the arguments or options required by a command
	const MIuint nArgs = vwCmdArgsText.GetNumberArgsPresent();
	MIuint nArgsMandatoryCnt = 0;
	SetCmdArgs_t::const_iterator it = m_setCmdArgs.begin();
	while( it != m_setCmdArgs.end() )
	{
		const CMICmdArgValBase * pArg( *it );
		const CMIUtilString & rArgName( pArg->GetName() ); MIunused( rArgName );
		if( pArg->GetIsMandatory() )
			nArgsMandatoryCnt++;
		if( !const_cast< CMICmdArgValBase * >( pArg )->Validate( vwCmdArgsText ) )
		{
			if( pArg->GetIsMandatory() && !pArg->GetFound() )
				m_setCmdArgsThatAreMissing.push_back( const_cast< CMICmdArgValBase * >( pArg ) );
			else if( pArg->GetFound() ) 
			{
				if( pArg->GetIsMissingOptions() )
					m_setCmdArgsMissingInfo.push_back( const_cast< CMICmdArgValBase * >( pArg ) );
				else if( !pArg->GetValid() )
					m_setCmdArgsThatNotValid.push_back( const_cast< CMICmdArgValBase * >( pArg ) );
			}
		}
		if( pArg->GetFound() && !pArg->GetIsHandledByCmd() )
		{
			m_bIsArgsPresentButNotHandledByCmd = true;
			m_setCmdArgsNotHandledByCmd.push_back( const_cast< CMICmdArgValBase * >( pArg ) );
		}

		// Next
		++it;
	}

	// Check that one or more argument objects have any issues to report...

	if( nArgs < nArgsMandatoryCnt )
	{
		SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_N_OPTIONS_REQUIRED ), nArgsMandatoryCnt ) );
		return MIstatus::failure;
	}
	
	if( !vwCmdArgsText.IsEmpty() )
	{
		SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_CONTEXT_NOT_ALL_EATTEN ), vwCmdArgsText.GetArgsLeftToParse().c_str() ) );
		return MIstatus::failure;
	}

	if( IsArgsPresentButNotHandledByCmd() )
		WarningArgsNotHandledbyCmdLogFile( vStrMiCmd );

	CMIUtilString strListMissing;
	CMIUtilString strListInvalid;
	CMIUtilString strListMissingInfo;
	const bool bArgsMissing = (m_setCmdArgsThatAreMissing.size() > 0);
	const bool bArgsInvalid = (m_setCmdArgsThatNotValid.size() > 0);
	const bool bArgsMissingInfo = (m_setCmdArgsMissingInfo.size() > 0);
	if( !(bArgsMissing || bArgsInvalid || bArgsMissingInfo) )
		return MIstatus::success;
	if( bArgsMissing )
	{
		MIuint i = 0;
		SetCmdArgs_t::const_iterator it = m_setCmdArgsThatAreMissing.begin();
		while( it != m_setCmdArgsThatAreMissing.end() )
		{
			if( i++ > 0 )
				strListMissing += m_constStrCommaSpc;

			const CMICmdArgValBase * pArg( *it );
			strListMissing += pArg->GetName();

			// Next
			++it;
		}
	}
	if( bArgsInvalid )
	{
		MIuint i = 0;
		SetCmdArgs_t::const_iterator it = m_setCmdArgsThatNotValid.begin();
		while( it != m_setCmdArgsThatNotValid.end() )
		{
			if( i++ > 0 )
				strListMissing += m_constStrCommaSpc;

			const CMICmdArgValBase * pArg( *it );
			strListInvalid += pArg->GetName();

			// Next
			++it;
		}
	}
	if( bArgsMissingInfo )
	{
		MIuint i = 0;
		SetCmdArgs_t::const_iterator it = m_setCmdArgsMissingInfo.begin();
		while( it != m_setCmdArgsMissingInfo.end() )
		{
			if( i++ > 0 )
				strListMissingInfo += m_constStrCommaSpc;

			const CMICmdArgValBase * pArg( *it );
			strListMissingInfo += pArg->GetName();

			// Next
			++it;
		}
	}
	if( bArgsMissing && bArgsInvalid )
	{
		SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_VALIDATION_MAN_INVALID ), strListMissing.c_str(), strListInvalid.c_str() ) );
		return MIstatus::failure;
	}
	if( bArgsMissing )
	{
		SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_VALIDATION_MANDATORY ), strListMissing.c_str() ) );
		return MIstatus::failure;
	}
	if( bArgsMissingInfo )
	{
		SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_VALIDATION_MISSING_INF ), strListMissingInfo.c_str() ) );
		return MIstatus::failure;
	}
	if( bArgsInvalid )
	{
		SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_VALIDATION_INVALID ), strListInvalid.c_str() ) );
		return MIstatus::failure;
	}
	
	return MIstatus::success;
}