Fix completion bug - case insensitive competions of command names sometimes got the path prepended to them

darcs-hash:20071028090605-75c98-b623c6bf3f5a5144cdecaf0c005d4acb980e33f1.gz
This commit is contained in:
liljencrantz 2007-10-28 19:06:05 +10:00
parent 5082054bcb
commit baa6a40d6f
3 changed files with 41 additions and 22 deletions

View file

@ -180,9 +180,9 @@ static void complete_free_entry( complete_entry_t *c );
*/ */
void completion_allocate( array_list_t *context, void completion_allocate( array_list_t *context,
const wchar_t *comp, const wchar_t *comp,
const wchar_t *desc, const wchar_t *desc,
int flags ) int flags )
{ {
completion_t *res = halloc( context, sizeof( completion_t) ); completion_t *res = halloc( context, sizeof( completion_t) );
res->completion = halloc_wcsdup( context, comp ); 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 \param comp the list to add all completions to
*/ */
static void complete_cmd( const wchar_t *cmd, static void complete_cmd( const wchar_t *cmd,
array_list_t *comp, array_list_t *comp,
int use_function, int use_function,
int use_builtin, int use_builtin,
int use_command ) int use_command )
{ {
wchar_t *path; wchar_t *path;
wchar_t *path_cpy; wchar_t *path_cpy;
@ -1109,23 +1109,43 @@ static void complete_cmd( const wchar_t *cmd,
path_cpy = wcsdup( path ); path_cpy = wcsdup( path );
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state ); for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
nxt_path != 0; nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) ) 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_completion = wcsdupcat( nxt_path,
(nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"), add_slash?L"/":L"",
cmd ); cmd );
if( ! nxt_completion ) if( ! nxt_completion )
continue; continue;
prev_count = al_get_count( comp );
if( expand_string( 0, if( expand_string( 0,
nxt_completion, nxt_completion,
comp, comp,
ACCEPT_INCOMPLETE | ACCEPT_INCOMPLETE |
EXECUTABLES_ONLY ) != EXPAND_ERROR ) EXECUTABLES_ONLY ) != EXPAND_ERROR )
{ {
for( i=prev_count; i<al_get_count( comp ); i++ )
{
completion_t *c = (completion_t *)al_get( comp, i );
if(c->flags & COMPLETE_NO_CASE )
{
c->completion = halloc_wcsdup( comp, c->completion + path_len + add_slash );
}
}
} }
} }
free( path_cpy ); free( path_cpy );
complete_cmd_desc( cmd, comp ); complete_cmd_desc( cmd, comp );

View file

@ -247,9 +247,9 @@ void complete_load( const wchar_t *cmd, int reload );
\param flags completion flags \param flags completion flags
*/ */
void completion_allocate( array_list_t *context, void completion_allocate( array_list_t *context,
const wchar_t *comp, const wchar_t *comp,
const wchar_t *desc, const wchar_t *desc,
int flags ); int flags );
#endif #endif

View file

@ -1144,8 +1144,7 @@ int wildcard_expand( const wchar_t *wc,
int c = al_get_count( out ); int c = al_get_count( out );
int res = wildcard_expand_internal( wc, base_dir, flags, out ); int res = wildcard_expand_internal( wc, base_dir, flags, out );
int i; int i;
if( flags & ACCEPT_INCOMPLETE ) if( flags & ACCEPT_INCOMPLETE )
{ {
wchar_t *wc_base=L""; wchar_t *wc_base=L"";