From effe6f47a372d35fa47ab508e7c905d64fbb9b54 Mon Sep 17 00:00:00 2001 From: axel Date: Mon, 13 Feb 2006 05:03:01 +1000 Subject: [PATCH] Minor hallocifications darcs-hash:20060212190301-ac50b-c15b9a8c6c2897189c4343946d9bd115eefb4972.gz --- expand.c | 55 ++++++++++++++++++++++++---------------------------- parse_util.c | 49 ++++++++++++++++++++++++---------------------- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/expand.c b/expand.c index cdc34102e..f2023fb23 100644 --- a/expand.c +++ b/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 ); diff --git a/parse_util.c b/parse_util.c index fd645ce70..2ea8d3ecf 100644 --- a/parse_util.c +++ b/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; ibuff, &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; }