aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--builtin.c4
-rw-r--r--doc_src/and.txt12
-rw-r--r--doc_src/doc.hdr2
-rw-r--r--doc_src/or.txt12
-rw-r--r--parser.c74
-rw-r--r--parser.h2
-rw-r--r--proc.h3
7 files changed, 25 insertions, 84 deletions
diff --git a/builtin.c b/builtin.c
index 34e16ac7..d62b0c91 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 ca454bce..9de49192 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
- <tt>and COMMAND1; COMMAND2</tt>
+ <tt>COMMAND1; and COMMAND2</tt>
\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 <tt>make install</tt>, which installs the program.
<pre>
-and make; make install
+make; and make install
</pre>
-\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
-
-<pre>
-or and make; make install; make clean
-</pre>
diff --git a/doc_src/doc.hdr b/doc_src/doc.hdr
index 7c1c4856..3795eb73 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.
- <a href="builtins.html#source">.</a>, read and execute the commands in a file
+- <a href="builtins.html#and">and</a>, execute second command if first suceeds
- <a href="builtins.html#bg">bg</a>, set a command to the background
- <a href="builtins.html#begin">begin</a>, execute a block of commands
- <a href="builtins.html#bind">bind</a>, change keyboard bindings
@@ -709,6 +710,7 @@ builtins or shellscript functions, and can only be used inside fish.
- <a href="commands.html#mimedb">mimedb</a>, view mimedata about a file
- <a href="commands.html#nextd">nextd</a>, move forward in the directory history
- <a href="builtins.html#not">not</a>, negates the exit status of any command
+- <a href="builtins.html#or">or</a>, execute second command if first fails
- <a href="commands.html#popd">popd</a>, move to the topmost directory on the directory stack
- <a href="commands.html#prevd">prevd</a>, move backwards in the direcotry stack
- <a href="commands.html#pushd">pushd</a>, push the surrent directory onto the directory stack
diff --git a/doc_src/or.txt b/doc_src/or.txt
index 3fc40f3c..d84e8286 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
- <tt>or COMMAND1; COMMAND2</tt>
+ <tt>COMMAND1; or COMMAND2</tt>
\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 <tt>make clean</tt>, which removes the files created by the build process
<pre>
-or make; make clean
+make; or make clean
</pre>
-\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
-
-<pre>
-or and make; make install; make clean
-</pre>
diff --git a/parser.c b/parser.c
index 64f68f3a..d0db20c4 100644
--- a/parser.c
+++ b/parser.c
@@ -222,18 +222,6 @@ The fish parser. Contains functions for parsing code.
/**
- And block description
-*/
-#define AND_BLOCK _( L"'and' conditional block" )
-
-
-/**
- block description
-*/
-#define OR_BLOCK _( L"'or' conditional block" )
-
-
-/**
Unknown block description
*/
#define UNKNOWN_BLOCK _( L"unknown/invalid block" )
@@ -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 0c23b1dd..0c572551 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 c0647018..b26b31e5 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;
}