mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Change syntax of 'and' and 'or' to infix order
darcs-hash:20060105153753-ac50b-4413a5d2652232bb38c97f5c673251193fc848ec.gz
This commit is contained in:
parent
6a0460f51e
commit
f6b2b9f9a5
7 changed files with 25 additions and 84 deletions
|
@ -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" ),
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
74
parser.c
74
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() );
|
||||
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( 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() );
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
2
parser.h
2
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 */
|
||||
}
|
||||
;
|
||||
|
||||
|
|
3
proc.h
3
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue