diff options
author | Sanne Wouda <sanne.wouda@gmail.com> | 2015-04-05 20:07:17 +0200 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2015-04-19 16:56:48 -0700 |
commit | 32936b0eb95c9cee54d3887328e4bfd01c961922 (patch) | |
tree | dfbaf159a3f6d20acaa4ab9de3515c76feb64ee4 /input_common.cpp | |
parent | 3559f20c8ffca8b036ff4aa6833e9e4c67eea7fc (diff) |
Change lookahead_list into a queue
Using builtin `commandline -f`, one would expect to have commands executed in
the order that they were given. This motivates the change to a queue.
Unfortunately, fish internals still need lookahead_list to act as a stack. Add
and rename functions to support both cases and have lookahead_list as
a std::deque internally.
This code is delicate, and we should probably dog-food this in nightly for
a while before the next-minor release.
Fixes #1567
Diffstat (limited to 'input_common.cpp')
-rw-r--r-- | input_common.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/input_common.cpp b/input_common.cpp index 045cb8f3..b748ca22 100644 --- a/input_common.cpp +++ b/input_common.cpp @@ -38,7 +38,7 @@ Implementation file for the low level input library #define WAIT_ON_ESCAPE 10 /** Characters that have been read and returned by the sequence matching code */ -static std::stack<wint_t, std::vector<wint_t> > lookahead_list; +static std::deque<wint_t> lookahead_list; /* Queue of pairs of (function pointer, argument) to be invoked. Expected to be mostly empty. */ typedef std::pair<void (*)(void *), void *> callback_info_t; @@ -53,19 +53,24 @@ static bool has_lookahead(void) static wint_t lookahead_pop(void) { - wint_t result = lookahead_list.top(); - lookahead_list.pop(); + wint_t result = lookahead_list.front(); + lookahead_list.pop_front(); return result; } -static void lookahead_push(wint_t c) +static void lookahead_push_back(wint_t c) { - lookahead_list.push(c); + lookahead_list.push_back(c); } -static wint_t lookahead_top(void) +static void lookahead_push_front(wint_t c) { - return lookahead_list.top(); + lookahead_list.push_front(c); +} + +static wint_t lookahead_front(void) +{ + return lookahead_list.front(); } /** Callback function for handling interrupts on reading */ @@ -278,7 +283,7 @@ wchar_t input_common_readch(int timed) { if (!timed) { - while (has_lookahead() && lookahead_top() == WEOF) + while (has_lookahead() && lookahead_front() == WEOF) lookahead_pop(); if (! has_lookahead()) return input_common_readch(0); @@ -289,9 +294,14 @@ wchar_t input_common_readch(int timed) } -void input_common_unreadch(wint_t ch) +void input_common_queue_ch(wint_t ch) +{ + lookahead_push_back(ch); +} + +void input_common_next_ch(wint_t ch) { - lookahead_push(ch); + lookahead_push_front(ch); } void input_common_add_callback(void (*callback)(void *), void *arg) |