aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-12-14 11:35:37 +1000
committerGravatar axel <axel@liljencrantz.se>2006-12-14 11:35:37 +1000
commit997f2dffbf52584899830d8d123d8557c7ec4b54 (patch)
tree2380f2cfb5b0ba0fa3354401390292e6c06565e0
parent1289e0313491576d90b257e1d4bc6786c902f510 (diff)
Make syntax highlighter flag invalid command types as subcommands for 'command' or 'builtin' builtins. Also make sure that the '--' switch is understood by the highlighter
darcs-hash:20061214013537-ac50b-9d84fe371eed10ce48ade5ebe88b00442658d67a.gz
-rw-r--r--highlight.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/highlight.c b/highlight.c
index bc386003..be8dcbd4 100644
--- a/highlight.c
+++ b/highlight.c
@@ -542,6 +542,10 @@ void highlight_shell( wchar_t * buff,
wchar_t *cmd=0;
int accept_switches = 1;
+ int use_function = 1;
+ int use_command = 1;
+ int use_builtin = 1;
+
CHECK( buff, );
CHECK( color, );
@@ -640,6 +644,19 @@ void highlight_shell( wchar_t * buff,
if( parser_is_subcommand( cmd ) )
{
+ if( wcscmp( cmd, L"builtin" )==0)
+ {
+ use_function = 0;
+ use_command = 0;
+ use_builtin = 1;
+ }
+ else if( wcscmp( cmd, L"command" )==0)
+ {
+ use_command = 1;
+ use_function = 0;
+ use_builtin = 0;
+ }
+
tok_next( &tok );
if( !parser_is_block( cmd ) &&
parser_is_help( tok_last( &tok ), 3) )
@@ -654,6 +671,12 @@ void highlight_shell( wchar_t * buff,
}
else
{
+ if( wcscmp( tok_last( &tok ), L"--" ) == 0 )
+ {
+ color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
+ mark = tok_get_pos( &tok );
+ }
+
is_subcommand = 1;
}
tok_set_pos( &tok, mark );
@@ -674,8 +697,11 @@ void highlight_shell( wchar_t * buff,
function, since we don't have to stat
any files for that
*/
- is_cmd |= builtin_exists( cmd );
- is_cmd |= function_exists( cmd );
+ if( use_builtin )
+ is_cmd |= builtin_exists( cmd );
+
+ if( use_function )
+ is_cmd |= function_exists( cmd );
/*
Moving on to expensive tests
@@ -684,13 +710,15 @@ void highlight_shell( wchar_t * buff,
/*
Check if this is a regular command
*/
- is_cmd |= !!(tmp=path_get_path( context, cmd ));
+ if( use_command )
+ is_cmd |= !!(tmp=path_get_path( context, cmd ));
/*
Could not find the command. Maybe it is
a path for a implicit cd command.
*/
- is_cmd |= !!(tmp=path_get_cdpath( context, cmd ));
+ if( use_builtin || (use_function && function_exists( L"cd") ) )
+ is_cmd |= !!(tmp=path_get_cdpath( context, cmd ));
if( is_cmd )
{
@@ -803,6 +831,9 @@ void highlight_shell( wchar_t * buff,
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_END;
had_cmd = 0;
+ use_command = 1;
+ use_function = 1;
+ use_builtin = 1;
accept_switches = 1;
}
else
@@ -819,6 +850,9 @@ void highlight_shell( wchar_t * buff,
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_END;
had_cmd = 0;
+ use_command = 1;
+ use_function = 1;
+ use_builtin = 1;
accept_switches = 1;
break;
}