diff --git a/complete.c b/complete.c index 72b161d6c..8dfc124f7 100644 --- a/complete.c +++ b/complete.c @@ -245,7 +245,8 @@ void completion_allocate( array_list_t *context, { completion_t *res = halloc( context, sizeof( completion_t) ); res->completion = halloc_wcsdup( context, comp ); - res->description = halloc_wcsdup( context, desc ); + if( desc ) + res->description = halloc_wcsdup( context, desc ); res->flags = flags; al_push( context, res ); } @@ -1135,24 +1136,6 @@ const wchar_t *complete_get_desc( const wchar_t *filename ) return (wchar_t *)get_desc_buff->buff; } - -/** - Convert all string completions in src into completion_t structs in - dest. All source strings will be free'd. -*/ -static void completion_convert_list( array_list_t *src, array_list_t *dest ) -{ - int i; - - for( i=0; ifish can understand the contents of the /proc - filesystem, all the users processes are searched for matches. + Otherwise, any job matching the specified string is matched, and + the job pgid is returned. If no job matches, all child processes + are searched. If no child processes match, and fish can + understand the contents of the /proc filesystem, all the users + processes are searched for matches. */ static int find_process( const wchar_t *proc, @@ -372,14 +372,20 @@ static int find_process( const wchar_t *proc, if( wcsncmp( proc, jid, wcslen(proc ) )==0 ) { - al_push( out, - wcsdupcat2( jid+wcslen(proc), - COMPLETE_SEP_STR, - COMPLETE_JOB_DESC_VAL, - j->command, - (void *)0 ) ); - + string_buffer_t desc_buff; + + sb_init( &desc_buff ); + + sb_printf( &desc_buff, + COMPLETE_JOB_DESC_VAL, + j->command ); + + completion_allocate( out, + jid+wcslen(proc), + (wchar_t *)desc_buff.buff, + 0 ); + sb_destroy( &desc_buff ); } } @@ -422,11 +428,10 @@ static int find_process( const wchar_t *proc, { if( flags & ACCEPT_INCOMPLETE ) { - wchar_t *res = wcsdupcat2( j->command + offset + wcslen(proc), - COMPLETE_SEP_STR, - COMPLETE_JOB_DESC, - (void *)0 ); - al_push( out, res ); + completion_allocate( out, + j->command + offset + wcslen(proc), + COMPLETE_JOB_DESC, + 0 ); } else { @@ -459,11 +464,10 @@ static int find_process( const wchar_t *proc, { if( flags & ACCEPT_INCOMPLETE ) { - wchar_t *res = wcsdupcat2( p->actual_cmd + offset + wcslen(proc), - COMPLETE_SEP_STR, - COMPLETE_CHILD_PROCESS_DESC, - (void *)0); - al_push( out, res ); + completion_allocate( out, + p->actual_cmd + offset + wcslen(proc), + COMPLETE_CHILD_PROCESS_DESC, + 0 ); } else { @@ -575,13 +579,10 @@ static int find_process( const wchar_t *proc, { if( flags & ACCEPT_INCOMPLETE ) { - wchar_t *res = wcsdupcat2( cmd + offset + wcslen(proc), - COMPLETE_SEP_STR, - COMPLETE_PROCESS_DESC, - (void *)0); - if( res ) - al_push( out, res ); - + completion_allocate( out, + cmd + offset + wcslen(proc), + COMPLETE_PROCESS_DESC, + 0 ); } else { @@ -625,13 +626,17 @@ static int expand_pid( wchar_t *in, { if( wcsncmp( in+1, SELF_STR, wcslen(in+1) )==0 ) { - wchar_t *res = wcsdupcat2( SELF_STR+wcslen(in+1), COMPLETE_SEP_STR, COMPLETE_SELF_DESC, (void *)0 ); - al_push( out, res ); + completion_allocate( out, + SELF_STR+wcslen(in+1), + COMPLETE_SELF_DESC, + 0 ); } else if( wcsncmp( in+1, LAST_STR, wcslen(in+1) )==0 ) { - wchar_t *res = wcsdupcat2( LAST_STR+wcslen(in+1), COMPLETE_SEP_STR, COMPLETE_LAST_DESC, (void *)0 ); - al_push( out, res ); + completion_allocate( out, + LAST_STR+wcslen(in+1), + COMPLETE_LAST_DESC, + 0 ); } } else @@ -1519,36 +1524,6 @@ static void remove_internal_separator( const void *s, int conv ) *out=0; } -static void glorf( array_list_t *comp, int from ) -{ - int i; - for( i=from; i 0 ) && ( wcschr( L"/=@:", next[wcslen(next)-1] ) != 0 ) ) - flags |= COMPLETE_NO_SPACE; - - completion_allocate( comp, next, desc, flags ); - item = al_pop( comp ); - al_set( comp, i, item ); - free( next ); - } -} - - /** The real expansion function. expand_one is just a wrapper around this one. @@ -1566,8 +1541,6 @@ int expand_string( void *context, int res = EXPAND_OK; int start_count = al_get_count( end_out ); - int end_out_count = al_get_count( end_out ); - CHECK( str, EXPAND_ERROR ); CHECK( end_out, EXPAND_ERROR ); @@ -1712,7 +1685,9 @@ int expand_string( void *context, return EXPAND_OK; } else + { al_push( out, next ); + } } else { @@ -1745,57 +1720,75 @@ int expand_string( void *context, if( ((flags & ACCEPT_INCOMPLETE) && (!(flags & EXPAND_SKIP_WILDCARDS))) || wildcard_has( next, 1 ) ) { + wchar_t *start, *rest; + array_list_t *list = out; if( next[0] == '/' ) { - wc_res = wildcard_expand( &next[1], L"/",flags, out ); + start = L"/"; + rest = &next[1]; } else { - wc_res = wildcard_expand( next, L"", flags, out ); + start = L""; + rest = next; } - free( next ); - switch( wc_res ) + + if( flags & ACCEPT_INCOMPLETE ) { - case 0: + list = end_out; + } + + wc_res = wildcard_expand( rest, start, flags, list ); + + free( next ); + + if( !(flags & ACCEPT_INCOMPLETE) ) + { + + switch( wc_res ) { - if( !(flags & ACCEPT_INCOMPLETE) ) + case 0: { - if( res == EXPAND_OK ) - res = EXPAND_WILDCARD_NO_MATCH; + if( !(flags & ACCEPT_INCOMPLETE) ) + { + if( res == EXPAND_OK ) + res = EXPAND_WILDCARD_NO_MATCH; + break; + } + } + + case 1: + { + int j; + res = EXPAND_WILDCARD_MATCH; + sort_list( out ); + + for( j=0; j= 0 && S_ISDIR(buf.st_mode) ) { sb_append( sb, desc ); @@ -527,8 +518,11 @@ int wildcard_expand( const wchar_t *wc, get_desc( long_name, &sb_desc, flags & EXECUTABLES_ONLY ); - al_push( out, - wcsdupcat(name, (wchar_t *)sb_desc.buff) ); + completion_allocate( out, + name, + (wchar_t *)sb_desc.buff, + 0 ); + } free( long_name );