Minor hallocifications

darcs-hash:20060212190301-ac50b-c15b9a8c6c2897189c4343946d9bd115eefb4972.gz
This commit is contained in:
axel 2006-02-13 05:03:01 +10:00
parent 7eb3a5a17d
commit effe6f47a3
2 changed files with 51 additions and 53 deletions

View File

@ -156,9 +156,6 @@ static wchar_t *expand_var( wchar_t *in )
return env_get( 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 ) void expand_variable_array( const wchar_t *val, array_list_t *out )
{ {
if( val ) if( val )
@ -714,31 +711,6 @@ static int expand_pid( wchar_t *in,
return 1; 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. 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 is_ok= 1;
int empty=0; 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-- ) for( i=last_idx; (i>=0) && is_ok && !empty; i-- )
{ {
c = in[i]; c = in[i];
@ -836,8 +833,6 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
break; break;
} }
var_tmp_init();
sb_append_substring( var_tmp, &in[start_pos], var_len ); sb_append_substring( var_tmp, &in[start_pos], var_len );
var_val = expand_var( (wchar_t *)var_tmp->buff ); var_val = expand_var( (wchar_t *)var_tmp->buff );

View File

@ -94,7 +94,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
{ {
if( wcschr( L"\'\"", *pos ) ) if( wcschr( L"\'\"", *pos ) )
{ {
wchar_t *end = quote_end( pos ); const wchar_t *end = quote_end( pos );
if( end && *end) if( end && *end)
{ {
pos=end; pos=end;
@ -464,14 +464,14 @@ int parse_util_load( const wchar_t *cmd,
void (*on_load)(const wchar_t *cmd), void (*on_load)(const wchar_t *cmd),
int reload ) int reload )
{ {
array_list_t path_list; static array_list_t *path_list=0;
static string_buffer_t *path=0;
int i; int i;
string_buffer_t path;
time_t *tm; time_t *tm;
int reloaded = 0; int reloaded = 0;
hash_table_t *loaded; hash_table_t *loaded;
/* /*
Do we know where to look Do we know where to look
*/ */
@ -520,30 +520,35 @@ int parse_util_load( const wchar_t *cmd,
*/ */
if( !reload && tm ) if( !reload && tm )
return 0; return 0;
if( !path_list )
path_list = al_halloc( global_context);
al_init( &path_list );
if( !path )
sb_init( &path ); path = sb_halloc( global_context );
else
expand_variable_array( path_var, &path_list ); sb_clear( path );
expand_variable_array( path_var, path_list );
/* /*
Iterate over path searching for suitable completion files 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; struct stat buf;
wchar_t *next = (wchar_t *)al_get( &path_list, i ); wchar_t *next = (wchar_t *)al_get( path_list, i );
sb_clear( &path ); sb_clear( path );
sb_append2( &path, next, L"/", cmd, L".fish", (void *)0 ); sb_append2( path, next, L"/", cmd, L".fish", (void *)0 );
if( (wstat( (wchar_t *)path.buff, &buf )== 0) && if( (wstat( (wchar_t *)path->buff, &buf )== 0) &&
(waccess( (wchar_t *)path.buff, R_OK ) == 0) ) (waccess( (wchar_t *)path->buff, R_OK ) == 0) )
{ {
if( !tm || (*tm != buf.st_mtime ) ) 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 ); wchar_t *src_cmd = wcsdupcat( L". ", esc );
if( !tm ) if( !tm )
{ {
tm = malloc(sizeof(time_t)*2); tm = malloc(sizeof(time_t)*2);
@ -588,10 +593,8 @@ int parse_util_load( const wchar_t *cmd,
hash_put( loaded, intern( cmd ), tm ); hash_put( loaded, intern( cmd ), tm );
} }
sb_destroy( &path ); al_foreach( path_list, (void (*)(const void *))&free );
al_foreach( &path_list, (void (*)(const void *))&free ); al_truncate( path_list, 0 );
al_destroy( &path_list );
return reloaded; return reloaded;
} }