mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Add support for checking the existance of specific variable array elements
darcs-hash:20070130204344-ac50b-d006de7693722677d052f7559923753acd27a4a2.gz
This commit is contained in:
parent
dcad2ef17b
commit
55af8e4966
1 changed files with 47 additions and 2 deletions
|
@ -621,10 +621,55 @@ static int builtin_set( wchar_t **argv )
|
|||
int i;
|
||||
for( i=woptind; i<argc; i++ )
|
||||
{
|
||||
if( !env_exist( argv[i], scope ) )
|
||||
wchar_t *arg = argv[i];
|
||||
int slice=0;
|
||||
|
||||
if( !(dest = wcsdup(arg)))
|
||||
{
|
||||
retcode++;
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
if( wcschr( dest, L'[' ) )
|
||||
{
|
||||
slice = 1;
|
||||
*wcschr( dest, L'[' )=0;
|
||||
}
|
||||
|
||||
if( slice )
|
||||
{
|
||||
array_list_t indexes;
|
||||
array_list_t result;
|
||||
int j;
|
||||
|
||||
al_init( &result );
|
||||
al_init( &indexes );
|
||||
|
||||
tokenize_variable_array( env_get( dest ), &result );
|
||||
|
||||
if( !parse_index( &indexes, arg, dest, al_get_count( &result ) ) )
|
||||
{
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode = 1;
|
||||
break;
|
||||
}
|
||||
for( j=0; j<al_get_count( &indexes ); j++ )
|
||||
{
|
||||
long idx = al_get_long( &indexes, j );
|
||||
if( idx < 1 || idx > al_get_count( &result ) )
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !env_exist( arg, scope ) )
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
}
|
||||
|
||||
free( dest );
|
||||
|
||||
}
|
||||
return retcode;
|
||||
|
|
Loading…
Reference in a new issue