diff --git a/builtin_set.c b/builtin_set.c index 3c64da4bb..5fc9b52d0 100644 --- a/builtin_set.c +++ b/builtin_set.c @@ -682,7 +682,7 @@ int builtin_set( wchar_t **argv ) array_list_t result; al_init(&result); - expand_variable_array( env_get(dest), &result ); + tokenize_variable_array( env_get(dest), &result ); if( erase ) { erase_values(&result, &indexes); diff --git a/common.c b/common.c index af0eab42c..2c9dac8c2 100644 --- a/common.c +++ b/common.c @@ -1403,3 +1403,29 @@ int common_get_height() return termsize.ws_row; } +void tokenize_variable_array( const wchar_t *val, array_list_t *out ) +{ + if( val ) + { + wchar_t *cpy = wcsdup( val ); + wchar_t *pos, *start; + + if( !cpy ) + { + die_mem(); + } + + for( start=pos=cpy; *pos; pos++ ) + { + if( *pos == ARRAY_SEP ) + { + *pos=0; + al_push( out, start==cpy?cpy:wcsdup(start) ); + start=pos+1; + } + } + al_push( out, start==cpy?cpy:wcsdup(start) ); + } +} + + diff --git a/common.h b/common.h index 4dbb83a02..1de6f8de9 100644 --- a/common.h +++ b/common.h @@ -296,6 +296,16 @@ void common_handle_winch( int signal ); */ void write_screen( const wchar_t *msg, string_buffer_t *buff ); +/** + Tokenize the specified string into the specified array_list_t. + Each new element is allocated using malloc and must be freed by the + caller. + + \param val the input string. The contents of this string is not changed. + \param out the list in which to place the elements. +*/ +void tokenize_variable_array( const wchar_t *val, array_list_t *out ); + #endif diff --git a/env.c b/env.c index 9c54c59a9..ba7ec5d22 100644 --- a/env.c +++ b/env.c @@ -396,7 +396,7 @@ static void setup_path() al_init( &l ); if( path ) - expand_variable_array( path, &l ); + tokenize_variable_array( path, &l ); for( j=0; path_el[j]; j++ ) { @@ -438,7 +438,7 @@ static void setup_path() al_foreach( &l, (void (*)(const void *))&free ); path = env_get( L"PATH" ); al_truncate( &l, 0 ); - expand_variable_array( path, &l ); + tokenize_variable_array( path, &l ); } } diff --git a/expand.c b/expand.c index b6dcff827..b1ce99168 100644 --- a/expand.c +++ b/expand.c @@ -130,32 +130,6 @@ static wchar_t *expand_var( wchar_t *in ) return env_get( in ); } -void expand_variable_array( const wchar_t *val, array_list_t *out ) -{ - if( val ) - { - wchar_t *cpy = wcsdup( val ); - wchar_t *pos, *start; - - if( !cpy ) - { - die_mem(); - } - - for( start=pos=cpy; *pos; pos++ ) - { - if( *pos == ARRAY_SEP ) - { - *pos=0; - al_push( out, start==cpy?cpy:wcsdup(start) ); - start=pos+1; - } - } - al_push( out, start==cpy?cpy:wcsdup(start) ); - } -} - - /** Test if the specified string does not contain character which can not be used inside a quoted string. @@ -188,7 +162,7 @@ wchar_t *expand_escape_variable( const wchar_t *in ) string_buffer_t buff; al_init( &l ); - expand_variable_array( in, &l ); + tokenize_variable_array( in, &l ); sb_init( &buff ); switch( al_get_count( &l) ) @@ -834,7 +808,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx ) if( is_ok ) { - expand_variable_array( var_val, &var_item_list ); + tokenize_variable_array( var_val, &var_item_list ); if( !all_vars ) { int j; diff --git a/expand.h b/expand.h index b6ebfc65b..7b60eb88b 100644 --- a/expand.h +++ b/expand.h @@ -178,16 +178,6 @@ wchar_t *expand_escape_variable( const wchar_t *in ); wchar_t *expand_tilde(wchar_t *in); -/** - Tokenize the specified string into the specified array_list_t. - Each new element is allocated using malloc and must be freed by the - caller. - - \param val the input string. The contents of this string is not changed. - \param out the list in which to place the elements. -*/ -void expand_variable_array( const wchar_t *val, array_list_t *out ); - /** Test if the specified argument is clean, i.e. it does not contain any tokens which need to be expanded or otherwise altered. Clean diff --git a/function.c b/function.c index bfb2ddd81..00b38f195 100644 --- a/function.c +++ b/function.c @@ -87,7 +87,7 @@ static void autoload_names( array_list_t *out, int get_hidden ) al_init( &path_list ); - expand_variable_array( path_var, &path_list ); + tokenize_variable_array( path_var, &path_list ); for( i=0; i