mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Add more descriptive error messages when trying to use variables in command names
darcs-hash:20060421142939-ac50b-d1809fa4687706b433d1d0a5e0a0c9d791de510f.gz
This commit is contained in:
parent
a7f977836a
commit
de2405b35a
4 changed files with 44 additions and 13 deletions
|
@ -1029,7 +1029,7 @@ static int builtin_function( wchar_t **argv )
|
||||||
{
|
{
|
||||||
event_t *e;
|
event_t *e;
|
||||||
|
|
||||||
if( !wcsvarname( woptarg ) )
|
if( wcsvarname( woptarg ) )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_( L"%ls: Invalid variable name '%ls'\n" ),
|
_( L"%ls: Invalid variable name '%ls'\n" ),
|
||||||
|
@ -1145,7 +1145,7 @@ static int builtin_function( wchar_t **argv )
|
||||||
argc-woptind );
|
argc-woptind );
|
||||||
res=1;
|
res=1;
|
||||||
}
|
}
|
||||||
else if( !(is_binding?wcsbindingname( argv[woptind] ) : wcsvarname( argv[woptind] ) ))
|
else if( !(is_binding?wcsbindingname( argv[woptind] ) : !wcsvarname( argv[woptind] ) ))
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_( L"%ls: Illegal function name '%ls'\n" ),
|
_( L"%ls: Illegal function name '%ls'\n" ),
|
||||||
|
@ -2584,7 +2584,7 @@ static int builtin_for( wchar_t **argv )
|
||||||
argv[0] );
|
argv[0] );
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
}
|
}
|
||||||
else if ( !wcsvarname(argv[1]) )
|
else if ( wcsvarname(argv[1]) )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_( L"%ls: '%ls' is not a valid variable name\n" ),
|
_( L"%ls: '%ls' is not a valid variable name\n" ),
|
||||||
|
|
6
common.c
6
common.c
|
@ -400,17 +400,17 @@ wchar_t **strv2wcsv( const char **in )
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int wcsvarname( wchar_t *str )
|
wchar_t *wcsvarname( wchar_t *str )
|
||||||
{
|
{
|
||||||
while( *str )
|
while( *str )
|
||||||
{
|
{
|
||||||
if( (!iswalnum(*str)) && (*str != L'_' ) )
|
if( (!iswalnum(*str)) && (*str != L'_' ) )
|
||||||
{
|
{
|
||||||
return 0;
|
return str;
|
||||||
}
|
}
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
9
common.h
9
common.h
|
@ -138,7 +138,14 @@ wchar_t *wcsdupcat2( const wchar_t *a, ... );
|
||||||
Test if the given string is a valid variable name
|
Test if the given string is a valid variable name
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int wcsvarname( wchar_t *str );
|
|
||||||
|
/**
|
||||||
|
Test if the given string is a valid variable name.
|
||||||
|
|
||||||
|
\return null if this is a valid name, and a pointer to the first invalid character otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
|
wchar_t *wcsvarname( wchar_t *str );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
36
parser.c
36
parser.c
|
@ -1981,7 +1981,8 @@ static int parse_job( process_t *p,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int tmp;
|
int tmp;
|
||||||
|
wchar_t *cmd = (wchar_t *)al_get( args, 0 );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We couln't find the specified command.
|
We couln't find the specified command.
|
||||||
|
|
||||||
|
@ -1996,19 +1997,42 @@ static int parse_job( process_t *p,
|
||||||
cause the job to silently not execute. We
|
cause the job to silently not execute. We
|
||||||
also print an error message.
|
also print an error message.
|
||||||
*/
|
*/
|
||||||
if( wcschr( (wchar_t *)al_get( args, 0 ), L'=' ) )
|
if( wcschr( cmd, L'=' ) )
|
||||||
{
|
{
|
||||||
debug( 0,
|
debug( 0,
|
||||||
COMMAND_ASSIGN_ERR_MSG,
|
COMMAND_ASSIGN_ERR_MSG,
|
||||||
(wchar_t *)al_get( args, 0 ) );
|
(wchar_t *)al_get( args, 0 ) );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else if(cmd[0]==L'$')
|
||||||
|
{
|
||||||
|
wchar_t *val = env_get( cmd+1 );
|
||||||
|
if( val )
|
||||||
|
{
|
||||||
|
debug( 0,
|
||||||
|
_(L"Variables may not be used as commands. Define a function like 'function %ls; %ls $argv; end' instead. For more information, see the help section for the function command by typing 'help function'." ),
|
||||||
|
cmd+1,
|
||||||
|
val,
|
||||||
|
cmd );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug( 0,
|
||||||
|
_(L"Variables may not be used as commands. Define a function instead. For more information, see the help section for the function command by typing 'help function'." ),
|
||||||
|
cmd );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(wcschr( cmd, L'$' ))
|
||||||
{
|
{
|
||||||
|
debug( 0,
|
||||||
|
_(L"Commands may not contain variables. Use the eval builtin instead, like 'eval %ls'. For more information, see the help section for the eval command by typing 'help eval'." ),
|
||||||
|
cmd,
|
||||||
|
cmd );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
debug( 0,
|
debug( 0,
|
||||||
_(L"Unknown command '%ls'"),
|
_(L"Unknown command '%ls'"),
|
||||||
(wchar_t *)al_get( args, 0 ) );
|
cmd );
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = current_tokenizer_pos;
|
tmp = current_tokenizer_pos;
|
||||||
|
|
Loading…
Reference in a new issue