From 44477db354f67c4eacfced89fac5fbf3dbeaa3ff Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 8 Dec 2018 20:25:14 +0000 Subject: lineedit: more case-insensitive comparisons in tab completion --- libbb/bb_qsort.c | 12 ++++++++++++ libbb/lineedit.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'libbb') diff --git a/libbb/bb_qsort.c b/libbb/bb_qsort.c index 505045533..7afddf468 100644 --- a/libbb/bb_qsort.c +++ b/libbb/bb_qsort.c @@ -17,3 +17,15 @@ void FAST_FUNC qsort_string_vector(char **sv, unsigned count) { qsort(sv, count, sizeof(char*), bb_pstrcmp); } + +#if ENABLE_PLATFORM_MINGW32 +static int bb_pstrcasecmp(const void *a, const void *b) +{ + return strcasecmp(*(char**)a, *(char**)b); +} + +void FAST_FUNC qsort_string_vector_case(char **sv, unsigned count) +{ + qsort(sv, count, sizeof(char*), bb_pstrcasecmp); +} +#endif diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 979e0d544..89178bbc3 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -684,6 +684,9 @@ static void input_forward(void) # if ENABLE_PLATFORM_MINGW32 /* use case-insensitive comparisons for filenames */ # define is_prefixed_with(s, k) is_prefixed_with_case(s, k) +# define qsort_string_vector(s, c) qsort_string_vector_case(s, c) +# define strcmp(s, t) strcasecmp(s, t) +# define strncmp(s, t, n) strncasecmp(s, t, n) # endif static void free_tab_completion_data(void) @@ -1278,7 +1281,11 @@ static NOINLINE void input_tab(smallint *lastWasTab) for (cp = chosen_match; *cp; cp++) { unsigned n; for (n = 1; n < num_matches; n++) { +# if !ENABLE_PLATFORM_MINGW32 if (matches[n][cp - chosen_match] != *cp) { +# else + if (tolower(matches[n][cp - chosen_match]) != tolower(*cp)) { +# endif goto stop; } } @@ -1351,6 +1358,13 @@ static NOINLINE void input_tab(smallint *lastWasTab) free(match_buf); } +# if ENABLE_PLATFORM_MINGW32 +# undef is_prefixed_with +# undef qsort_string_vector +# undef strcmp +# undef strncmp +# endif + #endif /* FEATURE_TAB_COMPLETION */ -- cgit v1.2.3-55-g6feb