From 364c96f45c5420c84162abf00cd1960b8aeaddf4 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 9 Jul 2019 15:10:32 +0300 Subject: [PATCH] engine: console: sort output in commmand autocomplete for bind --- engine/common/con_utils.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index e5d931ea..cf29aae8 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -598,6 +598,16 @@ static void Con_AddCommandToList( const char *s, const char *unused1, const char list->cmds[list->matchCount++] = copystring( s ); } +/* +================= +Con_SortCmds +================= +*/ +static int Con_SortCmds( const void *arg1, const void *arg2 ) +{ + return Q_stricmp( *(const char **)arg1, *(const char **)arg2 ); +} + /* ===================================== Cmd_GetCommandsList @@ -632,6 +642,8 @@ qboolean Cmd_GetCommandsList( const char *s, char *completedname, int length ) Q_strncpy( completedname, matchbuf, length ); if( list.matchCount == 1 ) return true; + qsort( list.cmds, list.matchCount, sizeof( char* ), Con_SortCmds ); + for( i = 0; i < list.matchCount; i++ ) { Q_strncpy( matchbuf, list.cmds[i], sizeof( matchbuf )); @@ -1026,16 +1038,6 @@ qboolean Cmd_AutocompleteName( const char *source, int arg, char *buffer, size_t return false; } -/* -================= -Con_SortCmds -================= -*/ -static int Con_SortCmds( const void *arg1, const void *arg2 ) -{ - return Q_stricmp( *(const char **)arg1, *(const char **)arg2 ); -} - /* =============== Con_PrintCmdMatches