From 51c345311a3922cd8753ae3b172d148b6d189cfe Mon Sep 17 00:00:00 2001 From: axel Date: Wed, 30 Nov 2005 05:50:30 +1000 Subject: [PATCH] Make the not builtin work with shellscript functions darcs-hash:20051129195030-ac50b-7ada30d327f2dcc8ad23f56b0a36c975cb90c481.gz --- exec.c | 24 +++++++++++++----------- expand.c | 6 ++++-- function.h | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/exec.c b/exec.c index 739e2bf1e..e95023c6b 100644 --- a/exec.c +++ b/exec.c @@ -941,15 +941,23 @@ void exec( job_t *j ) case INTERNAL_FUNCTION: { int status = proc_get_last_status(); - + /* Handle output from a block or function. This usually means do nothing, but in the case of pipes, we have - to buffer such io, since otherwisethe internal pipe + to buffer such io, since otherwise the internal pipe buffer might overflow. */ if( !io_buffer ) { + /* + No buffer, se we exit directly. This means we + have to manually set the exit status. + */ + if( p->next == 0 ) + { + proc_set_last_status( j->negate?(status?0:1):status); + } p->completed = 1; break; } @@ -960,8 +968,6 @@ void exec( job_t *j ) if( io_buffer->param2.out_buffer->used != 0 ) { - - pid = fork(); if( pid == 0 ) { @@ -1044,7 +1050,6 @@ void exec( job_t *j ) { debug( 3, L"Set status of %ls to %d using short circut", j->command, p->status ); - proc_set_last_status( p->status ); proc_set_last_status( j->negate?(p->status?0:1):p->status ); } break; @@ -1093,10 +1098,7 @@ void exec( job_t *j ) case EXTERNAL: { - -// fwprintf( stderr, -// L"fork on %ls\n", j->command ); - pid = fork (); + pid = fork(); if( pid == 0 ) { /* @@ -1114,8 +1116,8 @@ void exec( job_t *j ) { /* The fork failed. */ debug( 0, FORK_ERROR ); - wperror (L"fork"); - exit (1); + wperror( L"fork" ); + exit( 1 ); } else { diff --git a/expand.c b/expand.c index 6c9322f68..96b887046 100644 --- a/expand.c +++ b/expand.c @@ -92,7 +92,8 @@ parameter expansion. any tokens which need to be expanded or otherwise altered. Clean strings can be passed through expand_string and expand_one without changing them. About 90% of all strings are clean, so skipping - expantion on them actually does save a small amount of time. + expantion on them actually does save a small amount of time, since + it avoids multiple memory allocations during the expantion process. */ static int is_clean( const wchar_t *in ) { @@ -339,7 +340,8 @@ static int match_pid( const wchar_t *cmd, Searches for a job with the specified job id, or a job or process which has the string \c proc as a prefix of its commandline. - If accept_incomplete is true, the remaining string for any matches are inserted. + If accept_incomplete is true, the remaining string for any matches + are inserted. If accept_incomplete is false, any job matching the specified string is matched, and the job pgid is returned. If no job diff --git a/function.h b/function.h index 30b1d0d9f..cb4930dd8 100644 --- a/function.h +++ b/function.h @@ -58,7 +58,7 @@ void function_set_desc( const wchar_t *name, const wchar_t *desc ); /** Returns true if the function witrh the name name exists. */ -int function_exists( const wchar_t *name); +int function_exists( const wchar_t *name ); /** Insert all function names into l. These are not copies of the strings and should not be freed after use.