void MCButton::GetLabel(MCExecContext& ctxt, MCStringRef& r_label)
{
	if (entry != NULL)
		r_label = MCValueRetain(getlabeltext());
	else
		r_label = MCValueRetain(label);
}
Exemple #2
0
void MCR_copyerror(MCStringRef &r_error)
{
    if (regexperror == nil)
        r_error = MCValueRetain(kMCEmptyString);
    else
        r_error = MCValueRetain(regexperror);
}
Exemple #3
0
void MCPlatformHandleApplicationStartup(int p_argc, MCStringRef *p_argv, MCStringRef *p_envp, int& r_error_code, MCStringRef & r_error_message)
{
    struct X_init_options t_options;
    t_options.argc = p_argc;
    t_options.argv = p_argv;
    t_options.envp = p_envp;
    t_options.app_code_path = nullptr;

	if (X_init(t_options))
	{
		r_error_code = 0;
		r_error_message = nil;
		return;
	}

    r_error_code = -1;

    if (MCresult == nullptr)
    {
        /* TODO[2017-04-05] X_init() failed before initialising global
         * variables.  This could be because something horrible happened, or it
         * could be because it found "-h" in the arguments.  It's better to
         * quit without an error message than to crash, but it the future it
         * would be good to distinguish between the two. */
        r_error_message = MCValueRetain(kMCEmptyString);
    }
    else if (MCValueGetTypeCode(MCresult -> getvalueref()) == kMCValueTypeCodeString)
    {
        r_error_message = (MCStringRef)MCValueRetain(MCresult->getvalueref());
    }
    else
    {
        r_error_message = MCValueRetain(MCSTR("Unknown error occurred"));
    }
}
MCReferencedImageRep::MCReferencedImageRep(MCStringRef p_file_name, MCStringRef p_search_key)
{
	m_file_name = MCValueRetain(p_file_name);
	m_search_key = MCValueRetain(p_search_key);
	m_url_data = nil;
	
	// MW-2013-09-25: [[ Bug 10983 ]] No load has yet been attempted.
	m_url_load_attempted = false;
}
Exemple #5
0
Boolean MCEPS::import(MCStringRef fname, IO_handle stream)
{
	size = (uint4)MCS_fsize(stream);
	delete postscript;
	postscript = new char[size + 1];
	if (IO_read(postscript, size, stream) != IO_NORMAL)
		return False;
	postscript[size] = '\0';
	uindex_t t_sep;
    MCStringRef t_fname;
    if (MCStringLastIndexOfChar(fname, PATH_SEPARATOR, UINDEX_MAX, kMCCompareExact, t_sep))
        /* UNCHECKED */ MCStringCopySubstring(fname, MCRangeMake(t_sep + 1, MCStringGetLength(fname) - (t_sep + 1)), t_fname);
    else
        t_fname = MCValueRetain(fname);
    
    MCNewAutoNameRef t_name;
    if (!MCNameCreateAndRelease(t_fname, &t_name))
        return False;
    setname(*t_name);
	setextents();
	rect.width = (uint2)(ex * xscale / xf);
	rect.height = (uint2)(ey * yscale / yf);
	if (flags & F_SHOW_BORDER)
	{
		rect.width += borderwidth << 1;
		rect.height += borderwidth << 1;
	}
	return True;
}
Exemple #6
0
void MCArraysEvalMatrixMultiply(MCExecContext& ctxt, MCArrayRef p_left, MCArrayRef p_right, MCArrayRef& r_result)
{
	// MW-2014-03-14: [[ Bug 11924 ]] If both are empty arrays, then the result
	//   is empty.
    if (MCArrayIsEmpty(p_left) && MCArrayIsEmpty(p_right))
    {
        r_result = MCValueRetain(kMCEmptyArray);
        return;
    }
    
    // MW-2014-03-14: [[ Bug 11924 ]] If either array is empty, then its a mismatch.
	MCAutoPointer<matrix_t> t_left, t_right, t_product;
	if (MCArrayIsEmpty(p_left) || MCArrayIsEmpty(p_right) ||
        !MCArraysCopyMatrix(ctxt, p_left, &t_left) || !MCArraysCopyMatrix(ctxt, p_right, &t_right) ||
		!MCMatrixMultiply(*t_left, *t_right, &t_product))
	{
		ctxt.LegacyThrow(EE_MATRIXMULT_MISMATCH);
		return;
	}

	if (MCArraysCreateWithMatrix(*t_product, r_result))
		return;

	ctxt.Throw();
}
Exemple #7
0
void MCArraysDoUnion(MCExecContext& ctxt, MCArrayRef p_dst_array, MCArrayRef p_src_array, bool p_recursive)
{
	MCNameRef t_key;
	MCValueRef t_src_value;
    MCValueRef t_dst_value;
	uintptr_t t_iterator;
	t_iterator = 0;
    
    bool t_is_array;
    
	while(MCArrayIterate(p_src_array, t_iterator, t_key, t_src_value))
	{
		if (MCArrayFetchValue(p_dst_array, ctxt . GetCaseSensitive(), t_key, t_dst_value))
        {
            if (p_recursive && MCValueIsArray(t_dst_value) && MCValueIsArray(t_src_value))
            {
                MCArraysExecUnionRecursive(ctxt, (MCArrayRef)t_dst_value, (MCArrayRef)t_src_value);
                if (ctxt . HasError())
                    return;
            }
			continue;
        }
        
		if (!MCArrayStoreValue(p_dst_array, ctxt . GetCaseSensitive(), t_key, MCValueRetain(t_src_value)))
		{
			ctxt . Throw();
			return;
		}
	}
}
void MCPlayer::gethotspots(MCStringRef &r_hotspots)
{
    MCStringRef t_spots;
    t_spots = MCValueRetain(kMCEmptyString);
    
    r_hotspots = t_spots;
}
Exemple #9
0
bool MCArraysCopyExtents(MCArrayRef self, MCListRef& r_list)
{
	MCAutoArray<array_extent_t> t_extents;
	if (!MCArraysCopyExtents(self, t_extents.PtrRef(), t_extents.SizeRef()))
		return false;

	uindex_t t_dimensions = t_extents.Size();

	if (t_dimensions == 0)
	{
		r_list = MCValueRetain(kMCEmptyList);
		return true;
	}

	MCAutoListRef t_list;
	if (!MCListCreateMutable('\n', &t_list))
		return false;

	for (uindex_t i = 0; i < t_dimensions; i++)
	{
		MCAutoStringRef t_string;
		if (!MCStringFormat(&t_string, "%d,%d", t_extents[i].min, t_extents[i].max))
			return false;
		if (!MCListAppend(*t_list, *t_string))
			return false;
	}

	return MCListCopy(*t_list, r_list);
}
Exemple #10
0
void MCDebuggingGetBreakpoints(MCExecContext& ctxt, MCStringRef& r_value)
{
	if (MCB_unparsebreaks(r_value))
		return;

	r_value = MCValueRetain(kMCEmptyString);
}
Exemple #11
0
void MCDebuggingGetWatchedVariables(MCExecContext& ctxt, MCStringRef& r_value)
{
	if (MCB_unparsewatches(r_value))
		return;

	r_value = MCValueRetain(kMCEmptyString);
}
Exemple #12
0
MCPlayer::MCPlayer(const MCPlayer &sref) : MCControl(sref)
{
	nextplayer = nil;
	filename = MCValueRetain(sref.filename);
	istmpfile = False;
	scale = 1.0;
	rate = sref.rate;
	lasttime = sref.lasttime;
	starttime = sref.starttime;
	endtime = sref.endtime;
	disposable = istmpfile = False;
	userCallbackStr = MCValueRetain(sref.userCallbackStr);
	formattedwidth = formattedheight = 0;
	loudness = sref.loudness;
	dontuseqt = False;
	usingqt = False;
}
Exemple #13
0
// In standalone mode, we try to work out what went wrong...
void MCModeGetStartupErrorMessage(MCStringRef& r_caption, MCStringRef& r_text)
{
	r_caption = MCSTR("Initialization Error");
	if (MCValueGetTypeCode(MCresult -> getvalueref()) == kMCValueTypeCodeString)
		r_text = MCValueRetain((MCStringRef)MCresult -> getvalueref());
	else
		r_text = MCSTR("unknown reason");
}
Exemple #14
0
MCPlayer::MCPlayer()
{	
	flags |= F_TRAVERSAL_ON;
	nextplayer = nil;
	rect.width = rect.height = 128;
	filename = MCValueRetain(kMCEmptyString);
	istmpfile = False;
	scale = 1.0;
	rate = 1.0;
	lasttime = 0;
	starttime = endtime = MAXUINT4;
	disposable = istmpfile = False;
	userCallbackStr = MCValueRetain(kMCEmptyString);
	formattedwidth = formattedheight = 0;
	loudness = 100;
	dontuseqt = False;
	usingqt = False;
}
Exemple #15
0
void MCKeywordsExecSwitch(MCExecContext& ctxt, MCExpression *condition, MCExpression **cases, uindex_t case_count, int2 default_case, uint2 *case_offsets, MCStatement *statements, uint2 line, uint2 pos)
{
    MCAutoValueRef t_value;
    MCAutoStringRef t_cond;
	if (condition != NULL)
	{
        if (!ctxt . TryToEvaluateExpression(condition, line, pos, EE_SWITCH_BADCOND, &t_value))
            return;
        
        if (!ctxt . ConvertToString(*t_value, &t_cond))
        {
            ctxt . LegacyThrow(EE_SWITCH_BADCOND);
            return;
        }
	}
    else
        t_cond = MCValueRetain(kMCTrueString);
    
	int2 match = default_case;
	uint2 i;
	for (i = 0 ; i < case_count ; i++)
	{
        MCAutoValueRef t_case;
        MCAutoStringRef t_case_string;
        
        if (!ctxt . TryToEvaluateExpression(cases[i], line, pos, EE_SWITCH_BADCASE, &t_case))
            return;
        
        if (!ctxt . ConvertToString(*t_case, &t_case_string))
        {
            ctxt . LegacyThrow(EE_SWITCH_BADCASE);
            return;
        }
        
		if (MCStringIsEqualTo(*t_cond, *t_case_string, ctxt . GetStringComparisonType()))
        {
            match = case_offsets[i];
            break;
        }
	}
    
	if (match >= 0)
	{
		MCStatement *tspr = statements;
		while (match--)
			tspr = tspr->getnext();
        
        // SN-2014-08-06: [[ Bug 13122 ]] If we get an EXIT_SWITCH, it's all right
        Exec_stat t_stat;
        t_stat = MCKeywordsExecuteStatements(ctxt, tspr, EE_SWITCH_BADSTATEMENT);
        if (t_stat == ES_EXIT_SWITCH)
            t_stat = ES_NORMAL;
        
        ctxt . SetExecStat(t_stat);
    }
}
static void MCInterfaceButtonIconParse(MCExecContext& ctxt, MCStringRef p_input, MCInterfaceButtonIcon& r_output)
{
    if (MCU_stoui4(p_input, r_output . id))
        r_output . type = kMCInterfaceButtonIconId;
    else
    {
        r_output . type = kMCInterfaceButtonIconCustom;
        r_output . custom = MCValueRetain(p_input);
    }
}
Exemple #17
0
void MCPurchaseVerify(MCPurchase *p_purchase, bool p_verified)
{
    MCAndroidPurchase *t_android_data = (MCAndroidPurchase*)p_purchase->platform_data;
    if (p_purchase->state == kMCPurchaseStateUnverified)
    {
        if (p_verified)
        {
            switch (t_android_data->purchase_state) {
                case PURCHASED:
                    p_purchase->state = kMCPurchaseStatePaymentReceived;
                    break;
                    
                case CANCELED:
                {
                    //MCLog("verified canceled purchase", nil);
                    p_purchase->state = kMCPurchaseStateCancelled;
                    purchase_confirm(p_purchase);
                    break;
                }
                
                case ALREADY_ENTITLED:
                {
                    MCLog("found ALREADY_ENTITLED purchase", nil);
                    p_purchase->state = kMCPurchaseStateAlreadyEntitled;
                    break;
                }
                case INVALID_SKU:
                    p_purchase->state = kMCPurchaseStateInvalidSKU;
                    break;
                    
                case REFUNDED:
                    //MCLog("verified refunded purchase", nil);
                    p_purchase->state = kMCPurchaseStateRefunded;
                    break;
                    
                case RESTORED:
                    p_purchase->state = kMCPurchaseStateRestored;
                    break;
                    
                default:
                    break;
            }
            MCPurchaseNotifyUpdate(p_purchase);
        }
        else
        {
            p_purchase->state = kMCPurchaseStateError;

            t_android_data->error = MCValueRetain(MCSTR("unable to verify message from billing service"));                                                 
			MCPurchaseNotifyUpdate(p_purchase);

            MCPurchaseRelease(p_purchase);
        }
    }
}
bool MCAndroidSystem::GetAddress(MCStringRef& r_address)
{
	extern MCStringRef MCcmd;
    MCAutoStringRef t_address;
    bool t_success;
    t_success = MCStringFormat(&t_address, "android:%@", MCcmd);
    if (t_success)
        r_address = MCValueRetain(*t_address);
    
	return t_success;
}
Exemple #19
0
// JS-2013-07-01: [[ EnhancedFilter ]] Updated to support case-sensitivity and caching.
// MW-2013-07-01: [[ EnhancedFilter ]] Tweak to take 'const char *' and copy pattern as required.
// MW-2013-07-01: [[ EnhancedFilter ]] Removed 'usecache' parameter as there's
//   no reason not to use the cache.
regexp *MCR_compile(MCStringRef exp, bool casesensitive)
{
	Boolean found = False;
	regexp *re = nil;
	int flags = REG_EXTENDED;
    if (!casesensitive)
        flags |= REG_ICASE;

	// Search the cache.
	uint2 i;
	for (i = 0 ; i < PATTERN_CACHE_SIZE ; i++)
	{
		if (MCregexcache[i] &&
            MCStringIsEqualTo(exp, MCregexcache[i]->pattern, casesensitive ? kMCStringOptionCompareExact : kMCStringOptionCompareCaseless) &&
			flags == MCregexcache[i]->flags)
		{
			found = True;
			re = MCregexcache[i];
			break;
		}
	}
	
	// If the pattern isn't found with the given flags, then create a new one.
	if (re == nil)
	{
		/* UNCHECKED */ re = new regexp;
		/* UNCHECKED */ re->pattern = MCValueRetain(exp);
		re->flags = flags;
		int status;
		status = regcomp(&re->rexp, exp, flags);
		if (status != REG_OKAY)
		{
			regerror(status, nil, regexperror);
			MCValueRelease(re->pattern);
			delete re;
			return(nil);
		}
	}
	
	// If the pattern is new, put it in the cache.
	if (!found)
	{
		uint2 i;
		MCR_free(MCregexcache[PATTERN_CACHE_SIZE - 1]);
		for (i = PATTERN_CACHE_SIZE - 1 ; i ; i--)
		{
			MCregexcache[i] = MCregexcache[i - 1];
		}
		MCregexcache[0] = re;
	}
	
	return re;
}
Exemple #20
0
void MCPurchaseGetTransactionIdentifier(MCExecContext& ctxt,MCPurchase *p_purchase, MCStringRef& r_identifier)
{
    MCAndroidPurchase *t_android_data = (MCAndroidPurchase*)p_purchase->platform_data;
    
    if (t_android_data->order_id != nil)
    {
        r_identifier = MCValueRetain(t_android_data->order_id);
        return;
    }
    
    ctxt.Throw();
}
Exemple #21
0
bool MCWidgetPopupAtLocationWithProperties(MCNameRef p_kind, const MCPoint &p_at, MCArrayRef p_properties, MCValueRef &r_result)
{
	MCPoint t_at;
	t_at = MCmousestackptr->stacktogloballoc(p_at);
	
	MCWidgetPopup *t_popup;
	t_popup = nil;
	
	t_popup = new (nothrow) MCWidgetPopup();
	if (t_popup == nil)
	{
		// TODO - throw memory error
		return false;
	}
	
	MCWidgetPopup *t_old_popup;
	t_old_popup = s_widget_popup;
	s_widget_popup = t_popup;

    t_popup -> setparent(MCdispatcher);
	MCdispatcher -> add_transient_stack(t_popup);
	
	if (!t_popup->openpopup(p_kind, t_at, p_properties))
	{
		t_popup->close();
		delete t_popup;
		s_widget_popup = t_old_popup;
		return false;
	}
	
	while (t_popup->getopened() && !MCquit)
	{
		MCU_resetprops(True);
		// MW-2011-09-08: [[ Redraw ]] Make sure we flush any updates.
		MCRedrawUpdateScreen();
		MCscreen->siguser();
		MCscreen->wait(REFRESH_INTERVAL, True, True);
	}
	
	MCValueRef t_result;
	t_result = MCValueRetain(t_popup->getpopupresult());
	
    MCerrorlock++;
    if (t_popup->del(false))
        t_popup->scheduledelete();
    MCerrorlock--;
    
	s_widget_popup = t_old_popup;
	
	r_result = t_result;
	
	return true;
}
Exemple #22
0
void MCPurchaseGetSignature(MCExecContext& ctxt,MCPurchase *p_purchase, MCStringRef& r_signature)
{
    MCAndroidPurchase *t_android_data = (MCAndroidPurchase*)p_purchase->platform_data;
    
    if (t_android_data->signature != nil)
    {
        r_signature = MCValueRetain(t_android_data->signature);
        return;
    }
    
    ctxt.Throw();
}
Exemple #23
0
void MCPurchaseGetDeveloperPayload(MCExecContext& ctxt,MCPurchase *p_purchase, MCStringRef& r_payload)
{
    MCAndroidPurchase *t_android_data = (MCAndroidPurchase*)p_purchase->platform_data;
    
    if (t_android_data->developer_payload != nil)
    {
        r_payload = MCValueRetain(t_android_data->developer_payload);
        return;
    }
    
    ctxt.Throw();
}
bool MCValueInter(MCValueRef p_value, MCValueRef& r_unique_value)
{
	// If the value is already unique then this is just a copy.
	if (MCValueIsUnique(p_value))
	{
		MCValueRetain(p_value);
		r_unique_value = p_value;
		return true;
	}

	return __MCValueInter((__MCValue *)p_value, false, r_unique_value);
}
Exemple #25
0
bool MCPurchaseGetError(MCPurchase *p_purchase, MCStringRef& r_error)
{
    if (p_purchase == nil || p_purchase->state != kMCPurchaseStateError)
        return false;
    
    MCAndroidPurchase *t_android_data = (MCAndroidPurchase*)p_purchase->platform_data;
    
    if (t_android_data == nil)
        return false;
    
    r_error = MCValueRetain(t_android_data->error);

	return true;
}
static bool __MCValueInter(__MCValue *self, bool p_release, MCValueRef& r_unique_self)
{
	// Compute the hash code for the value.
	hash_t t_hash;
	t_hash = MCValueHash(self);

	// See if the value is already in the table.
	uindex_t t_target_slot;
	t_target_slot = __MCValueFindUniqueValueBucket(self, t_hash);

	// If a slot wasn't found, then rehash.
	if (t_target_slot == UINDEX_MAX)
	{
		if (!__MCValueRehashUniqueValues(1))
			return false;

		t_target_slot = __MCValueFindUniqueValueBucketAfterRehash(self, t_hash);
	}

	// If we still don't have a slot then just fail (this could happen if
	// memory is exhausted).
	if (t_target_slot == UINDEX_MAX)
		return false;

	// If the slot is not empty and not deleted then take that value.
	if (s_unique_values[t_target_slot] . value != UINTPTR_MIN &&
		s_unique_values[t_target_slot] . value != UINTPTR_MAX)
	{
		if (p_release)
			MCValueRelease(self);

		r_unique_self = MCValueRetain((MCValueRef)s_unique_values[t_target_slot] . value);
		return true;
	}

	// Otherwise we must first ensure we have an immutable version of the
	// value and then insert it into the table.
	if (!__MCValueImmutableCopy(self, p_release, self))
		return false;

	self -> flags |= kMCValueFlagIsInterred;
	s_unique_values[t_target_slot] . hash = t_hash;
	s_unique_values[t_target_slot] . value = (uintptr_t)self;
	s_unique_value_count += 1;

	// Finally return the value in the target slot.
	r_unique_self = self;
	return true;
}
Exemple #27
0
void MCDebuggingGetTraceStack(MCExecContext& ctxt, MCStringRef& r_value)
{
	if (MCtracestackptr == nil)
	{
		r_value = (MCStringRef)MCValueRetain(kMCEmptyString);
		return;
	}

	MCAutoValueRef t_value;
	if (MCtracestackptr -> names(P_NAME, &t_value))
		if (ctxt.ConvertToString(*t_value, r_value))
		return;

	ctxt . Throw();
}
Exemple #28
0
// MW-2015-03-09: [[ Bug 14139 ]] Fixed licensing issue with thirdparties
void MCLicenseGetRevLicenseInfoByKey(MCExecContext& ctxt, MCNameRef p_key, MCArrayRef& r_info)
{
    MCValueRef t_value;
    if (MClicenseparameters . addons == nil ||
        !MCArrayFetchValue(MClicenseparameters . addons, ctxt . GetCaseSensitive(), p_key, t_value))
        {
            r_info = MCValueRetain(kMCEmptyArray);
            return;
        }
    
    if (ctxt . ConvertToArray(t_value, r_info))
        return;
    
    ctxt . Throw();
}
Exemple #29
0
void MCPlayer::setfilename(MCStringRef vcname,
                           MCStringRef fname, Boolean istmp)
{
	// AL-2014-05-27: [[ Bug 12517 ]] Incoming strings can be nil
    MCNewAutoNameRef t_vcname;
    if (vcname != nil)
        MCNameCreate(vcname, &t_vcname);
    else
        t_vcname = kMCEmptyName;
    
	setname(*t_vcname);
	filename = MCValueRetain(fname != nil ? fname : kMCEmptyString);
	istmpfile = istmp;
	disposable = True;
}
Exemple #30
0
static MCStringRef windows_query_locale(uint4 t_index)
{
	// Allocate a buffer for the locale information
	int t_buf_size;
	t_buf_size = GetLocaleInfoW(LOCALE_USER_DEFAULT, t_index, NULL, 0);
	wchar_t* t_buffer = new wchar_t[t_buf_size];
	
	// Get the locale information and create a StringRef from it
	if (GetLocaleInfoW(LOCALE_USER_DEFAULT, t_index, t_buffer, t_buf_size) == 0)
		return MCValueRetain(kMCEmptyString);
	MCStringRef t_string;
	MCStringCreateWithChars(t_buffer, MCU_max(0, t_buf_size - 1), t_string);
	delete[] t_buffer;
	
	return t_string;
}