From 04c7d872614dc2b4a7bff12dd30d461da9b81881 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 3 Jan 2012 10:54:06 -0800 Subject: [PATCH] More work towards supporting builtin scripts --- FishsFish.xcodeproj/project.pbxproj | 4 +++ fish.cpp | 2 +- internalize_scripts.py | 4 +-- parse_util.cpp | 48 +++++++++++++++++++---------- parse_util.h | 4 +-- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/FishsFish.xcodeproj/project.pbxproj b/FishsFish.xcodeproj/project.pbxproj index 26015f3ad..feefbbd95 100644 --- a/FishsFish.xcodeproj/project.pbxproj +++ b/FishsFish.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXFileReference section */ + D049018814B3802E003CEFBC /* builtin_scripts.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_scripts.cpp; sourceTree = ""; }; + D049018914B3802E003CEFBC /* builtin_scripts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = builtin_scripts.h; sourceTree = ""; }; D0A0850313B3ACEE0099B651 /* builtin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = builtin.h; sourceTree = ""; }; D0A0850413B3ACEE0099B651 /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = ""; }; D0A0850513B3ACEE0099B651 /* complete.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = complete.h; sourceTree = ""; }; @@ -120,6 +122,8 @@ D0A0853213B3ACEE0099B651 /* builtin_jobs.cpp */, D0A0853313B3ACEE0099B651 /* builtin_set.cpp */, D0A0853413B3ACEE0099B651 /* builtin_ulimit.cpp */, + D049018914B3802E003CEFBC /* builtin_scripts.h */, + D049018814B3802E003CEFBC /* builtin_scripts.cpp */, D0A0853513B3ACEE0099B651 /* builtin.cpp */, D0A0850413B3ACEE0099B651 /* common.h */, D0A0853613B3ACEE0099B651 /* common.cpp */, diff --git a/fish.cpp b/fish.cpp index 2758594ab..b44d48bd4 100644 --- a/fish.cpp +++ b/fish.cpp @@ -279,7 +279,6 @@ static int fish_parse_opt( int argc, char **argv, char **cmd_ptr ) int main( int argc, char **argv ) { struct stat tmp; - stat("----------FISH_HIT_MAIN----------", &tmp); int res=1; char *cmd=0; int my_optind=0; @@ -290,6 +289,7 @@ int main( int argc, char **argv ) is_interactive_session=1; program_name=L"fish"; + stat("----------FISH_HIT_MAIN----------", &tmp); my_optind = fish_parse_opt( argc, argv, &cmd ); diff --git a/internalize_scripts.py b/internalize_scripts.py index 8b447aa05..99f20445e 100755 --- a/internalize_scripts.py +++ b/internalize_scripts.py @@ -72,7 +72,7 @@ fd.write("""struct builtin_script_t { fd.write('\n') fd.write('\n') -fd.write('extern const struct builtin_script_t builtin_scripts[%d];\n' % len(funcs)) +fd.write('extern const struct builtin_script_t internal_function_scripts[%d];\n' % len(funcs)) fd.write('\n') fd.close() @@ -86,7 +86,7 @@ for func in funcs: # Output the refs func_refs = ["{%s, %s}" % (stringize(func.name), func.cfunc_name()) for func in funcs] -fd.write('const struct builtin_script_t builtin_scripts[%d] =\n' % len(funcs)) +fd.write('const struct builtin_script_t internal_function_scripts[%d] =\n' % len(funcs)) fd.write('{\n\t') fd.write(',\n\t'.join(func_refs)) fd.write('\n};\n') diff --git a/parse_util.cpp b/parse_util.cpp index 2b1872fd1..533e61a5a 100644 --- a/parse_util.cpp +++ b/parse_util.cpp @@ -36,6 +36,7 @@ #include "signal.h" #include "wildcard.h" #include "halloc_util.h" +#include "builtin_scripts.h" /** Maximum number of autoloaded items opf a specific type to keep in @@ -816,14 +817,16 @@ static void parse_util_autounload( const wchar_t *path_var_name, } static int parse_util_load_internal( const wchar_t *cmd, + const struct builtin_script_t *builtin_scripts, + size_t builtin_script_count, void (*on_load)(const wchar_t *cmd), int reload, autoload_t *loaded, const std::vector &path_list ); -int parse_util_load( const wchar_t *cmd, - const wchar_t *path_var_name, +int parse_util_load( const wcstring &cmd, + const wcstring &path_var_name, void (*on_load)(const wchar_t *cmd), int reload ) { @@ -834,15 +837,12 @@ int parse_util_load( const wchar_t *cmd, int res; int c, c2; - CHECK( path_var_name, 0 ); - CHECK( cmd, 0 ); - CHECK_BLOCK( 0 ); // debug( 0, L"Autoload %ls in %ls", cmd, path_var_name ); - parse_util_autounload( path_var_name, cmd, on_load ); - path_var = env_get( path_var_name ); + parse_util_autounload( path_var_name.c_str(), cmd.c_str(), on_load ); + path_var = env_get( path_var_name.c_str() ); /* Do we know where to look? @@ -866,7 +866,7 @@ int parse_util_load( const wchar_t *cmd, hash_init( all_loaded, &hash_wcs_func, &hash_wcs_cmp ); } - loaded = (autoload_t *)hash_get( all_loaded, path_var_name ); + loaded = (autoload_t *)hash_get( all_loaded, path_var_name.c_str() ); if( loaded ) { @@ -876,7 +876,7 @@ int parse_util_load( const wchar_t *cmd, */ if( wcscmp( path_var, loaded->old_path ) != 0 ) { - parse_util_load_reset( path_var_name, on_load); + parse_util_load_reset( path_var_name.c_str(), on_load); reload = parse_util_load( cmd, path_var_name, on_load, reload ); return reload; } @@ -884,12 +884,12 @@ int parse_util_load( const wchar_t *cmd, /** Warn and fail on infinite recursion */ - if( hash_get( &loaded->is_loading, cmd ) ) + if( hash_get( &loaded->is_loading, cmd.c_str() ) ) { debug( 0, _( L"Could not autoload item '%ls', it is already being autoloaded. " L"This is a circular dependency in the autoloading scripts, please remove it."), - cmd ); + cmd.c_str() ); return 1; } @@ -908,7 +908,7 @@ int parse_util_load( const wchar_t *cmd, DIE_MEM(); } hash_init( &loaded->load_time, &hash_wcs_func, &hash_wcs_cmp ); - hash_put( all_loaded, wcsdup(path_var_name), loaded ); + hash_put( all_loaded, wcsdup(path_var_name.c_str()), loaded ); hash_init( &loaded->is_loading, &hash_wcs_func, &hash_wcs_cmp ); @@ -920,21 +920,30 @@ int parse_util_load( const wchar_t *cmd, c = path_list.size(); - hash_put( &loaded->is_loading, cmd, cmd ); + hash_put( &loaded->is_loading, cmd.c_str(), cmd.c_str() ); + + /* Figure out which builtin-scripts array to search (if any) */ + const builtin_script_t *builtins = NULL; + size_t builtin_count = 0; + if (cmd == L"fish_function_path") + { + builtins = internal_function_scripts; + builtin_count = sizeof internal_function_scripts / sizeof *internal_function_scripts; + } /* Do the actual work in the internal helper function */ - res = parse_util_load_internal( cmd, on_load, reload, loaded, path_list ); + res = parse_util_load_internal( cmd.c_str(), builtins, builtin_count, on_load, reload, loaded, path_list ); - autoload_t *loaded2 = (autoload_t *)hash_get( all_loaded, path_var_name ); + autoload_t *loaded2 = (autoload_t *)hash_get( all_loaded, path_var_name.c_str() ); if( loaded2 == loaded ) { /** Cleanup */ - hash_remove( &loaded->is_loading, cmd, 0, 0 ); + hash_remove( &loaded->is_loading, cmd.c_str(), 0, 0 ); } c2 = path_list.size(); @@ -955,6 +964,8 @@ int parse_util_load( const wchar_t *cmd, */ static int parse_util_load_internal( const wchar_t *cmd, + const struct builtin_script_t *builtin_scripts, + size_t builtin_script_count, void (*on_load)(const wchar_t *cmd), int reload, autoload_t *loaded, @@ -998,6 +1009,11 @@ static int parse_util_load_internal( const wchar_t *cmd, sb_clear( path ); } + /* + Look for built-in scripts. + */ + + /* Iterate over path searching for suitable completion files */ diff --git a/parse_util.h b/parse_util.h index a1b0b74ec..4fa534024 100644 --- a/parse_util.h +++ b/parse_util.h @@ -122,8 +122,8 @@ int parse_util_get_offset( wchar_t *buff, int line, int line_offset ); \param on_unload a callback function to run if a suitable file is found, which has not already been run. unload will also be called for old files which are unloaded. \param reload wheter to recheck file timestamps on already loaded files */ -int parse_util_load( const wchar_t *cmd, - const wchar_t *path_var_name, +int parse_util_load( const wcstring &cmd, + const wcstring &path_var_name, void (*on_unload)(const wchar_t *cmd), int reload );