From 4ee1cc3b374ccf2bba12353d459e189f65f37244 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 10 Jul 2012 20:30:54 -0700 Subject: [PATCH] Fix for https://github.com/fish-shell/fish-shell/issues/168 Make ^ only act as a redirect at the beginning of a token --- common.cpp | 7 +++++++ env.cpp | 2 +- fish_tests.cpp | 4 ++-- tokenizer.cpp | 42 +++++++++++++++++++++++++++++++++--------- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/common.cpp b/common.cpp index cf77d1e2a..66f19fca4 100644 --- a/common.cpp +++ b/common.cpp @@ -104,6 +104,10 @@ static struct winsize termsize; void show_stackframe() { + /* Hack to avoid showing backtraces in the tester */ + if (program_name && ! wcscmp(program_name, L"(ignore)")) + return; + void *trace[32]; char **messages = (char **)NULL; 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, ... ) { + /* Hack to not print error messages in the tests */ + if ( program_name && ! wcscmp(program_name, L"(ignore)") ) + return; va_list va; wcstring sb; diff --git a/env.cpp b/env.cpp index ef53906ab..b17df3865 100644 --- a/env.cpp +++ b/env.cpp @@ -63,7 +63,7 @@ /** 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 diff --git a/fish_tests.cpp b/fish_tests.cpp index 0e8591d2e..917da8786 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -314,10 +314,10 @@ static void test_tok() { - const wchar_t *str = L"string &1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)]"; + const wchar_t *str = L"string &1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)] not_a_redirect^ ^ ^^is_a_redirect"; 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; diff --git a/tokenizer.cpp b/tokenizer.cpp index 7fe35b2b0..be6aee43f 100644 --- a/tokenizer.cpp +++ b/tokenizer.cpp @@ -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 int is_string_char( wchar_t c ) +static bool is_string_char( wchar_t c, bool is_first ) { - 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; start = tok->buff; - + bool is_first = true; + while( 1 ) { @@ -308,7 +331,7 @@ static void read_string( tokenizer *tok ) default: { - if( !is_string_char(*(tok->buff)) ) + if( !is_string_char(*(tok->buff), is_first) ) { do_loop=0; } @@ -383,6 +406,7 @@ static void read_string( tokenizer *tok ) break; tok->buff++; + is_first = false; } if( (!tok->accept_unfinished) && (mode!=0) ) @@ -609,13 +633,13 @@ void tok_next( tokenizer *tok ) break; case L'>': - read_redirect( tok, 1 ); + read_redirect( tok, 1 ); return; case L'<': - read_redirect( tok, 0 ); + read_redirect( tok, 0 ); return; case L'^': - read_redirect( tok, 2 ); + read_redirect( tok, 2 ); return; default: