From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wfrww-0007TB-Vd for qemu-devel@nongnu.org; Thu, 01 May 2014 10:27:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wfrwq-0001NO-Lp for qemu-devel@nongnu.org; Thu, 01 May 2014 10:26:58 -0400 From: Hani Benhabiles Date: Thu, 1 May 2014 15:26:42 +0100 Message-Id: <1398954402-17826-1-git-send-email-kroosec@gmail.com> Subject: [Qemu-devel] [PATCH] readline: Sort completions before printing them. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-trivial@nongnu.org, lcapitulino@redhat.com, stefanha@redhat.com, xiawenc@linux.vnet.ibm.com Signed-off-by: Hani Benhabiles --- util/readline.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/readline.c b/util/readline.c index 8441be4..8d2a0d3 100644 --- a/util/readline.c +++ b/util/readline.c @@ -272,6 +272,11 @@ void readline_set_completion_index(ReadLineState *rs, int index) rs->completion_index = index; } +static int completion_comp(const void *a, const void *b) +{ + return strcmp(*(const char **) a, *(const char **) b); +} + static void readline_completion(ReadLineState *rs) { int len, i, j, max_width, nb_cols, max_prefix; @@ -297,6 +302,8 @@ static void readline_completion(ReadLineState *rs) if (len > 0 && rs->completions[0][len - 1] != '/') readline_insert_char(rs, ' '); } else { + qsort(rs->completions, rs->nb_completions, sizeof(char *), + completion_comp); rs->printf_func(rs->opaque, "\n"); max_width = 0; max_prefix = 0; -- 1.8.3.2