Rename function expand_variable_array to tokenize_variable_array and move it from expand.c to common.c, since it is used by fish_pager, which should not depend on expand.o

darcs-hash:20060529111342-ac50b-315d7dcf04e05fa8f32e16801e6793ac4e4e022e.gz
This commit is contained in:
axel 2006-05-29 21:13:42 +10:00
parent 79b466441b
commit d46dade284
9 changed files with 44 additions and 44 deletions

View file

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

View file

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

View file

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

4
env.c
View file

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

View file

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

View file

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

View file

@ -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<al_get_count( &path_list ); i++ )
{
wchar_t *ndir = (wchar_t *)al_get( &path_list, i );

View file

@ -524,7 +524,7 @@ int output_color_code( const wchar_t *val )
return FISH_COLOR_NORMAL;
al_init( &el );
expand_variable_array( val, &el );
tokenize_variable_array( val, &el );
for( j=0; j<al_get_count( &el ); j++ )
{

View file

@ -558,7 +558,7 @@ int parse_util_load( const wchar_t *cmd,
else
sb_clear( path );
expand_variable_array( path_var, path_list );
tokenize_variable_array( path_var, path_list );
/*
Iterate over path searching for suitable completion files