Removed some al_list functions

This commit is contained in:
ridiculousfish 2012-02-10 01:37:30 -08:00
parent 910863e9ea
commit d975187433
11 changed files with 13 additions and 133 deletions

View file

@ -111,7 +111,7 @@ int autoload_t::load( const wcstring &cmd, bool reload )
/* Get the list of paths from which we will try to load */
std::vector<wcstring> path_list;
tokenize_variable_array2( path_var, path_list );
tokenize_variable_array( path_var, path_list );
/* Try loading it */
res = this->locate_file_and_maybe_load_it( cmd, true, reload, path_list );
@ -131,7 +131,7 @@ bool autoload_t::can_load( const wcstring &cmd, const env_vars &vars )
const wcstring path_var(path_var_ptr);
std::vector<wcstring> path_list;
tokenize_variable_array2( path_var, path_list );
tokenize_variable_array( path_var, path_list );
return this->locate_file_and_maybe_load_it( cmd, false, false, path_list );
}

View file

@ -273,7 +273,7 @@ static int update_values( wcstring_list_t &list,
{
/*
The '- 1' below is because the indices in fish are
one-based, but the array_list_t uses zero-based indices
one-based, but the vector uses zero-based indices
*/
long ind = indexes[i] - 1;
const wcstring newv = values[ i ];
@ -592,7 +592,7 @@ static int builtin_set( parser_t &parser, wchar_t **argv )
// al_init( &indexes );
env_var_t dest_str = env_get_string(dest);
if (! dest_str.missing())
tokenize_variable_array2( dest_str, result );
tokenize_variable_array( dest_str, result );
if( !parse_index( indexes, arg, dest, result.size() ) )
{
@ -706,7 +706,7 @@ static int builtin_set( parser_t &parser, wchar_t **argv )
const env_var_t dest_str = env_get_string(dest);
if (! dest_str.missing())
tokenize_variable_array2( dest_str, result );
tokenize_variable_array( dest_str, result );
for( ; woptind<argc; woptind++ )
{

View file

@ -132,23 +132,6 @@ void show_stackframe()
}
}
wchar_t **list_to_char_arr( array_list_t *l )
{
wchar_t ** res = (wchar_t **)malloc( sizeof(wchar_t *)*(al_get_count( l )+1) );
int i;
if( res == 0 )
{
DIE_MEM();
}
for( i=0; i<al_get_count( l ); i++ )
{
res[i] = (wchar_t *)al_get(l,i);
}
res[i]='\0';
return res;
}
wcstring_list_t completions_to_wcstring_list( const std::vector<completion_t> &list )
{
wcstring_list_t strings;
@ -219,24 +202,6 @@ int fgetws2( wchar_t **b, int *len, FILE *f )
}
/**
Wrapper for wcsfilecmp
*/
static int str_cmp( const void *a, const void *b )
{
wchar_t *c= *((wchar_t **)a);
wchar_t *d= *((wchar_t **)b);
return wcsfilecmp( c, d );
}
void sort_list( array_list_t *comp )
{
qsort( comp->arr,
al_get_count( comp ),
sizeof( void*),
&str_cmp );
}
static bool string_sort_predicate(const wcstring& d1, const wcstring& d2)
{
return wcsfilecmp(d1.c_str(), d2.c_str()) < 0;
@ -1799,7 +1764,7 @@ int common_get_height()
return termsize.ws_row;
}
void tokenize_variable_array2( const wcstring &val, std::vector<wcstring> &out)
void tokenize_variable_array( const wcstring &val, std::vector<wcstring> &out)
{
size_t pos = 0, end = val.size();
while (pos < end) {
@ -1811,39 +1776,6 @@ void tokenize_variable_array2( const wcstring &val, std::vector<wcstring> &out)
out.push_back(val.substr(pos, end - pos));
}
void tokenize_variable_array( const wchar_t *val, array_list_t *out )
{
if( val )
{
wchar_t *cpy = wcsdup( val );
wchar_t *pos, *start;
wchar_t *next;
if( !cpy )
{
DIE_MEM();
}
for( start=pos=cpy; *pos; pos++ )
{
if( *pos == ARRAY_SEP )
{
*pos=0;
next = start==cpy?cpy:wcsdup(start);
if( !next )
DIE_MEM();
al_push( out, next );
start=pos+1;
}
}
next = start==cpy?cpy:wcsdup(start);
if( !next )
DIE_MEM();
al_push( out, next );
}
}
bool string_prefixes_string(const wcstring &proposed_prefix, const wcstring &value) {
size_t prefix_size = proposed_prefix.size();
return prefix_size <= value.size() && value.compare(0, prefix_size, proposed_prefix) == 0;

View file

@ -188,12 +188,6 @@ extern const wchar_t *program_name;
*/
void show_stackframe();
/**
Take an array_list_t containing wide strings and converts them to a
single null-terminated wchar_t **. The array is allocated using
malloc, and needs to be fred's by the caller.
*/
wchar_t **list_to_char_arr( array_list_t *l );
wcstring_list_t completions_to_wcstring_list( const std::vector<completion_t> &completions );
@ -210,12 +204,6 @@ wcstring_list_t completions_to_wcstring_list( const std::vector<completion_t> &c
*/
int fgetws2( wchar_t **buff, int *len, FILE *f );
/**
Sorts an array_list of wide strings according to the
wcsfilecmp-function from the util library
*/
void sort_list( array_list_t *comp );
void sort_strings( std::vector<wcstring> &strings);
void sort_completions( std::vector<completion_t> &strings);
@ -566,8 +554,7 @@ void write_screen( const wchar_t *msg, string_buffer_t *buff );
\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 );
void tokenize_variable_array2( const wcstring &val, wcstring_list_t &out);
void tokenize_variable_array( const wcstring &val, wcstring_list_t &out);
/**
Make sure the specified direcotry exists. If needed, try to create

View file

@ -427,7 +427,7 @@ static void setup_path()
if( !path.missing() )
{
tokenize_variable_array2( path, lst );
tokenize_variable_array( path, lst );
}
for( j=0; path_el[j]; j++ )
@ -470,7 +470,7 @@ static void setup_path()
path = env_get_string( L"PATH" );
lst.resize(0);
tokenize_variable_array2( path, lst );
tokenize_variable_array( path, lst );
}
}
}

View file

@ -187,7 +187,7 @@ wcstring expand_escape_variable( const wcstring &in )
wcstring_list_t lst;
wcstring buff;
tokenize_variable_array2( in, lst );
tokenize_variable_array( in, lst );
switch( lst.size() )
{
@ -882,7 +882,7 @@ static int expand_variables_internal( parser_t &parser, wchar_t * const in, std:
if( is_ok )
{
tokenize_variable_array2( var_val, var_item_list );
tokenize_variable_array( var_val, var_item_list );
if( !all_vars )
{

View file

@ -118,7 +118,7 @@ static void autoload_names( std::set<wcstring> &names, int get_hidden )
wcstring_list_t path_list;
tokenize_variable_array2( path_var, path_list );
tokenize_variable_array( path_var, path_list );
for( i=0; i<path_list.size(); i++ )
{
const wcstring &ndir_str = path_list.at(i);

View file

@ -1197,25 +1197,6 @@ static void launch( char *filter, const string_list_t &files, int fileno )
}
/**
Clean up one entry from the hash table of launch files
*/
static void clear_entry( void *key, void *val )
{
/*
The key is a mime value, either from the libraries internal hash
table of mime types or from the command line. Either way, it
should not be freed.
The value is an array_list_t of filenames. The filenames com from
the argument list and should not be freed. The arraylist,
however, should be destroyed and freed.
*/
array_list_t *l = (array_list_t *)val;
al_destroy( l );
free( l );
}
/**
Do locale specific init
*/

View file

@ -529,7 +529,7 @@ int output_color_code( const wcstring &val, bool is_background ) {
return FISH_COLOR_NORMAL;
wcstring_list_t el;
tokenize_variable_array2( val, el );
tokenize_variable_array( val, el );
for(size_t j=0; j < el.size(); j++ ) {
const wcstring &next = el.at(j);

View file

@ -581,16 +581,6 @@ int hash_ptr_cmp( void *a,
return a == b;
}
void al_init( array_list_t *l )
{
memset( l, 0, sizeof( array_list_t ) );
}
void al_destroy( array_list_t *l )
{
free( l->arr );
}
/**
Real implementation of all al_push_* versions. Pushes arbitrary
element to end of list.

10
util.h
View file

@ -315,16 +315,6 @@ int hash_ptr_cmp( void *a,
void *b );
/**
Initialize the list.
*/
void al_init( array_list_t *l );
/**
Destroy the list and free memory used by it.
*/
void al_destroy( array_list_t *l );
/**
Append element to list