From baa6a40d6f7502787a0af8fe57a69659ea6ceac4 Mon Sep 17 00:00:00 2001 From: liljencrantz Date: Sun, 28 Oct 2007 19:06:05 +1000 Subject: [PATCH] Fix completion bug - case insensitive competions of command names sometimes got the path prepended to them darcs-hash:20071028090605-75c98-b623c6bf3f5a5144cdecaf0c005d4acb980e33f1.gz --- complete.c | 54 +++++++++++++++++++++++++++++++++++++----------------- complete.h | 6 +++--- wildcard.c | 3 +-- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/complete.c b/complete.c index 91331149d..f69987645 100644 --- a/complete.c +++ b/complete.c @@ -180,9 +180,9 @@ static void complete_free_entry( complete_entry_t *c ); */ void completion_allocate( array_list_t *context, - const wchar_t *comp, - const wchar_t *desc, - int flags ) + const wchar_t *comp, + const wchar_t *desc, + int flags ) { completion_t *res = halloc( context, sizeof( completion_t) ); res->completion = halloc_wcsdup( context, comp ); @@ -1067,10 +1067,10 @@ static const wchar_t *complete_function_desc( const wchar_t *fn ) \param comp the list to add all completions to */ static void complete_cmd( const wchar_t *cmd, - array_list_t *comp, - int use_function, - int use_builtin, - int use_command ) + array_list_t *comp, + int use_function, + int use_builtin, + int use_command ) { wchar_t *path; wchar_t *path_cpy; @@ -1109,23 +1109,43 @@ static void complete_cmd( const wchar_t *cmd, path_cpy = wcsdup( path ); for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state ); - nxt_path != 0; - nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) ) + nxt_path != 0; + nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) ) { + int prev_count; + int i; + int path_len = wcslen(nxt_path); + int add_slash; + + if( !path_len ) + { + continue; + } + + add_slash = nxt_path[path_len-1]!=L'/'; nxt_completion = wcsdupcat( nxt_path, - (nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"), - cmd ); + add_slash?L"/":L"", + cmd ); if( ! nxt_completion ) continue; - + + prev_count = al_get_count( comp ); + if( expand_string( 0, - nxt_completion, - comp, - ACCEPT_INCOMPLETE | - EXECUTABLES_ONLY ) != EXPAND_ERROR ) + nxt_completion, + comp, + ACCEPT_INCOMPLETE | + EXECUTABLES_ONLY ) != EXPAND_ERROR ) { + for( i=prev_count; iflags & COMPLETE_NO_CASE ) + { + c->completion = halloc_wcsdup( comp, c->completion + path_len + add_slash ); + } + } } - } free( path_cpy ); complete_cmd_desc( cmd, comp ); diff --git a/complete.h b/complete.h index 6c3bd9315..128db4685 100644 --- a/complete.h +++ b/complete.h @@ -247,9 +247,9 @@ void complete_load( const wchar_t *cmd, int reload ); \param flags completion flags */ void completion_allocate( array_list_t *context, - const wchar_t *comp, - const wchar_t *desc, - int flags ); + const wchar_t *comp, + const wchar_t *desc, + int flags ); #endif diff --git a/wildcard.c b/wildcard.c index a2cf09b04..9456b85f7 100644 --- a/wildcard.c +++ b/wildcard.c @@ -1144,8 +1144,7 @@ int wildcard_expand( const wchar_t *wc, int c = al_get_count( out ); int res = wildcard_expand_internal( wc, base_dir, flags, out ); int i; - - + if( flags & ACCEPT_INCOMPLETE ) { wchar_t *wc_base=L"";