mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 10:57:30 +08:00
block: Use an integer to count blocks
This commit is contained in:
parent
dff7db2f16
commit
330e8a86c7
|
@ -91,19 +91,17 @@ maybe_t<int> builtin_block(parser_t &parser, io_streams_t &streams, const wchar_
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (parser.global_event_blocks.empty()) {
|
||||
if (!parser.global_event_blocks) {
|
||||
streams.err.append_format(_(L"%ls: No blocks defined\n"), cmd);
|
||||
return STATUS_CMD_ERROR;
|
||||
}
|
||||
parser.global_event_blocks.pop_front();
|
||||
--parser.global_event_blocks;
|
||||
return STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
size_t block_idx = 0;
|
||||
block_t *block = parser.block_at_index(block_idx);
|
||||
|
||||
event_blockage_t eb = {};
|
||||
|
||||
switch (opts.scope) {
|
||||
case LOCAL: {
|
||||
// If this is the outermost block, then we're global
|
||||
|
@ -128,9 +126,9 @@ maybe_t<int> builtin_block(parser_t &parser, io_streams_t &streams, const wchar_
|
|||
}
|
||||
}
|
||||
if (block) {
|
||||
block->event_blocks.push_front(eb);
|
||||
++block->event_blocks;
|
||||
} else {
|
||||
parser.global_event_blocks.push_front(eb);
|
||||
++parser.global_event_blocks;
|
||||
}
|
||||
|
||||
return STATUS_CMD_OK;
|
||||
|
|
|
@ -173,9 +173,9 @@ static bool event_is_blocked(parser_t &parser, const event_t &e) {
|
|||
const block_t *block;
|
||||
size_t idx = 0;
|
||||
while ((block = parser.block_at_index(idx++))) {
|
||||
if (event_block_list_blocks_type(block->event_blocks)) return true;
|
||||
if (block->event_blocks) return true;
|
||||
}
|
||||
return event_block_list_blocks_type(parser.global_event_blocks);
|
||||
return parser.global_event_blocks;
|
||||
}
|
||||
|
||||
wcstring event_get_desc(const parser_t &parser, const event_t &evt) {
|
||||
|
|
17
src/parser.h
17
src/parser.h
|
@ -24,19 +24,10 @@
|
|||
#include "util.h"
|
||||
#include "wait_handle.h"
|
||||
|
||||
struct event_t;
|
||||
class io_chain_t;
|
||||
class autoclose_fd_t;
|
||||
|
||||
/// event_blockage_t represents a block on events.
|
||||
struct event_blockage_t {};
|
||||
|
||||
class io_chain_t;
|
||||
struct event_t;
|
||||
struct job_group_t;
|
||||
typedef std::list<event_blockage_t> event_blockage_list_t;
|
||||
|
||||
inline bool event_block_list_blocks_type(const event_blockage_list_t &ebls) {
|
||||
return !ebls.empty();
|
||||
}
|
||||
|
||||
/// Types of blocks.
|
||||
enum class block_type_t : uint8_t {
|
||||
|
@ -73,7 +64,7 @@ class block_t {
|
|||
wcstring function_name{};
|
||||
|
||||
/// List of event blocks.
|
||||
event_blockage_list_t event_blocks{};
|
||||
uint64_t event_blocks{};
|
||||
|
||||
// If this is a function block, the function args. Otherwise empty.
|
||||
wcstring_list_t function_args{};
|
||||
|
@ -329,7 +320,7 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
|
|||
void assert_can_execute() const;
|
||||
|
||||
/// Global event blocks.
|
||||
event_blockage_list_t global_event_blocks;
|
||||
uint64_t global_event_blocks{};
|
||||
|
||||
/// Evaluate the expressions contained in cmd.
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue
Block a user