Make it possible to specify the -u switch tom complete without actually specifying any new completions, since it affects all previous completions

darcs-hash:20070128032416-ac50b-93b943d712ac072f1bdb7f568e8064f73ffb85e0.gz
This commit is contained in:
axel 2007-01-28 13:24:16 +10:00
parent fcbdb6f2a7
commit fc87b3c4b4
2 changed files with 100 additions and 53 deletions

View file

@ -128,35 +128,73 @@ static void builtin_complete_add( array_list_t *cmd,
const wchar_t *desc )
{
int i;
int has_content =( wcslen( short_opt ) ||
al_get_count( gnu_opt ) ||
al_get_count( old_opt ) ||
comp );
for( i=0; i<al_get_count( cmd ); i++ )
{
builtin_complete_add2( al_get( cmd, i ),
COMMAND,
short_opt,
gnu_opt,
old_opt,
result_mode,
authorative,
condition,
comp,
desc );
if( has_content )
{
builtin_complete_add2( al_get( cmd, i ),
COMMAND,
short_opt,
gnu_opt,
old_opt,
result_mode,
authorative,
condition,
comp,
desc );
}
else
{
complete_add( al_get( cmd, i ),
COMMAND,
0,
0,
0,
0,
authorative,
0,
0,
0 );
}
}
for( i=0; i<al_get_count( path ); i++ )
{
builtin_complete_add2( al_get( path, i ),
PATH,
short_opt,
gnu_opt,
old_opt,
result_mode,
authorative,
condition,
comp,
desc );
}
if( has_content )
{
builtin_complete_add2( al_get( path, i ),
PATH,
short_opt,
gnu_opt,
old_opt,
result_mode,
authorative,
condition,
comp,
desc );
}
else
{
complete_add( al_get( cmd, i ),
PATH,
0,
0,
0,
0,
authorative,
0,
0,
0 );
}
}
}
/**

View file

@ -346,8 +346,10 @@ static int condition_test( const wchar_t *condition )
*/
static void complete_free_opt_recursive( complete_entry_opt_t *o )
{
if( o->next != 0 )
complete_free_opt_recursive( o->next );
if( !o )
return;
complete_free_opt_recursive( o->next );
halloc_free( o );
}
@ -425,41 +427,48 @@ void complete_add( const wchar_t *cmd,
c->short_opt_str = wcsdup(L"");
}
opt = halloc( 0, sizeof( complete_entry_opt_t ) );
opt->next = c->first_option;
c->first_option = opt;
c->authorative = authorative;
if( short_opt != L'\0' )
if( short_opt != L'\0' || long_opt )
{
int len = 1 + ((result_mode & NO_COMMON) != 0);
c->short_opt_str =
realloc( c->short_opt_str,
sizeof(wchar_t)*(wcslen( c->short_opt_str ) + 1 + len) );
wcsncat( c->short_opt_str,
&short_opt, 1 );
if( len == 2 )
opt = halloc( 0, sizeof( complete_entry_opt_t ) );
opt->next = c->first_option;
c->first_option = opt;
if( short_opt != L'\0' )
{
wcscat( c->short_opt_str, L":" );
int len = 1 + ((result_mode & NO_COMMON) != 0);
c->short_opt_str =
realloc( c->short_opt_str,
sizeof(wchar_t)*(wcslen( c->short_opt_str ) + 1 + len) );
wcsncat( c->short_opt_str,
&short_opt, 1 );
if( len == 2 )
{
wcscat( c->short_opt_str, L":" );
}
}
opt->short_opt = short_opt;
opt->result_mode = result_mode;
opt->old_mode=old_mode;
opt->comp = comp?halloc_wcsdup(opt, comp):L"";
opt->condition = condition?halloc_wcsdup(opt, condition):L"";
opt->long_opt = long_opt?halloc_wcsdup(opt, long_opt):L"" ;
if( desc && wcslen( desc ) )
{
opt->desc = halloc_wcsdup( opt, desc );
}
else
{
opt->desc = L"";
}
}
opt->short_opt = short_opt;
opt->result_mode = result_mode;
opt->old_mode=old_mode;
opt->comp = comp?halloc_wcsdup(opt, comp):L"";
opt->condition = condition?halloc_wcsdup(opt, condition):L"";
opt->long_opt = long_opt?halloc_wcsdup(opt, long_opt):L"" ;
if( desc && wcslen( desc ) )
{
opt->desc = halloc_wcsdup( opt, desc );
}
else
{
opt->desc = L"";
}
}
/**