예제 #1
0
//++ ------------------------------------------------------------------------------------
// Details: Create list of argument objects each holding a value extract from the command
//          options line.
// Type:    Method.
// Args:    vrTxt   - (R) Some options text.
// Return:  bool -  True = yes valid arg, false = no.
// Throws:  None.
//--
bool
CMICmdArgValListOfN::CreateList(const CMIUtilString &vrTxt)
{
    CMIUtilString::VecString_t vecOptions;
    if ((m_eArgType == eArgValType_StringQuoted) || (m_eArgType == eArgValType_StringQuotedNumber) ||
        (m_eArgType == eArgValType_StringQuotedNumberPath) || (m_eArgType == eArgValType_StringAnything))
    {
        if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
            return MIstatus::failure;
    }
    else if (vrTxt.Split(" ", vecOptions) == 0)
        return MIstatus::failure;

    CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
    while (it != vecOptions.end())
    {
        const CMIUtilString &rOption = *it;
        CMICmdArgValBase *pOption = CreationObj(rOption, m_eArgType);
        if (pOption != nullptr)
            m_argValue.push_back(pOption);
        else
            return MIstatus::failure;

        // Next
        ++it;
    }

    return MIstatus::success;
}
예제 #2
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;
}
예제 #3
0
//++ ------------------------------------------------------------------------------------
// Details: Examine the string and determine if it is a valid string type argument.
// Type:    Method.
// Args:    vrTxt   - (R) Some text.
// Return:  bool -  True = yes valid arg, false = no.
// Throws:  None.
//--
bool
CMICmdArgValListOfN::IsListOfN(const CMIUtilString &vrTxt) const
{
    CMIUtilString::VecString_t vecOptions;
    if ((m_eArgType == eArgValType_StringQuoted) || (m_eArgType == eArgValType_StringQuotedNumber) ||
        (m_eArgType == eArgValType_StringQuotedNumberPath) || (m_eArgType == eArgValType_StringAnything))
    {
        if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
            return false;
    }
    else if (vrTxt.Split(" ", vecOptions) == 0)
        return false;

    CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
    while (it != vecOptions.end())
    {
        const CMIUtilString &rOption = *it;
        if (!IsExpectedCorrectType(rOption, m_eArgType))
            break;

        // Next
        ++it;
    }

    return true;
}
예제 #4
0
//++
// 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;
}
예제 #5
0
//++ ------------------------------------------------------------------------------------
// Details:	Parse the text following *this argument and extract the options the values of
//			CMICmdArgValListBase::m_eArgType forming argument objects for each of those
//			options extracted.
// Type:	Method.
// Args:	vrwTxt		- (RW)	The command's argument options string.
//			nArgIndex	- (R)	The Nth arg position in argument context from the left.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMICmdArgValOptionLong::ExtractExpectedOptions( CMICmdArgContext & vrwTxt, const MIuint nArgIndex ) 
{
	CMIUtilString::VecString_t vecOptions;
	MIuint nOptionsPresent = 0;
	if( (m_eExpectingOptionType != eArgValType_StringQuoted) && 
		(m_eExpectingOptionType != eArgValType_StringQuotedNumber) &&
		(m_eExpectingOptionType != eArgValType_StringQuotedNumberPath) )
		nOptionsPresent = vrwTxt.GetArgsLeftToParse().Split( " ", vecOptions );
	else
		nOptionsPresent = vrwTxt.GetArgsLeftToParse().SplitConsiderQuotes( " ", vecOptions );
	if( nOptionsPresent == 0 )
		return MIstatus::failure;

	MIuint nArgIndexCnt = 0;
	MIuint nTypeCnt = 0;
	MIuint nTypeCnt2 = 0;
	MIuint nFoundNOptionsCnt = 0;
	CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
	while( it != vecOptions.end() )
	{
		// Move to the Nth argument position from left before do validation/checking
		if( nArgIndexCnt++ == nArgIndex )
		{
			nTypeCnt++;
			const CMIUtilString & rOption( *it ); 
			if( IsExpectedCorrectType( rOption, m_eExpectingOptionType ) )
			{
				nTypeCnt2++;
				CMICmdArgValBase * pOptionObj = CreationObj( rOption, m_eExpectingOptionType );
				if( (pOptionObj != nullptr) && vrwTxt.RemoveArgAtPos( rOption, nArgIndex ) )
				{
					nFoundNOptionsCnt++;
					m_vecArgsExpected.push_back( pOptionObj );
				}
			}

			// Is the sequence 'options' of same type broken. Expecting the same type until the
			// next argument.
			if( nTypeCnt != nTypeCnt2 )
				return MIstatus::failure;

			if( nFoundNOptionsCnt == m_nExpectingNOptions )
				return MIstatus::success;
		}

		// Next
		++it;
	}
	if( nFoundNOptionsCnt != m_nExpectingNOptions )
		return MIstatus::failure;

	return MIstatus::success;
}
예제 #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    - (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;
}
예제 #7
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;
}
예제 #8
0
//++ ------------------------------------------------------------------------------------
// Details:	Parse the command's argument options string and try to extract only the next
//			word delimited by the next space.
// Type:	Method.
// Args:	vrwArgContext	- (RW) The command's argument options string.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMICmdArgValString::ValidateSingleText( CMICmdArgContext & vrwArgContext )
{
	if( vrwArgContext.GetNumberArgsPresent() == 1 )
	{
		const CMIUtilString & rArg( vrwArgContext.GetArgsLeftToParse() ); 
		if( IsStringArg( rArg ) )
		{
			m_bFound = true;
			m_bValid = true;
			m_argValue = rArg;
			vrwArgContext.RemoveArg( rArg );
			return MIstatus::success;
		}
		else
			return MIstatus::failure;
	}
	
	// More than one option...
	const CMIUtilString::VecString_t vecOptions( vrwArgContext.GetArgs() );
	CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
	while( it != vecOptions.end() )
	{
		const CMIUtilString & rArg( *it ); 
		if( IsStringArg( rArg )  )
		{
			m_bFound = true;
				
			if( vrwArgContext.RemoveArg( rArg ) )
			{
				m_bValid = true;
				m_argValue = rArg;
				return MIstatus::success;
			}
			else
				return MIstatus::failure;
		}
		
		// Next
		++it;
	}

	return MIstatus::failure;
}