/* =============== Field_CompleteCommand =============== */ void Field_CompleteCommand( char *cmd, qboolean doCommands, qboolean doCvars ) { int completionArgument = 0; // Skip leading whitespace and quotes cmd = Com_SkipCharset( cmd, " \"" ); Cmd_TokenizeStringIgnoreQuotes( cmd ); completionArgument = Cmd_Argc(); // If there is trailing whitespace on the cmd if ( *(cmd + strlen( cmd )-1) == ' ' ) { completionString = ""; completionArgument++; } else completionString = Cmd_Argv( completionArgument - 1 ); if ( completionArgument > 1 ) { const char *baseCmd = Cmd_Argv( 0 ); char *p; if ( baseCmd[0] == '\\' || baseCmd[0] == '/' ) baseCmd++; if( ( p = Field_FindFirstSeparator( cmd ) ) ) Field_CompleteCommand( p + 1, qtrue, qtrue ); // Compound command else Cmd_CompleteArgument( baseCmd, cmd, completionArgument ); } else { if ( completionString[0] == '\\' || completionString[0] == '/' ) completionString++; matchCount = 0; shortestMatch[ 0 ] = 0; if ( strlen( completionString ) == 0 ) return; if ( doCommands ) Cmd_CommandCompletion( FindMatches ); if ( doCvars ) Cvar_CommandCompletion( FindMatches ); if ( !Field_Complete() ) { // run through again, printing matches if ( doCommands ) Cmd_CommandCompletion( PrintMatches ); if ( doCvars ) Cvar_CommandCompletion( PrintCvarMatches ); } } }
/** * \brief Complete console command or cvar. */ PRIVATE void CompleteCommand( void ) { char *cmd, *s; s = key_lines[edit_line]+1; if( *s == '\\' || *s == '/' ) { s++; } completionString = s; Cmd_CommandCompletion( FindMatches ); cmd = shortestMatch; if( ! cmd ) { // TODO: For now Cvar_CommandCompletion( FindMatches ); cmd = shortestMatch; } if( cmd ) { key_lines[ edit_line ][ 1 ] = '/'; com_strlcpy( key_lines[ edit_line ] + 2, cmd, sizeof( key_lines[ edit_line ] ) - 2 ); key_linepos = strlen( cmd ) + 2; key_lines[ edit_line ][ key_linepos ] = ' '; key_linepos++; key_lines[ edit_line ][ key_linepos ] = 0; return; } }
static void Win_CompleteCommand(qboolean showMatches) { field_t *edit; field_t temp; edit = &win_consoleField; if(win_acLength == 0) { // only look at the first token for completion purposes Cmd_TokenizeString(edit->buffer); Q_strncpyz(win_completionString, Cmd_Argv(0), sizeof(win_completionString)); if(win_completionString[0] == '\\' || win_completionString[0] == '/') { Q_strncpyz(win_completionString, win_completionString + 1, sizeof(win_completionString)); } win_matchCount = 0; win_matchIndex = 0; win_currentMatch[0] = 0; if(strlen(win_completionString) == 0) { return; } Cmd_CommandCompletion(Win_FindMatches); Cvar_CommandCompletion(Win_FindMatches); if(win_matchCount == 0) { return; // no matches } Com_Memcpy(&temp, edit, sizeof(field_t)); if(win_matchCount == 1) { Com_sprintf(edit->buffer, sizeof(edit->buffer), "%s", win_currentMatch); if(Cmd_Argc() == 1) { Q_strcat(win_consoleField.buffer, sizeof(win_consoleField.buffer), " "); } else { Win_ConcatRemaining(temp.buffer, win_completionString); } edit->cursor = strlen(edit->buffer); } else { // multiple matches, complete to shortest Com_sprintf(edit->buffer, sizeof(edit->buffer), "%s", win_currentMatch); win_acLength = edit->cursor = strlen(edit->buffer); Win_ConcatRemaining(temp.buffer, win_completionString); showMatches = qtrue; } } else if(win_matchCount != 1) { // get the next match and show instead char lastMatch[MAX_TOKEN_CHARS]; Q_strncpyz(lastMatch, win_currentMatch, sizeof(lastMatch)); win_matchIndex++; if(win_matchIndex == win_matchCount) { win_matchIndex = 0; } win_findMatchIndex = 0; Cmd_CommandCompletion(Win_FindIndexMatch); Cvar_CommandCompletion(Win_FindIndexMatch); Com_Memcpy(&temp, edit, sizeof(field_t)); // and print it Com_sprintf(edit->buffer, sizeof(edit->buffer), "%s", win_currentMatch); edit->cursor = strlen(edit->buffer); Win_ConcatRemaining(temp.buffer, lastMatch); } // hijack it if(win_matchCount == 1) { win_acLength = strlen(win_currentMatch); } // run through again, printing matches if(showMatches && win_matchCount > 0) { memcpy(&temp, edit, sizeof(*edit)); temp.buffer[win_acLength] = '\0'; Sys_Print(va("] %s\n", temp.buffer)); Cmd_CommandCompletion(Win_PrintMatches); Cvar_CommandCompletion(Win_PrintCvarMatches); } }