Tree @HEAD (Download .tar.gz)
- ..
- widecharwidth
- ast.cpp
- ast.h
- ast_node_types.inc
- autoload.cpp
- autoload.h
- builtin.cpp
- builtin.h
- builtin_argparse.cpp
- builtin_argparse.h
- builtin_bg.cpp
- builtin_bg.h
- builtin_bind.cpp
- builtin_bind.h
- builtin_block.cpp
- builtin_block.h
- builtin_builtin.cpp
- builtin_builtin.h
- builtin_cd.cpp
- builtin_cd.h
- builtin_command.cpp
- builtin_command.h
- builtin_commandline.cpp
- builtin_commandline.h
- builtin_complete.cpp
- builtin_complete.h
- builtin_contains.cpp
- builtin_contains.h
- builtin_disown.cpp
- builtin_disown.h
- builtin_echo.cpp
- builtin_echo.h
- builtin_emit.cpp
- builtin_emit.h
- builtin_eval.cpp
- builtin_eval.h
- builtin_exit.cpp
- builtin_exit.h
- builtin_fg.cpp
- builtin_fg.h
- builtin_function.cpp
- builtin_function.h
- builtin_functions.cpp
- builtin_functions.h
- builtin_history.cpp
- builtin_history.h
- builtin_jobs.cpp
- builtin_jobs.h
- builtin_math.cpp
- builtin_math.h
- builtin_printf.cpp
- builtin_printf.h
- builtin_pwd.cpp
- builtin_pwd.h
- builtin_random.cpp
- builtin_random.h
- builtin_read.cpp
- builtin_read.h
- builtin_realpath.cpp
- builtin_realpath.h
- builtin_return.cpp
- builtin_return.h
- builtin_set.cpp
- builtin_set.h
- builtin_set_color.cpp
- builtin_set_color.h
- builtin_source.cpp
- builtin_source.h
- builtin_status.cpp
- builtin_status.h
- builtin_string.cpp
- builtin_string.h
- builtin_test.cpp
- builtin_test.h
- builtin_type.cpp
- builtin_type.h
- builtin_ulimit.cpp
- builtin_ulimit.h
- builtin_wait.cpp
- builtin_wait.h
- color.cpp
- color.h
- common.cpp
- common.h
- complete.cpp
- complete.h
- enum_set.h
- env.cpp
- env.h
- env_dispatch.cpp
- env_dispatch.h
- env_universal_common.cpp
- env_universal_common.h
- event.cpp
- event.h
- exec.cpp
- exec.h
- expand.cpp
- expand.h
- fallback.cpp
- fallback.h
- fd_monitor.cpp
- fd_monitor.h
- fds.cpp
- fds.h
- fish.cpp
- fish_indent.cpp
- fish_key_reader.cpp
- fish_test_helper.cpp
- fish_tests.cpp
- fish_version.cpp
- fish_version.h
- flog.cpp
- flog.h
- function.cpp
- function.h
- future_feature_flags.cpp
- future_feature_flags.h
- global_safety.h
- highlight.cpp
- highlight.h
- history.cpp
- history.h
- history_file.cpp
- history_file.h
- input.cpp
- input.h
- input_common.cpp
- input_common.h
- intern.cpp
- intern.h
- io.cpp
- io.h
- iothread.cpp
- iothread.h
- job_group.cpp
- job_group.h
- kill.cpp
- kill.h
- lru.h
- maybe.h
- null_terminated_array.cpp
- null_terminated_array.h
- operation_context.cpp
- operation_context.h
- output.cpp
- output.h
- pager.cpp
- pager.h
- parse_constants.h
- parse_execution.cpp
- parse_execution.h
- parse_tree.cpp
- parse_tree.h
- parse_util.cpp
- parse_util.h
- parser.cpp
- parser.h
- parser_keywords.cpp
- parser_keywords.h
- path.cpp
- path.h
- postfork.cpp
- postfork.h
- print_help.cpp
- print_help.h
- proc.cpp
- proc.h
- reader.cpp
- reader.h
- redirection.cpp
- redirection.h
- sanity.cpp
- sanity.h
- screen.cpp
- screen.h
- signal.cpp
- signal.h
- termsize.cpp
- termsize.h
- timer.cpp
- timer.h
- tinyexpr.cpp
- tinyexpr.h
- tokenizer.cpp
- tokenizer.h
- topic_monitor.cpp
- topic_monitor.h
- trace.cpp
- trace.h
- utf8.cpp
- utf8.h
- util.cpp
- util.h
- wcstringutil.cpp
- wcstringutil.h
- wgetopt.cpp
- wgetopt.h
- wildcard.cpp
- wildcard.h
- wutil.cpp
- wutil.h
builtin_block.cpp @HEAD — raw · history · blame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | // Implementation of the bind builtin. #include "config.h" // IWYU pragma: keep #include "builtin_block.h" #include <cstddef> #include "builtin.h" #include "common.h" #include "event.h" #include "fallback.h" // IWYU pragma: keep #include "io.h" #include "parser.h" #include "wgetopt.h" #include "wutil.h" // IWYU pragma: keep enum { UNSET, GLOBAL, LOCAL }; struct block_cmd_opts_t { int scope = UNSET; bool erase = false; bool print_help = false; }; static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; static const wchar_t *const short_options = L":eghl"; static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'}, {L"local", no_argument, nullptr, 'l'}, {L"global", no_argument, nullptr, 'g'}, {L"help", no_argument, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'h': { opts.print_help = true; break; } case 'g': { opts.scope = GLOBAL; break; } case 'l': { opts.scope = LOCAL; break; } case 'e': { opts.erase = true; break; } case ':': { builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { DIE("unexpected retval from wgetopt_long"); } } } *optind = w.woptind; return STATUS_CMD_OK; } /// The block builtin, used for temporarily blocking events. maybe_t<int> builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); block_cmd_opts_t opts; int optind; int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { builtin_print_help(parser, streams, cmd); return STATUS_CMD_OK; } if (opts.erase) { if (opts.scope != UNSET) { streams.err.append_format(_(L"%ls: Can not specify scope when removing block\n"), cmd); return STATUS_INVALID_ARGS; } if (parser.global_event_blocks.empty()) { streams.err.append_format(_(L"%ls: No blocks defined\n"), cmd); return STATUS_CMD_ERROR; } parser.global_event_blocks.pop_front(); 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 if (block_idx + 1 >= parser.blocks().size()) { block = nullptr; } break; } case GLOBAL: { block = nullptr; break; } case UNSET: { while (block && !block->is_function_call()) { // Set it in function scope block = parser.block_at_index(++block_idx); } break; } default: { DIE("unexpected scope"); } } if (block) { block->event_blocks.push_front(eb); } else { parser.global_event_blocks.push_front(eb); } return STATUS_CMD_OK; } |