Ejemplo n.º 1
0
void MCArraysExecCombineAsSet(MCExecContext& ctxt, MCArrayRef p_array, MCStringRef p_element_delimiter, MCStringRef& r_string)
{
	// String into which the combined keys are accumulated
    MCAutoStringRef t_string;
    
    // The array keys are not added in any particular order
    MCNameRef t_key;
    MCValueRef t_value_ignored;
    uintptr_t t_iterator = 0;
    while (MCArrayIterate(p_array, t_iterator, t_key, t_value_ignored))
    {
        bool t_success;
        t_success = true;
        if (*t_string == nil)
            t_success = MCStringMutableCopy(MCNameGetString(t_key), &t_string);
        else
            t_success = MCStringAppendFormat(*t_string, "%@%@", p_element_delimiter, t_key);
        
        if (!t_success)
        {
            ctxt . Throw();
            return;
        }
    }
    
    MCStringCopy(*t_string, r_string);
}
Ejemplo n.º 2
0
static void get_new_filter(MCStringRef *p_types, uint4 p_type_count, MCStringRef &r_filters)
{
	MCAutoStringRef t_filters;
	/* UNCHECKED */ MCStringCreateMutable(0, &t_filters);

	for(uint4 t_type_index = 0; t_type_index < p_type_count; ++t_type_index)
	{
		MCAutoStringRefArray t_split;
		/* UNCHECKED */ MCStringsSplit(p_types[t_type_index], '|', t_split.PtrRef(), t_split.CountRef());

		if (t_split.Count() < 1 || 
			(t_split.Count() == 1 && MCStringIsEmpty(t_split[0])))
			continue;

		if (t_type_index != 0)
			/* UNCHECKED */ MCStringAppendChar(*t_filters, '\0');

		/* UNCHECKED */ MCStringAppend(*t_filters, t_split[0]);

		if (t_split.Count() < 2)
			/* UNCHECKED */ MCStringAppendChars(*t_filters, L"\0*.*", 4);
		else
		{
			MCAutoStringRefArray t_extensions;
			/* UNCHECKED */ MCStringsSplit(t_split[1], ',', t_extensions.PtrRef(), t_extensions.CountRef());
			// SN-2014-07-28: [[ Bug 12972 ]] Filters "Tag|" should be understood as "Tag"
			//  and allow all the file types
			if (t_extensions.Count() == 0 || 
					(t_extensions.Count() == 1 && MCStringIsEmpty(t_extensions[0])))
				/* UNCHECKED */ MCStringAppendChars(*t_filters, L"\0*.*", 4);
			else
			{
				for (unsigned int i = 0; i < t_extensions.Count(); ++i)
				{
					if (i != 0)
						/* UNCHECKED*/ MCStringAppendChar(*t_filters, ';');
					else
						/* UNCHECKED*/ MCStringAppendChar(*t_filters, '\0');

					/* UNCHECKED */ MCStringAppendFormat(*t_filters, "*.%@", t_extensions[i]);
				}
			}
		}
	}

	if (MCStringIsEmpty(*t_filters))
		/* UNCHECKED */ MCStringCreateWithNativeChars((char_t*)"All Files\0*.*\0\0", 15, r_filters);
	else
	{
		/* UNCHECKED */ MCStringAppendChar(*t_filters, '\0');
		MCStringCopy(*t_filters, r_filters);
	}
}
Ejemplo n.º 3
0
static HRESULT append_shellitem_path_and_release(IShellItem *p_item, bool p_first, MCStringRef &x_string)
{
	HRESULT t_hresult;
	t_hresult = S_OK;

	bool t_succeeded;
	t_succeeded = true;

	WCHAR *t_filename;
	t_filename = NULL;
	if (t_succeeded)
	{
		t_hresult = p_item -> GetDisplayName(SIGDN_FILESYSPATH, &t_filename);
		t_succeeded = SUCCEEDED(t_hresult);
	}
	
	if (t_succeeded)
	{
		if (x_string == nil)
			MCStringCreateMutable(0, x_string);
		else if (!MCStringIsMutable(x_string))
		{
			MCStringRef t_clone;
			MCStringMutableCopy(x_string, t_clone);
			MCValueAssign(x_string, t_clone);
		}

		MCAutoStringRef t_rev_filename;
		MCAutoStringRef t_native_filename;
		
		/* UNCHECKED */ MCStringCreateWithChars(t_filename, lstrlenW(t_filename), &t_native_filename);
		/* UNCHECKED */ MCS_pathfromnative(*t_native_filename, &t_rev_filename);
		/* UNCHECKED */ MCStringAppendFormat(x_string, p_first ? "%@" : "\n%@", *t_rev_filename);
	}

	if (t_filename != NULL)
		CoTaskMemFree(t_filename);

	if (p_item != NULL)
		p_item -> Release();

	return t_hresult;
}
Ejemplo n.º 4
0
void MCLicenseGetRevLicenseInfo(MCExecContext& ctxt, MCStringRef& r_info)
{
    static const char *s_deploy_targets[] =
    {
        "Windows",
        "Mac OS X",
        "Linux",
        "iOS",
        "Android",
        "Windows Mobile",
        "Linux Mobile",
        "Server",
        "iOS Embedded",
        "Android Embedded",
        "HTML5",
        "FileMaker",
    };
    
    bool t_success;
    
    MCAutoStringRef t_info;
    t_success = MCStringCreateMutable(0, &t_info);
    
    MCStringRef t_license_name;
    t_license_name = MClicenseparameters . license_name;
    if (t_license_name == nil)
        t_license_name = kMCEmptyString;

    MCStringRef t_license_org;
    t_license_org = MClicenseparameters . license_organization;
    if (t_license_org == nil)
        t_license_org = kMCEmptyString;

    MCAutoStringRef t_class;
    if (t_success)
        t_success = MCStringFromLicenseClass(MClicenseparameters . license_class, false, &t_class);
    
    if (t_success)
        t_success = MCStringAppendFormat(*t_info, "%@\n%@\n%@\n%u\n",
                                         t_license_name, t_license_org,
                                         *t_class,
                                         MClicenseparameters . license_multiplicity);
    
    if (MClicenseparameters . deploy_targets != 0)
    {
        bool t_first;
        t_first = true;
        for(uint32_t i = 0; t_success && i < sizeof(s_deploy_targets) / sizeof(s_deploy_targets[0]); i++)
        {
            if ((MClicenseparameters . deploy_targets & (1 << i)) != 0)
            {
                t_success = MCStringAppendFormat(*t_info, t_first ? "%s" : ",%s", s_deploy_targets[i]);
                t_first = false;
            }
        }
    }
    
    // AL-2014-11-04: [[ Bug 13865 ]] Don't add an extra line between deploy targets and addons

    if (t_success && MClicenseparameters . addons != nil)
    {
        MCAutoStringRef t_keys;
        t_success = (MCArrayListKeys(MClicenseparameters . addons, ',', &t_keys) &&
                    MCStringAppendFormat(*t_info, "\n%@", *t_keys));
    }
    
    if (t_success)
        if (MCStringAppendFormat(*t_info, "\n%s", MCStringIsEmpty(MClicenseparameters . license_token) ? "Global" : "Local") &&
                MCStringCopy(*t_info, r_info))
            return;
    
    ctxt . Throw();
}
Ejemplo n.º 5
0
void MCArraysExecSplitByColumn(MCExecContext& ctxt, MCStringRef p_string, MCArrayRef& r_array)
{
    MCStringRef t_row_delim, t_column_delim;
    t_row_delim = ctxt . GetRowDelimiter();
    t_column_delim = ctxt . GetColumnDelimiter();
    
    // Output array
    MCAutoArrayRef t_array;
    if (!MCArrayCreateMutable(&t_array))
    {
        ctxt . Throw();
        return;
    }
    
    // Temporary array for storing columns
    MCAutoArray<MCStringRef> t_temp_array;
    
    // Iterate over the rows of the input string
    uindex_t t_offset, t_length;
    t_offset = 0;
    t_length = MCStringGetLength(p_string);
    
    bool t_success;
    t_success = true;
    
    uindex_t t_row_index;
    t_row_index = 0;
    
    while (t_success && t_offset < t_length)
    {
        // Find the end of this row
        MCRange t_row_found;
        if (!MCStringFind(p_string, MCRangeMake(t_offset, UINDEX_MAX), t_row_delim, ctxt . GetStringComparisonType(), &t_row_found))
        {
            t_row_found . offset = t_length;
            t_row_found . length = 0;
        }
        
        // Iterate over the cells of this row
        uindex_t t_cell_offset, t_column_index;
        t_cell_offset = t_offset;
        t_column_index = 0;
        while (t_success && t_cell_offset <= t_row_found . offset)
        {
            // Find the end of this cell
            MCRange t_cell_found;
            if (!MCStringFind(p_string, MCRangeMake(t_cell_offset, UINDEX_MAX), t_column_delim, ctxt . GetStringComparisonType(), &t_cell_found) || t_cell_found . offset > t_row_found . offset)
            {
                t_cell_found . offset = t_row_found . offset;
                // AL-2014-08-04: [[ Bug 13090 ]] Make sure cell offset is incremented eventually when the delimiter is not found
                t_cell_found . length = 1;
            }
            
            // Check that the output array has a slot for this column
            if (t_temp_array.Size() <= t_column_index)
                t_temp_array.Extend(t_column_index + 1);
            
            // Check that a string has been created to store this column
            MCRange t_range;
            t_range = MCRangeMake(t_cell_offset, t_cell_found . offset - t_cell_offset);
            if (t_temp_array[t_column_index] == nil)
            {
                t_success = MCStringCreateMutable(0, t_temp_array[t_column_index]);
                
                // AL-2014-08-04: [[ Bug 13090 ]] If we are creating a new column, make sure we pad with empty cells 'above' this one
                uindex_t t_rows = t_row_index;
                while (t_success && t_rows--)
                    t_success = MCStringAppend(t_temp_array[t_column_index], t_row_delim);
                
                if (t_success)
                    t_success = MCStringAppendFormat(t_temp_array[t_column_index], "%*@", &t_range, p_string);
            }
            else
            {
                // AL-2014-06-12: [[ Bug 12610 ]] Range parameter to MCStringFormat must be a pointer to an MCRange
                t_success = MCStringAppendFormat(t_temp_array[t_column_index], "%@%*@", t_row_delim, &t_range, p_string);
            }
            
            // Next cell
            t_column_index++;
            t_cell_offset = t_cell_found . offset + t_cell_found . length;
        }
        
        // AL-2014-08-04: [[ Bug 13090 ]] Pad the rest of this row with empty cells
        index_t t_pad_number;
        t_pad_number = t_temp_array . Size() - t_column_index;
        if (t_success && t_pad_number > 0)
        {
            while (t_success && t_pad_number--)
                t_success = MCStringAppend(t_temp_array[t_column_index++], t_row_delim);
        }
        
        // Next row
        t_row_index++;
        t_offset = t_row_found . offset + t_row_found . length;
    }
    
    // Convert the temporary array into a "proper" array
    for (uindex_t i = 0; i < t_temp_array.Size() && t_success; i++)
    {
        t_success = MCArrayStoreValueAtIndex(*t_array, i + 1, t_temp_array[i]);
        MCValueRelease(t_temp_array[i]);
    }

    if (t_success)
        t_success = MCArrayCopy(*t_array, r_array);
    
    if (!t_success)
        ctxt . Throw();
}
Ejemplo n.º 6
0
static MCStringRef windows_convert_time_format(MCStringRef p_format)
{
	MCStringRef t_output;
	MCStringCreateMutable(0, t_output);
	uindex_t t_offset = 0;
	
	while (t_offset < MCStringGetLength(p_format))
	{
		unichar_t t_char;
		t_char = MCStringGetCharAtIndex(p_format, t_offset++);
		
		if (t_char == '\'')
		{
			// Copy quoted strings to the output with no conversion
			while ((t_char = MCStringGetCharAtIndex(p_format, t_offset++)) != '\'')
				MCStringAppendChar(t_output, t_char);
		}
		else
		{
			// Is this a day/month/year specifier?
			if (t_char == 'h' || t_char == 'H' || t_char == 'm' || t_char == 's' || t_char == 't')
			{
				// Count the number of consecutive identical characters
				unichar_t t_want = t_char;
				int t_count = 1;
				while ((t_char = MCStringGetCharAtIndex(p_format, t_offset)) == t_want)
                {
                    t_count++;
                    t_offset++;
                }
				
				// Append the correct formatting instruction
				switch (t_want)
				{
					case 'h':
						if (t_count == 1)
							MCStringAppendFormat(t_output, "%%#I");
						else if (t_count == 2)
							MCStringAppendFormat(t_output, "%%I");
						break;
						
					case 'H':
						if (t_count == 1)
							MCStringAppendFormat(t_output, "%%#H");
						else if (t_count == 2)
							MCStringAppendFormat(t_output, "%%H");
						break;
						
					case 'm':
						if (t_count == 1)
							MCStringAppendFormat(t_output, "%%#M");
						else if (t_count == 2)
							MCStringAppendFormat(t_output, "%%M");
						break;
						
					case 's':
						if (t_count == 1)
							MCStringAppendFormat(t_output, "%%#S");
						else if (t_count == 2)
							MCStringAppendFormat(t_output, "%%S");
						break;
						
					case 't':
						MCStringAppendFormat(t_output, "%%p");
				}
			}
			else
			{
				// Unknown character, copy it to the output
				MCStringAppendChar(t_output, t_char);
			}
		}
	}
	
	MCValueRelease(p_format);
	return t_output;
}
Ejemplo n.º 7
0
static MCStringRef windows_convert_date_format(MCStringRef p_format)
{
	MCStringRef t_output;
	MCStringCreateMutable(0, t_output);
	uindex_t t_offset = 0;
	
	while (t_offset < MCStringGetLength(p_format))
	{
		unichar_t t_char;
		t_char = MCStringGetCharAtIndex(p_format, t_offset++);
		
		if (t_char == '\'')
		{
			// Copy quoted strings to the output with no conversion
			while ((t_char = MCStringGetCharAtIndex(p_format, t_offset++)) != '\'')
				   MCStringAppendChar(t_output, t_char);
		}
		else
		{
			// Is this a day/month/year specifier?
			if (t_char == 'd' || t_char == 'M' || t_char == 'y')
			{
				// Count the number of consecutive identical characters
				unichar_t t_want = t_char;
				int t_count = 1;
				while (MCStringGetCharAtIndex(p_format, t_offset) == t_want)
                {
					t_count++;
                    t_offset++;
                }
				
				// Append the correct formatting instruction
				switch (t_char)
				{
				case 'd':
					if (t_count == 1)
						MCStringAppendFormat(t_output, "%%#d");
					else if (t_count == 2)
						MCStringAppendFormat(t_output, "%%d");
					else if (t_count == 3)
						MCStringAppendFormat(t_output, "%%a");
					else if (t_count == 4)
						MCStringAppendFormat(t_output, "%%A");
					break;
						
				case 'M':
					if (t_count == 1)
						MCStringAppendFormat(t_output, "%%#m");
					else if (t_count == 2)
						MCStringAppendFormat(t_output, "%%m");
					else if (t_count == 3)
						MCStringAppendFormat(t_output, "%%b");
					else if (t_count == 4)
						MCStringAppendFormat(t_output, "%%B");
					break;
						
				case 'y':
					if (t_count == 1)
						MCStringAppendFormat(t_output, "%%#y");
					else if (t_count == 2)
						MCStringAppendFormat(t_output, "%%y");
					else if (t_count == 4)
						MCStringAppendFormat(t_output, "%%Y");
					break;
				}
			}
			else
			{
				// Unknown character, copy it to the output
				MCStringAppendChar(t_output, t_char);
			}
		}
	}
	
	MCValueRelease(p_format);
	return t_output;
}