From fdaa79416a72450a1ed69e501b1cb92c7985cf6f Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 9 Feb 2006 03:37:18 +1000 Subject: Make sure dynamically loaded functions are completable, even if they have not yet been loaded darcs-hash:20060208173718-ac50b-40c93b82f3b8a717d220642e22c4b4005d8871d0.gz --- function.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) (limited to 'function.c') diff --git a/function.c b/function.c index a3f76b0b..58d83f4e 100644 --- a/function.c +++ b/function.c @@ -45,7 +45,10 @@ typedef struct static hash_table_t function; static int is_autoload = 0; - +/** + Make sure that if the specified function is a dynamically loaded + function, it has been fully loaded. +*/ static int load( const wchar_t *name ) { int was_autoload = is_autoload; @@ -64,8 +67,50 @@ static int load( const wchar_t *name ) return res; } -static void load_all() -{ +/** + Insert a list of all dynamically loaded functions into the + specified list. +*/ +static void autoload_names( array_list_t *out, int get_hidden ) +{ + int i; + + array_list_t path_list; + const wchar_t *path_var = env_get( L"fish_function_path" ); + + if( ! path_var ) + return; + + al_init( &path_list ); + + expand_variable_array( path_var, &path_list ); + for( i=0; id_name; + wchar_t *suffix; + if( !get_hidden && fn[0] == L'_' ) + continue; + + suffix = wcsrchr( fn, L'.' ); + if( suffix && (wcscmp( suffix, L".fish" ) == 0 ) ) + { + wchar_t *dup; + *suffix = 0; + dup = wcsdup( fn ); + if( !dup ) + die_mem(); + al_push( out, dup ); + } + } + closedir(dir); + } + al_foreach( &path_list, (void (*)(const void *))&free ); + al_destroy( &path_list ); } @@ -133,7 +178,6 @@ void function_add( const wchar_t *name, int function_exists( const wchar_t *cmd ) { - function_data_t *data; if( parser_is_reserved(cmd) ) return 0; @@ -210,7 +254,7 @@ static void get_names_internal( const void *key, void function_get_names( array_list_t *list, int get_hidden ) { - load_all(); + autoload_names( list, get_hidden ); if( get_hidden ) hash_get_keys( &function, list ); @@ -242,5 +286,3 @@ int function_get_definition_offset( const wchar_t *argv ) return data->definition_offset; } - - -- cgit v1.2.3