bool MCImageRepGetReferencedWithScale(const char *p_base, const char *p_extension, MCGFloat p_scale, MCImageRep *&r_rep)
{
	bool t_success;
	t_success = true;
	
	MCImageRep *t_rep;
	t_rep = nil;
	
	char *t_default_path;
	t_default_path = nil;
	
	const char **t_labels;
	t_labels = nil;
	
	if (t_success)
		t_success = MCImageGetLabelsForScale(p_scale, t_labels);
	
	// construct default path as base path with first tag for the given scale
	if (t_success)
		t_success = MCCStringFormat(t_default_path, "%s%s%s", p_base, t_labels[0], p_extension);
	
	if (t_success)
	{
		MCCachedImageRep *t_cached_rep;
		t_cached_rep = nil;
		
		if (MCCachedImageRep::FindWithKey(t_default_path, t_cached_rep))
			t_rep = t_cached_rep->Retain();
		// not in cache, so see if default path exists.
		else if (MCS_exists(t_default_path, True))
			t_success = MCImageRepCreateReferencedWithSearchKey(t_default_path, t_default_path, t_rep);
		// else loop through remaining labels and check for matching files
		else
		{
			for (uint32_t i = 1; t_success && t_rep == nil && t_labels[i] != nil; i++)
			{
				char *t_scaled_path;
				t_scaled_path = nil;
				
				t_success = MCCStringFormat(t_scaled_path, "%s%s%s", p_base, t_labels[i], p_extension);
				
				if (t_success && MCS_exists(t_scaled_path, True))
					t_success = MCImageRepCreateReferencedWithSearchKey(t_scaled_path, t_default_path, t_rep);
				
				MCCStringFree(t_scaled_path);
			}
		}
	}
	
	MCCStringFree(t_default_path);
	
	if (t_success)
		r_rep = t_rep;
	
	return t_success;
}
예제 #2
0
Exec_stat MCHandleAdGetTopLeft(void *context, MCParameter *p_parameters)
{
	bool t_success;
	t_success = true;
    
    MCExecPoint ep(nil, nil, nil);
    MCExecContext t_ctxt(ep);
	t_ctxt . SetTheResultToEmpty();
    
	char *t_ad;
	t_ad = nil;
	if (t_success)
		t_success = MCParseParameters(p_parameters, "s", &t_ad);
	
    MCAdTopLeft t_top_left = {0,0};
	if (t_success)
		t_success = MCAdGetTopLeftOfAd(t_ctxt, t_ad, t_top_left);
    
    if (t_success)
    {
        MCAutoRawCString t_top_left_string;
        t_success = MCCStringFormat(t_top_left_string, "%u,%u", t_top_left.x, t_top_left.y);
        if (t_success)
            if (t_top_left_string.Borrow() != nil)
                ep.copysvalue(t_top_left_string.Borrow());
    }
    
    if (t_success)
        MCresult->store(ep, False);
    
    MCCStringFree(t_ad);
    
    return t_ctxt.GetStat();
}
예제 #3
0
bool MCNativeControl::FormatColor(MCExecPoint& ep, uint16_t p_red, uint16_t p_green, uint16_t p_blue, uint16_t p_alpha)
{
    char *t_colorstring = nil;

    p_red >>= 8;
    p_green >>= 8;
    p_blue >>= 8;
    p_alpha >>= 8;
    
    if (p_alpha != 255)
        MCCStringFormat(t_colorstring, "%u,%u,%u,%u", p_red, p_green, p_blue, p_alpha);
    else
        MCCStringFormat(t_colorstring, "%u,%u,%u", p_red, p_green, p_blue);
    ep.grabbuffer(t_colorstring, MCCStringLength(t_colorstring));
	
	return true;
}
예제 #4
0
static bool load_custom_font_file_into_buffer_from_path(const char *p_path, char *&r_buffer, uint32_t &r_size)
{     
    bool t_success;
    t_success = true;
    
    char *t_font_path;
    t_font_path = nil;
    if (t_success)
        t_success = MCCStringFormat(t_font_path, "%s/%s%s", MCcmd, s_font_folder, p_path);
    
    if (t_success)
        t_success = MCS_exists(t_font_path, true);
    
    IO_handle t_font_file_handle;
    t_font_file_handle = nil;
    if (t_success)
	{
        t_font_file_handle = MCS_open(t_font_path, IO_READ_MODE, false, false, 0);
		t_success = t_font_file_handle != nil;
	}
    
    uint32_t t_file_size;
    t_file_size = 0;
    char *t_buffer;
    t_buffer = nil;
	if (t_success)
	{
		t_file_size = MCS_fsize(t_font_file_handle);
		t_success = MCMemoryAllocate(t_file_size + 1, t_buffer);
	}
    
	if (t_success)
	{
		IO_stat t_read_stat;
		uint32_t t_bytes_read;
        t_bytes_read = 0;
		while (t_success && t_bytes_read < t_file_size)
		{
			uint32_t t_count;
			t_count = t_file_size - t_bytes_read;
			t_read_stat = MCS_read(t_buffer + t_bytes_read, 1, t_count, t_font_file_handle);
			t_bytes_read += t_count;
			t_success = (t_read_stat == IO_NORMAL || (t_read_stat == IO_EOF && t_bytes_read == t_file_size));
		}
	}
    
    if (t_success)
    {
        r_buffer = t_buffer;
        r_size = t_file_size;
    }
    else
        /*UNCHECKED */ MCMemoryDelete(t_buffer);
    
    /*UNCHECKED */ MCCStringFree(t_font_path);
    
    return t_success;
}
예제 #5
0
bool MCExecPointSetRect(MCExecPoint &ep, int2 p_left, int2 p_top, int2 p_right, int2 p_bottom)
{
	char *t_buffer = nil;
	if (!MCCStringFormat(t_buffer, "%d,%d,%d,%d", p_left, p_top, p_right, p_bottom))
		return false;
	
	ep.grabbuffer(t_buffer, MCCStringLength(t_buffer));
	return true;
}
예제 #6
0
static int readdir_r_wrapper(DIR *dirp, struct dirent *entry, struct dirent **result)
{
	if (dirp -> __dd_fd < 0)
	{
		DIR_wrapper *t_wrapper;
		t_wrapper = (DIR_wrapper *)dirp;
		
		if (t_wrapper -> index == t_wrapper -> entry_count)
		{
			*result = nil;
			return 0;
		}
		
		char *t_item_path;
		MCCStringFormat(t_item_path, "%s/%s", s_redirect_base, t_wrapper -> entries[t_wrapper -> index]);
		struct stat t_stat;
		lstat(t_item_path, &t_stat);
		MCCStringFree(t_item_path);
		
		entry -> d_fileno = t_stat . st_ino;
		if (S_ISBLK(t_stat . st_mode))
			entry -> d_type = DT_BLK;
		else if (S_ISCHR(t_stat . st_mode))
			entry -> d_type = DT_CHR;
		else if (S_ISDIR(t_stat . st_mode))
			entry -> d_type = DT_DIR;
		else if (S_ISFIFO(t_stat . st_mode))
			entry -> d_type = DT_FIFO;
		else if (S_ISREG(t_stat . st_mode))
			entry -> d_type = DT_REG;
		else if (S_ISLNK(t_stat . st_mode))
			entry -> d_type = DT_LNK;
		else if (S_ISSOCK(t_stat . st_mode))
			entry -> d_type = DT_SOCK;
		else if (S_ISWHT(t_stat . st_mode))
			entry -> d_type = DT_WHT;
		else
			entry -> d_type = DT_UNKNOWN;
		
		strcpy(entry -> d_name, t_wrapper -> entries[t_wrapper -> index]);
		
		entry -> d_reclen = sizeof(struct dirent) - sizeof(entry -> d_name) + ((strlen(entry -> d_name) + 4) & ~3);
		
		t_wrapper -> index += 1;
		
		*result = entry;
		
		return 0;
	}
	
	return readdir_r_trampoline(dirp, entry, result);
}
예제 #7
0
bool MCSessionCreateSession(MCSessionIndexRef p_index, MCStringRef p_session_id, MCSession *&r_session)
{
	bool t_success = true;
	
	MCSession *t_session = NULL;

	MCAutoStringRef t_remote_addr_string;
	char *t_remote_addr;
	t_remote_addr = NULL;

	if (MCS_getenv(MCSTR("REMOTE_ADDR"), &t_remote_addr_string))
		MCCStringClone(MCStringGetCString(*t_remote_addr_string), t_remote_addr);
	
	t_success = MCMemoryNew(t_session);
	
	if (t_success)
		t_success = MCCStringClone(t_remote_addr ? t_remote_addr : "", t_session->ip);

	if (t_success)
	{
		if (p_session_id != nil && !MCStringIsEmpty(p_session_id))
		{
			t_session->id = strdup(MCStringGetCString(p_session_id));
			t_success = true;
		}
		else
		{
			MCAutoStringRef t_session_id;
			t_success = MCSessionGenerateID(&t_session_id);
			t_session->id = strdup(MCStringGetCString(*t_session_id));
		}
	}
	
	if (t_success)
		t_success = MCCStringFormat(t_session->filename, "%s_%s", t_remote_addr ? t_remote_addr : "", t_session->id);
	
	if (t_success)
		t_success = MCSessionIndexAddSession(p_index, t_session);
	
	if (t_success)
		r_session = t_session;
	else
	{
		if (t_session != NULL)
			MCSessionCloseSession(t_session, false);
	}
	
	return t_success;
}
예제 #8
0
bool MCFileSystemListEntries(const char *p_folder, uint32_t p_options, MCFileSystemListCallback p_callback, void *p_context)
{
	bool t_success = true;
	
	char *t_resolved_path = nil;
	DIR *t_dir = nil;
	t_success = MCFileSystemPathResolve(p_folder, t_resolved_path);
	
	if (t_success)
	{
		t_dir = opendir(t_resolved_path);
		t_success = t_dir != nil;
	}
	
	if (t_success)
	{
		struct dirent *t_entry = nil;
		struct stat t_entry_stat;
		MCFileSystemEntry t_fs_entry;
		while (t_success && nil != (t_entry = readdir(t_dir)))
		{
			if (!MCCStringEqual(t_entry->d_name, ".") && !MCCStringEqual(t_entry->d_name, ".."))
			{
				char *t_child_path = nil;
				t_success = MCCStringFormat(t_child_path, "%s/%s", t_resolved_path, t_entry->d_name);
				if (t_success)
					t_success = -1 != lstat(t_child_path, &t_entry_stat);
				MCCStringFree(t_child_path);
				if (t_success)
				{
					t_fs_entry.filename = t_entry->d_name;
					if (S_ISLNK(t_entry_stat.st_mode))
						t_fs_entry.type = kMCFileSystemEntryLink;
					else if (S_ISDIR(t_entry_stat.st_mode))
						t_fs_entry.type = kMCFileSystemEntryFolder;
					else
						t_fs_entry.type = kMCFileSystemEntryFile;
					
					t_success = p_callback(p_context, t_fs_entry);
				}
			}
		}
		closedir(t_dir);
	}
	MCCStringFree(t_resolved_path);
	
	return t_success;
}
예제 #9
0
bool MCDispatch::loadexternal(const char *p_external)
{
	char *t_filename;
#if defined(TARGET_SUBPLATFORM_ANDROID)
	extern bool revandroid_loadExternalLibrary(const char *p_external, char*& r_filename);
	// MW-2013-08-07: [[ ExternalsApiV5 ]] Make sure we only use the leaf name
	//   of the external when loading.
	if (strrchr(p_external, '/') != nil)
		p_external = strrchr(p_external, '/') + 1;
	if (!revandroid_loadExternalLibrary(p_external, t_filename))
		return false;

	// Don't try and load any drivers as externals.
	if (strncmp(p_external, "db", 2) == 0)
	{
		delete t_filename;
		return true;
	}
#elif !defined(_SERVER)
	if (p_external[0] == '/')
	{
		if (!MCCStringClone(p_external, t_filename))
			return false;
	}
	else if (!MCCStringFormat(t_filename, "%.*s/%s", strrchr(MCcmd, '/') - MCcmd, MCcmd, p_external))
		return false;
#else
	if (!MCCStringClone(p_external, t_filename))
		return false;
#endif
	
	if (m_externals == nil)
		m_externals = new MCExternalHandlerList;
	
	bool t_loaded;
	t_loaded = m_externals -> Load(t_filename);
	delete t_filename;
	
	if (m_externals -> IsEmpty())
	{
		delete m_externals;
		m_externals = nil;
}

	return t_loaded;
}
예제 #10
0
파일: srvcgi.cpp 프로젝트: bduck/livecode
static bool cgi_send_cookies(void)
{
	bool t_success = true;
	
	char *t_cookie_header = NULL;
	MCExecPoint ep;
	
	for (uint32_t i = 0; t_success && i < MCservercgicookiecount; i++)
	{
		t_success = MCCStringFormat(t_cookie_header, "Set-Cookie: %s=%s", MCservercgicookies[i].name, MCservercgicookies[i].value);
		
		if (t_success && MCservercgicookies[i].expires != 0)
		{
			ep.setuint(MCservercgicookies[i].expires);
			t_success = MCD_convert(ep, CF_SECONDS, CF_UNDEFINED, CF_INTERNET_DATE, CF_UNDEFINED);
			if (t_success)
			{
				MCString t_date;
				t_date = ep.getsvalue();
				t_success = MCCStringAppendFormat(t_cookie_header, "; Expires=%.*s", t_date.getlength(), t_date.getstring());
			}
		}
		
		if (t_success && MCservercgicookies[i].path != NULL)
			t_success = MCCStringAppendFormat(t_cookie_header, "; Path=%s", MCservercgicookies[i].path);
		
		if (t_success && MCservercgicookies[i].domain != NULL)
			t_success = MCCStringAppendFormat(t_cookie_header, "; Domain=%s", MCservercgicookies[i].domain);

		if (t_success && MCservercgicookies[i].secure)
			t_success = MCCStringAppend(t_cookie_header, "; Secure");
		
		if (t_success && MCservercgicookies[i].http_only)
			t_success = MCCStringAppend(t_cookie_header, "; HttpOnly");
		
		if (t_success)
			t_success = MCCStringAppend(t_cookie_header, "\n");
		
		if (t_success)
			t_success = IO_NORMAL == MCS_write(t_cookie_header, 1, MCCStringLength(t_cookie_header), IO_stdout);
		MCCStringFree(t_cookie_header);
		t_cookie_header = NULL;
	}
	return t_success;
}
예제 #11
0
void add_dialog_filters(GtkWidget *dialog, char * const p_types[], uint4 p_type_count )
{
	GtkFileFilter *filter ;
	
	if ( p_type_count >= 1 ) 
	{
		for (uint4 a=0; a < p_type_count; a++)
		{
			char *t_filter_name, *t_filter_masks;
			t_filter_name = get_filter_name(p_types[a]);
			t_filter_masks = get_filter_masks(p_types[a]);

			filter = gtk_file_filter_new();
			gtk_file_filter_set_name(filter, t_filter_name);
			
			if (strcasecmp (t_filter_name, "All files") != 0)
			{
				for ( uint4 m = 0 ; m < get_filter_count(t_filter_masks); m++)
				{
					char *t_filter_mask;
					t_filter_mask = get_filter_mask(m, t_filter_masks);
					
					char *filter_mask;
					filter_mask = nil;
					MCCStringFormat(filter_mask, "*.%s", t_filter_mask);

					gtk_file_filter_add_pattern(filter, filter_mask);

					MCCStringFree(filter_mask);
					delete t_filter_mask;
				}
			}
			else
				gtk_file_filter_add_pattern ( filter, "*" );

			gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ) , filter ) ;

			delete t_filter_name;
			delete t_filter_masks;
		}
	}
		
}
예제 #12
0
bool MCFileSystemListEntries(const char *p_folder, uint32_t p_options, MCFileSystemListCallback p_callback, void *p_context)
{
	bool t_success;
	t_success = true;

	char *t_pattern;
	t_pattern = nil;
	if (t_success)
		t_success = MCCStringFormat(t_pattern, "%s%s", p_folder, MCCStringEndsWith(p_folder, "/") ? "*" : "/*");

	void *t_native_pattern;
	t_native_pattern = nil;
	if (t_success)
		t_success = MCFileSystemPathToNative(t_pattern, t_native_pattern);

	HANDLE t_find_handle;
	WIN32_FIND_DATAW t_find_data;
	t_find_handle = INVALID_HANDLE_VALUE;
	if (t_success)
	{
		t_find_handle = FindFirstFileW((LPCWSTR)t_native_pattern, &t_find_data);
		if (t_find_handle == INVALID_HANDLE_VALUE)
			t_success = false;
	}

	while(t_success)
	{
		char *t_entry_filename;
		if (t_success)
			t_success = MCFileSystemPathFromNative(t_find_data . cFileName, t_entry_filename);

		MCFileSystemEntry t_entry;
		if (t_success)
		{
			t_entry . type = (t_find_data . dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ? kMCFileSystemEntryFolder : kMCFileSystemEntryFile;
			t_entry . filename = t_entry_filename;

			t_success = p_callback(p_context, t_entry);
		}

		MCCStringFree(t_entry_filename);

		////

		if (!FindNextFileW(t_find_handle, &t_find_data))
		{
			if (GetLastError() == ERROR_NO_MORE_FILES)
				break;

			t_success = false;
		}
	}

	if (t_find_handle != INVALID_HANDLE_VALUE)
		FindClose(t_find_handle);

	MCMemoryDeallocate(t_native_pattern);
	MCCStringFree(t_pattern);

	return t_success;
}
예제 #13
0
static void compute_simulator_redirect(const char *p_input, char*& r_output)
{
	if (s_redirects == nil)
	{
		r_output = (char *)p_input;
		return;
	}

	char *t_resolved_input;
	t_resolved_input = nil;
	if (*p_input != '/')
	{
		char *t_cwd;
		t_cwd = getcwd(nil, 0);
		MCCStringFormat(t_resolved_input, "%s/%s", t_cwd, p_input);
		free(t_cwd);
	}
	else
		MCCStringClone(p_input, t_resolved_input);
	
	char **t_components;
	uint32_t t_component_count;
	MCCStringSplit(t_resolved_input, '/', t_components, t_component_count);
	MCCStringFree(t_resolved_input);
	
	uint32_t t_count;
	t_count = 1;
	for(uint32_t j = 1; j < t_component_count; j++)
	{
		if (MCCStringEqual(t_components[j], ".") ||
			MCCStringEqual(t_components[j], ""))
		{
			MCCStringFree(t_components[j]);
			continue;
		}
		
		if (MCCStringEqual(t_components[j], ".."))
		{
			MCCStringFree(t_components[j]);
			if (t_count > 1)
			{
				MCCStringFree(t_components[t_count - 1]);
				t_count -= 1;
			}
			continue;
		}
		
		t_components[t_count] = t_components[j];
		t_count += 1;
	}
	
	MCCStringCombine(t_components, t_count, '/', t_resolved_input);
	MCCStringArrayFree(t_components, t_count);
	
	r_output = t_resolved_input;
	
	if (MCCStringBeginsWith(t_resolved_input, s_redirect_base))
	{
		const char *t_input_leaf;
		t_input_leaf = t_resolved_input + strlen(s_redirect_base) + 1;
		for(uint32_t i = 0; i < s_redirect_count; i++)
		{
			if (MCCStringEqual(s_redirects[i] . src, t_input_leaf))
			{
				r_output = strdup(s_redirects[i] . dst);
				break;
			}
			
			if (MCCStringBeginsWith(t_input_leaf, s_redirects[i] . src) &&
				t_input_leaf[MCCStringLength(s_redirects[i] . src)] == '/')
			{
				MCCStringFormat(r_output, "%s%s", s_redirects[i] . dst, t_input_leaf + MCCStringLength(s_redirects[i] . src));
				break;
			}
		}
	
	}
	
	if (r_output != t_resolved_input)
		MCCStringFree(t_resolved_input);
}
예제 #14
0
// This method reads a stack from the given stream. The stack is set to
// have parent MCDispatch, and filename MCcmd. It is designed to be used
// for embedded stacks/deployed stacks/revlet stacks.
IO_stat MCDispatch::readstartupstack(IO_handle stream, MCStack*& r_stack)
{
	char version[8];
	uint1 charset, type;
	char *newsf;
	if (readheader(stream, version) != IO_NORMAL
	        || IO_read_uint1(&charset, stream) != IO_NORMAL
	        || IO_read_uint1(&type, stream) != IO_NORMAL
	        || IO_read_string(newsf, stream) != IO_NORMAL)
		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;

	MCtranslatechars = charset != CHARSET;
	delete newsf; // stackfiles is obsolete

	MCStack *t_stack = nil;
	/* UNCHECKED */ MCStackSecurityCreateStack(t_stack);
	t_stack -> setparent(this);
	
	// MM-2013-10-30: [[ Bug 11333 ]] Set the filename of android mainstack to apk/mainstack (previously was just apk).
	//   This solves relative file path referencing issues.
#ifdef TARGET_SUBPLATFORM_ANDROID
    char *t_filename;
    /* UNCHECKED */ MCMemoryNewArray(MCCStringLength(MCcmd) + 11, t_filename);
    MCCStringFormat(t_filename, "%s/mainstack", MCcmd);
	t_stack -> setfilename(t_filename);
#else
   	t_stack -> setfilename(strclone(MCcmd));
#endif
	
	
	if (IO_read_uint1(&type, stream) != IO_NORMAL
	        || type != OT_STACK && type != OT_ENCRYPT_STACK
	        || t_stack->load(stream, version, type) != IO_NORMAL)
	{
		delete t_stack;
		return IO_ERROR;
	}

	if (t_stack->load_substacks(stream, version) != IO_NORMAL
	        || IO_read_uint1(&type, stream) != IO_NORMAL
	        || type != OT_END)
	{
		delete t_stack;
		return IO_ERROR;
	}

	// We are reading the startup stack, so this becomes the root of the
	// stack list.
	stacks = t_stack;

	r_stack = t_stack;

#ifndef _MOBILE
	// Make sure parent script references are up to date.
	if (s_loaded_parent_script_reference)
		t_stack -> resolveparentscripts();
#else
	// Mark the stack as needed parentscript resolution. This is done after
	// aux stacks have been loaded.
	if (s_loaded_parent_script_reference)
		t_stack -> setextendedstate(True, ECS_USES_PARENTSCRIPTS);
#endif

	return IO_NORMAL;
}