Add syntax check to see that the for builtin is not given an insufficient number of arguments

darcs-hash:20060926124109-ac50b-b088397933fa7ea539e48fa9fcd461de8295f7ce.gz
This commit is contained in:
axel 2006-09-26 22:41:09 +10:00
parent b71f5d09b0
commit d0f1870735
3 changed files with 42 additions and 1 deletions

View file

@ -2454,7 +2454,7 @@ static int builtin_for( wchar_t **argv )
if( argc < 3)
{
sb_printf( sb_err,
_( L"%ls: Expected at least two arguments, got %d\n"),
BUILTIN_FOR_ERR_COUNT,
argv[0] ,
argc );
builtin_print_help( argv[0], sb_err );

View file

@ -62,6 +62,11 @@ enum
*/
#define BUILTIN_FOR_ERR_IN _( L"%ls: Second argument must be 'in'\n" )
/**
Error message for insufficient number of arguments
*/
#define BUILTIN_FOR_ERR_COUNT _( L"%ls: Expected at least two arguments, got %d\n")
/**
Error message when too many arguments are supplied to a builtin
*/

View file

@ -3043,6 +3043,8 @@ int parser_test( const wchar_t * buff,
current_tokenizer_pos = tok_get_pos( &tok );
int last_type = tok_last_type( &tok );
int end_of_cmd = 0;
switch( last_type )
{
case TOK_STRING:
@ -3512,6 +3514,8 @@ int parser_test( const wchar_t * buff,
had_cmd = 0;
is_pipeline=0;
forbid_pipeline=0;
end_of_cmd = 1;
break;
}
@ -3558,6 +3562,8 @@ int parser_test( const wchar_t * buff,
needs_cmd=1;
is_pipeline=1;
had_cmd=0;
end_of_cmd = 1;
}
break;
}
@ -3590,6 +3596,7 @@ int parser_test( const wchar_t * buff,
}
had_cmd = 0;
end_of_cmd = 1;
break;
}
@ -3610,6 +3617,35 @@ int parser_test( const wchar_t * buff,
}
break;
}
if( end_of_cmd )
{
if( cmd && wcscmp( cmd, L"for" ) == 0 )
{
if( arg_count >= 0 && arg_count < 2 )
{
/*
Not enough arguments to the for builtin
*/
err = 1;
if( out )
{
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
BUILTIN_FOR_ERR_COUNT,
L"for",
arg_count );
print_errors( out, prefix );
}
}
}
}
}
if( needs_cmd )