Example #1
0
// ----------------------------------------------------------------------------
// TextLanguage::getAutocompletionList
//
// Returns a string containing all words and functions that can be used
// directly in scintilla for an autocompletion list
// ----------------------------------------------------------------------------
string TextLanguage::autocompletionList(string start, bool include_custom)
{
	// Firstly, add all functions and word lists to a wxArrayString
	wxArrayString list;
	start = start.Lower();

	// Add word lists
	for (unsigned type = 0; type < 4; type++)
	{
		for (auto& word : word_lists_[type].list)
			if (word.Lower().StartsWith(start))
				list.Add(S_FMT("%s?%d", word, type + 1));

		if (!include_custom)
			continue;

		for (auto& word : word_lists_custom_[type].list)
			if (word.Lower().StartsWith(start))
				list.Add(S_FMT("%s?%d", word, type + 1));
	}

	// Add functions
	for (auto& func : functions_)
		if (func.name().Lower().StartsWith(start))
			list.Add(S_FMT("%s%s", func.name(), "?3"));

	// Sort the list
	list.Sort();

	// Now build a string of the list items separated by spaces
	string ret;
	for (unsigned a = 0; a < list.size(); a++)
		ret += list[a] + " ";

	return ret;
}
Example #2
0
/* RunDialog::getSelectedCommandLine
 * Returns a command line based on the currently selected run
 * configuration and resources
 *******************************************************************/
string RunDialog::getSelectedCommandLine(Archive* archive, string map_name, string map_file)
{
	Executables::game_exe_t* exe = Executables::getGameExe(choice_game_exes->GetSelection());
	if (exe)
	{
		// Get exe path
		const string exe_path = getExecutablePath(exe);

		if (exe_path.IsEmpty())
			return "";

		string path = S_FMT("\"%s\"", exe_path);

		unsigned cfg = choice_config->GetSelection();
		if (cfg < exe->configs.size())
		{
			path += " ";
			path += exe->configs[cfg].value;
		}

		// IWAD
		Archive* bra = theArchiveManager->baseResourceArchive();
		path.Replace("%i", S_FMT("\"%s\"", bra ? bra->getFilename() : ""));

		// Resources
		path.Replace("%r", getSelectedResourceList());

		// Archive (+ temp map if specified)
		if (map_file.IsEmpty() && archive)
			path.Replace("%a", S_FMT("\"%s\"", archive->getFilename()));
		else
		{
			if (archive)
				path.Replace("%a", S_FMT("\"%s\" \"%s\"", archive->getFilename(), map_file));
			else
				path.Replace("%a", S_FMT("\"%s\"", map_file));
		}

		// Running an archive yields no map name, so don't try to warp
		if (map_name.IsEmpty())
		{
			path.Replace("-warp ", wxEmptyString);
			path.Replace("+map ",  wxEmptyString);
			path.Replace("%mn",    wxEmptyString);
			path.Replace("%mw",    wxEmptyString);
		}
		// Map name
		else
		{
			path.Replace("%mn", map_name);

			// Map warp
			if (path.Contains("%mw"))
			{
				string mn = map_name.Lower();

				// MAPxx
				string mapnum;
				if (mn.StartsWith("map", &mapnum))
					path.Replace("%mw", mapnum);

				// ExMx
				else if (map_name.length() == 4 && mn[0] == 'e' && mn[2] == 'm')
					path.Replace("%mw", S_FMT("%c %c", mn[1], mn[3]));
			}
		}

		// Extra parameters
		if (!text_extra_params->GetValue().IsEmpty())
		{
			path += " ";
			path += text_extra_params->GetValue();
		}

		LOG_MESSAGE(2, "Run command: %s", path);
		return path;
	}

	return "";
}
Example #3
0
size_t BasicSearchTree::FindMatches(const string& s,set<size_t> &result,bool caseSensitive,bool is_prefix)
{

    // NOTE: Current algorithm is suboptimal, but certainly it's much better
    // than an exhaustive search.


    result.clear();
    string s2,curcmp,s3;
    nSearchTreeNode ncurnode;
    SearchTreeNode* curnode = 0;
    BasicSearchTreeIterator it(this);
    SearchTreeItemsMap::iterator it2;

    bool matches;

    if(!caseSensitive)
        s2 = s.Lower();
    else
        s2 = s;

    while(!it.eof())
    {
        matches = false;
        ncurnode = *it;
        curnode = m_pNodes[*it];
        if(!curnode)
            break; // Error! Found a NULL Node
        if(curnode->m_depth < s.length())
        {   // Node's string is shorter than S, therefore it CANNOT be a suffix
            // However, we can test if it does NOT match the current string.
            if(!curnode->m_depth)
                matches = true;
            else
            {
                s3 = s2.substr(curnode->GetLabelStartDepth(),curnode->GetLabelLen());
                curcmp = curnode->GetLabel(this);
                if(!caseSensitive)
                    curcmp = curcmp.Lower();
                matches = (s3 == curcmp);
            }
        }
        else
        {
            if(curnode->GetLabelStartDepth() >= s2.length())
                matches = is_prefix;
            else
            {
                s3 = s2.substr(curnode->GetLabelStartDepth());
                curcmp = curnode->GetLabel(this);
                if(!caseSensitive)
                    curcmp = curcmp.Lower();
                matches = curcmp.StartsWith(s3);
            }

            if(matches)
            {
                // Begin items addition
                if(!is_prefix)
                {
                    // Easy part: Only one length to search
                    it2 = curnode->m_Items.find(s2.length());
                    if(it2 != curnode->m_Items.end())
                        result.insert(it2->second);
                }
                else
                {
                    for(it2 = curnode->m_Items.lower_bound(s2.length()); it2 != curnode->m_Items.end(); ++it2)
                    {
                        result.insert(it2->second);
                    }
                }
                matches = is_prefix;
                // End items addition
            }
        }
        it.FindNext(matches);
    }
    return result.size();
}