aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/reader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/reader.cpp')
-rw-r--r--src/reader.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/reader.cpp b/src/reader.cpp
index eaf5829f..7aae5f6f 100644
--- a/src/reader.cpp
+++ b/src/reader.cpp
@@ -222,7 +222,7 @@ public:
/**
Saved position used by token history search
*/
- int token_history_pos;
+ size_t token_history_pos;
/**
Saved search string for token history search. Not handled by command_line_changed.
@@ -2232,7 +2232,7 @@ static void handle_token_history(int forward, int reset)
return;
wcstring str;
- long current_pos;
+ size_t current_pos;
if (reset)
{
@@ -2268,7 +2268,7 @@ static void handle_token_history(int forward, int reset)
}
else
{
- if (current_pos == -1)
+ if (current_pos == size_t(-1))
{
data->token_history_buff.clear();
@@ -2306,26 +2306,26 @@ static void handle_token_history(int forward, int reset)
//debug( 3, L"new '%ls'", data->token_history_buff.c_str() );
tokenizer_t tok(data->token_history_buff.c_str(), TOK_ACCEPT_UNFINISHED);
- for (; tok_has_next(&tok); tok_next(&tok))
+ tok_t token;
+ while (tok.next(&token))
{
- switch (tok_last_type(&tok))
+ switch (token.type)
{
case TOK_STRING:
{
- if (wcsstr(tok_last(&tok), data->search_buff.c_str()))
+ if (token.text.find(data->search_buff) != wcstring::npos)
{
//debug( 3, L"Found token at pos %d\n", tok_get_pos( &tok ) );
- if (tok_get_pos(&tok) >= current_pos)
+ if (token.offset >= current_pos)
{
break;
}
//debug( 3, L"ok pos" );
- const wcstring last_tok = tok_last(&tok);
- if (find(data->search_prev.begin(), data->search_prev.end(), last_tok) == data->search_prev.end())
+ if (find(data->search_prev.begin(), data->search_prev.end(), token.text) == data->search_prev.end())
{
- data->token_history_pos = tok_get_pos(&tok);
- str = tok_last(&tok);
+ data->token_history_pos = token.offset;
+ str = token.text;
}
}
@@ -2514,7 +2514,7 @@ void reader_run_command(parser_t &parser, const wcstring &cmd)
struct timeval time_before, time_after;
- wcstring ft = tok_first(cmd.c_str());
+ wcstring ft = tok_first(cmd);
if (! ft.empty())
env_set(L"_", ft.c_str(), ENV_GLOBAL);
@@ -3063,14 +3063,13 @@ static wchar_t unescaped_quote(const wcstring &str, size_t pos)
/* Returns true if the last token is a comment. */
static bool text_ends_in_comment(const wcstring &text)
{
- token_type last_type = TOK_NONE;
tokenizer_t tok(text.c_str(), TOK_ACCEPT_UNFINISHED | TOK_SHOW_COMMENTS | TOK_SQUASH_ERRORS);
- while (tok_has_next(&tok))
+ tok_t token;
+ while (tok.next(&token))
{
- last_type = tok_last_type(&tok);
- tok_next(&tok);
+ // pass
}
- return last_type == TOK_COMMENT;
+ return token.type == TOK_COMMENT;
}
const wchar_t *reader_readline(int nchars)