From 9cd279e0e9e119c279bd957434a1d30d5c60abc4 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 26 Dec 2011 23:13:05 -0800 Subject: [PATCH] Migrate some more off of al_list --- common.cpp | 11 +++++++++++ common.h | 1 + parse_util.cpp | 28 ++++++++++------------------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/common.cpp b/common.cpp index 90fe6c197..21871f8b8 100644 --- a/common.cpp +++ b/common.cpp @@ -1765,6 +1765,17 @@ int common_get_height() return termsize.ws_row; } +void tokenize_variable_array2( const wcstring &val, std::vector &out) +{ + size_t pos = 0, end = val.size(); + while (pos < end) { + size_t next_pos = val.find(ARRAY_SEP, pos); + if (next_pos == wcstring::npos) next_pos = end; + out.push_back(val.substr(pos, next_pos - pos)); + pos = next_pos + 1; //skip the separator + } +} + void tokenize_variable_array( const wchar_t *val, array_list_t *out ) { if( val ) diff --git a/common.h b/common.h index f23a915c2..07eb1217f 100644 --- a/common.h +++ b/common.h @@ -530,6 +530,7 @@ void write_screen( const wchar_t *msg, string_buffer_t *buff ); \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, std::vector &out); /** Make sure the specified direcotry exists. If needed, try to create diff --git a/parse_util.cpp b/parse_util.cpp index 6ec78fb48..2b1872fd1 100644 --- a/parse_util.cpp +++ b/parse_util.cpp @@ -819,7 +819,7 @@ static int parse_util_load_internal( const wchar_t *cmd, void (*on_load)(const wchar_t *cmd), int reload, autoload_t *loaded, - array_list_t *path_list ); + const std::vector &path_list ); int parse_util_load( const wchar_t *cmd, @@ -827,8 +827,6 @@ int parse_util_load( const wchar_t *cmd, void (*on_load)(const wchar_t *cmd), int reload ) { - array_list_t *path_list=0; - autoload_t *loaded; wchar_t *path_var; @@ -917,12 +915,10 @@ int parse_util_load( const wchar_t *cmd, loaded->old_path = wcsdup( path_var ); } - - path_list = (array_list_t *)al_new(); + std::vector path_list; + tokenize_variable_array2( path_var, path_list ); - tokenize_variable_array( path_var, path_list ); - - c = al_get_count( path_list ); + c = path_list.size(); hash_put( &loaded->is_loading, cmd, cmd ); @@ -941,11 +937,7 @@ int parse_util_load( const wchar_t *cmd, hash_remove( &loaded->is_loading, cmd, 0, 0 ); } - c2 = al_get_count( path_list ); - - al_foreach( path_list, &free ); - al_destroy( path_list ); - free( path_list ); + c2 = path_list.size(); /** Make sure we didn't 'drop' something @@ -966,11 +958,11 @@ static int parse_util_load_internal( const wchar_t *cmd, void (*on_load)(const wchar_t *cmd), int reload, autoload_t *loaded, - array_list_t *path_list ) + const std::vector &path_list ) { static string_buffer_t *path=0; time_t *tm; - int i; + size_t i; int reloaded = 0; /* @@ -1009,12 +1001,12 @@ static int parse_util_load_internal( const wchar_t *cmd, /* Iterate over path searching for suitable completion files */ - for( i=0; ibuff, &buf )== 0) && (waccess( (wchar_t *)path->buff, R_OK ) == 0) )