Make sure that command specific completions can handle input strings with wildcards reasonably well

darcs-hash:20060219011432-ac50b-89a73a3d414f2dbd8a213b851fcb1c494e022eae.gz
This commit is contained in:
axel 2006-02-19 11:14:32 +10:00
parent 0840c9248f
commit 43ab84397b
7 changed files with 56 additions and 10 deletions

View file

@ -2968,8 +2968,10 @@ static int builtin_case( wchar_t **argv )
for( i=1; i<argc; i++ )
{
free( unescaped );
unescaped = unescape( argv[i], 1);
unescaped = parse_util_unescape_wildcards( argv[i] );
if( wildcard_match( current_block->param1.switch_value, unescaped ) )
{
current_block->skip = 0;

View file

@ -527,8 +527,6 @@ int wcsvarname( wchar_t *str )
str++;
}
return 1;
}

View file

@ -1001,17 +1001,21 @@ static void copy_strings_with_prefix( array_list_t *comp_out,
array_list_t *possible_comp )
{
int i;
wchar_t *wc;
wchar_t *wc, *tmp;
wc = expand_one( 0,
tmp = expand_one( 0,
wcsdup(wc_escaped), EXPAND_SKIP_SUBSHELL | EXPAND_SKIP_WILDCARDS);
if(!wc)
if(!tmp)
return;
if( wc[0] == L'~' )
if( tmp[0] == L'~' )
{
wc=expand_tilde(wc);
tmp=expand_tilde(wc);
}
wc = parse_util_unescape_wildcards( tmp );
free(tmp);
// int str_len = wcslen( str );
for( i=0; i<al_get_count( possible_comp ); i++ )

2
main.c
View file

@ -205,7 +205,7 @@ int main( int argc, char **argv )
my_optind = optind;
is_login |= strcmp( argv[0], "-fish") == 0;
is_login |= (strcmp( argv[0], "-fish") == 0);
is_interactive_session &= (cmd == 0);
is_interactive_session &= (my_optind == argc);

View file

@ -25,6 +25,7 @@
#include "intern.h"
#include "exec.h"
#include "env.h"
#include "wildcard.h"
#include "halloc_util.h"
/**
@ -641,4 +642,41 @@ void parse_util_set_argv( wchar_t **argv )
}
}
wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
{
wchar_t *in, *out;
wchar_t *unescaped = wcsdup(str);
if( !unescaped )
die_mem();
for( in=out=unescaped; *in; in++ )
{
switch( *in )
{
case L'\\':
if( *(in+1) )
{
in++;
*(out++)=*in;
}
*(out++)=*in;
break;
case L'*':
*(out++)=ANY_STRING;
break;
case L'?':
*(out++)=ANY_CHAR;
break;
default:
*(out++)=*in;
break;
}
}
return unescaped;
}

View file

@ -87,4 +87,9 @@ void parse_util_load_reset( const wchar_t *path_var );
*/
void parse_util_set_argv( wchar_t **argv );
/**
Make duplicate string, unescape wildcard characters but n ot performing any other character transformation
*/
wchar_t *parse_util_unescape_wildcards( const wchar_t *in );
#endif

View file

@ -72,7 +72,6 @@ int wildcard_has( const wchar_t *str, int internal )
\param str String to be matched.
\param wc The wildcard.
\param is_first Whether files beginning with dots should not be matched against wildcards.
\param wc_unescaped Whether the unescaped special character ANY_CHAR abd ANY_STRING should be used instead of '?' and '*' for wildcard matching
*/