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:
axel 2007-01-22 01:01:14 +10:00
parent a1ec38f53b
commit 66c045c439
5 changed files with 115 additions and 27 deletions

View file

@ -98,7 +98,7 @@ extern wchar_t *program_name;
char c; \
show_stackframe(); \
read( 0, &c, 1 ); \
exit(1 ); \
exit( 1 ); \
} \
@ -140,15 +140,15 @@ extern wchar_t *program_name;
*/
#define N_(wstr) wstr
/*
Print a stack trace to stderr
*/
void show_stackframe();
/**
Take an array_list_t containing wide strings and converts them to a
single null-terminated wchar_t **. The array is allocated using
halloc, and uses the \c context parameter as context. If \c context
is not noll, all elements of the \c array_list_t are also
registered to \c context using \c halloc_register().
malloc, and needs to be fred's by the caller.
*/
wchar_t **list_to_char_arr( array_list_t *l );

View file

@ -20,7 +20,7 @@ The following switches change what the commandline builtin does
will cause any additional arguments to be interpreted as readline
functions, and these functions will be injected into the reader, so
that they will be returned to the reader before any additional
actual keypresses are read.
actual key presses are read.
The following switches change the way \c commandline updates the

111
env.c
View file

@ -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;
}
}
}

17
exec.c
View file

@ -272,12 +272,15 @@ static int handle_child_io( io_data_t *io, int exit_on_error )
switch( io->io_mode )
{
case IO_CLOSE:
{
if( close(io->fd) )
{
debug( 0, _(L"Failed to close file descriptor %d"), io->fd );
wperror( L"close" );
}
break;
}
case IO_FILE:
{
if( (tmp=wopen( io->param1.filename,
@ -827,9 +830,13 @@ void exec( job_t *j )
if( block_io )
{
if( j->io )
{
j->io = io_add( io_duplicate( j, block_io), j->io );
}
else
{
j->io=io_duplicate( j, block_io);
}
}
@ -868,7 +875,7 @@ void exec( job_t *j )
if( !setup_child_process( j, 0 ) )
{
/*
launch_process never returns
launch_process _never_ returns
*/
launch_process( j->first_process );
}
@ -1195,8 +1202,10 @@ void exec( job_t *j )
}
if( exec_error )
{
break;
}
switch( p->type )
{
@ -1331,7 +1340,7 @@ void exec( job_t *j )
( !p->next );
/*
If the output of a builtin is to be sent to aninternal
If the output of a builtin is to be sent to an internal
buffer, there is no need to fork. This helps out the
performance quite a bit in complex completion code.
*/
@ -1360,7 +1369,6 @@ void exec( job_t *j )
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?(!p->status):p->status );
}
break;
}
/*
@ -1376,7 +1384,6 @@ void exec( job_t *j )
print correct output to stdout and stderr, and
then exit.
*/
p->pid = getpid();
setup_child_process( j, p );
do_builtin_io( sb_out->used ? (wchar_t *)sb_out->buff : 0, sb_err->used ? (wchar_t *)sb_err->buff : 0 );

View file

@ -568,6 +568,7 @@ void signal_set_handlers()
exit(1);
}
#ifdef SIGWINCH
act.sa_flags = SA_SIGINFO;
act.sa_sigaction= &handle_winch;
if( sigaction( SIGWINCH, &act, 0 ) )
@ -575,6 +576,7 @@ void signal_set_handlers()
wperror( L"sigaction" );
exit(1);
}
#endif
act.sa_flags = SA_SIGINFO;
act.sa_sigaction= &handle_hup;