From 195902a645b794092959ac3818f367104c7ffeb8 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 8 Dec 2018 15:45:44 +0000 Subject: lineedit: improvements to tab completion Since getpwent isn't implemented for WIN32 there's no point in enabling FEATURE_USERNAME_COMPLETION. Use case-insensitive comparisons when matching filenames. The code to exclude non-executables when tab completing executables is WIN32-specific and shouldn't omit directories. --- libbb/compare_string_array.c | 13 +++++++++++++ libbb/lineedit.c | 19 +++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'libbb') diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c index 01a9df0e2..7ccdaef8a 100644 --- a/libbb/compare_string_array.c +++ b/libbb/compare_string_array.c @@ -27,6 +27,19 @@ char* FAST_FUNC is_prefixed_with(const char *string, const char *key) #endif } +#if ENABLE_PLATFORM_MINGW32 +char* FAST_FUNC is_prefixed_with_case(const char *string, const char *key) +{ + while (*key != '\0') { + if (tolower(*key) != tolower(*string)) + return NULL; + key++; + string++; + } + return (char*)string; +} +#endif + /* * Return NULL if string is not suffixed with key. Return pointer to the * beginning of prefix key in string. If key is an empty string return pointer diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 19b579782..979e0d544 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -681,6 +681,11 @@ static void input_forward(void) //Also, perhaps "foo b needs to complete to "foo bar" , //not "foo bar ... +# if ENABLE_PLATFORM_MINGW32 +/* use case-insensitive comparisons for filenames */ +# define is_prefixed_with(s, k) is_prefixed_with_case(s, k) +# endif + static void free_tab_completion_data(void) { if (matches) { @@ -897,8 +902,11 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) if (stat(found, &st) && lstat(found, &st)) goto cont; /* hmm, remove in progress? */ - if (type == FIND_EXE_ONLY && !file_is_executable(found)) +# if ENABLE_PLATFORM_MINGW32 + if (type == FIND_EXE_ONLY && !S_ISDIR(st.st_mode) && + !file_is_executable(found)) goto cont; +# endif /* Save only name */ len = strlen(name_found); @@ -2005,16 +2013,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) char *after_home_user; /* /home/user[/something] -> ~[/something] */ -#if !ENABLE_PLATFORM_MINGW32 after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf); -#else - after_home_user = NULL; - l = strlen(home_pwd_buf); - if (l != 0 - && strncasecmp(home_pwd_buf, cwd_buf, l) == 0) { - after_home_user = cwd_buf + l; - } -#endif if (after_home_user && (*after_home_user == '/' || *after_home_user == '\0') ) { -- cgit v1.2.3-55-g6feb