Exec_stat MCProperty::mode_set(MCExecPoint& ep)
{
	switch(which)
	{
	case P_REV_CRASH_REPORT_SETTINGS:
		{
			MCVariableValue *t_settings;
			t_settings = ep . getarray();

			if (t_settings == NULL)
				break;

			MCExecPoint ep_key(ep);

			if (t_settings -> fetch_element(ep_key, "verbose") == ES_NORMAL)
				MCU_stob(ep_key . getsvalue(), MCcrashreportverbose);

			if (t_settings -> fetch_element(ep_key, "filename") == ES_NORMAL)
			{
				if (MCcrashreportfilename != NULL)
					delete MCcrashreportfilename;
				MCcrashreportfilename = ep_key . getsvalue() . getlength() > 0 ? ep_key . getsvalue() . clone() : NULL;
			}
		}
		break;

	case P_REV_LICENSE_LIMITS:
		{
			if(!MCenvironmentactive)
				break;

			MCVariableValue *t_settings = ep.getarray();

			if (t_settings == NULL)
				break;

			MCExecPoint ep_key(ep);

			if (t_settings -> fetch_element(ep_key, "token") == ES_NORMAL)
				MClicenseparameters . license_token = ep_key . getsvalue() . clone();

			if (t_settings -> fetch_element(ep_key, "name") == ES_NORMAL)
				MClicenseparameters . license_name = ep_key . getsvalue() . clone();

			if (t_settings -> fetch_element(ep_key, "organization") == ES_NORMAL)
				MClicenseparameters . license_organization = ep_key . getsvalue() . clone();

			if (t_settings -> fetch_element(ep_key, "class") == ES_NORMAL)
			{
				static struct { const char *tag; uint32_t value; } s_class_map[] =
				{
					{ "community", kMCLicenseClassCommunity },
					{ "commercial", kMCLicenseClassCommercial },
					{ "professional", kMCLicenseClassProfessional },
					{ NULL, kMCLicenseClassNone }
				};
				
				uint4 t_index;
				for(t_index = 0; s_class_map[t_index] . tag != NULL; ++t_index)
					if (ep_key . getsvalue() == s_class_map[t_index] . tag)
						break;

				MClicenseparameters . license_class = s_class_map[t_index] . value;
			}

			if (t_settings -> fetch_element(ep_key, "multiplicity") == ES_NORMAL && ep_key . ton() == ES_NORMAL)
				MClicenseparameters . license_multiplicity = ep_key . getuint4();

			if (t_settings -> fetch_element(ep_key, "scriptlimit") == ES_NORMAL && ep_key . ton() == ES_NORMAL)
				MClicenseparameters . script_limit = ep_key . getnvalue() <= 0 ? 0 : ep_key . getuint4();

			if (t_settings -> fetch_element(ep_key, "dolimit") == ES_NORMAL && ep_key . ton() == ES_NORMAL)
				MClicenseparameters . do_limit = ep_key . getnvalue() <= 0 ? 0 : ep_key . getuint4();

			if (t_settings -> fetch_element(ep_key, "usinglimit") == ES_NORMAL && ep_key . ton() == ES_NORMAL)
				MClicenseparameters . using_limit = ep_key . getnvalue() <= 0 ? 0 : ep_key . getuint4();

			if (t_settings -> fetch_element(ep_key, "insertlimit") == ES_NORMAL && ep_key . ton() == ES_NORMAL)
				MClicenseparameters . insert_limit = ep_key . getnvalue() <= 0 ? 0 : ep_key . getuint4();

			if (t_settings -> fetch_element(ep_key, "deploy") == ES_NORMAL)
			{
				static struct { const char *tag; uint32_t value; } s_deploy_map[] =
				{
					{ "windows", kMCLicenseDeployToWindows },
					{ "macosx", kMCLicenseDeployToMacOSX },
					{ "linux", kMCLicenseDeployToLinux },
					{ "ios", kMCLicenseDeployToIOS },
					{ "android", kMCLicenseDeployToAndroid },
					{ "winmobile", kMCLicenseDeployToWinMobile },
					{ "meego", kMCLicenseDeployToLinuxMobile },
					{ "server", kMCLicenseDeployToServer },
					{ "ios-embedded", kMCLicenseDeployToIOSEmbedded },
					{ "android-embedded", kMCLicenseDeployToIOSEmbedded },
				};

				MClicenseparameters . deploy_targets = 0;

				uint32_t t_target_count;
				char **t_targets;
				t_target_count = 0;
				t_targets = nil;
				if (MCCStringSplit(ep_key . getcstring(), ',', t_targets, t_target_count))
				{
					for(uint32_t i = 0; i < t_target_count; i++)
					{
						for(uint32_t j = 0; j < sizeof(s_deploy_map) / sizeof(s_deploy_map[0]); j++)
							if (MCCStringEqualCaseless(s_deploy_map[j] . tag, t_targets[i]))
							{
								MClicenseparameters . deploy_targets |= s_deploy_map[j] . value;
								break;
							}
					}
					MCCStringArrayFree(t_targets, t_target_count);
				}
			}

			if (t_settings -> fetch_element(ep_key, "addons") == ES_NORMAL && ep_key . getformat() == VF_ARRAY)
				MClicenseparameters . addons = new MCVariableValue(*(ep_key . getarray()));
		}
		break;

	case P_REV_MESSAGE_BOX_REDIRECT:
		{
			MCObject *t_object;
			t_object = getobj(ep);
			if (t_object != NULL)
				MCmessageboxredirect = t_object;
			else
				MCmessageboxredirect = NULL;
		}
		break;

#ifdef FEATURE_PROPERTY_LISTENER
	// MM-2012-11-06: [[ Property Listener ]]
	case P_REV_PROPERTY_LISTENER_THROTTLE_TIME:
		if (ep.getuint4(MCpropertylistenerthrottletime, line, pos, EE_OBJECT_NAN) != ES_NORMAL)
			return ES_ERROR;			
		break;
#endif
			
	default:
		return ES_NOT_HANDLED;
	}

	return ES_NORMAL;
}
Beispiel #2
0
Exec_stat MCFunction::evalparams(Functions func, MCParameter *params,
                                 MCExecPoint &ep)
{
	uint4 nparams = 0;
	real8 n, tn, oldn;
	n = oldn = 0.0;
	MCSortnode *mditems = NULL;
	// JS-2013-06-19: [[ StatsFunctions ]] Support for new stats functions based on arithmeticMean
	if (func == F_AVG_DEV || func == F_POP_STD_DEV || func == F_POP_VARIANCE || func == F_SMP_STD_DEV || func == F_SMP_VARIANCE)
	{ //use recursion to get average first
		if (evalparams(F_ARI_MEAN, params, ep) != ES_NORMAL)
			return ES_ERROR;
		oldn = ep.getnvalue();
	}
	// JS-2013-06-19: [[ StatsFunctions ]] Support for geometricMean
	if (func == F_GEO_MEAN)
	{ //use recursion to count items first
		if (evalparams(F_UNDEFINED, params, ep) != ES_NORMAL)
			return ES_ERROR;
		oldn = ep.getnvalue();
	}
	if (func == F_MEDIAN)
	{ //use recursion to count items first
		if (evalparams(F_UNDEFINED, params, ep) != ES_NORMAL)
			return ES_ERROR;
		mditems = new MCSortnode[(uint4)ep.getnvalue()];
	}
	if (params != NULL && params->getnext() == NULL)
	{
		if (params->eval(ep) != ES_NORMAL)
		{
			MCeerror->add(EE_FUNCTION_BADSOURCE, line, pos);
			return ES_ERROR;
		}
		if (ep.getformat() == VF_ARRAY)
		{
			if (ep.getarray() -> is_array() && ep.getarray()->get_array()->dofunc(ep, func, nparams, n, oldn, mditems) != ES_NORMAL)
			{
				MCeerror->add(EE_FUNCTION_BADSOURCE, line, pos);
				return ES_ERROR;
			}
		}
		else
		{
			MCString s(ep.getsvalue());
			uint4 length = s.getlength();
			const char *sptr = s.getstring();
			MCU_skip_spaces(sptr, length);
			while (length != 0)
			{
				s.setstring(sptr);
				if (!MCU_strchr(sptr, length, ','))
				{
					s.setlength(length);
					length = 0;
				}
				else
				{
					s.setlength(sptr - s.getstring());
					MCU_skip_char(sptr, length);
					MCU_skip_spaces(sptr, length);
				}
				if (s.getlength() == 0)
					tn = 0.0;
				else
					if (!MCU_stor8(s, tn))
					{
						MCeerror->add
						(EE_FUNCTION_NAN, 0, 0, s);
						return ES_ERROR;
					}
				MCU_dofunc(func, nparams, n, tn, oldn, mditems);
			}
		}
	}
	else
	{
		MCParameter *tparam = params;
		while (tparam != NULL)
		{
			if (tparam->eval(ep) != ES_NORMAL || ep.ton() != ES_NORMAL)
			{
				MCeerror->add(EE_FUNCTION_BADSOURCE, line, pos);
				return ES_ERROR;
			}
			MCU_dofunc(func, nparams, n, ep.getnvalue(), oldn, mditems);
			tparam = tparam->getnext();
		}
	}
	
	if (nparams != 0)
		switch (func)
	{
		// JS-2013-06-19: [[ StatsFunctions ]] Support for arithmeticMean (was average)
		case F_ARI_MEAN:
			n /= nparams;
			break;
		// JS-2013-06-19: [[ StatsFunctions ]] Support for averageDeviation
		case F_AVG_DEV:
			n /= nparams;
			break;
		// JS-2013-06-19: [[ StatsFunctions ]] Support for harmonicMean
		case F_HAR_MEAN:
			n = nparams/n;
			break;
		case F_MEDIAN:
			{
				uint4 toffset;
				MCU_sort(mditems, nparams, ST_ASCENDING, ST_NUMERIC);
				toffset = (nparams + 1)/2 - 1;
				if ((nparams % 2) != 0) //odd
					n = mditems[toffset].nvalue;
				else //even average 2 closest values
					n = (mditems[toffset].nvalue + mditems[toffset+1].nvalue)/2;
				break;
			}
		// JS-2013-06-19: [[ StatsFunctions ]] Support for populationStandardDeviation
		case F_POP_STD_DEV:
			n = sqrt(n/nparams);
			break;
		// JS-2013-06-19: [[ StatsFunctions ]] Support for populationVariance
		case F_POP_VARIANCE:
			n /= nparams;
			break;
		// JS-2013-06-19: [[ StatsFunctions ]] Support for sampleStandardDeviation (was stdDev)
		case F_SMP_STD_DEV:
			n = sqrt(n/(nparams - 1));
			break;
		// JS-2013-06-19: [[ StatsFunctions ]] Support for sampleVariance
		case F_SMP_VARIANCE:
			n /= nparams - 1;
			break;
		case F_UNDEFINED:
			n = nparams;
			break;
		default:
			break;
		}
	ep.setnvalue(n);
	delete mditems;
	return ES_NORMAL;
}