From c1945f8275fdf31220fcd8dccbf36d02e69278fa Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 14 Dec 2006 23:40:25 +1000 Subject: [PATCH] Minor highlighting tweaks to make highlighter handle switches to 'command' and 'builtin' builtins more correctly darcs-hash:20061214134025-ac50b-e17f79d1d4d7594ab20a358296f84dbb6356f42b.gz --- highlight.c | 17 +++++++++++++---- parser.c | 15 +-------------- parser.h | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/highlight.c b/highlight.c index be8dcbd48..47d1ad749 100644 --- a/highlight.c +++ b/highlight.c @@ -644,6 +644,9 @@ void highlight_shell( wchar_t * buff, if( parser_is_subcommand( cmd ) ) { + + int sw; + if( wcscmp( cmd, L"builtin" )==0) { use_function = 0; @@ -658,20 +661,26 @@ void highlight_shell( wchar_t * buff, } tok_next( &tok ); + + sw = parser_is_switch( tok_last( &tok ) ); + if( !parser_is_block( cmd ) && - parser_is_help( tok_last( &tok ), 3) ) + sw == ARG_SWITCH ) { /* The 'builtin' and 'command' builtins are normally followed by another command, but if they are invoked - with the -h option, their help text - is displayed instead + with a switch, they aren't. + */ + use_command = 1; + use_function = 1; + use_builtin = 2; } else { - if( wcscmp( tok_last( &tok ), L"--" ) == 0 ) + if( sw == ARG_SKIP ) { color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM; mark = tok_get_pos( &tok ); diff --git a/parser.c b/parser.c index 6c0fae480..6daddaa91 100644 --- a/parser.c +++ b/parser.c @@ -510,20 +510,7 @@ static int parser_skip_arguments( const wchar_t *cmd ) (void *)0 ); } -enum -{ - ARG_NON_SWITCH, - ARG_SWITCH, - ARG_SKIP -} - ; - - -/** - Check if the specified argument is a switch. Return ARG_SWITCH if yes, - ARG_NON_SWITCH if no and ARG_SKIP if the argument is '--' -*/ -static int parser_is_switch( const wchar_t *cmd ) +int parser_is_switch( const wchar_t *cmd ) { if( wcscmp( cmd, L"--" ) == 0 ) return ARG_SKIP; diff --git a/parser.h b/parser.h index 7bf6b8866..2fccf9750 100644 --- a/parser.h +++ b/parser.h @@ -15,6 +15,17 @@ #define PARSER_TEST_ERROR 1 #define PARSER_TEST_INCOMPLETE 2 +/** + REturn valuse for parser_is_switch() +*/ +enum +{ + ARG_NON_SWITCH, + ARG_SWITCH, + ARG_SKIP +} + ; + /** event_block_t represents a block on events of the specified type */ @@ -220,6 +231,13 @@ int eval_args( const wchar_t *line, void error( int ec, int p, const wchar_t *str, ... ); +/** + Check if the specified argument is a switch. Return ARG_SWITCH if yes, + ARG_NON_SWITCH if no and ARG_SKIP if the argument is '--' +*/ +int parser_is_switch( const wchar_t *cmd ); + + /** Tests if the specified commands parameters should be interpreted as another command, which will be true if the command is either 'command', 'exec', 'if', 'while' or 'builtin'.