From: Hani Benhabiles Date: Thu, 1 May 2014 14:26:42 +0000 (+0100) Subject: readline: Sort completions before printing them. X-Git-Tag: qemu-xen-4.6.0-rc1~469^2~2 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=307b2f01488ae0fab18a8f0538e7c750842e74dd;p=qemu-xen.git readline: Sort completions before printing them. Signed-off-by: Hani Benhabiles Signed-off-by: Michael Tokarev --- diff --git a/util/readline.c b/util/readline.c index a3fd2cb466..8baec55509 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; @@ -295,6 +300,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;