diff --git a/builtin.c b/builtin.c index 1ac1110e0..7c5267c6a 100644 --- a/builtin.c +++ b/builtin.c @@ -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 ); diff --git a/builtin.h b/builtin.h index 4b0c72a88..c8610313d 100644 --- a/builtin.h +++ b/builtin.h @@ -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 */ diff --git a/parser.c b/parser.c index 3c9d4c89d..c7088ff4c 100644 --- a/parser.c +++ b/parser.c @@ -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 )