mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Add support for sending arguments whenusing the source builtin
darcs-hash:20060214195636-ac50b-511c211368103df6923d63cef99ce20a88d31be3.gz
This commit is contained in:
parent
7ac922def6
commit
3e165297ce
3 changed files with 38 additions and 27 deletions
12
builtin.c
12
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
|
||||
|
|
27
exec.c
27
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 )
|
||||
|
|
26
parse_util.c
26
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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue