コード例 #1
0
ファイル: exec-debugging.cpp プロジェクト: alilloyd/livecode
void MCDebuggingSetDebugContext(MCExecContext& ctxt, MCStringRef p_value)
{
	uindex_t t_length = MCStringGetLength(p_value);
	bool t_in_quotes;
	t_in_quotes = false;
	uindex_t t_offset;

	/*for (t_offset = 0; t_offset < t_length; t_offset++)
	{
		if (!t_in_quotes && MCStringGetNativeCharAtIndex(p_value, t_offset) == ',')
			break;

		if (MCStringGetNativeCharAtIndex(p_value, t_offset) == '"')
			t_in_quotes = !t_in_quotes;
	}
     
    if (t_offset < t_length)*/
    
	if (MCStringLastIndexOfChar(p_value, ',', t_length, kMCStringOptionCompareExact, t_offset))
	{
		MCAutoStringRef t_head;
		MCAutoStringRef t_tail;
		int4 t_line;
		MCObjectPtr t_object;		

		if (MCStringDivideAtIndex(p_value, t_offset, &t_head, &t_tail) &&
			MCInterfaceTryToResolveObject(ctxt, *t_head, t_object) &&
			MCU_strtol(*t_tail, t_line))
		{
			for (uint2 i = 0; i < MCnexecutioncontexts; i++)
			{
				if (MCexecutioncontexts[i] -> GetObject() == t_object . object && 
                    MCexecutioncontexts[i] -> GetLine() == t_line)
				{
					MCdebugcontext = i;
					break;
				}
			}
			return;
		}
	}
	else
	{
		int4 i;
		if (MCU_strtol(p_value, i) && i <= MCnexecutioncontexts)
			MCdebugcontext = i - 1;
		else
			MCdebugcontext = MAXUINT2;
		return;
	}

	ctxt . Throw();
}
コード例 #2
0
ファイル: mblcontrol.cpp プロジェクト: Bjoernke/livecode
bool MCNativeControl::ParseRange(MCExecPoint &ep, uint32_t &r_start, uint32_t &r_length)
{
	const char *sptr = ep.getsvalue().getstring();
	uint4 l = ep.getsvalue().getlength();
	uint32_t d1, d2;
	Boolean done;
	d1 = MCU_strtol(sptr, l, ',', done, True, False);
	if (!done || l == 0)
		return false;
	d2 = MCU_strtol(sptr, l, '\0', done, True, False);
	if (!done || l != 0)
		return false;
    
    r_start = d1;
    r_length = d2;
    
    return true;
}
コード例 #3
0
ファイル: mblcontrol.cpp プロジェクト: Bjoernke/livecode
static bool MCParseRGBA(const MCString &p_data, bool p_require_alpha, uint1 &r_red, uint1 &r_green, uint1 &r_blue, uint1 &r_alpha)
{
	bool t_success = true;
	Boolean t_parsed;
	uint2 r, g, b, a;
	const char *t_data = p_data.getstring();
	uint32_t l = p_data.getlength();
	if (t_success)
	{
		r = MCU_max(0, MCU_min(255, MCU_strtol(t_data, l, ',', t_parsed)));
		t_success = t_parsed;
	}
	if (t_success)
	{
		g = MCU_max(0, MCU_min(255, MCU_strtol(t_data, l, ',', t_parsed)));
		t_success = t_parsed;
	}
	if (t_success)
	{
		b = MCU_max(0, MCU_min(255, MCU_strtol(t_data, l, ',', t_parsed)));
		t_success = t_parsed;
	}
	if (t_success)
	{
		a = MCU_max(0, MCU_min(255, MCU_strtol(t_data, l, ',', t_parsed)));
		if (!t_parsed)
		{
			if (p_require_alpha)
				t_success = false;
			else
				a = 255;
		}
	}
	
	if (t_success)
	{
		r_red = r;
		r_green = g;
		r_blue = b;
		r_alpha = a;
	}
	return t_success;
}
コード例 #4
0
// This call is primarily designed to be used by the plugin installer. As this
// is generally installed 'per-user', we simply scan '/proc' for processes owned
// by the calling user.
bool MCSystemListProcesses(MCSystemListProcessesCallback p_callback, void* p_context)
{
	bool t_success;
	t_success = true;

	DIR *t_dir;
	t_dir = nil;
	if (t_success)
	{
		t_dir = opendir("/proc");
		if (t_dir == nil)
			t_success = false;
	}

	if (t_success)
	{
		dirent *t_entry;
		while(t_success)
		{
			// Fetch the next entry
			t_entry = readdir(t_dir);
			if (t_entry == nil)
				break;

			// Work out if the entry is a process id
			int32_t t_pid;
            MCAutoStringRef t_dname;
            /* UNCHECKED */ MCStringCreateWithCString(t_entry -> d_name, &t_dname);
			if (!MCU_strtol(*t_dname, t_pid))
				continue;

			// Work out the full path ("/proc/<int>") and stat so we can
			// check ownership.
			char t_path[6 + I4L + 1];
			struct stat64 t_stat;
			sprintf(t_path, "/proc/%u", t_pid);
			stat64(t_path, &t_stat);
			if (t_stat . st_uid != getuid())
				continue;

			// We have a viable process to report. First fetch its path
            MCAutoStringRef t_exe_link, t_exe_path;
            /* UNCHECKED */ MCStringFormat(&t_exe_link, "/proc/%u/exe", t_pid);
			if (!MCS_resolvepath(*t_exe_link, &t_exe_path))
			{
				t_success = false;
				break;
			}

			// Next fetch its 'description' from the first line of the status
			// file.
			char t_status_file[6 + I4L + 7 + 1];
			char t_status[256];
			FILE *t_stream;
			sprintf(t_status_file, "/proc/%u/status", t_pid);
			t_stream = fopen(t_status_file, "r");
			if (t_stream != nil)
			{
				if (fgets(t_status, 256, t_stream) != nil)
				{
					char *t_tab;
					t_tab = strchr(t_status, '\t');
					if (t_tab != nil)
						MCMemoryMove(t_status, t_tab + 1, MCCStringLength(t_tab + 1));
				}
				else
					t_status[0] = '\0';
				fclose(t_stream);
			}
			else
				t_status[0] = '\0';

            MCAutoStringRef t_status_str;
            /* UNCHECKED */ MCStringCreateWithSysString(t_status, &t_status_str);
			t_success = p_callback(p_context, t_pid, *t_exe_path, *t_status_str);
		}
	}

	if (t_dir != nil)
		closedir(t_dir);

	return t_success;
}