diff --git a/function.c b/function.c index a3f76b0b2..58d83f4ec 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; } - - diff --git a/function.h b/function.h index e130bcef9..7ee12d61f 100644 --- a/function.h +++ b/function.h @@ -69,8 +69,15 @@ int function_exists( const wchar_t *name ); void function_get_names( array_list_t *list, int get_hidden ); +/** + Returns tha absolute path of the file where the specified function + was defined. Returns 0 if the file was defined on the commandline. +*/ const wchar_t *function_get_definition_file( const wchar_t *name ); +/** + Returns the linenumber where the definition of the specified function started +*/ int function_get_definition_offset( const wchar_t *name ); #endif