aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ask.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/ask.c b/ask.c
index 0adfd64..22d329f 100644
--- a/ask.c
+++ b/ask.c
@@ -297,9 +297,12 @@ static char *get_input(FILE *in, FILE *out, const char *prompt, const char *init
return picked;
}
-static int cmp_len(const void *a, const void *b)
+static int cmp_len(const void *v1, const void *v2)
{
- return (int)(strlen(*(char**)a) - strlen(*(char**)b));
+ char *s1 = *(char**)v1, *s2 = *(char**)v2;
+ size_t len1 = strlen(s1), len2 = strlen(s2);
+ if (len1 != len2) return (int)(len1 - len2);
+ return strcmp(s1, s2);
}
int main(int argc, char *argv[])
@@ -404,8 +407,8 @@ int main(int argc, char *argv[])
if (tcsetattr(fileno(tty_out), TCSAFLUSH, &bb_termios) == -1)
return 1;
- // Prefer shorter matches, but otherwise keep original order (mergesort is stable)
- mergesort(opts, (size_t)nopts, sizeof(char*), cmp_len);
+ // Prefer shorter matches, but otherwise use alphabetic order
+ qsort(opts, (size_t)nopts, sizeof(char*), cmp_len);
char *output = get_input(tty_in, tty_out, prompt, query, nopts, opts);
fflush(tty_out);