904 lines · 16.7 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <stdio.h>#include "dat.h"#include "fns.h" /* key up events are sent even if in console mode */  #define		MAXCMDLINE	256char	key_lines[32][MAXCMDLINE];int		key_linepos;int		shift_down=false;int	anykeydown; int		edit_line=0;int		history_line=0; char	*keybindings[256];qboolean	consolekeys[256];	// if true, can't be rebound while in consoleqboolean	menubound[256];	// if true, can't be rebound while in menuint		keyshift[256];		// key to map to if shift held down in consoleqboolean	keydown[256]; typedef struct{	char	*name;	int		keynum;} keyname_t; keyname_t keynames[] ={	{"TAB", K_TAB},	{"ENTER", K_ENTER},	{"ESCAPE", K_ESCAPE},	{"SPACE", K_SPACE},	{"BACKSPACE", K_BACKSPACE},	{"UPARROW", K_UPARROW},	{"DOWNARROW", K_DOWNARROW},	{"LEFTARROW", K_LEFTARROW},	{"RIGHTARROW", K_RIGHTARROW}, 	{"ALT", K_ALT},	{"CTRL", K_CTRL},	{"SHIFT", K_SHIFT},		{"F1", K_F1},	{"F2", K_F2},	{"F3", K_F3},	{"F4", K_F4},	{"F5", K_F5},	{"F6", K_F6},	{"F7", K_F7},	{"F8", K_F8},	{"F9", K_F9},	{"F10", K_F10},	{"F11", K_F11},	{"F12", K_F12}, 	{"INS", K_INS},	{"DEL", K_DEL},	{"PGDN", K_PGDN},	{"PGUP", K_PGUP},	{"HOME", K_HOME},	{"END", K_END}, 	{"MOUSE1", K_MOUSE1},	{"MOUSE2", K_MOUSE2},	{"MOUSE3", K_MOUSE3}, 	{"JOY1", K_JOY1},	{"JOY2", K_JOY2},	{"JOY3", K_JOY3},	{"JOY4", K_JOY4}, 	{"AUX1", K_AUX1},	{"AUX2", K_AUX2},	{"AUX3", K_AUX3},	{"AUX4", K_AUX4},	{"AUX5", K_AUX5},	{"AUX6", K_AUX6},	{"AUX7", K_AUX7},	{"AUX8", K_AUX8},	{"AUX9", K_AUX9},	{"AUX10", K_AUX10},	{"AUX11", K_AUX11},	{"AUX12", K_AUX12},	{"AUX13", K_AUX13},	{"AUX14", K_AUX14},	{"AUX15", K_AUX15},	{"AUX16", K_AUX16},	{"AUX17", K_AUX17},	{"AUX18", K_AUX18},	{"AUX19", K_AUX19},	{"AUX20", K_AUX20},	{"AUX21", K_AUX21},	{"AUX22", K_AUX22},	{"AUX23", K_AUX23},	{"AUX24", K_AUX24},	{"AUX25", K_AUX25},	{"AUX26", K_AUX26},	{"AUX27", K_AUX27},	{"AUX28", K_AUX28},	{"AUX29", K_AUX29},	{"AUX30", K_AUX30},	{"AUX31", K_AUX31},	{"AUX32", K_AUX32}, 	{"KP_HOME",			K_KP_HOME },	{"KP_UPARROW",		K_KP_UPARROW },	{"KP_PGUP",			K_KP_PGUP },	{"KP_LEFTARROW",	K_KP_LEFTARROW },	{"KP_5",			K_KP_5 },	{"KP_RIGHTARROW",	K_KP_RIGHTARROW },	{"KP_END",			K_KP_END },	{"KP_DOWNARROW",	K_KP_DOWNARROW },	{"KP_PGDN",			K_KP_PGDN },	{"KP_ENTER",		K_KP_ENTER },	{"KP_INS",			K_KP_INS },	{"KP_DEL",			K_KP_DEL },	{"KP_SLASH",		K_KP_SLASH },	{"KP_MINUS",		K_KP_MINUS },	{"KP_PLUS",			K_KP_PLUS }, 	{"MWHEELUP", K_MWHEELUP },	{"MWHEELDOWN", K_MWHEELDOWN }, 	{"PAUSE", K_PAUSE}, 	{"SEMICOLON", ';'},	// because a raw semicolon seperates commands 	{NULL,0}}; /*============================================================================== 			LINE TYPING INTO THE CONSOLE ==============================================================================*/ void CompleteCommand (void){	char	*cmd, *s; 	s = key_lines[edit_line]+1;	if (*s == '\\' || *s == '/')		s++; 	cmd = Cmd_CompleteCommand (s);	if (!cmd)		cmd = Cvar_CompleteVariable (s);	if (cmd)	{		key_lines[edit_line][1] = '/';		strcpy (key_lines[edit_line]+2, cmd);		key_linepos = strlen(cmd)+2;		key_lines[edit_line][key_linepos] = ' ';		key_linepos++;		key_lines[edit_line][key_linepos] = 0;		return;	}} /*====================Key_Console Interactive line editing and console scrollback====================*/void Key_Console (int key){ 	switch ( key )	{	case K_KP_SLASH:		key = '/';		break;	case K_KP_MINUS:		key = '-';		break;	case K_KP_PLUS:		key = '+';		break;	case K_KP_HOME:		key = '7';		break;	case K_KP_UPARROW:		key = '8';		break;	case K_KP_PGUP:		key = '9';		break;	case K_KP_LEFTARROW:		key = '4';		break;	case K_KP_5:		key = '5';		break;	case K_KP_RIGHTARROW:		key = '6';		break;	case K_KP_END:		key = '1';		break;	case K_KP_DOWNARROW:		key = '2';		break;	case K_KP_PGDN:		key = '3';		break;	case K_KP_INS:		key = '0';		break;	case K_KP_DEL:		key = '.';		break;	} 	if ( ( toupper( key ) == 'V' && keydown[K_CTRL] ) ||		 ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keydown[K_SHIFT] ) )	{		char *cbd;				if ( ( cbd = Sys_GetClipboardData() ) != 0 )		{			int i; 			strtok( cbd, "\n\r\b" ); 			i = strlen( cbd );			if ( i + key_linepos >= MAXCMDLINE)				i= MAXCMDLINE - key_linepos; 			if ( i > 0 )			{				cbd[i]=0;				strcat( key_lines[edit_line], cbd );				key_linepos += i;			}			free( cbd );		} 		return;	} 	if ( key == 'l' ) 	{		if ( keydown[K_CTRL] )		{			Cbuf_AddText ("clear\n");			return;		}	} 	if ( key == K_ENTER || key == K_KP_ENTER )	{	// backslash text are commands, else chat		if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/')			Cbuf_AddText (key_lines[edit_line]+2);	// skip the >		else			Cbuf_AddText (key_lines[edit_line]+1);	// valid command 		Cbuf_AddText ("\n");		Com_Printf ("%s\n",key_lines[edit_line]);		edit_line = (edit_line + 1) & 31;		history_line = edit_line;		key_lines[edit_line][0] = ']';		key_linepos = 1;		if (cls.state == ca_disconnected)			SCR_UpdateScreen ();	// force an update, because the command									// may take some time		return;	} 	if (key == K_TAB)	{	// command completion		CompleteCommand ();		return;	}		if ( ( key == K_BACKSPACE ) || ( key == K_LEFTARROW ) || ( key == K_KP_LEFTARROW ) || ( ( key == 'h' ) && ( keydown[K_CTRL] ) ) )	{		if (key_linepos > 1)			key_linepos--;		return;	} 	if ( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ||		 ( ( key == 'p' ) && keydown[K_CTRL] ) )	{		do		{			history_line = (history_line - 1) & 31;		} while (history_line != edit_line				&& !key_lines[history_line][1]);		if (history_line == edit_line)			history_line = (edit_line+1)&31;		strcpy(key_lines[edit_line], key_lines[history_line]);		key_linepos = strlen(key_lines[edit_line]);		return;	} 	if ( ( key == K_DOWNARROW ) || ( key == K_KP_DOWNARROW ) ||		 ( ( key == 'n' ) && keydown[K_CTRL] ) )	{		if (history_line == edit_line) return;		do		{			history_line = (history_line + 1) & 31;		}		while (history_line != edit_line			&& !key_lines[history_line][1]);		if (history_line == edit_line)		{			key_lines[edit_line][0] = ']';			key_linepos = 1;		}		else		{			strcpy(key_lines[edit_line], key_lines[history_line]);			key_linepos = strlen(key_lines[edit_line]);		}		return;	} 	if (key == K_PGUP || key == K_KP_PGUP )	{		con.display -= 2;		return;	} 	if (key == K_PGDN || key == K_KP_PGDN ) 	{		con.display += 2;		if (con.display > con.current)			con.display = con.current;		return;	} 	if (key == K_HOME || key == K_KP_HOME )	{		con.display = con.current - con.totallines + 10;		return;	} 	if (key == K_END || key == K_KP_END )	{		con.display = con.current;		return;	}		if (key < 32 || key > 127)		return;	// non printable			if (key_linepos < MAXCMDLINE-1)	{		key_lines[edit_line][key_linepos] = key;		key_linepos++;		key_lines[edit_line][key_linepos] = 0;	} } //============================================================================ qboolean	chat_team;char		chat_buffer[MAXCMDLINE];int			chat_bufferlen = 0; void Key_Message (int key){ 	if ( key == K_ENTER || key == K_KP_ENTER )	{		if (chat_team)			Cbuf_AddText ("say_team \"");		else			Cbuf_AddText ("say \"");		Cbuf_AddText(chat_buffer);		Cbuf_AddText("\"\n"); 		cls.key_dest = key_game;		chat_bufferlen = 0;		chat_buffer[0] = 0;		return;	} 	if (key == K_ESCAPE)	{		cls.key_dest = key_game;		chat_bufferlen = 0;		chat_buffer[0] = 0;		return;	} 	if (key < 32 || key > 127)		return;	// non printable 	if (key == K_BACKSPACE)	{		if (chat_bufferlen)		{			chat_bufferlen--;			chat_buffer[chat_bufferlen] = 0;		}		return;	} 	if (chat_bufferlen == sizeof(chat_buffer)-1)		return; // all full 	chat_buffer[chat_bufferlen++] = key;	chat_buffer[chat_bufferlen] = 0;} //============================================================================  /*===================Key_StringToKeynum Returns a key number to be used to index keybindings[] by looking atthe given string.  Single ascii characters return themselves, whilethe K_* names are matched up.===================*/int Key_StringToKeynum (char *str){	keyname_t	*kn;		if (!str || !str[0])		return -1;	if (!str[1])		return str[0]; 	for (kn=keynames ; kn->name ; kn++)	{		if (!cistrcmp(str,kn->name))			return kn->keynum;	}	return -1;} /*===================Key_KeynumToString Returns a string (either a single ascii char, or a K_* name) for thegiven keynum.FIXME: handle quote special (general escape sequence?)===================*/char *Key_KeynumToString (int keynum){	keyname_t	*kn;		static	char	tinystr[2];		if (keynum == -1)		return "<KEY NOT FOUND>";	if (keynum > 32 && keynum < 127)	{	// printable ascii		tinystr[0] = keynum;		tinystr[1] = 0;		return tinystr;	}		for (kn=keynames ; kn->name ; kn++)		if (keynum == kn->keynum)			return kn->name; 	return "<UNKNOWN KEYNUM>";}  /*===================Key_SetBinding===================*/void Key_SetBinding (int keynum, char *binding){	char	*new;	int		l;				if (keynum == -1)		return; // free old bindings	if (keybindings[keynum])	{		Z_Free (keybindings[keynum]);		keybindings[keynum] = NULL;	}

Lines 1–500 of 904.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t