diff options
Diffstat (limited to 'src/qcommon/cmd.c')
-rw-r--r-- | src/qcommon/cmd.c | 76 |
1 files changed, 70 insertions, 6 deletions
diff --git a/src/qcommon/cmd.c b/src/qcommon/cmd.c index 97687467..e04f314c 100644 --- a/src/qcommon/cmd.c +++ b/src/qcommon/cmd.c @@ -240,7 +240,10 @@ Cmd_Exec_f =============== */ void Cmd_Exec_f( void ) { - char *f; + union { + char *c; + void *v; + } f; int len; char filename[MAX_QPATH]; @@ -250,17 +253,17 @@ void Cmd_Exec_f( void ) { } Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) ); - COM_DefaultExtension( filename, sizeof( filename ), ".cfg" ); - len = FS_ReadFile( filename, (void **)&f); - if (!f) { + COM_DefaultExtension( filename, sizeof( filename ), ".cfg" ); + len = FS_ReadFile( filename, &f.v); + if (!f.c) { Com_Printf ("couldn't exec %s\n",Cmd_Argv(1)); return; } Com_Printf ("execing %s\n",Cmd_Argv(1)); - Cbuf_InsertText (f); + Cbuf_InsertText (f.c); - FS_FreeFile (f); + FS_FreeFile (f.v); } @@ -314,6 +317,7 @@ typedef struct cmd_function_s struct cmd_function_s *next; char *name; xcommand_t function; + completionFunc_t complete; } cmd_function_t; @@ -468,6 +472,22 @@ char *Cmd_Cmd(void) } /* + Replace command separators with space to prevent interpretation + This is a hack to protect buggy qvms + https://bugzilla.icculus.org/show_bug.cgi?id=3593 +*/ +void Cmd_Args_Sanitize( void ) { + int i; + for ( i = 1 ; i < cmd.argc ; i++ ) { + char* c = cmd.argv[i]; + while ((c = strpbrk(c, "\n\r;"))) { + *c = ' '; + ++c; + } + } +} + +/* ============ Cmd_TokenizeString @@ -623,12 +643,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 ============ */ @@ -668,6 +704,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 ); + } + } +} + /* ============ @@ -759,6 +810,17 @@ void Cmd_List_f (void) } /* +================== +Cmd_CompleteCfgName +================== +*/ +void Cmd_CompleteCfgName( char *args, int argNum ) { + if( argNum == 2 ) { + Field_CompleteFilename( "", "cfg", qfalse ); + } +} + +/* ============ Cmd_Init ============ @@ -766,7 +828,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); } |