Migrate functions like parser_keywords_is_block to wcstring

This commit is contained in:
ridiculousfish 2012-01-30 09:46:33 -08:00
parent f988dcd6f9
commit 8e4e30d266
6 changed files with 42 additions and 20 deletions

View file

@ -607,16 +607,16 @@ const wchar_t *wsetlocale(int category, const wchar_t *locale)
return (wchar_t *)setlocale_buff->buff;
}
int contains_internal( const wchar_t *a, ... )
bool contains_internal( const wchar_t *a, ... )
{
wchar_t *arg;
const wchar_t *arg;
va_list va;
int res = 0;
CHECK( a, 0 );
va_start( va, a );
while( (arg=va_arg(va, wchar_t *) )!= 0 )
while( (arg=va_arg(va, const wchar_t *) )!= 0 )
{
if( wcscmp( a,arg) == 0 )
{
@ -626,7 +626,28 @@ int contains_internal( const wchar_t *a, ... )
}
va_end( va );
return res;
return res;
}
/* wcstring variant of contains_internal. The first parameter is a wcstring, the rest are const wchar_t* */
__sentinel bool contains_internal( const wcstring &needle, ... )
{
const wchar_t *arg;
va_list va;
int res = 0;
va_start( va, needle );
while( (arg=va_arg(va, const wchar_t *) )!= 0 )
{
if( needle == arg)
{
res=1;
break;
}
}
va_end( va );
return res;
}
int read_blocked(int fd, void *buf, size_t count)

View file

@ -440,7 +440,8 @@ const wchar_t *wsetlocale( int category, const wchar_t *locale );
\return zero if needle is not found, of if needle is null, non-zero otherwise
*/
__sentinel int contains_internal( const wchar_t *needle, ... );
__sentinel bool contains_internal( const wchar_t *needle, ... );
__sentinel bool contains_internal( const wcstring &needle, ... );
/**
Call read while blocking the SIGCHLD signal. Should only be called

View file

@ -646,7 +646,7 @@ void tokenize( const wchar_t * const buff, int * const color, const int pos, arr
int mark = tok_get_pos( &tok );
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMAND;
if( parser_keywords_is_subcommand( cmd.c_str() ) )
if( parser_keywords_is_subcommand( cmd ) )
{
int sw;
@ -668,7 +668,7 @@ void tokenize( const wchar_t * const buff, int * const color, const int pos, arr
sw = parser_keywords_is_switch( tok_last( &tok ) );
if( !parser_keywords_is_block( cmd.c_str() ) &&
if( !parser_keywords_is_block( cmd ) &&
sw == ARG_SWITCH )
{
/*

View file

@ -1887,7 +1887,7 @@ int parser_t::parse_job( process_t *p,
builtin_exists(args->at(0).completion.c_str()))
{
p->type = INTERNAL_BUILTIN;
is_new_block |= parser_keywords_is_block( args->at( 0 ).completion.c_str() );
is_new_block |= parser_keywords_is_block( args->at( 0 ).completion );
}
}

View file

@ -14,15 +14,15 @@ Functions having to do with parser keywords, like testing if a function is a blo
#include "parser_keywords.h"
int parser_keywords_is_switch( const wchar_t *cmd )
bool parser_keywords_is_switch( const wcstring &cmd )
{
if( wcscmp( cmd, L"--" ) == 0 )
if( cmd == L"--" )
return ARG_SKIP;
else
return cmd[0] == L'-';
return ! cmd.empty() && cmd.at(0) == L'-';
}
int parser_keywords_skip_arguments( const wchar_t *cmd )
bool parser_keywords_skip_arguments( const wcstring &cmd )
{
return contains( cmd,
L"else",
@ -30,7 +30,7 @@ int parser_keywords_skip_arguments( const wchar_t *cmd )
}
int parser_keywords_is_subcommand( const wchar_t *cmd )
bool parser_keywords_is_subcommand( const wcstring &cmd )
{
return parser_keywords_skip_arguments( cmd ) ||
@ -46,7 +46,7 @@ int parser_keywords_is_subcommand( const wchar_t *cmd )
}
int parser_keywords_is_block( const wchar_t *word)
bool parser_keywords_is_block( const wcstring &word)
{
return contains( word,
L"for",
@ -57,7 +57,7 @@ int parser_keywords_is_block( const wchar_t *word)
L"begin" );
}
int parser_keywords_is_reserved( const wchar_t *word)
bool parser_keywords_is_reserved( const wcstring &word)
{
return parser_keywords_is_block(word) ||
parser_keywords_is_subcommand( word ) ||

View file

@ -23,7 +23,7 @@ enum
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_keywords_is_switch( const wchar_t *cmd );
bool parser_keywords_is_switch( const wcstring &cmd );
/**
@ -33,7 +33,7 @@ int parser_keywords_is_switch( const wchar_t *cmd );
\return 1 of the command parameter is a command, 0 otherwise
*/
int parser_keywords_is_subcommand( const wchar_t *cmd );
bool parser_keywords_is_subcommand( const wcstring &cmd );
/**
Tests if the specified command is a reserved word, i.e. if it is
@ -44,20 +44,20 @@ int parser_keywords_is_subcommand( const wchar_t *cmd );
\param word The command name to test
\return 1 of the command parameter is a command, 0 otherwise
*/
int parser_keywords_is_reserved( const wchar_t *word );
bool parser_keywords_is_reserved( const wcstring &word );
/**
Test if the specified string is command that opens a new block
*/
int parser_keywords_is_block( const wchar_t *word);
bool parser_keywords_is_block( const wcstring &word);
/**
Check if the specified command is one of the builtins that cannot
have arguments, any followin argument is interpreted as a new
command
*/
int parser_keywords_skip_arguments( const wchar_t *cmd );
bool parser_keywords_skip_arguments( const wcstring &cmd );
#endif