aboutsummaryrefslogtreecommitdiffstats
path: root/code/qcommon/cmd.c
diff options
context:
space:
mode:
authortma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2008-09-16 21:05:22 +0000
committertma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2008-09-16 21:05:22 +0000
commit660be5cc7d3989740b4e6fbd8ed8b1d9c46ebd20 (patch)
treec609227c4de7d3ea10310714c3262d58665b3ffa /code/qcommon/cmd.c
parent134e4522a3a9eb3f3e2f8e3646eb3d3999d49694 (diff)
downloadioquake3-aero-660be5cc7d3989740b4e6fbd8ed8b1d9c46ebd20.tar.gz
ioquake3-aero-660be5cc7d3989740b4e6fbd8ed8b1d9c46ebd20.zip
* Move command argument completion from being hard coded to being associated
with the individual commands to be completed git-svn-id: svn://svn.icculus.org/quake3/trunk@1472 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/qcommon/cmd.c')
-rw-r--r--code/qcommon/cmd.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/code/qcommon/cmd.c b/code/qcommon/cmd.c
index 8ce1526..1f05452 100644
--- a/code/qcommon/cmd.c
+++ b/code/qcommon/cmd.c
@@ -313,6 +313,7 @@ typedef struct cmd_function_s
struct cmd_function_s *next;
char *name;
xcommand_t function;
+ completionFunc_t complete;
} cmd_function_t;
@@ -584,12 +585,28 @@ void Cmd_AddCommand( const char *cmd_name, xcommand_t function ) {
cmd = S_Malloc (sizeof(cmd_function_t));
cmd->name = CopyString( cmd_name );
cmd->function = function;
+ cmd->complete = NULL;
cmd->next = cmd_functions;
cmd_functions = cmd;
}
/*
============
+Cmd_SetCommandCompletionFunc
+============
+*/
+void Cmd_SetCommandCompletionFunc( const char *command, completionFunc_t complete ) {
+ cmd_function_t *cmd;
+
+ for( cmd = cmd_functions; cmd; cmd = cmd->next ) {
+ if( !Q_stricmp( command, cmd->name ) ) {
+ cmd->complete = complete;
+ }
+ }
+}
+
+/*
+============
Cmd_RemoveCommand
============
*/
@@ -629,6 +646,21 @@ void Cmd_CommandCompletion( void(*callback)(const char *s) ) {
}
}
+/*
+============
+Cmd_CompleteArgument
+============
+*/
+void Cmd_CompleteArgument( const char *command, char *args, int argNum ) {
+ cmd_function_t *cmd;
+
+ for( cmd = cmd_functions; cmd; cmd = cmd->next ) {
+ if( !Q_stricmp( command, cmd->name ) && cmd->complete ) {
+ cmd->complete( args, argNum );
+ }
+ }
+}
+
/*
============
@@ -720,6 +752,17 @@ void Cmd_List_f (void)
}
/*
+==================
+Cmd_CompleteCfgName
+==================
+*/
+void Cmd_CompleteCfgName( char *args, int argNum ) {
+ if( argNum == 2 ) {
+ Field_CompleteFilename( "", "cfg", qfalse );
+ }
+}
+
+/*
============
Cmd_Init
============
@@ -727,7 +770,9 @@ Cmd_Init
void Cmd_Init (void) {
Cmd_AddCommand ("cmdlist",Cmd_List_f);
Cmd_AddCommand ("exec",Cmd_Exec_f);
+ Cmd_SetCommandCompletionFunc( "exec", Cmd_CompleteCfgName );
Cmd_AddCommand ("vstr",Cmd_Vstr_f);
+ Cmd_SetCommandCompletionFunc( "vstr", Cvar_CompleteCvarName );
Cmd_AddCommand ("echo",Cmd_Echo_f);
Cmd_AddCommand ("wait", Cmd_Wait_f);
}