bool IDockScreenDisplay::EvalBool (const CString &sCode, bool *retbResult, CString *retsError)

//	EvalBool
//
//	Evaluates the given string

	{
	CCodeChainCtx Ctx;
	Ctx.SetScreen(&m_DockScreen);
	Ctx.SaveAndDefineSourceVar(m_pLocation);
	Ctx.SaveAndDefineDataVar(m_pData);

	char *pPos = sCode.GetPointer();
	ICCItem *pExp = Ctx.Link(sCode, 1, NULL);

	ICCItem *pResult = Ctx.Run(pExp);	//	LATER:Event
	Ctx.Discard(pExp);

	if (pResult->IsError())
		{
		*retsError = pResult->GetStringValue();
		Ctx.Discard(pResult);
		return false;
		}

	*retbResult = !pResult->IsNil();
	Ctx.Discard(pResult);

	return true;
	}
Example #2
0
bool CMission::ParseCriteria (const CString &sCriteria, SCriteria *retCriteria)

//	ParseCriteria
//
//	Parses criteria. Returns TRUE if successful.

{
    //	Initialize

    *retCriteria = SCriteria();

    //	Parse

    char *pPos = sCriteria.GetPointer();
    while (*pPos != '\0')
    {
        switch (*pPos)
        {
        case '*':
            retCriteria->bIncludeOpen = true;
            retCriteria->bIncludeUnavailable = true;
            retCriteria->bIncludeActive = true;
            retCriteria->bIncludeRecorded = true;
            break;

        case 'a':
            retCriteria->bIncludeActive = true;
            break;

        case 'o':
            retCriteria->bIncludeOpen = true;
            break;

        case 'r':
            retCriteria->bIncludeRecorded = true;
            break;

        case 'u':
            retCriteria->bIncludeUnavailable = true;
            break;

        case 'S':
            retCriteria->bOnlySourceOwner = true;
            break;

        case '+':
        case '-':
        {
            bool bRequired = (*pPos == '+');
            bool bBinaryParam;
            CString sParam = ParseCriteriaParam(&pPos, false, &bBinaryParam);

            if (bRequired)
            {
                if (bBinaryParam)
                    retCriteria->SpecialRequired.Insert(sParam);
                else
                    retCriteria->AttribsRequired.Insert(sParam);
            }
            else
            {
                if (bBinaryParam)
                    retCriteria->SpecialNotAllowed.Insert(sParam);
                else
                    retCriteria->AttribsNotAllowed.Insert(sParam);
            }
            break;
        }
        }

        pPos++;
    }

    //	Make sure we include some missions

    if (!retCriteria->bIncludeUnavailable
            && !retCriteria->bIncludeActive
            && !retCriteria->bIncludeRecorded
            && !retCriteria->bIncludeOpen)
    {
        retCriteria->bIncludeUnavailable = true;
        retCriteria->bIncludeActive = true;
        retCriteria->bIncludeRecorded = true;
        retCriteria->bIncludeOpen = true;
    }

    return true;
}