mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 10:01:14 -03:00
Minor code edits. Add curly brackets in various places, add or rewrite various comments, fix indentation, etc.
darcs-hash:20070121150114-ac50b-4fd6965cb2c557178923f8afa944835166e08423.gz
This commit is contained in:
111
env.c
111
env.c
@@ -202,7 +202,9 @@ static void clear_hash_entry( void *key, void *data )
|
||||
{
|
||||
var_entry_t *entry = (var_entry_t *)data;
|
||||
if( entry->export )
|
||||
{
|
||||
has_changed = 1;
|
||||
}
|
||||
|
||||
free( (void *)key );
|
||||
free( (void *)data );
|
||||
@@ -257,8 +259,12 @@ static int is_locale( const wchar_t *key )
|
||||
{
|
||||
int i;
|
||||
for( i=0; locale_variable[i]; i++ )
|
||||
{
|
||||
if( wcscmp(locale_variable[i], key ) == 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -303,8 +309,11 @@ static void handle_locale()
|
||||
for( i=2; locale_variable[i]; i++ )
|
||||
{
|
||||
const wchar_t *val = env_get( locale_variable[i] );
|
||||
|
||||
if( val )
|
||||
{
|
||||
wsetlocale( cat[i], val );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,8 +327,10 @@ static void handle_locale()
|
||||
strings should be reloaded. We do both and hope for the
|
||||
best.
|
||||
*/
|
||||
|
||||
extern int _nl_msg_cat_cntr;
|
||||
++_nl_msg_cat_cntr;
|
||||
_nl_msg_cat_cntr++;
|
||||
|
||||
dcgettext( "fish", "Changing language to English", LC_MESSAGES );
|
||||
|
||||
if( is_interactive )
|
||||
@@ -343,17 +354,24 @@ static void universal_callback( int type,
|
||||
wchar_t *str=0;
|
||||
|
||||
if( is_locale( name ) )
|
||||
{
|
||||
handle_locale();
|
||||
}
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case SET:
|
||||
case SET_EXPORT:
|
||||
{
|
||||
str=L"SET";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERASE:
|
||||
{
|
||||
str=L"ERASE";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( str )
|
||||
@@ -404,19 +422,27 @@ static void setup_path()
|
||||
al_init( &l );
|
||||
|
||||
if( path )
|
||||
{
|
||||
tokenize_variable_array( path, &l );
|
||||
}
|
||||
|
||||
for( j=0; path_el[j]; j++ )
|
||||
{
|
||||
|
||||
int has_el=0;
|
||||
|
||||
for( i=0; i<al_get_count( &l); i++ )
|
||||
{
|
||||
wchar_t * el = (wchar_t *)al_get( &l, i );
|
||||
size_t len = wcslen( el );
|
||||
|
||||
while( (len > 0) && (el[len-1]==L'/') )
|
||||
{
|
||||
len--;
|
||||
if( (wcslen( path_el[j] ) == len) && (wcsncmp( el, path_el[j], len)==0) )
|
||||
}
|
||||
|
||||
if( (wcslen( path_el[j] ) == len) &&
|
||||
(wcsncmp( el, path_el[j], len)==0) )
|
||||
{
|
||||
has_el = 1;
|
||||
}
|
||||
@@ -456,6 +482,7 @@ static void setup_path()
|
||||
|
||||
static void env_set_defaults()
|
||||
{
|
||||
|
||||
if( !env_get( L"USER" ) )
|
||||
{
|
||||
struct passwd *pw = getpwuid( getuid());
|
||||
@@ -463,6 +490,7 @@ static void env_set_defaults()
|
||||
env_set( L"USER", unam, ENV_GLOBAL );
|
||||
free( unam );
|
||||
}
|
||||
|
||||
if( !env_get( L"HOME" ) )
|
||||
{
|
||||
wchar_t *unam = env_get( L"USER" );
|
||||
@@ -473,6 +501,7 @@ static void env_set_defaults()
|
||||
free( dir );
|
||||
free( unam_narrow );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void env_init()
|
||||
@@ -541,13 +570,17 @@ void env_init()
|
||||
key = str2wcs(*p);
|
||||
|
||||
if( !key )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
val = wcschr( key, L'=' );
|
||||
|
||||
|
||||
if( val == 0 )
|
||||
{
|
||||
env_set( key, L"", ENV_EXPORT );
|
||||
}
|
||||
else
|
||||
{
|
||||
*val = L'\0';
|
||||
@@ -557,7 +590,9 @@ void env_init()
|
||||
while( *pos )
|
||||
{
|
||||
if( *pos == L':' )
|
||||
{
|
||||
*pos = ARRAY_SEP;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
|
||||
@@ -609,8 +644,10 @@ void env_destroy()
|
||||
b_destroy( &export_buffer );
|
||||
|
||||
while( &top->env != global )
|
||||
{
|
||||
env_pop();
|
||||
|
||||
}
|
||||
|
||||
hash_destroy( &env_read_only );
|
||||
|
||||
hash_destroy( &env_electric );
|
||||
@@ -624,8 +661,8 @@ void env_destroy()
|
||||
}
|
||||
|
||||
/**
|
||||
Find the scope hashtable containing the variable with the specified
|
||||
key
|
||||
Search all visible scopes in order for the specified key. Return
|
||||
the first scope in which it was found.
|
||||
*/
|
||||
static env_node_t *env_get_node( const wchar_t *key )
|
||||
{
|
||||
@@ -643,9 +680,13 @@ static env_node_t *env_get_node( const wchar_t *key )
|
||||
}
|
||||
|
||||
if( env->new_scope )
|
||||
{
|
||||
env = global_env;
|
||||
}
|
||||
else
|
||||
{
|
||||
env = env->next;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -693,13 +734,15 @@ int env_set( const wchar_t *key,
|
||||
}
|
||||
}
|
||||
/*
|
||||
Do not actually create a umask variable, on env_get, it will be calculated dynamically
|
||||
Do not actually create a umask variable, on env_get, it will
|
||||
be calculated dynamically
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Zero element arrays are internaly not coded as null but as this placeholder string
|
||||
Zero element arrays are internaly not coded as null but as this
|
||||
placeholder string
|
||||
*/
|
||||
if( !val )
|
||||
{
|
||||
@@ -716,7 +759,9 @@ int env_set( const wchar_t *key,
|
||||
env_universal_get_export( key );
|
||||
}
|
||||
else
|
||||
{
|
||||
export = (var_mode & ENV_EXPORT );
|
||||
}
|
||||
|
||||
env_universal_set( key, val, export );
|
||||
is_universal = 1;
|
||||
@@ -732,15 +777,15 @@ int env_set( const wchar_t *key,
|
||||
key );
|
||||
|
||||
if( e->export )
|
||||
{
|
||||
has_changed_new = 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( (var_mode & ENV_LOCAL) ||
|
||||
(var_mode & ENV_GLOBAL) )
|
||||
{
|
||||
node = ( var_mode & ENV_GLOBAL )?global_env:top;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -770,8 +815,10 @@ int env_set( const wchar_t *key,
|
||||
env_universal_get_export( key );
|
||||
}
|
||||
else
|
||||
{
|
||||
export = (var_mode & ENV_EXPORT );
|
||||
|
||||
}
|
||||
|
||||
env_universal_set( key, val, export );
|
||||
is_universal = 1;
|
||||
|
||||
@@ -788,8 +835,9 @@ int env_set( const wchar_t *key,
|
||||
*/
|
||||
node = top;
|
||||
while( node->next && !node->new_scope )
|
||||
{
|
||||
node = node->next;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -806,13 +854,15 @@ int env_set( const wchar_t *key,
|
||||
Try to reuse previous key string
|
||||
*/
|
||||
if( !k )
|
||||
{
|
||||
k = wcsdup(key);
|
||||
|
||||
}
|
||||
|
||||
old_entry = (var_entry_t *)v;
|
||||
if( old_entry && old_entry->size >= val_len )
|
||||
{
|
||||
entry = old_entry;
|
||||
|
||||
|
||||
if( !!(var_mode & ENV_EXPORT) || entry->export )
|
||||
{
|
||||
entry->export = !!(var_mode & ENV_EXPORT);
|
||||
@@ -827,8 +877,10 @@ int env_set( const wchar_t *key,
|
||||
sizeof(wchar_t )*(val_len+1));
|
||||
|
||||
if( !entry )
|
||||
{
|
||||
DIE_MEM();
|
||||
|
||||
}
|
||||
|
||||
entry->size = val_len;
|
||||
|
||||
if( var_mode & ENV_EXPORT)
|
||||
@@ -848,8 +900,10 @@ int env_set( const wchar_t *key,
|
||||
}
|
||||
|
||||
if( free_val )
|
||||
{
|
||||
free((void *)val);
|
||||
|
||||
}
|
||||
|
||||
has_changed = has_changed_old || has_changed_new;
|
||||
}
|
||||
|
||||
@@ -895,8 +949,10 @@ static int try_remove( env_node_t *n,
|
||||
wchar_t *old_key, *old_val;
|
||||
|
||||
if( n == 0 )
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
hash_remove( &n->env,
|
||||
key,
|
||||
&old_key_void,
|
||||
@@ -919,12 +975,18 @@ static int try_remove( env_node_t *n,
|
||||
}
|
||||
|
||||
if( var_mode & ENV_LOCAL )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( n->new_scope )
|
||||
{
|
||||
return try_remove( global_env, key, var_mode );
|
||||
}
|
||||
else
|
||||
{
|
||||
return try_remove( n->next, key, var_mode );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1018,7 +1080,10 @@ wchar_t *env_get( const wchar_t *key )
|
||||
}
|
||||
|
||||
if( i!=0)
|
||||
{
|
||||
sb_append( &dyn_var, ARRAY_SEP_STR );
|
||||
}
|
||||
|
||||
sb_append( &dyn_var, next );
|
||||
}
|
||||
|
||||
@@ -1060,13 +1125,19 @@ wchar_t *env_get( const wchar_t *key )
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return res->val;
|
||||
}
|
||||
}
|
||||
|
||||
if( env->new_scope )
|
||||
{
|
||||
env = global_env;
|
||||
}
|
||||
else
|
||||
{
|
||||
env = env->next;
|
||||
}
|
||||
}
|
||||
if( !proc_had_barrier)
|
||||
{
|
||||
@@ -1081,7 +1152,9 @@ wchar_t *env_get( const wchar_t *key )
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
int env_exist( const wchar_t *key, int mode )
|
||||
@@ -1118,12 +1191,18 @@ int env_exist( const wchar_t *key, int mode )
|
||||
}
|
||||
|
||||
if( mode & ENV_LOCAL )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if( env->new_scope )
|
||||
{
|
||||
env = global_env;
|
||||
}
|
||||
else
|
||||
{
|
||||
env = env->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user