Example #1
0
static int Key_CompleteKeyName (const char *partial, const char **match)
{
	int matches = 0;
	const char *localMatch[MAX_COMPLETE];
	size_t len;
	const keyName_t *kn;

	len = strlen(partial);
	if (!len) {
		for (kn = keyNames; kn->name; kn++) {
			Com_Printf("%s\n", kn->name);
		}
		return 0;
	}

	/* check for partial matches */
	for (kn = keyNames; kn->name; kn++) {
		if (!strncmp(partial, kn->name, len)) {
			Com_Printf("%s\n", kn->name);
			localMatch[matches++] = kn->name;
			if (matches >= MAX_COMPLETE)
				break;
		}
	}

	return Cmd_GenericCompleteFunction(len, match, matches, localMatch);
}
Example #2
0
static int M_CompleteMusic (const char* partial, const char** match)
{
	int n = 0;
	while (char const* const filename = FS_NextFileFromFileList("music/*.ogg")) {
		if (Cmd_GenericCompleteFunction(filename, partial, match)) {
			Com_Printf("%s\n", filename);
			++n;
		}
	}
	FS_NextFileFromFileList(nullptr);
	return n;
}
Example #3
0
/**
 * @brief Complete function for ui_push
 * @sa Cmd_AddParamCompleteFunction
 * @sa UI_PushWindow
 * @note Does not really complete the input - but shows at least all parsed windows
 */
int UI_CompleteWithWindow (const char *partial, const char **match)
{
	int n = 0;
	for (uiNode_t** i = ui_global.windows, ** const end = i + ui_global.numWindows; i != end; ++i) {
		char const* const name = (*i)->name;
		if (Cmd_GenericCompleteFunction(name, partial, match)) {
			Com_Printf("%s\n", name);
			++n;
		}
	}
	return n;
}
Example #4
0
/**
 * @brief Unix like tab completion for console variables
 * @param partial The beginning of the variable we try to complete
 * @param[out] match The found entry of the list we are searching, in case of more than one entry their common suffix is returned.
 * @sa Cmd_CompleteCommand
 * @sa Key_CompleteCommand
 */
int Cvar_CompleteVariable (const char* partial, const char** match)
{
	int n = 0;
	for (cvar_t const* cvar = cvarVars; cvar; cvar = cvar->next) {
#ifndef DEBUG
		if (cvar->flags & CVAR_DEVELOPER)
			continue;
#endif
		if (Cmd_GenericCompleteFunction(cvar->name, partial, match)) {
			Com_Printf("[var] %-20s = \"%s\"\n", cvar->name, cvar->string);
			if (cvar->description)
				Com_Printf(S_COLOR_GREEN "      %s\n", cvar->description);
			++n;
		}
	}
	return n;
}
Example #5
0
static int S_CompleteSounds (const char *partial, const char **match)
{
    char const* const soundExtensions[] = SAMPLE_TYPES;

    int n = 0;
    for (char const* const* extension = soundExtensions; *extension; ++extension) {
        char pattern[MAX_OSPATH];
        Com_sprintf(pattern, sizeof(pattern), "sound/**.%s", *extension);
        FS_BuildFileList(pattern);
        while (char const* filename = FS_NextFileFromFileList(pattern)) {
            char const* const fileWithPath = filename + 6;
            if (Cmd_GenericCompleteFunction(fileWithPath, partial, match)) {
                Com_Printf("%s\n", fileWithPath);
                ++n;
            }
        }
        FS_NextFileFromFileList(0);
    }
    return n;
}
Example #6
0
/**
 * @brief Unix like tab completion for console commands
 * @param[in] partial The beginning of the command we try to complete
 * @param[out] match The found entry of the list we are searching, in case of more than one entry their common suffix is returned.
 * @sa Cvar_CompleteVariable
 * @sa Key_CompleteCommand
 */
int Cmd_CompleteCommand (const char *partial, const char **match)
{
	const cmd_function_t *cmd;
	const cmd_alias_t *a;
	const char *localMatch[MAX_COMPLETE];
	int len, matches = 0;

	len = strlen(partial);

	if (!len)
		return 0;

	/* check for partial matches in commands */
	for (cmd = cmd_functions; cmd; cmd = cmd->next) {
		if (!strncmp(partial, cmd->name, len)) {
			Com_Printf("[cmd] %s\n", cmd->name);
			if (cmd->description)
				Com_Printf(S_COLOR_GREEN "      %s\n", cmd->description);
			localMatch[matches++] = cmd->name;
			if (matches >= MAX_COMPLETE)
				break;
		}
	}

	/* and then aliases */
	if (matches < MAX_COMPLETE) {
		for (a = cmd_alias; a; a = a->next) {
			if (!strncmp(partial, a->name, len)) {
				Com_Printf("[ali] %s\n", a->name);
				localMatch[matches++] = a->name;
				if (matches >= MAX_COMPLETE)
					break;
			}
		}
	}

	return Cmd_GenericCompleteFunction(len, match, matches, localMatch);
}
Example #7
0
static int S_CompleteSounds (const char *partial, const char **match)
{
	const char *filename;
	int matches = 0;
	char *localMatch[MAX_COMPLETE];
	size_t len = strlen(partial);
	const char *soundExtensions[] = SAMPLE_TYPES;
	const char **extension = soundExtensions;
	int returnValue;

	/* check for partial matches */
	while (*extension) {
		char pattern[MAX_OSPATH];
		Com_sprintf(pattern, sizeof(pattern), "sound/**.%s", *extension);
		FS_BuildFileList(pattern);
		while ((filename = FS_NextFileFromFileList(pattern)) != NULL) {
			char fileWithPath[MAX_OSPATH];
			Com_sprintf(fileWithPath, sizeof(fileWithPath), "%s", filename + 6);
			if (!len) {
				Com_Printf("%s\n", fileWithPath);
			} else if (!strncmp(partial, fileWithPath, len)) {
				Com_Printf("%s\n", fileWithPath);
				localMatch[matches++] = strdup(fileWithPath);
				if (matches >= MAX_COMPLETE)
					break;
			}
		}
		FS_NextFileFromFileList(NULL);
		extension++;
	}

	returnValue = Cmd_GenericCompleteFunction(len, match, matches, (const char **)localMatch);
	while (--matches >= 0)
		free(localMatch[matches]);
	return returnValue;
}