diff --git a/builtin.c b/builtin.c index 5089765a2..8514dad8d 100644 --- a/builtin.c +++ b/builtin.c @@ -61,6 +61,8 @@ #include "translate.h" #include "halloc.h" #include "halloc_util.h" +#include "parse_util.h" +#include "expand.h" /** The default prompt for the read command @@ -1941,9 +1943,9 @@ static int builtin_source( wchar_t ** argv ) argc = builtin_count_args( argv ); - if( argc != 2 ) + if( argc < 2 ) { - sb_printf( sb_err, _( L"%ls: Expected exactly one argument, got %d\n" ), argv[0], argc ); + sb_printf( sb_err, _( L"%ls: Expected at least one argument, got %d\n" ), argv[0], argc ); builtin_print_help( argv[0], sb_err ); return 1; } @@ -1983,9 +1985,12 @@ static int builtin_source( wchar_t ** argv ) parser_push_block( SOURCE ); reader_push_current_filename( fn_intern ); - + + current_block->param1.source_dest = fn_intern; + parse_util_set_argv( argv+2); + res = reader_read( fd ); parser_pop_block(); if( res ) @@ -2008,7 +2013,6 @@ static int builtin_source( wchar_t ** argv ) return res; } - /** Make the specified job the first job of the job list. Moving jobs around in the list makes the list reflect the order in which the diff --git a/exec.c b/exec.c index e004d17f4..90d930bfa 100644 --- a/exec.c +++ b/exec.c @@ -39,6 +39,7 @@ #include "translate.h" #include "halloc.h" #include "halloc_util.h" +#include "parse_util.h" /** Prototype for the getpgid library function. The prototype for this @@ -789,9 +790,6 @@ void exec( job_t *j ) { case INTERNAL_FUNCTION: { - wchar_t **arg; - int i; - string_buffer_t sb; wchar_t * def = halloc_register( j, wcsdup( function_get_definition( p->argv[0] ))); //fwprintf( stderr, L"run function %ls\n", argv[0] ); @@ -805,26 +803,9 @@ void exec( job_t *j ) current_block->param2.function_call_process = p; current_block->param1.function_name = halloc_register( current_block, wcsdup( p->argv[0] ) ); - - if( builtin_count_args(p->argv)>1 ) - { - sb_init( &sb ); - - for( i=1, arg=p->argv+1; *arg; i++, arg++ ) - { - if( i != 1 ) - sb_append( &sb, ARRAY_SEP_STR ); - sb_append( &sb, *arg ); - } - - env_set( L"argv", (wchar_t *)sb.buff, ENV_LOCAL ); - sb_destroy( &sb ); - } - else - { - env_set( L"argv", 0, ENV_LOCAL ); - } - + + parse_util_set_argv( p->argv+1 ); + parser_forbid_function( p->argv[0] ); if( p->next ) diff --git a/parse_util.c b/parse_util.c index ade13fe17..ce5820b80 100644 --- a/parse_util.c +++ b/parse_util.c @@ -24,6 +24,7 @@ #include "expand.h" #include "intern.h" #include "exec.h" +#include "env.h" #include "halloc_util.h" /** @@ -599,3 +600,28 @@ int parse_util_load( const wchar_t *cmd, return reloaded; } +void parse_util_set_argv( wchar_t **argv ) +{ + if( *argv ) + { + wchar_t **arg; + string_buffer_t sb; + sb_init( &sb ); + + for( arg=argv; *arg; arg++ ) + { + if( arg != argv ) + sb_append( &sb, ARRAY_SEP_STR ); + sb_append( &sb, *arg ); + } + + env_set( L"argv", (wchar_t *)sb.buff, ENV_LOCAL ); + sb_destroy( &sb ); + } + else + { + env_set( L"argv", 0, ENV_LOCAL ); + } +} + +