aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-15 05:56:36 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-15 05:56:36 +1000
commit3e165297ce4a2f29117ff957c0e8946e0dd8b3ef (patch)
treed7b3e7ed6470880d093781702c3321b5ae23f8af
parent7ac922def63ec365973a447d0b5a40b942e5a502 (diff)
Add support for sending arguments whenusing the source builtin
darcs-hash:20060214195636-ac50b-511c211368103df6923d63cef99ce20a88d31be3.gz
-rw-r--r--builtin.c12
-rw-r--r--exec.c27
-rw-r--r--parse_util.c26
3 files changed, 38 insertions, 27 deletions
diff --git a/builtin.c b/builtin.c
index 5089765a..8514dad8 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 e004d17f..90d930bf 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 ade13fe1..ce5820b8 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 );
+ }
+}
+
+