diff --git a/builtin.c b/builtin.c index 34e16ac7d..d62b0c914 100644 --- a/builtin.c +++ b/builtin.c @@ -2807,9 +2807,7 @@ static int builtin_begin( wchar_t **argv ) */ static int builtin_end( wchar_t **argv ) { - if( !current_block->outer || - current_block->type == OR || - current_block->type == AND ) + if( !current_block->outer ) { sb_printf( sb_err, _( L"%ls: Not inside of block\n" ), diff --git a/doc_src/and.txt b/doc_src/and.txt index ca454bce6..9de49192e 100644 --- a/doc_src/and.txt +++ b/doc_src/and.txt @@ -2,22 +2,16 @@ \section and and - Conditionally execute a command \subsection and-synopsis Synopsis - and COMMAND1; COMMAND2 + COMMAND1; and COMMAND2 \subsection and-description Description -The \c and builtin is used to execute one command, and if it returns -zero status, also execute a second command. +The \c and builtin is used to execute a command if the current exit status (as set by the last previous command) is zero \subsection and-example Example The following code runs the \c make command to build a program, and if it suceeds, it runs make install, which installs the program.
-and make; make install +make; and make install-\c or and \c and can be nested, as in this example, that attempts to build and install a program, and removed the files created by the build process on failiure - -
-or and make; make install; make clean -diff --git a/doc_src/doc.hdr b/doc_src/doc.hdr index 7c1c4856b..3795eb738 100644 --- a/doc_src/doc.hdr +++ b/doc_src/doc.hdr @@ -678,6 +678,7 @@ The following commands are distributed with fish. Many of them are builtins or shellscript functions, and can only be used inside fish. - ., read and execute the commands in a file +- and, execute second command if first suceeds - bg, set a command to the background - begin, execute a block of commands - bind, change keyboard bindings @@ -709,6 +710,7 @@ builtins or shellscript functions, and can only be used inside fish. - mimedb, view mimedata about a file - nextd, move forward in the directory history - not, negates the exit status of any command +- or, execute second command if first fails - popd, move to the topmost directory on the directory stack - prevd, move backwards in the direcotry stack - pushd, push the surrent directory onto the directory stack diff --git a/doc_src/or.txt b/doc_src/or.txt index 3fc40f3ce..d84e82864 100644 --- a/doc_src/or.txt +++ b/doc_src/or.txt @@ -2,22 +2,16 @@ \section or or - Conditionally execute a command \subsection or-synopsis Synopsis - or COMMAND1; COMMAND2 + COMMAND1; or COMMAND2 \subsection or-description Description -The \c or builtin is used to execute one command, and if it returns -non-zero status, also execute a second command. +The \c or builtin is used to execute a command if the current exit status (as set by the last previous command) is non-zero \subsection or-example Example The following code runs the \c make command to build a program, or if it fails, it runs make clean, which removes the files created by the build process
-or make; make clean +make; or make clean-\c or and \c and can be nested, as in this example, that attempts to build and install a program, and removed the files created by the build process on failiure - -
-or and make; make install; make clean -diff --git a/parser.c b/parser.c index 64f68f3a0..d0db20c41 100644 --- a/parser.c +++ b/parser.c @@ -221,18 +221,6 @@ The fish parser. Contains functions for parsing code. #define BEGIN_BLOCK _( L"unconditional block" ) -/** - And block description -*/ -#define AND_BLOCK _( L"'and' conditional block" ) - - -/** - block description -*/ -#define OR_BLOCK _( L"'or' conditional block" ) - - /** Unknown block description */ @@ -354,8 +342,6 @@ void parser_push_block( int type ) if( (new->type != FUNCTION_DEF) && (new->type != FAKE) && - (new->type != OR) && - (new->type != AND) && (new->type != TOP) ) { env_push( type == FUNCTION_CALL ); @@ -370,8 +356,6 @@ void parser_pop_block() if( (current_block->type != FUNCTION_DEF ) && (current_block->type != FAKE) && - (current_block->type != OR) && - (current_block->type != AND) && (current_block->type != TOP) ) { env_pop(); @@ -452,12 +436,6 @@ const wchar_t *parser_get_block_desc( int block ) case BEGIN: return BEGIN_BLOCK; - case AND: - return AND_BLOCK; - - case OR: - return OR_BLOCK; - default: return UNKNOWN_BLOCK; } @@ -1570,7 +1548,7 @@ static int parse_job( process_t *p, } else { - parser_push_block( AND ); + j->skip = proc_get_last_status(); free( nxt ); continue; } @@ -1584,7 +1562,7 @@ static int parse_job( process_t *p, } else { - parser_push_block( OR ); + j->skip = !proc_get_last_status(); free( nxt ); continue; } @@ -1987,18 +1965,6 @@ static void eval_job( tokenizer *tok ) j->first_process = calloc( 1, sizeof( process_t ) ); - /* Copy the command name */ - if( current_block->type == OR ) - { - skip = (proc_get_last_status() == 0 ); - parser_pop_block(); - } - else if( current_block->type == AND ) - { - skip = (proc_get_last_status() != 0 ); - parser_pop_block(); - } - if( parse_job( j->first_process, j, tok ) && j->first_process->argv ) @@ -2026,6 +1992,7 @@ static void eval_job( tokenizer *tok ) skip |= current_block->skip; skip |= j->wildcard_error; + skip |= j->skip; if(!skip ) { @@ -2205,31 +2172,16 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type ) //debug( 2, L"Status %d\n", proc_get_last_status() ); - switch( prev_block_type ) - { - case OR: - case AND: - debug( 1, - COND_ERR_MSG ); - fwprintf( stderr, L"%ls", parser_current_line() ); - - h = builtin_help_get( prev_block_type == OR? L"or": L"and" ); - if( h ) - fwprintf( stderr, L"%s", h ); - break; - - default: - debug( 1, - L"%ls", parser_get_block_desc( current_block->type ) ); - debug( 1, - BLOCK_END_ERR_MSG ); - fwprintf( stderr, L"%ls", parser_current_line() ); + debug( 1, + L"%ls", parser_get_block_desc( current_block->type ) ); + debug( 1, + BLOCK_END_ERR_MSG ); + fwprintf( stderr, L"%ls", parser_current_line() ); - h = builtin_help_get( L"end" ); - if( h ) - fwprintf( stderr, L"%s", h ); - break; - } + h = builtin_help_get( L"end" ); + if( h ) + fwprintf( stderr, L"%s", h ); + break; } prev_block_type = current_block->type; @@ -2395,7 +2347,7 @@ int parser_test( wchar_t * buff, } } - require_additional_commands=2; + require_additional_commands=1; } /* diff --git a/parser.h b/parser.h index 0c23b1dd1..0c5725510 100644 --- a/parser.h +++ b/parser.h @@ -115,8 +115,6 @@ enum block_type SUBST, /**< Command substitution scope */ TOP, /**< Outermost block */ BEGIN, /**< Unconditional block */ - AND, /**< And block */ - OR, /**< Or block */ } ; diff --git a/proc.h b/proc.h index c0647018e..b26b31e54 100644 --- a/proc.h +++ b/proc.h @@ -152,6 +152,9 @@ typedef struct job /** This flag is set to one on wildcard expansion errors. It means that the current command should not be executed */ int wildcard_error; + /** Skip executing this job. This flag is set by the short-circut builtins, i.e. and and or */ + int skip; + /** Pointer to the next job */ struct job *next; }