예제 #1
0
bool MCContactAddPropertyWithLabel(MCExecPoint& ep, MCVariableValue *p_contact, MCNameRef p_property, MCNameRef p_label, MCVariableValue *p_value)
{
	MCVariableValue *t_element;
	MCVariableValue *t_array;
	if (p_contact->lookup_element(ep, MCNameGetOldString(p_property), t_array) != ES_NORMAL ||
		t_array->lookup_element(ep, MCNameGetOldString(p_label), t_array) != ES_NORMAL)
		return false;
	
	uindex_t t_index = 1;
	if (!t_array->is_array())
		t_index = 1;
	else
		t_index = t_array->get_array()->getnfilled() + 1;
	
	return t_array->lookup_index(ep, t_index, t_element) == ES_NORMAL &&
		t_element->assign(*p_value);
}
예제 #2
0
bool MCContactAddProperty(MCArrayRef p_contact, MCNameRef p_property, MCStringRef p_value)
{
#ifdef /* MCContactAddProperty */ LEGACY_EXEC
	MCVariableValue *t_element;
	return p_contact->lookup_element(ep, MCNameGetOldString(p_property), t_element) == ES_NORMAL &&
    t_element->assign_string(p_value);
#endif /* MCContactAddProperty */
   
    return MCArrayStoreValue(p_contact, false, p_property, p_value);
}
예제 #3
0
bool MCContactAddProperty(MCExecPoint& ep, MCVariableValue *p_contact, MCNameRef p_property, MCString p_value)
{
	MCVariableValue *t_element;
	return p_contact->lookup_element(ep, MCNameGetOldString(p_property), t_element) == ES_NORMAL &&
		t_element->assign_string(p_value);
}
예제 #4
0
// MW-2012-02-17: [[ LogFonts ]] Actually load the stack file (wrapped by readfile
//   to handle font table cleanup).
IO_stat MCDispatch::doreadfile(const char *openpath, const char *inname, IO_handle &stream, MCStack *&sptr)
{
	Boolean loadhome = False;
	char version[8];

	if (readheader(stream, version) == IO_NORMAL)
	{
		if (strcmp(version, MCversionstring) > 0)
		{
			MCresult->sets("stack was produced by a newer version");
			return IO_ERROR;
		}

		// MW-2008-10-20: [[ ParentScripts ]] Set the boolean flag that tells us whether
		//   parentscript resolution is required to false.
		s_loaded_parent_script_reference = false;

		uint1 charset, type;
		char *newsf;
		if (IO_read_uint1(&charset, stream) != IO_NORMAL
		        || IO_read_uint1(&type, stream) != IO_NORMAL
		        || IO_read_string(newsf, stream) != IO_NORMAL)
		{
			MCresult->sets("stack is corrupted, check for ~ backup file");
			return IO_ERROR;
		}
		delete newsf; // stackfiles is obsolete
		MCtranslatechars = charset != CHARSET;
		sptr = nil;
		/* UNCHECKED */ MCStackSecurityCreateStack(sptr);
		if (stacks == NULL)
			sptr->setparent(this);
		else
			sptr->setparent(stacks);
		sptr->setfilename(strclone(openpath));

		if (MCModeCanLoadHome() && type == OT_HOME)
		{
			char *lstring = NULL;
			char *cstring = NULL;
			IO_read_string(lstring, stream);
			IO_read_string(cstring, stream);
			delete lstring;
			delete cstring;
		}

		MCresult -> clear();

		if (IO_read_uint1(&type, stream) != IO_NORMAL
		    || type != OT_STACK && type != OT_ENCRYPT_STACK
		    || sptr->load(stream, version, type) != IO_NORMAL)
		{
			if (MCresult -> isclear())
				MCresult->sets("stack is corrupted, check for ~ backup file");
			destroystack(sptr, False);
			sptr = NULL;
			return IO_ERROR;
		}
		
		// MW-2011-08-09: [[ Groups ]] Make sure F_GROUP_SHARED is set
		//   appropriately.
		sptr -> checksharedgroups();
		
		if (sptr->load_substacks(stream, version) != IO_NORMAL
		        || IO_read_uint1(&type, stream) != IO_NORMAL
		        || type != OT_END)
		{
			if (MCresult -> isclear())
				MCresult->sets("stack is corrupted, check for ~ backup file");
			destroystack(sptr, False);
			sptr = NULL;
			return IO_ERROR;
		}

		if (stacks != NULL)
		{
			MCStack *tstk = stacks;
			do
			{
				if (sptr->hasname(tstk->getname()))
				{
					MCAutoNameRef t_stack_name;
					/* UNCHECKED */ t_stack_name . Clone(sptr -> getname());

					delete sptr;
					sptr = NULL;

					if (strequal(tstk->getfilename(), openpath))
						sptr = tstk;
					else
					{
						MCdefaultstackptr->getcard()->message_with_args(MCM_reload_stack, MCNameGetOldString(tstk->getname()), openpath);
						tstk = stacks;
						do
						{
							if (MCNameIsEqualTo(t_stack_name, tstk->getname(), kMCCompareCaseless))
							{
								sptr = tstk;
								break;
							}
							tstk = (MCStack *)tstk->next();
						}
						while (tstk != stacks);
					}

					return IO_NORMAL;
				}
				tstk = (MCStack *)tstk->next();
			}
			while (tstk != stacks);
		}
		
		appendstack(sptr);
		
		sptr->extraopen(false);

		// MW-2008-10-28: [[ ParentScript ]]
		// We just loaded a stackfile, so check to see if parentScript resolution
		// is required and if so do it.
		// MW-2009-01-28: [[ Inherited parentScripts ]]
		// Resolving parentScripts may allocate memory, so 'resolveparentscripts'
		// will return false if it fails to allocate what it needs. At some point
		// this needs to be dealt with by deleting the stack and returning an error,
		// *However* at the time of writing, 'readfile' isn't designed to handle
		// this - so we just ignore the result for now (note that all the 'load'
		// methods *fail* to check for no-memory errors!).
		if (s_loaded_parent_script_reference)
			sptr -> resolveparentscripts();
		
	}
	else
	{
		MCS_seek_set(stream, 0);
		if (stacks == NULL)
		{
			MCnoui = True;
			MCscreen = new MCUIDC;
			/* UNCHECKED */ MCStackSecurityCreateStack(stacks);
			MCdefaultstackptr = MCstaticdefaultstackptr = stacks;
			stacks->setparent(this);
			stacks->setname_cstring("revScript");
			uint4 size = (uint4)MCS_fsize(stream);
			char *script = new char[size + 2];
			script[size] = '\n';
			script[size + 1] = '\0';
			if (IO_read(script, sizeof(char), size, stream) != IO_NORMAL
			        || !stacks->setscript(script))
			{
				delete script;
				return IO_ERROR;
			}
		}
		else
		{
			char *tname = strclone(inname);
			
			// MW-2008-06-12: [[ Bug 6476 ]] Media won't open HC stacks
			if (!MCdispatcher->cut(True) || hc_import(tname, stream, sptr) != IO_NORMAL)
			{
				MCresult->sets("file is not a stack");
				delete tname;
				return IO_ERROR;
			}
		}
	}
	return IO_NORMAL;
}
예제 #5
0
Exec_stat MCDispatch::handle(Handler_type htype, MCNameRef mess, MCParameter *params, MCObject *pass_from)
{
	Exec_stat stat = ES_NOT_HANDLED;

	bool t_has_passed;
	t_has_passed = false;
	
	if (MCcheckstack && MCU_abs(MCstackbottom - (char *)&stat) > MCrecursionlimit)
	{
		MCeerror->add(EE_RECURSION_LIMIT, 0, 0);
		MCerrorptr = stacks;
		return ES_ERROR;
	}

	// MW-2011-06-30: Move handling of library stacks from MCStack::handle.
	if (MCnusing > 0)
	{
		for (uint32_t i = MCnusing; i > 0 && (stat == ES_PASS || stat == ES_NOT_HANDLED); i -= 1)
		{
			stat = MCusing[i - 1]->handle(htype, mess, params, nil);

			// MW-2011-08-22: [[ Bug 9686 ]] Make sure we exit as soon as the
			//   message is handled.
			if (stat != ES_NOT_HANDLED && stat != ES_PASS)
				return stat;

			if (stat == ES_PASS)
				t_has_passed = true;
		}

		if (t_has_passed && stat == ES_NOT_HANDLED)
			stat = ES_PASS;
	}

	if ((stat == ES_NOT_HANDLED || stat == ES_PASS) && MCbackscripts != NULL)
	{
		MCObjectList *optr = MCbackscripts;
		do
		{
			if (!optr->getremoved())
			{
				stat = optr->getobject()->handle(htype, mess, params, nil);
				if (stat != ES_NOT_HANDLED && stat != ES_PASS)
					return stat;
				if (stat == ES_PASS)
					t_has_passed = true;
			}
			optr = optr->next();
		}
		while (optr != MCbackscripts);
	}

	if ((stat == ES_NOT_HANDLED || stat == ES_PASS) && m_externals != nil)
	{
		Exec_stat oldstat = stat;
		stat = m_externals -> Handle(this, htype, mess, params);

		// MW-2011-08-22: [[ Bug 9686 ]] Make sure we exit as soon as the
		//   message is handled.
		if (stat != ES_NOT_HANDLED && stat != ES_PASS)
			return stat;

		if (oldstat == ES_PASS && stat == ES_NOT_HANDLED)
			stat = ES_PASS;
	}

#ifdef TARGET_SUBPLATFORM_IPHONE
	extern Exec_stat MCIPhoneHandleMessage(MCNameRef message, MCParameter *params);
	if (stat == ES_NOT_HANDLED || stat == ES_PASS)
	{
		stat = MCIPhoneHandleMessage(mess, params);
		
		if (stat != ES_NOT_HANDLED && stat != ES_PASS)
			return stat;
	}
#endif

#ifdef _MOBILE
	if (stat == ES_NOT_HANDLED || stat == ES_PASS)
	{
		stat = MCHandlePlatformMessage(htype, MCNameGetOldString(mess), params);

		// MW-2011-08-22: [[ Bug 9686 ]] Make sure we exit as soon as the
		//   message is handled.
		if (stat != ES_NOT_HANDLED && stat != ES_PASS)
			return stat;
	}
#endif

	if (MCmessagemessages && stat != ES_PASS)
		MCtargetptr->sendmessage(htype, mess, False);
		
	if (t_has_passed)
		return ES_PASS;

	return stat;
}
예제 #6
0
void MCError::add(uint2 id, uint2 line, uint2 pos, MCNameRef n)
{
	add(id, line, pos, MCNameGetOldString(n));
}
예제 #7
0
bool MCServerDebugListVariables(uint32_t p_start, uint32_t p_count, MCServerDebugListVariablesCallback p_callback, void *p_context)
{
	if (s_variable_view == NULL)
		return true;
	
	if (p_count > s_variable_view -> view_length)
		p_count = s_variable_view -> view_length;
	
	p_start = MCU_min(p_start, s_variable_view -> view_length - p_count);
	
	MCExecPoint ep;
	for(uint32_t i = p_start; i < p_start + p_count; i++)
	{
		MCVariableInfo *t_owner;
		MCHashentry *t_element;
		MCVariableViewLookupEntry(s_variable_view, i, t_owner, t_element);
		
		const char *t_name_ptr;
		uint32_t t_name_length;
		MCVariableValue *t_value;
		if (t_element == NULL)
		{
			if (t_owner -> scope == kMCVariableScopeElement)
			{
				t_value = &t_owner -> element -> value;
				t_name_ptr = t_owner -> element -> string;
				t_name_length = strlen(t_name_ptr);
			}
			else
			{
				t_value = &t_owner -> variable -> getvalue();
				t_name_ptr = MCNameGetOldString(t_owner -> variable -> getname()) . getstring();
				t_name_length = MCNameGetOldString(t_owner -> variable -> getname()) . getlength();
			}
		}
		else
		{
			t_value = &t_element -> value;
			t_name_ptr = t_element -> string;
			t_name_length = strlen(t_name_ptr);
		}
		
		char t_name[64];
		t_name_length = MCU_min(63U, t_name_length);
		memcpy(t_name, t_name_ptr, t_name_length);
		t_name[t_name_length] = '\0';
		
		uint32_t t_depth;
		t_depth = t_element == NULL ? t_owner -> depth : t_owner -> depth + 1;
		
		bool t_expanded;
		t_expanded = t_element == NULL && t_owner -> is_expanded;
		
		bool t_array;
		t_array = t_value -> is_array();
		
		char t_val[65];
		bool t_truncated;
		t_truncated = false;
		if (t_array)
			t_val[0] = '\0';
		else
		{
			uint32_t t_val_length;
			t_value -> fetch(ep);
			t_val_length = ep . getsvalue() . getlength();
			
			t_truncated = t_val_length > 64;
			if (t_truncated)
				t_val_length = 64;
			memcpy(t_val, ep . getsvalue() . getstring(), t_val_length);
			t_val[t_val_length] = '\0';
			if (strlen(t_val) < t_val_length)
				t_truncated = true;
			
			char *t_break;
			t_break = strchr(t_val, '\n');
			if (t_break != NULL)
			{
				*t_break = '\0';
				t_truncated = true;
			}
		}

		char t_scope;
		if (t_element != NULL)
			t_scope = 'E';
		else
		{
			switch(t_owner -> scope)
			{
				case kMCVariableScopeElement: t_scope = 'E'; break;
				case kMCVariableScopeLocal: t_scope = 'L'; break;
				case kMCVariableScopeParameter: t_scope = 'P'; break;
				case kMCVariableScopeScript: t_scope = 'S'; break;
				case kMCVariableScopeGlobal: t_scope = 'G'; break;
			}
		}
		
		if (!p_callback(p_context, i, t_depth, t_scope, t_array ? t_expanded : t_truncated, t_name, t_array ? NULL : t_val))
			return false;
	}
						
	return true;
}