More work towards supporting builtin scripts

This commit is contained in:
ridiculousfish 2012-01-03 10:54:06 -08:00
parent 6abf3db13e
commit 04c7d87261
5 changed files with 41 additions and 21 deletions

View file

@ -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 = "<group>"; };
D049018914B3802E003CEFBC /* builtin_scripts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = builtin_scripts.h; sourceTree = "<group>"; };
D0A0850313B3ACEE0099B651 /* builtin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = builtin.h; sourceTree = "<group>"; };
D0A0850413B3ACEE0099B651 /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = "<group>"; };
D0A0850513B3ACEE0099B651 /* complete.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = complete.h; sourceTree = "<group>"; };
@ -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 */,

View file

@ -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 );

View file

@ -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')

View file

@ -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<wcstring> &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
*/

View file

@ -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 );