Change syntax of 'and' and 'or' to infix order

darcs-hash:20060105153753-ac50b-4413a5d2652232bb38c97f5c673251193fc848ec.gz
This commit is contained in:
axel 2006-01-06 01:37:53 +10:00
parent 6a0460f51e
commit f6b2b9f9a5
7 changed files with 25 additions and 84 deletions

View file

@ -2807,9 +2807,7 @@ static int builtin_begin( wchar_t **argv )
*/ */
static int builtin_end( wchar_t **argv ) static int builtin_end( wchar_t **argv )
{ {
if( !current_block->outer || if( !current_block->outer )
current_block->type == OR ||
current_block->type == AND )
{ {
sb_printf( sb_err, sb_printf( sb_err,
_( L"%ls: Not inside of block\n" ), _( L"%ls: Not inside of block\n" ),

View file

@ -2,22 +2,16 @@
\section and and - Conditionally execute a command \section and and - Conditionally execute a command
\subsection and-synopsis Synopsis \subsection and-synopsis Synopsis
<tt>and COMMAND1; COMMAND2</tt> <tt>COMMAND1; and COMMAND2</tt>
\subsection and-description Description \subsection and-description Description
The \c and builtin is used to execute one command, and if it returns The \c and builtin is used to execute a command if the current exit status (as set by the last previous command) is zero
zero status, also execute a second command.
\subsection and-example Example \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. 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> <pre>
and make; make install make; and make install
</pre> </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>

View file

@ -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. 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#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#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#begin">begin</a>, execute a block of commands
- <a href="builtins.html#bind">bind</a>, change keyboard bindings - <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#mimedb">mimedb</a>, view mimedata about a file
- <a href="commands.html#nextd">nextd</a>, move forward in the directory history - <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#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#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#prevd">prevd</a>, move backwards in the direcotry stack
- <a href="commands.html#pushd">pushd</a>, push the surrent directory onto the directory stack - <a href="commands.html#pushd">pushd</a>, push the surrent directory onto the directory stack

View file

@ -2,22 +2,16 @@
\section or or - Conditionally execute a command \section or or - Conditionally execute a command
\subsection or-synopsis Synopsis \subsection or-synopsis Synopsis
<tt>or COMMAND1; COMMAND2</tt> <tt>COMMAND1; or COMMAND2</tt>
\subsection or-description Description \subsection or-description Description
The \c or builtin is used to execute one command, and if it returns 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
non-zero status, also execute a second command.
\subsection or-example Example \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 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> <pre>
or make; make clean make; or make clean
</pre> </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>

View file

@ -221,18 +221,6 @@ The fish parser. Contains functions for parsing code.
#define BEGIN_BLOCK _( L"unconditional block" ) #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 Unknown block description
*/ */
@ -354,8 +342,6 @@ void parser_push_block( int type )
if( (new->type != FUNCTION_DEF) && if( (new->type != FUNCTION_DEF) &&
(new->type != FAKE) && (new->type != FAKE) &&
(new->type != OR) &&
(new->type != AND) &&
(new->type != TOP) ) (new->type != TOP) )
{ {
env_push( type == FUNCTION_CALL ); env_push( type == FUNCTION_CALL );
@ -370,8 +356,6 @@ void parser_pop_block()
if( (current_block->type != FUNCTION_DEF ) && if( (current_block->type != FUNCTION_DEF ) &&
(current_block->type != FAKE) && (current_block->type != FAKE) &&
(current_block->type != OR) &&
(current_block->type != AND) &&
(current_block->type != TOP) ) (current_block->type != TOP) )
{ {
env_pop(); env_pop();
@ -452,12 +436,6 @@ const wchar_t *parser_get_block_desc( int block )
case BEGIN: case BEGIN:
return BEGIN_BLOCK; return BEGIN_BLOCK;
case AND:
return AND_BLOCK;
case OR:
return OR_BLOCK;
default: default:
return UNKNOWN_BLOCK; return UNKNOWN_BLOCK;
} }
@ -1570,7 +1548,7 @@ static int parse_job( process_t *p,
} }
else else
{ {
parser_push_block( AND ); j->skip = proc_get_last_status();
free( nxt ); free( nxt );
continue; continue;
} }
@ -1584,7 +1562,7 @@ static int parse_job( process_t *p,
} }
else else
{ {
parser_push_block( OR ); j->skip = !proc_get_last_status();
free( nxt ); free( nxt );
continue; continue;
} }
@ -1987,18 +1965,6 @@ static void eval_job( tokenizer *tok )
j->first_process = calloc( 1, sizeof( process_t ) ); 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 ) && if( parse_job( j->first_process, j, tok ) &&
j->first_process->argv ) j->first_process->argv )
@ -2026,6 +1992,7 @@ static void eval_job( tokenizer *tok )
skip |= current_block->skip; skip |= current_block->skip;
skip |= j->wildcard_error; skip |= j->wildcard_error;
skip |= j->skip;
if(!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() ); //debug( 2, L"Status %d\n", proc_get_last_status() );
switch( prev_block_type ) debug( 1,
{ L"%ls", parser_get_block_desc( current_block->type ) );
case OR: debug( 1,
case AND: BLOCK_END_ERR_MSG );
debug( 1, fwprintf( stderr, L"%ls", parser_current_line() );
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() );
h = builtin_help_get( L"end" ); h = builtin_help_get( L"end" );
if( h ) if( h )
fwprintf( stderr, L"%s", h ); fwprintf( stderr, L"%s", h );
break; break;
}
} }
prev_block_type = current_block->type; prev_block_type = current_block->type;
@ -2395,7 +2347,7 @@ int parser_test( wchar_t * buff,
} }
} }
require_additional_commands=2; require_additional_commands=1;
} }
/* /*

View file

@ -115,8 +115,6 @@ enum block_type
SUBST, /**< Command substitution scope */ SUBST, /**< Command substitution scope */
TOP, /**< Outermost block */ TOP, /**< Outermost block */
BEGIN, /**< Unconditional block */ BEGIN, /**< Unconditional block */
AND, /**< And block */
OR, /**< Or block */
} }
; ;

3
proc.h
View file

@ -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 */ /** This flag is set to one on wildcard expansion errors. It means that the current command should not be executed */
int wildcard_error; 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 */ /** Pointer to the next job */
struct job *next; struct job *next;
} }