Beispiel #1
0
static void Key_History_Find_Forwards(void)
{
	int i;
	const char *partial = key_line + 1;
	char vabuf[1024];
	size_t digits = strlen(va(vabuf, sizeof(vabuf), "%i", HIST_MAXLINES));

	if (history_line == -1) // editing the "new" line
		return;

	if (strcmp(key_line + 1, history_searchstring)) // different string? Start a new search
	{
		strlcpy(history_searchstring, key_line + 1, sizeof(history_searchstring));
		i = 0;
	}
	else i = history_line + 1;

	if (!*partial)
		partial = "*";
	else if (!( strchr(partial, '*') || strchr(partial, '?') )) // no pattern?
		partial = va(vabuf, sizeof(vabuf), "*%s*", partial);

	for ( ; i < CONBUFFER_LINES_COUNT(&history); i++)
		if (matchpattern_with_separator(ConBuffer_GetLine(&history, i), partial, true, "", false))
		{
			Con_Printf("^2%*i^7 %s\n", (int)digits, i+1, ConBuffer_GetLine(&history, i));
			history_line = i;
			history_matchfound = true;
			return;
		}
}
Beispiel #2
0
static void Key_History_f(void)
{
	char *errchar = NULL;
	int i = 0;
	char vabuf[1024];
	size_t digits = strlen(va(vabuf, sizeof(vabuf), "%i", HIST_MAXLINES));

	if (Cmd_Argc () > 1)
	{
		if (!strcmp(Cmd_Argv (1), "-c"))
		{
			ConBuffer_Clear(&history);
			return;
		}
		i = strtol(Cmd_Argv (1), &errchar, 0);
		if ((i < 0) || (i > CONBUFFER_LINES_COUNT(&history)) || (errchar && *errchar))
			i = 0;
		else
			i = CONBUFFER_LINES_COUNT(&history) - i;
	}

	for ( ; i<CONBUFFER_LINES_COUNT(&history); i++)
		Con_Printf("^3%*i^7 %s\n", (int)digits, i+1, ConBuffer_GetLine(&history, i));
	Con_Printf("\n");
}
Beispiel #3
0
static qboolean Key_History_Get_foundCommand(void)
{
	if (!history_matchfound)
		return false;
	strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
	key_linepos = strlen(key_line);
	history_matchfound = false;
	return true;
}
Beispiel #4
0
static void Key_History_Up(void)
{
	if(history_line == -1) // editing the "new" line
		strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));

	if(history_line == -1)
	{
		history_line = CONBUFFER_LINES_COUNT(&history) - 1;
		if(history_line != -1)
		{
			strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
			key_linepos = strlen(key_line);
		}
	}
	else if(history_line > 0)
	{
		--history_line; // this also does -1 -> 0, so it is good
		strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
		key_linepos = strlen(key_line);
	}
}
Beispiel #5
0
static void Key_History_Find_All(void)
{
	const char *partial = key_line + 1;
	int i, count = 0;
	char vabuf[1024];
	size_t digits = strlen(va(vabuf, sizeof(vabuf), "%i", HIST_MAXLINES));
	Con_Printf("History commands containing \"%s\":\n", key_line + 1);

	if (!*partial)
		partial = "*";
	else if (!( strchr(partial, '*') || strchr(partial, '?') )) // no pattern?
		partial = va(vabuf, sizeof(vabuf), "*%s*", partial);

	for (i=0; i<CONBUFFER_LINES_COUNT(&history); i++)
		if (matchpattern_with_separator(ConBuffer_GetLine(&history, i), partial, true, "", false))
		{
			Con_Printf("%s%*i^7 %s\n", (i == history_line) ? "^2" : "^3", (int)digits, i+1, ConBuffer_GetLine(&history, i));
			count++;
		}
	Con_Printf("%i result%s\n\n", count, (count != 1) ? "s" : "");
}
Beispiel #6
0
static void Key_History_Last(void)
{
	if(history_line == -1) // editing the "new" line
		strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));

	if (CONBUFFER_LINES_COUNT(&history) > 0)
	{
		history_line = CONBUFFER_LINES_COUNT(&history) - 1;
		strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
		key_linepos = strlen(key_line);
	}
}
Beispiel #7
0
static void Key_History_Shutdown(void)
{
	// TODO write history to a file

	qfile_t *historyfile = FS_OpenRealFile("darkplaces_history.txt", "w", false);
	if(historyfile)
	{
		int i;
		for(i = 0; i < CONBUFFER_LINES_COUNT(&history); ++i)
			FS_Printf(historyfile, "%s\n", ConBuffer_GetLine(&history, i));
		FS_Close(historyfile);
	}

	ConBuffer_Shutdown(&history);
}
Beispiel #8
0
static void Key_History_Down(void)
{
	if(history_line == -1) // editing the "new" line
		return;

	if(history_line < CONBUFFER_LINES_COUNT(&history) - 1)
	{
		++history_line;
		strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
	}
	else
	{
		history_line = -1;
		strlcpy(key_line + 1, history_savedline, sizeof(key_line) - 1);
	}

	key_linepos = strlen(key_line);
}
Beispiel #9
0
static void Key_History_Shutdown(void)
{
	// TODO write history to a file

// not necessary for mobile
#ifndef DP_MOBILETOUCH
	qfile_t *historyfile = FS_OpenRealFile("darkplaces_history.txt", "w", false);
	if(historyfile)
	{
		int i;
		for(i = 0; i < CONBUFFER_LINES_COUNT(&history); ++i)
			FS_Printf(historyfile, "%s\n", ConBuffer_GetLine(&history, i));
		FS_Close(historyfile);
	}
#endif

	ConBuffer_Shutdown(&history);
}