Merge remote-tracking branch 'fishfish/master'

This commit is contained in:
maxfl 2012-06-18 21:27:47 +04:00
commit 78387fb391
4 changed files with 189 additions and 21 deletions

View File

@ -498,7 +498,7 @@ static int builtin_set( parser_t &parser, wchar_t **argv )
also specify scope
*/
if( query && (erase || list || global || local || universal || exportv || unexport ) )
if( query && (erase || list) )
{
append_format(stderr_buffer,
BUILTIN_ERR_COMBO,

63
env.cpp
View File

@ -1147,36 +1147,46 @@ int env_exist( const wchar_t *key, int mode )
{
if( is_read_only(key) || is_electric(key) )
{
//Such variables are never exported
if (mode & ENV_EXPORT)
{
return 0;
}
else if (mode & ENV_UNEXPORT)
{
return 1;
}
return 1;
}
}
if( ! (mode & ENV_UNIVERSAL) )
if( !(mode & ENV_UNIVERSAL) )
{
env = (mode & ENV_GLOBAL)?global_env:top;
while( env != 0 )
{
var_table_t::iterator result = env->env.find( key );
if ( result != env->env.end() )
{
res = result->second;
}
else
{
res = 0;
}
if( res != 0 )
{
return 1;
if (mode & ENV_EXPORT)
{
return res->exportv == 1;
}
else if (mode & ENV_UNEXPORT)
{
return res->exportv == 0;
}
return 1;
}
if( mode & ENV_LOCAL )
{
break;
}
if ( mode & ENV_LOCAL )
break;
if( env->new_scope )
{
env = global_env;
@ -1187,8 +1197,8 @@ int env_exist( const wchar_t *key, int mode )
}
}
}
if( ! (mode & ENV_LOCAL) && ! (mode & ENV_GLOBAL) )
if( !(mode & ENV_LOCAL) && !(mode & ENV_GLOBAL) )
{
if( ! get_proc_had_barrier())
{
@ -1197,10 +1207,23 @@ int env_exist( const wchar_t *key, int mode )
}
item = env_universal_get( key );
}
return item != 0;
if (item != NULL)
{
if (mode & ENV_EXPORT)
{
return env_universal_get_export(key) == 1;
}
else if (mode & ENV_UNEXPORT)
{
return env_universal_get_export(key) == 0;
}
return 1;
}
}
return 0;
}
/**

View File

@ -33,3 +33,130 @@ set -g smurf yellow
call3
call4
set -l foo 1
set -g bar 2
set -U baz 3
set -l -q foo
if test $status -ne 0
echo Test 5 fail
else
echo Test 5 pass
end;
if not set -g -q bar
echo Test 6 fail
else
echo Test 6 pass
end;
if not set -U -q baz
echo Test 7 fail
else
echo Test 7 pass
end;
set -u -l -q foo
if test $status -ne 0
echo Test 8 fail
else
echo Test 8 pass
end;
if not set -u -g -q bar
echo Test 9 fail
else
echo Test 9 pass
end;
if not set -u -U -q baz
echo Test 10 fail
else
echo Test 10 pass
end;
set -x -l -q foo
if test $status -eq 0
echo Test 11 fail
else
echo Test 11 pass
end;
if set -x -g -q bar
echo Test 12 fail
else
echo Test 12 pass
end;
if set -x -U -q baz
echo Test 13 fail
else
echo Test 13 pass
end;
set -x -l foo 1
set -x -g bar 2
set -x -U baz 3
set -l -q foo
if test $status -ne 0
echo Test 14 fail
else
echo Test 14 pass
end;
if not set -g -q bar
echo Test 15 fail
else
echo Test 15 pass
end;
if not set -U -q baz
echo Test 16 fail
else
echo Test 16 pass
end;
set -u -l -q foo
if test $status -ne 1
echo Test 17 fail
else
echo Test 17 pass
end;
if set -u -g -q bar
echo Test 18 fail
else
echo Test 18 pass
end;
if set -u -U -q baz
echo Test 19 fail
else
echo Test 19 pass
end;
set -x -l -q foo
if test $status -ne 0
echo Test 20 fail
else
echo Test 20 pass
end;
if not set -x -g -q bar
echo Test 21 fail
else
echo Test 21 pass
end;
if not set -x -U -q baz
echo Test 22 fail
else
echo Test 22 pass
end;
set -U -e baz

View File

@ -2,3 +2,21 @@ Test 1 pass
Test 2 pass
Test 3 pass
Test 4 pass
Test 5 pass
Test 6 pass
Test 7 pass
Test 8 pass
Test 9 pass
Test 10 pass
Test 11 pass
Test 12 pass
Test 13 pass
Test 14 pass
Test 15 pass
Test 16 pass
Test 17 pass
Test 18 pass
Test 19 pass
Test 20 pass
Test 21 pass
Test 22 pass