mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
Make ^ only act as a redirect at the beginning of a token
This commit is contained in:
parent
11dd904b6d
commit
4ee1cc3b37
4 changed files with 43 additions and 12 deletions
|
@ -104,6 +104,10 @@ static struct winsize termsize;
|
||||||
|
|
||||||
void show_stackframe()
|
void show_stackframe()
|
||||||
{
|
{
|
||||||
|
/* Hack to avoid showing backtraces in the tester */
|
||||||
|
if (program_name && ! wcscmp(program_name, L"(ignore)"))
|
||||||
|
return;
|
||||||
|
|
||||||
void *trace[32];
|
void *trace[32];
|
||||||
char **messages = (char **)NULL;
|
char **messages = (char **)NULL;
|
||||||
int i, trace_size = 0;
|
int i, trace_size = 0;
|
||||||
|
@ -668,6 +672,9 @@ ssize_t read_loop(int fd, void *buff, size_t count)
|
||||||
|
|
||||||
void debug( int level, const wchar_t *msg, ... )
|
void debug( int level, const wchar_t *msg, ... )
|
||||||
{
|
{
|
||||||
|
/* Hack to not print error messages in the tests */
|
||||||
|
if ( program_name && ! wcscmp(program_name, L"(ignore)") )
|
||||||
|
return;
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
wcstring sb;
|
wcstring sb;
|
||||||
|
|
2
env.cpp
2
env.cpp
|
@ -63,7 +63,7 @@
|
||||||
/**
|
/**
|
||||||
Command used to start fishd
|
Command used to start fishd
|
||||||
*/
|
*/
|
||||||
#define FISHD_CMD L"fishd ^/tmp/fishd.log.%s"
|
#define FISHD_CMD L"fishd ^ /tmp/fishd.log.%s"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Value denoting a null string
|
Value denoting a null string
|
||||||
|
|
|
@ -314,10 +314,10 @@ static void test_tok()
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
const wchar_t *str = L"string <redirection 2>&1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)]";
|
const wchar_t *str = L"string <redirection 2>&1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)] not_a_redirect^ ^ ^^is_a_redirect";
|
||||||
const int types[] =
|
const int types[] =
|
||||||
{
|
{
|
||||||
TOK_STRING, TOK_REDIRECT_IN, TOK_STRING, TOK_REDIRECT_FD, TOK_STRING, TOK_STRING, TOK_END
|
TOK_STRING, TOK_REDIRECT_IN, TOK_STRING, TOK_REDIRECT_FD, TOK_STRING, TOK_STRING, TOK_STRING, TOK_REDIRECT_OUT, TOK_REDIRECT_APPEND, TOK_STRING, TOK_END
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
|
@ -185,12 +185,34 @@ int tok_has_next( tokenizer *tok )
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Tests if this character can be a part of a string
|
Tests if this character can be a part of a string. The redirect ^ is allowed unless it's the first character.
|
||||||
*/
|
*/
|
||||||
|
static bool is_string_char( wchar_t c, bool is_first )
|
||||||
static int is_string_char( wchar_t c )
|
|
||||||
{
|
{
|
||||||
return !( !c || wcschr( SEP, c ) );
|
switch (c)
|
||||||
|
{
|
||||||
|
/* Unconditional separators */
|
||||||
|
case L'\0':
|
||||||
|
case L' ':
|
||||||
|
case L'\n':
|
||||||
|
case L'|':
|
||||||
|
case L'\t':
|
||||||
|
case L';':
|
||||||
|
case L'#':
|
||||||
|
case L'\r':
|
||||||
|
case L'<':
|
||||||
|
case L'>':
|
||||||
|
case L'&':
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* Conditional separator */
|
||||||
|
case L'^':
|
||||||
|
return ! is_first;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,7 +238,8 @@ static void read_string( tokenizer *tok )
|
||||||
int paran_count=0;
|
int paran_count=0;
|
||||||
|
|
||||||
start = tok->buff;
|
start = tok->buff;
|
||||||
|
bool is_first = true;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -308,7 +331,7 @@ static void read_string( tokenizer *tok )
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if( !is_string_char(*(tok->buff)) )
|
if( !is_string_char(*(tok->buff), is_first) )
|
||||||
{
|
{
|
||||||
do_loop=0;
|
do_loop=0;
|
||||||
}
|
}
|
||||||
|
@ -383,6 +406,7 @@ static void read_string( tokenizer *tok )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
tok->buff++;
|
tok->buff++;
|
||||||
|
is_first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (!tok->accept_unfinished) && (mode!=0) )
|
if( (!tok->accept_unfinished) && (mode!=0) )
|
||||||
|
@ -609,13 +633,13 @@ void tok_next( tokenizer *tok )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L'>':
|
case L'>':
|
||||||
read_redirect( tok, 1 );
|
read_redirect( tok, 1 );
|
||||||
return;
|
return;
|
||||||
case L'<':
|
case L'<':
|
||||||
read_redirect( tok, 0 );
|
read_redirect( tok, 0 );
|
||||||
return;
|
return;
|
||||||
case L'^':
|
case L'^':
|
||||||
read_redirect( tok, 2 );
|
read_redirect( tok, 2 );
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue