Exemple #1
0
static void __stdcall DoExtractString(char* scriptData, UInt32 dataLen, char* dest, ScriptEventList* eventList)
{
	// copy the string
	memcpy(dest, scriptData, dataLen);
	dest[dataLen] = 0;
	
	if (dataLen && dest[0] == '$' && eventList && eventList->m_script)	// variable name
	{
		Script::VariableInfo* varInfo = NULL;
		varInfo = eventList->m_script->GetVariableByName(dest + 1);
		if (varInfo)
		{
			ScriptEventList::Var* var;
			var = eventList->GetVariable(varInfo->idx);
			if (var)
			{
				StringVar* strVar;
				strVar = g_StringMap.Get(var->data);
				if (strVar)
					if (strVar->GetLength() < 0x100)		// replace string with contents of string var
						strcpy_s(dest, strVar->GetLength() + 1, strVar->GetCString());
			}
		}
	}			// "%e" becomes an empty string
	else if (dataLen == 2 && dest[0] == '%' && toupper(dest[1]) == 'E')
		dest[0] = 0;
}
	const char* GetString(UInt32 stringID)
	{
		StringVar* var = g_StringMap.Get(stringID);
		if (var)
			return var->GetCString();
		else
			return NULL;
	}
Exemple #3
0
AssignableStringVarToken::AssignableStringVarToken(UInt32 _id, UInt32 lbound, UInt32 ubound) : AssignableStringToken(_id, lbound, ubound)
{
	StringVar* strVar = g_StringMap.Get(value.arrID);
	if (strVar) {
		upper = (upper > strVar->GetLength()) ? strVar->GetLength() - 1 : upper;
		substring = strVar->SubString(lower, upper - lower + 1);
	}
}
bool Cmd_sv_Length_Execute(COMMAND_ARGS)
{
	*result = -1;			// sentinel value if extraction fails
	UInt32 strID = 0;
	if (ExtractArgs(EXTRACT_ARGS, &strID))
	{
		StringVar* str = g_StringMap.Get(strID);
		if (str)
			*result = str->GetLength();
	}

	return true;
}
Exemple #5
0
StringIterLoop::StringIterLoop(const ForEachContext* context)
{
	StringVar* srcVar = g_StringMap.Get(context->sourceID);
	StringVar* iterVar = g_StringMap.Get(context->iteratorID);
	if (srcVar && iterVar)
	{
		m_src = srcVar->String();
		m_curIndex = 0;
		m_iterID = context->iteratorID;
		if (m_src.length())
			iterVar->Set(m_src.substr(0, 1).c_str());
	}
}
bool StringVar_Find_Execute(COMMAND_ARGS, UInt32 mode, CommandInfo* commandInfo)
{
	*result = -1;
	UInt32 strID = 0;
	UInt32 startPos = 0;
	UInt32 numChars = -1;
	UInt32 bCaseSensitive = 0;
	UInt32 numToReplace = -1;			//replace all by default
	char toFind[kMaxMessageLength] = { 0 };

	UInt32 intResult = -1;

	if (!ExtractFormatStringArgs(0, toFind, PASS_FMTSTR_ARGS, commandInfo->numParams, &strID, &startPos, &numChars, &bCaseSensitive, &numToReplace))
		return true;

	StringVar* strVar = g_StringMap.Get(strID);
	if (strVar)
	{
		if (numChars == -1)
			numChars = strVar->GetLength() - startPos;

		switch (mode)
		{
		case eMode_svFind:
			intResult = strVar->Find(toFind, startPos, numChars, bCaseSensitive ? true : false);
			break;
		case eMode_svCount:
			intResult = strVar->Count(toFind, startPos, numChars, bCaseSensitive ? true : false);
			break;
		case eMode_svReplace:
			{
				std::string str(toFind);
				UInt32 splitPoint = str.find(GetSeparatorChar(scriptObj));
				if (splitPoint != -1 && splitPoint < str.length())
				{
					toFind[splitPoint] = '\0';
					char* replaceWith = (splitPoint == str.length() - 1) ? "" : toFind + splitPoint + 1;
					intResult = strVar->Replace(toFind, replaceWith, startPos, numChars, bCaseSensitive ? true : false, numToReplace);
				}
				break;
			}
		}
	}

	if (intResult != -1)
		*result = intResult;

	return true;
}
bool Cmd_sv_Set_Execute(COMMAND_ARGS)
{
	char buffer[kMaxMessageLength] = { 0 };
	UInt32 stringID = 0;
	if (ExtractFormatStringArgs(0, buffer, PASS_FMTSTR_ARGS, kCommandInfo_sv_Set.numParams, &stringID))
	{
		StringVar* var = g_StringMap.Get(stringID);
		if (var)
		{
			var->Set(buffer);
		}
	}

	return true;
}
Exemple #8
0
bool StringIterLoop::Update(COMMAND_ARGS)
{
	StringVar* iterVar = g_StringMap.Get(m_iterID);
	if (iterVar)
	{
		m_curIndex++;
		if (m_curIndex < m_src.length())
		{
			iterVar->Set(m_src.substr(m_curIndex, 1).c_str());
			return true;
		}
	}

	return false;
}
bool Cmd_sv_GetChar_Execute(COMMAND_ARGS)
{
	UInt32 strID = 0;
	UInt32 charPos = 0;
	*result = -1;			// error return value

	if (!ExtractArgs(EXTRACT_ARGS, &strID, &charPos))
		return true;

	StringVar* strVar = g_StringMap.Get(strID);
	if (strVar)
		*result = strVar->At(charPos);

	return true;
}
bool Cmd_sv_Insert_Execute(COMMAND_ARGS)
{
	UInt32 strID = 0;
	UInt32 insertionPos = 0;
	char subString[kMaxMessageLength] = { 0 };
	*result = 0;

	if (!ExtractFormatStringArgs(0, subString, PASS_FMTSTR_ARGS, kCommandInfo_sv_Insert.numParams, &strID, &insertionPos))
		return true;

	StringVar* lhs = g_StringMap.Get(strID);
	if (lhs)
		lhs->Insert(subString, insertionPos);

	return true;
}
Exemple #11
0
const char* ScriptToken::GetString() const
{
	static const char* empty = "";
	const char* result = NULL;

	if (type == kTokenType_String)
		result = value.str.c_str();
#if OBLIVION
	else if (type == kTokenType_StringVar && value.var)
	{
		StringVar* strVar = g_StringMap.Get(value.var->data);
		result = strVar ? strVar->GetCString() : NULL;
	}
#endif
	return result ? result : empty;
}
Exemple #12
0
bool AssignableStringVarToken::Assign(const char* str)
{
	StringVar* strVar = g_StringMap.Get(value.arrID);
	if (strVar) {
		UInt32 len = strVar->GetLength();
		if (lower <= upper && upper < len) {
			strVar->Erase(lower, upper-lower + 1);
			if (str) {
				strVar->Insert(str, lower);
				substring = strVar->String();
			}
			return true;
		}
	}

	return false;
}
bool AssignToStringVarLong(COMMAND_ARGS, const char* newValue)
{
	double strID = 0;
	UInt8 modIndex = 0;
	bool bTemp = ExpressionEvaluator::Active();
	StringVar* strVar = NULL;

	UInt32 len = (newValue) ? strlen(newValue) : 0;
	if (!newValue || len >= kMaxMessageLength)		//if null pointer or too long, assign an empty string
		newValue = "";

	if (ExtractSetStatementVar(scriptObj, eventList, scriptData, &strID, &modIndex)) {
		strVar = g_StringMap.Get(strID);
		bTemp = false;
	}
	else if (!bTemp) {
		_WARNING("Function must be used within a Set statement or NVSE expression");
		return false;
	}

	if (!modIndex)
		modIndex = scriptObj->GetModIndex();

	if (strVar)
	{
		strVar->Set(newValue);
		g_StringMap.MarkTemporary(strID, false);
	}
	else
		strID = g_StringMap.Add(modIndex, newValue, bTemp);

	*result = strID;

#if _DEBUG	// console feedback disabled in release by request (annoying when called from batch scripts)
	if (IsConsoleMode() && !bTemp)
	{
		if (len < 480)
			Console_Print("Assigned string >> \"%s\"", newValue);
		else
			Console_Print("Assigned string (too long to print)");
	}
#endif

	return true;
}
bool Cmd_sv_Compare_Execute(COMMAND_ARGS)
{
	*result = -2;			//sentinel value if comparison fails
	UInt32 stringID = 0;
	char buffer[kMaxMessageLength] = { 0 };
	UInt32 bCaseSensitive = 0;

	if (!ExtractFormatStringArgs(0, buffer, PASS_FMTSTR_ARGS, kCommandInfo_sv_Compare.numParams, &stringID, &bCaseSensitive))
		return true;

	StringVar* lhs = g_StringMap.Get(stringID);
	if (!lhs)
		return true;

	*result = lhs->Compare(buffer, bCaseSensitive ? true : false);

	return true;
}
bool Cmd_sv_ToNumeric_Execute(COMMAND_ARGS)
{
	UInt32 strID = 0;
	UInt32 startPos = 0;
	*result = 0;

	if (!ExtractArgs(EXTRACT_ARGS, &strID, &startPos))
		return true;

	StringVar* strVar = g_StringMap.Get(strID);
	if (strVar)
	{
		const char* cStr = strVar->GetCString();
		*result = strtod(cStr + startPos, NULL);
	}

	return true;
}
bool Cmd_sv_Erase_Execute(COMMAND_ARGS)
{
	*result = 0;
	UInt32 strID = 0;
	UInt32 startPos = 0;
	UInt32 howMany = -1;

	if (!ExtractArgs(EXTRACT_ARGS, &strID, &startPos, &howMany))
		return true;

	StringVar* strVar = g_StringMap.Get(strID);
	if (strVar)
	{
		if (howMany == -1)
			howMany = strVar->GetLength() - startPos;

		strVar->Erase(startPos, howMany);
	}

	return true;
}
bool Cmd_sv_SubString_Execute(COMMAND_ARGS)
{
	UInt32 rhStrID = 0;
	UInt32 startPos = 0;
	UInt32 howMany = -1;
	std::string subStr;

	if (ExtractArgs(EXTRACT_ARGS, &rhStrID, &startPos, &howMany))
	{
		StringVar* rhVar = g_StringMap.Get(rhStrID);
		if (!rhVar)
			return true;

		if (howMany == -1)
			howMany = rhVar->GetLength() - startPos;

		subStr = rhVar->SubString(startPos, howMany);
	}

	AssignToStringVar(PASS_COMMAND_ARGS, subStr.c_str());
	return true;
}
Exemple #18
0
static UInt32 __stdcall DoExtractString(char* scriptData, UInt32 dataLen, char* dest, ScriptEventList* eventList)
{
	// copy the string
	memcpy(dest, scriptData, dataLen);
	UInt32 newDataLen = dataLen;
	
	if (newDataLen && dest[0] == '$' && eventList && eventList->m_script)	// variable name
	{
		VariableInfo* varInfo = NULL;
		if ((newDataLen < 0x100) && (dest[newDataLen]))
			dest[newDataLen] = 0;
		varInfo = eventList->m_script->GetVariableByName(dest + 1);
		if (varInfo)
		{
			ScriptEventList::Var* var;
			var = eventList->GetVariable(varInfo->idx);
			if (var)
			{
				StringVar* strVar;
				strVar = g_StringMap.Get(var->data);
				if (strVar)
					if (strVar->GetLength() < 0x100) {		// replace string with contents of string var
						strcpy_s(dest, strVar->GetLength() + 1, strVar->GetCString());
						newDataLen = strVar->GetLength();
					}
			}
		}
	}			// "%e" becomes an empty string
	else if (newDataLen == 2 && dest[0] == '%' && toupper(dest[1]) == 'E') {
		newDataLen = 0;
	}
	// force zero terminated string
	if ((newDataLen < 0x100) && (dest[newDataLen]))
		dest[newDataLen] = 0;
	return dataLen;
}
	void SetString(UInt32 stringID, const char* newVal)
	{
		StringVar* var = g_StringMap.Get(stringID);
		if (var)
			var->Set(newVal);
	}
Exemple #20
0
void InteractiveMatlabDialog::SetResults()
{
//   MessageInterface::ShowMessage("SetResults() Entered \n");

   // need to execute the command
//   theCmd->Initialize();
   theCmd->Execute();

//   MessageInterface::ShowMessage("executed command \n");

   outputTextCtrl->AppendText(wxT("\nSent to Matlab:  "));
   wxString evaluationString = theCmd->FormEvalString();
   outputTextCtrl->AppendText(evaluationString.c_str());

//   MessageInterface::ShowMessage("got eval string \n");

   outputTextCtrl->AppendText(wxT("\n\n"));

   // output the results
   for (unsigned int i=0; i<outputStrings.Count(); i++)
   {
      Parameter *param = (Parameter *)theGuiInterpreter->GetConfiguredObject(
            wxString(outputStrings[i]));

      if (param->GetTypeName() == wxT("Array"))
      {
//         MessageInterface::ShowMessage("parameter is an array \n");

         Array *array = (Array *)param;
         int numRows = array->GetIntegerParameter(wxT("NumRows"));
         int numCols = array->GetIntegerParameter(wxT("NumCols"));

         // create rmatrix
         Rmatrix rmatrix = array->GetRmatrixParameter(wxT("RmatValue"));
//         MessageInterface::ShowMessage("got the array values\n");

         wxString os;
         os << array->GetName().c_str() << wxT(" = \n") ;

         for (int j=0; j<numRows; j++)
         {
           for (int k=0; k<numCols; k++)
             os << wxT("\t") << rmatrix(j, k);
           os << wxT("\n");
         }

         wxString paramString = os;
         outputTextCtrl->AppendText(paramString.c_str());

      }
      else if (param->GetTypeName() == wxT("String"))
      {
         wxString paramString;
         StringVar *stringVar = (StringVar *)param;
         paramString.Printf(wxT("%s = %s\n"), param->GetName().c_str(),
                                           stringVar->GetString().c_str());
         outputTextCtrl->AppendText(paramString);
      }
      else
//      if (param->GetTypeName() == "Variable")
      {
         wxString paramString;
         paramString.Printf(wxT("%s = %f\n"), param->GetName().c_str(),
                                           param->EvaluateReal());
         outputTextCtrl->AppendText(paramString);
      }
   }
}