mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-11 07:34:32 +00:00
Minor hallocifications
darcs-hash:20060212190301-ac50b-c15b9a8c6c2897189c4343946d9bd115eefb4972.gz
This commit is contained in:
parent
7eb3a5a17d
commit
effe6f47a3
2 changed files with 51 additions and 53 deletions
55
expand.c
55
expand.c
|
@ -156,9 +156,6 @@ static wchar_t *expand_var( wchar_t *in )
|
|||
return env_get( in );
|
||||
}
|
||||
|
||||
static string_buffer_t *var_tmp = 0;
|
||||
static array_list_t *var_idx_list;
|
||||
|
||||
void expand_variable_array( const wchar_t *val, array_list_t *out )
|
||||
{
|
||||
if( val )
|
||||
|
@ -714,31 +711,6 @@ static int expand_pid( wchar_t *in,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void var_tmp_init()
|
||||
{
|
||||
if( !var_tmp )
|
||||
{
|
||||
var_tmp = sb_halloc( global_context );
|
||||
if( !var_tmp )
|
||||
die_mem();
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_clear(var_tmp );
|
||||
}
|
||||
|
||||
if( !var_idx_list )
|
||||
{
|
||||
var_idx_list = al_halloc( global_context );
|
||||
if( !var_idx_list )
|
||||
die_mem();
|
||||
}
|
||||
else
|
||||
{
|
||||
al_truncate( var_idx_list, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Expand all environment variables in the string *ptr.
|
||||
|
||||
|
@ -761,6 +733,31 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
|||
int is_ok= 1;
|
||||
int empty=0;
|
||||
|
||||
static string_buffer_t *var_tmp = 0;
|
||||
static array_list_t *var_idx_list = 0;
|
||||
|
||||
if( !var_tmp )
|
||||
{
|
||||
var_tmp = sb_halloc( global_context );
|
||||
if( !var_tmp )
|
||||
die_mem();
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_clear(var_tmp );
|
||||
}
|
||||
|
||||
if( !var_idx_list )
|
||||
{
|
||||
var_idx_list = al_halloc( global_context );
|
||||
if( !var_idx_list )
|
||||
die_mem();
|
||||
}
|
||||
else
|
||||
{
|
||||
al_truncate( var_idx_list, 0 );
|
||||
}
|
||||
|
||||
for( i=last_idx; (i>=0) && is_ok && !empty; i-- )
|
||||
{
|
||||
c = in[i];
|
||||
|
@ -836,8 +833,6 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
|||
break;
|
||||
}
|
||||
|
||||
var_tmp_init();
|
||||
|
||||
sb_append_substring( var_tmp, &in[start_pos], var_len );
|
||||
|
||||
var_val = expand_var( (wchar_t *)var_tmp->buff );
|
||||
|
|
49
parse_util.c
49
parse_util.c
|
@ -94,7 +94,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
|||
{
|
||||
if( wcschr( L"\'\"", *pos ) )
|
||||
{
|
||||
wchar_t *end = quote_end( pos );
|
||||
const wchar_t *end = quote_end( pos );
|
||||
if( end && *end)
|
||||
{
|
||||
pos=end;
|
||||
|
@ -464,14 +464,14 @@ int parse_util_load( const wchar_t *cmd,
|
|||
void (*on_load)(const wchar_t *cmd),
|
||||
int reload )
|
||||
{
|
||||
array_list_t path_list;
|
||||
static array_list_t *path_list=0;
|
||||
static string_buffer_t *path=0;
|
||||
|
||||
int i;
|
||||
string_buffer_t path;
|
||||
time_t *tm;
|
||||
int reloaded = 0;
|
||||
hash_table_t *loaded;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Do we know where to look
|
||||
*/
|
||||
|
@ -520,30 +520,35 @@ int parse_util_load( const wchar_t *cmd,
|
|||
*/
|
||||
if( !reload && tm )
|
||||
return 0;
|
||||
|
||||
if( !path_list )
|
||||
path_list = al_halloc( global_context);
|
||||
|
||||
al_init( &path_list );
|
||||
|
||||
sb_init( &path );
|
||||
|
||||
expand_variable_array( path_var, &path_list );
|
||||
|
||||
|
||||
if( !path )
|
||||
path = sb_halloc( global_context );
|
||||
else
|
||||
sb_clear( path );
|
||||
|
||||
expand_variable_array( path_var, path_list );
|
||||
|
||||
/*
|
||||
Iterate over path searching for suitable completion files
|
||||
*/
|
||||
for( i=0; i<al_get_count( &path_list ); i++ )
|
||||
for( i=0; i<al_get_count( path_list ); i++ )
|
||||
{
|
||||
struct stat buf;
|
||||
wchar_t *next = (wchar_t *)al_get( &path_list, i );
|
||||
sb_clear( &path );
|
||||
sb_append2( &path, next, L"/", cmd, L".fish", (void *)0 );
|
||||
if( (wstat( (wchar_t *)path.buff, &buf )== 0) &&
|
||||
(waccess( (wchar_t *)path.buff, R_OK ) == 0) )
|
||||
wchar_t *next = (wchar_t *)al_get( path_list, i );
|
||||
sb_clear( path );
|
||||
sb_append2( path, next, L"/", cmd, L".fish", (void *)0 );
|
||||
if( (wstat( (wchar_t *)path->buff, &buf )== 0) &&
|
||||
(waccess( (wchar_t *)path->buff, R_OK ) == 0) )
|
||||
{
|
||||
if( !tm || (*tm != buf.st_mtime ) )
|
||||
{
|
||||
wchar_t *esc = escape( (wchar_t *)path.buff, 1 );
|
||||
wchar_t *esc = escape( (wchar_t *)path->buff, 1 );
|
||||
wchar_t *src_cmd = wcsdupcat( L". ", esc );
|
||||
|
||||
|
||||
if( !tm )
|
||||
{
|
||||
tm = malloc(sizeof(time_t)*2);
|
||||
|
@ -588,10 +593,8 @@ int parse_util_load( const wchar_t *cmd,
|
|||
hash_put( loaded, intern( cmd ), tm );
|
||||
}
|
||||
|
||||
sb_destroy( &path );
|
||||
al_foreach( &path_list, (void (*)(const void *))&free );
|
||||
|
||||
al_destroy( &path_list );
|
||||
al_foreach( path_list, (void (*)(const void *))&free );
|
||||
al_truncate( path_list, 0 );
|
||||
|
||||
return reloaded;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue