diff --git a/src/builtin.cpp b/src/builtin.cpp index d47a96c9b..e9b8c61a1 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -105,7 +105,7 @@ void builtin_wperror(const wchar_t *program_name, io_streams_t &streams) { } static const wchar_t *const short_options = L"+:h"; -static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, {}}; +static const struct woption long_options[] = {{L"help", no_argument, 'h'}, {}}; int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { diff --git a/src/builtins/argparse.cpp b/src/builtins/argparse.cpp index 34db468f9..195278551 100644 --- a/src/builtins/argparse.cpp +++ b/src/builtins/argparse.cpp @@ -62,10 +62,10 @@ struct argparse_cmd_opts_t { static const wchar_t *const short_options = L"+:hn:six:N:X:"; static const struct woption long_options[] = { - {L"stop-nonopt", no_argument, nullptr, 's'}, {L"ignore-unknown", no_argument, nullptr, 'i'}, - {L"name", required_argument, nullptr, 'n'}, {L"exclusive", required_argument, nullptr, 'x'}, - {L"help", no_argument, nullptr, 'h'}, {L"min-args", required_argument, nullptr, 'N'}, - {L"max-args", required_argument, nullptr, 'X'}, {}}; + {L"stop-nonopt", no_argument, 's'}, {L"ignore-unknown", no_argument, 'i'}, + {L"name", required_argument, 'n'}, {L"exclusive", required_argument, 'x'}, + {L"help", no_argument, 'h'}, {L"min-args", required_argument, 'N'}, + {L"max-args", required_argument, 'X'}, {}}; // Check if any pair of mutually exclusive options was seen. Note that since every option must have // a short name we only need to check those. @@ -462,8 +462,7 @@ static void populate_option_strings(const argparse_cmd_opts_t &opts, wcstring *s } if (!opt_spec->long_flag.empty()) { - long_options->push_back( - {opt_spec->long_flag.c_str(), arg_type, nullptr, opt_spec->short_flag}); + long_options->push_back({opt_spec->long_flag.c_str(), arg_type, opt_spec->short_flag}); } } long_options->push_back(woption{}); diff --git a/src/builtins/bind.cpp b/src/builtins/bind.cpp index 525c6b592..c5b31c47f 100644 --- a/src/builtins/bind.cpp +++ b/src/builtins/bind.cpp @@ -62,11 +62,13 @@ class builtin_bind_t { bool erase(const wchar_t *const *seq, bool all, const wchar_t *mode, bool use_terminfo, bool user, io_streams_t &streams); bool get_terminfo_sequence(const wcstring &seq, wcstring *out_seq, io_streams_t &streams) const; - bool insert(int optind, int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams); + bool insert(int optind, int argc, const wchar_t **argv, parser_t &parser, + io_streams_t &streams); void list_modes(io_streams_t &streams); - bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, parser_t &parser, io_streams_t &streams); - bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset, parser_t &parser, + bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, parser_t &parser, io_streams_t &streams); + bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset, + parser_t &parser, io_streams_t &streams); }; /// List a single key binding. @@ -141,7 +143,8 @@ bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bo } /// List all current key bindings. -void builtin_bind_t::list(const wchar_t *bind_mode, bool user, parser_t &parser, io_streams_t &streams) { +void builtin_bind_t::list(const wchar_t *bind_mode, bool user, parser_t &parser, + io_streams_t &streams) { const std::vector lst = input_mappings_->get_names(user); for (const input_mapping_name_t &binding : lst) { @@ -255,7 +258,8 @@ bool builtin_bind_t::erase(const wchar_t *const *seq, bool all, const wchar_t *m return res; } -bool builtin_bind_t::insert(int optind, int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { +bool builtin_bind_t::insert(int optind, int argc, const wchar_t **argv, parser_t &parser, + io_streams_t &streams) { const wchar_t *cmd = argv[0]; int arg_count = argc - optind; @@ -342,18 +346,18 @@ static int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high nc int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { const wchar_t *cmd = argv[0]; static const wchar_t *const short_options = L":aehkKfM:Lm:s"; - static const struct woption long_options[] = {{L"all", no_argument, nullptr, 'a'}, - {L"erase", no_argument, nullptr, 'e'}, - {L"function-names", no_argument, nullptr, 'f'}, - {L"help", no_argument, nullptr, 'h'}, - {L"key", no_argument, nullptr, 'k'}, - {L"key-names", no_argument, nullptr, 'K'}, - {L"list-modes", no_argument, nullptr, 'L'}, - {L"mode", required_argument, nullptr, 'M'}, - {L"preset", no_argument, nullptr, 'p'}, - {L"sets-mode", required_argument, nullptr, 'm'}, - {L"silent", no_argument, nullptr, 's'}, - {L"user", no_argument, nullptr, 'u'}, + static const struct woption long_options[] = {{L"all", no_argument, 'a'}, + {L"erase", no_argument, 'e'}, + {L"function-names", no_argument, 'f'}, + {L"help", no_argument, 'h'}, + {L"key", no_argument, 'k'}, + {L"key-names", no_argument, 'K'}, + {L"list-modes", no_argument, 'L'}, + {L"mode", required_argument, 'M'}, + {L"preset", no_argument, 'p'}, + {L"sets-mode", required_argument, 'm'}, + {L"silent", no_argument, 's'}, + {L"user", no_argument, 'u'}, {}}; int opt; diff --git a/src/builtins/block.cpp b/src/builtins/block.cpp index 665012759..bff86541f 100644 --- a/src/builtins/block.cpp +++ b/src/builtins/block.cpp @@ -26,10 +26,10 @@ static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high n int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { const 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'}, + static const struct woption long_options[] = {{L"erase", no_argument, 'e'}, + {L"local", no_argument, 'l'}, + {L"global", no_argument, 'g'}, + {L"help", no_argument, 'h'}, {}}; int opt; diff --git a/src/builtins/builtin.cpp b/src/builtins/builtin.cpp index f58d0462a..54ff76a47 100644 --- a/src/builtins/builtin.cpp +++ b/src/builtins/builtin.cpp @@ -20,10 +20,8 @@ struct builtin_cmd_opts_t { bool query = false; }; static const wchar_t *const short_options = L":hnq"; -static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, - {L"names", no_argument, nullptr, 'n'}, - {L"query", no_argument, nullptr, 'q'}, - {}}; +static const struct woption long_options[] = { + {L"help", no_argument, 'h'}, {L"names", no_argument, 'n'}, {L"query", no_argument, 'q'}, {}}; static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { diff --git a/src/builtins/command.cpp b/src/builtins/command.cpp index 77a978063..91dd8ce1e 100644 --- a/src/builtins/command.cpp +++ b/src/builtins/command.cpp @@ -24,9 +24,8 @@ struct command_cmd_opts_t { }; static const wchar_t *const short_options = L":ahqsv"; static const struct woption long_options[] = { - {L"help", no_argument, nullptr, 'h'}, {L"all", no_argument, nullptr, 'a'}, - {L"quiet", no_argument, nullptr, 'q'}, {L"query", no_argument, nullptr, 'q'}, - {L"search", no_argument, nullptr, 's'}, {}}; + {L"help", no_argument, 'h'}, {L"all", no_argument, 'a'}, {L"quiet", no_argument, 'q'}, + {L"query", no_argument, 'q'}, {L"search", no_argument, 's'}, {}}; static int parse_cmd_opts(command_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { diff --git a/src/builtins/commandline.cpp b/src/builtins/commandline.cpp index 0a0440fc4..51bf17f26 100644 --- a/src/builtins/commandline.cpp +++ b/src/builtins/commandline.cpp @@ -155,27 +155,27 @@ maybe_t builtin_commandline(parser_t &parser, io_streams_t &streams, const const auto &ld = parser.libdata(); static const wchar_t *const short_options = L":abijpctforhI:CBELSsP"; - static const struct woption long_options[] = {{L"append", no_argument, nullptr, 'a'}, - {L"insert", no_argument, nullptr, 'i'}, - {L"replace", no_argument, nullptr, 'r'}, - {L"current-buffer", no_argument, nullptr, 'b'}, - {L"current-job", no_argument, nullptr, 'j'}, - {L"current-process", no_argument, nullptr, 'p'}, - {L"current-selection", no_argument, nullptr, 's'}, - {L"current-token", no_argument, nullptr, 't'}, - {L"cut-at-cursor", no_argument, nullptr, 'c'}, - {L"function", no_argument, nullptr, 'f'}, - {L"tokenize", no_argument, nullptr, 'o'}, - {L"help", no_argument, nullptr, 'h'}, - {L"input", required_argument, nullptr, 'I'}, - {L"cursor", no_argument, nullptr, 'C'}, - {L"selection-start", no_argument, nullptr, 'B'}, - {L"selection-end", no_argument, nullptr, 'E'}, - {L"line", no_argument, nullptr, 'L'}, - {L"search-mode", no_argument, nullptr, 'S'}, - {L"paging-mode", no_argument, nullptr, 'P'}, - {L"paging-full-mode", no_argument, nullptr, 'F'}, - {L"is-valid", no_argument, nullptr, 1}, + static const struct woption long_options[] = {{L"append", no_argument, 'a'}, + {L"insert", no_argument, 'i'}, + {L"replace", no_argument, 'r'}, + {L"current-buffer", no_argument, 'b'}, + {L"current-job", no_argument, 'j'}, + {L"current-process", no_argument, 'p'}, + {L"current-selection", no_argument, 's'}, + {L"current-token", no_argument, 't'}, + {L"cut-at-cursor", no_argument, 'c'}, + {L"function", no_argument, 'f'}, + {L"tokenize", no_argument, 'o'}, + {L"help", no_argument, 'h'}, + {L"input", required_argument, 'I'}, + {L"cursor", no_argument, 'C'}, + {L"selection-start", no_argument, 'B'}, + {L"selection-end", no_argument, 'E'}, + {L"line", no_argument, 'L'}, + {L"search-mode", no_argument, 'S'}, + {L"paging-mode", no_argument, 'P'}, + {L"paging-full-mode", no_argument, 'F'}, + {L"is-valid", no_argument, 1}, {}}; int opt; diff --git a/src/builtins/complete.cpp b/src/builtins/complete.cpp index 0663f56e9..d01e747c4 100644 --- a/src/builtins/complete.cpp +++ b/src/builtins/complete.cpp @@ -150,29 +150,28 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wch bool unescape_output = true; static const wchar_t *const short_options = L":a:c:p:s:l:o:d:fFrxeuAn:C::w:hk"; - static const struct woption long_options[] = { - {L"exclusive", no_argument, nullptr, 'x'}, - {L"no-files", no_argument, nullptr, 'f'}, - {L"force-files", no_argument, nullptr, 'F'}, - {L"require-parameter", no_argument, nullptr, 'r'}, - {L"path", required_argument, nullptr, 'p'}, - {L"command", required_argument, nullptr, 'c'}, - {L"short-option", required_argument, nullptr, 's'}, - {L"long-option", required_argument, nullptr, 'l'}, - {L"old-option", required_argument, nullptr, 'o'}, - {L"subcommand", required_argument, nullptr, 'S'}, - {L"description", required_argument, nullptr, 'd'}, - {L"arguments", required_argument, nullptr, 'a'}, - {L"erase", no_argument, nullptr, 'e'}, - {L"unauthoritative", no_argument, nullptr, 'u'}, - {L"authoritative", no_argument, nullptr, 'A'}, - {L"condition", required_argument, nullptr, 'n'}, - {L"wraps", required_argument, nullptr, 'w'}, - {L"do-complete", optional_argument, nullptr, 'C'}, - {L"help", no_argument, nullptr, 'h'}, - {L"keep-order", no_argument, nullptr, 'k'}, - {L"escape", no_argument, nullptr, opt_escape}, - {}}; + static const struct woption long_options[] = {{L"exclusive", no_argument, 'x'}, + {L"no-files", no_argument, 'f'}, + {L"force-files", no_argument, 'F'}, + {L"require-parameter", no_argument, 'r'}, + {L"path", required_argument, 'p'}, + {L"command", required_argument, 'c'}, + {L"short-option", required_argument, 's'}, + {L"long-option", required_argument, 'l'}, + {L"old-option", required_argument, 'o'}, + {L"subcommand", required_argument, 'S'}, + {L"description", required_argument, 'd'}, + {L"arguments", required_argument, 'a'}, + {L"erase", no_argument, 'e'}, + {L"unauthoritative", no_argument, 'u'}, + {L"authoritative", no_argument, 'A'}, + {L"condition", required_argument, 'n'}, + {L"wraps", required_argument, 'w'}, + {L"do-complete", optional_argument, 'C'}, + {L"help", no_argument, 'h'}, + {L"keep-order", no_argument, 'k'}, + {L"escape", no_argument, opt_escape}, + {}}; bool have_x = false; @@ -356,8 +355,7 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wch prefix.append(L": "); if (maybe_t err_text = parse_util_detect_errors_in_argument_list(comp, prefix)) { - streams.err.append_format(L"%ls: %ls: contains a syntax error\n", cmd, - comp); + streams.err.append_format(L"%ls: %ls: contains a syntax error\n", cmd, comp); streams.err.append(*err_text); streams.err.push_back(L'\n'); return STATUS_CMD_ERROR; @@ -423,8 +421,8 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wch // Append any description. if (!next.description.empty()) { - faux_cmdline_with_completion.reserve( - faux_cmdline_with_completion.size() + 2 + next.description.size()); + faux_cmdline_with_completion.reserve(faux_cmdline_with_completion.size() + 2 + + next.description.size()); faux_cmdline_with_completion.push_back(L'\t'); faux_cmdline_with_completion.append(next.description); } diff --git a/src/builtins/contains.cpp b/src/builtins/contains.cpp index 1ab398234..1911ad452 100644 --- a/src/builtins/contains.cpp +++ b/src/builtins/contains.cpp @@ -19,7 +19,7 @@ struct contains_cmd_opts_t { }; static const wchar_t *const short_options = L"+:hi"; static const struct woption long_options[] = { - {L"help", no_argument, nullptr, 'h'}, {L"index", no_argument, nullptr, 'i'}, {}}; + {L"help", no_argument, 'h'}, {L"index", no_argument, 'i'}, {}}; static int parse_cmd_opts(contains_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { diff --git a/src/builtins/exit.cpp b/src/builtins/exit.cpp index ddd5fb9e4..47687a644 100644 --- a/src/builtins/exit.cpp +++ b/src/builtins/exit.cpp @@ -18,7 +18,7 @@ struct exit_cmd_opts_t { bool print_help = false; }; static const wchar_t *const short_options = L":h"; -static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, {}}; +static const struct woption long_options[] = {{L"help", no_argument, 'h'}, {}}; static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { diff --git a/src/builtins/function.cpp b/src/builtins/function.cpp index cb2dd6193..54672da4e 100644 --- a/src/builtins/function.cpp +++ b/src/builtins/function.cpp @@ -47,19 +47,18 @@ struct function_cmd_opts_t { // This command is atypical in using the "-" (RETURN_IN_ORDER) option for flag parsing. // This is needed due to the semantics of the -a/--argument-names flag. static const wchar_t *const short_options = L"-:a:d:e:hj:p:s:v:w:SV:"; -static const struct woption long_options[] = { - {L"description", required_argument, nullptr, 'd'}, - {L"on-signal", required_argument, nullptr, 's'}, - {L"on-job-exit", required_argument, nullptr, 'j'}, - {L"on-process-exit", required_argument, nullptr, 'p'}, - {L"on-variable", required_argument, nullptr, 'v'}, - {L"on-event", required_argument, nullptr, 'e'}, - {L"wraps", required_argument, nullptr, 'w'}, - {L"help", no_argument, nullptr, 'h'}, - {L"argument-names", required_argument, nullptr, 'a'}, - {L"no-scope-shadowing", no_argument, nullptr, 'S'}, - {L"inherit-variable", required_argument, nullptr, 'V'}, - {}}; +static const struct woption long_options[] = {{L"description", required_argument, 'd'}, + {L"on-signal", required_argument, 's'}, + {L"on-job-exit", required_argument, 'j'}, + {L"on-process-exit", required_argument, 'p'}, + {L"on-variable", required_argument, 'v'}, + {L"on-event", required_argument, 'e'}, + {L"wraps", required_argument, 'w'}, + {L"help", no_argument, 'h'}, + {L"argument-names", required_argument, 'a'}, + {L"no-scope-shadowing", no_argument, 'S'}, + {L"inherit-variable", required_argument, 'V'}, + {}}; /// \return the internal_job_id for a pid, or 0 if none. /// This looks through both active and finished jobs. @@ -222,9 +221,8 @@ static int validate_function_name(int argc, const wchar_t *const *argv, wcstring /// Define a function. Calls into `function.cpp` to perform the heavy lifting of defining a /// function. -int builtin_function(parser_t &parser, io_streams_t &streams, - const wcstring_list_t &c_args, const parsed_source_ref_t &source, - const ast::block_statement_t &func_node) { +int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args, + const parsed_source_ref_t &source, const ast::block_statement_t &func_node) { assert(source && "Missing source in builtin_function"); // The wgetopt function expects 'function' as the first argument. Make a new wcstring_list with // that property. This is needed because this builtin has a different signature than the other diff --git a/src/builtins/functions.cpp b/src/builtins/functions.cpp index cf3896cdf..499f036e5 100644 --- a/src/builtins/functions.cpp +++ b/src/builtins/functions.cpp @@ -40,18 +40,18 @@ struct functions_cmd_opts_t { const wchar_t *description = nullptr; }; static const wchar_t *const short_options = L":Ht:Dacd:ehnqv"; -static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'}, - {L"description", required_argument, nullptr, 'd'}, - {L"names", no_argument, nullptr, 'n'}, - {L"all", no_argument, nullptr, 'a'}, - {L"help", no_argument, nullptr, 'h'}, - {L"query", no_argument, nullptr, 'q'}, - {L"copy", no_argument, nullptr, 'c'}, - {L"details", no_argument, nullptr, 'D'}, - {L"no-details", no_argument, nullptr, 1}, - {L"verbose", no_argument, nullptr, 'v'}, - {L"handlers", no_argument, nullptr, 'H'}, - {L"handlers-type", required_argument, nullptr, 't'}, +static const struct woption long_options[] = {{L"erase", no_argument, 'e'}, + {L"description", required_argument, 'd'}, + {L"names", no_argument, 'n'}, + {L"all", no_argument, 'a'}, + {L"help", no_argument, 'h'}, + {L"query", no_argument, 'q'}, + {L"copy", no_argument, 'c'}, + {L"details", no_argument, 'D'}, + {L"no-details", no_argument, 1}, + {L"verbose", no_argument, 'v'}, + {L"handlers", no_argument, 'H'}, + {L"handlers-type", required_argument, 't'}, {}}; static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) diff --git a/src/builtins/history.cpp b/src/builtins/history.cpp index 9a9e050b8..3eb5114ef 100644 --- a/src/builtins/history.cpp +++ b/src/builtins/history.cpp @@ -57,20 +57,20 @@ struct history_cmd_opts_t { /// supported at least until fish 3.0 and possibly longer to avoid breaking everyones /// config.fish and other scripts. static const wchar_t *const short_options = L":CRcehmn:pt::z"; -static const struct woption long_options[] = {{L"prefix", no_argument, nullptr, 'p'}, - {L"contains", no_argument, nullptr, 'c'}, - {L"help", no_argument, nullptr, 'h'}, - {L"show-time", optional_argument, nullptr, 't'}, - {L"exact", no_argument, nullptr, 'e'}, - {L"max", required_argument, nullptr, 'n'}, - {L"null", no_argument, nullptr, 'z'}, - {L"case-sensitive", no_argument, nullptr, 'C'}, - {L"delete", no_argument, nullptr, 1}, - {L"search", no_argument, nullptr, 2}, - {L"save", no_argument, nullptr, 3}, - {L"clear", no_argument, nullptr, 4}, - {L"merge", no_argument, nullptr, 5}, - {L"reverse", no_argument, nullptr, 'R'}, +static const struct woption long_options[] = {{L"prefix", no_argument, 'p'}, + {L"contains", no_argument, 'c'}, + {L"help", no_argument, 'h'}, + {L"show-time", optional_argument, 't'}, + {L"exact", no_argument, 'e'}, + {L"max", required_argument, 'n'}, + {L"null", no_argument, 'z'}, + {L"case-sensitive", no_argument, 'C'}, + {L"delete", no_argument, 1}, + {L"search", no_argument, 2}, + {L"save", no_argument, 3}, + {L"clear", no_argument, 4}, + {L"merge", no_argument, 5}, + {L"reverse", no_argument, 'R'}, {}}; /// Remember the history subcommand and disallow selecting more than one history subcommand. diff --git a/src/builtins/jobs.cpp b/src/builtins/jobs.cpp index e6223ec01..994eade9c 100644 --- a/src/builtins/jobs.cpp +++ b/src/builtins/jobs.cpp @@ -126,10 +126,10 @@ maybe_t builtin_jobs(parser_t &parser, io_streams_t &streams, const wchar_t static const wchar_t *const short_options = L":cghlpq"; static const struct woption long_options[] = { - {L"command", no_argument, nullptr, 'c'}, {L"group", no_argument, nullptr, 'g'}, - {L"help", no_argument, nullptr, 'h'}, {L"last", no_argument, nullptr, 'l'}, - {L"pid", no_argument, nullptr, 'p'}, {L"quiet", no_argument, nullptr, 'q'}, - {L"query", no_argument, nullptr, 'q'}, {}}; + {L"command", no_argument, 'c'}, {L"group", no_argument, 'g'}, + {L"help", no_argument, 'h'}, {L"last", no_argument, 'l'}, + {L"pid", no_argument, 'p'}, {L"quiet", no_argument, 'q'}, + {L"query", no_argument, 'q'}, {}}; int opt; wgetopter_t w; diff --git a/src/builtins/math.cpp b/src/builtins/math.cpp index 232ba2f6f..071777884 100644 --- a/src/builtins/math.cpp +++ b/src/builtins/math.cpp @@ -36,9 +36,9 @@ struct math_cmd_opts_t { // This command is atypical in using the "+" (REQUIRE_ORDER) option for flag parsing. // This is needed because of the minus, `-`, operator in math expressions. static const wchar_t *const short_options = L"+:hs:b:"; -static const struct woption long_options[] = {{L"scale", required_argument, nullptr, 's'}, - {L"base", required_argument, nullptr, 'b'}, - {L"help", no_argument, nullptr, 'h'}, +static const struct woption long_options[] = {{L"scale", required_argument, 's'}, + {L"base", required_argument, 'b'}, + {L"help", no_argument, 'h'}, {}}; static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) @@ -259,7 +259,8 @@ static int evaluate_expression(const wchar_t *cmd, const parser_t &parser, io_st streams.err.append_format(L"'%ls'\n", expression.c_str()); if (error.len >= 2) { wcstring tildes(error.len - 2, L'~'); - streams.err.append_format(L"%*ls%ls%ls%ls\n", error.position - 1, L" ", L"^", tildes.c_str(), L"^"); + streams.err.append_format(L"%*ls%ls%ls%ls\n", error.position - 1, L" ", L"^", + tildes.c_str(), L"^"); } else { streams.err.append_format(L"%*ls%ls\n", error.position - 1, L" ", L"^"); } diff --git a/src/builtins/path.cpp b/src/builtins/path.cpp index e2dfe8b9e..9065fa435 100644 --- a/src/builtins/path.cpp +++ b/src/builtins/path.cpp @@ -428,16 +428,16 @@ static wcstring construct_short_opts(options_t *opts) { //!OCLINT(high npath co // Note that several long flags share the same short flag. That is okay. The caller is expected // to indicate that a max of one of the long flags sharing a short flag is valid. // Remember: adjust the completions in share/completions/ when options change -static const struct woption long_options[] = {{L"quiet", no_argument, nullptr, 'q'}, - {L"null-in", no_argument, nullptr, 'z'}, - {L"null-out", no_argument, nullptr, 'Z'}, - {L"perm", required_argument, nullptr, 'p'}, - {L"type", required_argument, nullptr, 't'}, - {L"invert", no_argument, nullptr, 'v'}, - {L"relative", no_argument, nullptr, 'R'}, - {L"reverse", no_argument, nullptr, 'r'}, - {L"unique", no_argument, nullptr, 'u'}, - {L"key", required_argument, nullptr, 1}, +static const struct woption long_options[] = {{L"quiet", no_argument, 'q'}, + {L"null-in", no_argument, 'z'}, + {L"null-out", no_argument, 'Z'}, + {L"perm", required_argument, 'p'}, + {L"type", required_argument, 't'}, + {L"invert", no_argument, 'v'}, + {L"relative", no_argument, 'R'}, + {L"reverse", no_argument, 'r'}, + {L"unique", no_argument, 'u'}, + {L"key", required_argument, 1}, {}}; static const std::unordered_map flag_to_function = { diff --git a/src/builtins/pwd.cpp b/src/builtins/pwd.cpp index a48ef09d2..664175276 100644 --- a/src/builtins/pwd.cpp +++ b/src/builtins/pwd.cpp @@ -20,9 +20,9 @@ /// The pwd builtin. Respect -P to resolve symbolic links. Respect -L to not do that (the default). static const wchar_t *const short_options = L"LPh"; -static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, - {L"logical", no_argument, nullptr, 'L'}, - {L"physical", no_argument, nullptr, 'P'}, +static const struct woption long_options[] = {{L"help", no_argument, 'h'}, + {L"logical", no_argument, 'L'}, + {L"physical", no_argument, 'P'}, {}}; maybe_t builtin_pwd(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { UNUSED(parser); diff --git a/src/builtins/read.cpp b/src/builtins/read.cpp index e432a03c8..0e7574b41 100644 --- a/src/builtins/read.cpp +++ b/src/builtins/read.cpp @@ -52,26 +52,26 @@ struct read_cmd_opts_t { } // namespace static const wchar_t *const short_options = L":ac:d:fghiLln:p:sStuxzP:UR:L"; -static const struct woption long_options[] = {{L"array", no_argument, nullptr, 'a'}, - {L"command", required_argument, nullptr, 'c'}, - {L"delimiter", required_argument, nullptr, 'd'}, - {L"export", no_argument, nullptr, 'x'}, - {L"function", no_argument, nullptr, 'f'}, - {L"global", no_argument, nullptr, 'g'}, - {L"help", no_argument, nullptr, 'h'}, - {L"line", no_argument, nullptr, 'L'}, - {L"list", no_argument, nullptr, 'a'}, - {L"local", no_argument, nullptr, 'l'}, - {L"nchars", required_argument, nullptr, 'n'}, - {L"null", no_argument, nullptr, 'z'}, - {L"prompt", required_argument, nullptr, 'p'}, - {L"prompt-str", required_argument, nullptr, 'P'}, - {L"right-prompt", required_argument, nullptr, 'R'}, - {L"shell", no_argument, nullptr, 'S'}, - {L"silent", no_argument, nullptr, 's'}, - {L"tokenize", no_argument, nullptr, 't'}, - {L"unexport", no_argument, nullptr, 'u'}, - {L"universal", no_argument, nullptr, 'U'}, +static const struct woption long_options[] = {{L"array", no_argument, 'a'}, + {L"command", required_argument, 'c'}, + {L"delimiter", required_argument, 'd'}, + {L"export", no_argument, 'x'}, + {L"function", no_argument, 'f'}, + {L"global", no_argument, 'g'}, + {L"help", no_argument, 'h'}, + {L"line", no_argument, 'L'}, + {L"list", no_argument, 'a'}, + {L"local", no_argument, 'l'}, + {L"nchars", required_argument, 'n'}, + {L"null", no_argument, 'z'}, + {L"prompt", required_argument, 'p'}, + {L"prompt-str", required_argument, 'P'}, + {L"right-prompt", required_argument, 'R'}, + {L"shell", no_argument, 'S'}, + {L"silent", no_argument, 's'}, + {L"tokenize", no_argument, 't'}, + {L"unexport", no_argument, 'u'}, + {L"universal", no_argument, 'U'}, {}}; static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) diff --git a/src/builtins/realpath.cpp b/src/builtins/realpath.cpp index a6d654a5a..32d32e7f4 100644 --- a/src/builtins/realpath.cpp +++ b/src/builtins/realpath.cpp @@ -25,7 +25,7 @@ struct realpath_cmd_opts_t { static const wchar_t *const short_options = L"+:hs"; static const struct woption long_options[] = { - {L"no-symlinks", no_argument, nullptr, 's'}, {L"help", no_argument, nullptr, 'h'}, {}}; + {L"no-symlinks", no_argument, 's'}, {L"help", no_argument, 'h'}, {}}; static int parse_cmd_opts(realpath_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { diff --git a/src/builtins/return.cpp b/src/builtins/return.cpp index f4a77c39d..2289b72a7 100644 --- a/src/builtins/return.cpp +++ b/src/builtins/return.cpp @@ -4,8 +4,8 @@ #include "return.h" #include -#include #include +#include #include #include "../builtin.h" @@ -21,7 +21,7 @@ struct return_cmd_opts_t { bool print_help = false; }; static const wchar_t *const short_options = L":h"; -static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, {}}; +static const struct woption long_options[] = {{L"help", no_argument, 'h'}, {}}; static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) { diff --git a/src/builtins/set.cpp b/src/builtins/set.cpp index 15375dab1..9417b884d 100644 --- a/src/builtins/set.cpp +++ b/src/builtins/set.cpp @@ -56,22 +56,22 @@ enum { // (REQUIRE_ORDER) option for flag parsing. This is not typical of most fish commands. It means // we stop scanning for flags when the first non-flag argument is seen. static const wchar_t *const short_options = L"+:LSUaefghlnpqux"; -static const struct woption long_options[] = {{L"export", no_argument, nullptr, 'x'}, - {L"global", no_argument, nullptr, 'g'}, - {L"function", no_argument, nullptr, 'f'}, - {L"local", no_argument, nullptr, 'l'}, - {L"erase", no_argument, nullptr, 'e'}, - {L"names", no_argument, nullptr, 'n'}, - {L"unexport", no_argument, nullptr, 'u'}, - {L"universal", no_argument, nullptr, 'U'}, - {L"long", no_argument, nullptr, 'L'}, - {L"query", no_argument, nullptr, 'q'}, - {L"show", no_argument, nullptr, 'S'}, - {L"append", no_argument, nullptr, 'a'}, - {L"prepend", no_argument, nullptr, 'p'}, - {L"path", no_argument, nullptr, opt_path}, - {L"unpath", no_argument, nullptr, opt_unpath}, - {L"help", no_argument, nullptr, 'h'}, +static const struct woption long_options[] = {{L"export", no_argument, 'x'}, + {L"global", no_argument, 'g'}, + {L"function", no_argument, 'f'}, + {L"local", no_argument, 'l'}, + {L"erase", no_argument, 'e'}, + {L"names", no_argument, 'n'}, + {L"unexport", no_argument, 'u'}, + {L"universal", no_argument, 'U'}, + {L"long", no_argument, 'L'}, + {L"query", no_argument, 'q'}, + {L"show", no_argument, 'S'}, + {L"append", no_argument, 'a'}, + {L"prepend", no_argument, 'p'}, + {L"path", no_argument, opt_path}, + {L"unpath", no_argument, opt_unpath}, + {L"help", no_argument, 'h'}, {}}; // Hint for invalid path operation with a colon. @@ -545,8 +545,8 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams // For our purposes it's read-only. if (env_var_t::flags_for(var_name) & env_var_t::flag_read_only) { streams.out.append(_(L" (read-only)\n")); - } - else streams.out.push_back(L'\n'); + } else + streams.out.push_back(L'\n'); for (size_t i = 0; i < vals.size(); i++) { if (vals.size() > 100) { @@ -626,8 +626,8 @@ static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, int ret = STATUS_CMD_OK; env_mode_flags_t scopes = compute_scope(opts); // `set -e` is allowed to be called with multiple scopes. - for (int bit = 0; 1< builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar int what = RLIMIT_FSIZE; static const wchar_t *const short_options = L":HSabcdefilmnqrstuvwyKPTh"; - static const struct woption long_options[] = { - {L"all", no_argument, nullptr, 'a'}, - {L"hard", no_argument, nullptr, 'H'}, - {L"soft", no_argument, nullptr, 'S'}, - {L"socket-buffers", no_argument, nullptr, 'b'}, - {L"core-size", no_argument, nullptr, 'c'}, - {L"data-size", no_argument, nullptr, 'd'}, - {L"nice", no_argument, nullptr, 'e'}, - {L"file-size", no_argument, nullptr, 'f'}, - {L"pending-signals", no_argument, nullptr, 'i'}, - {L"lock-size", no_argument, nullptr, 'l'}, - {L"resident-set-size", no_argument, nullptr, 'm'}, - {L"file-descriptor-count", no_argument, nullptr, 'n'}, - {L"queue-size", no_argument, nullptr, 'q'}, - {L"realtime-priority", no_argument, nullptr, 'r'}, - {L"stack-size", no_argument, nullptr, 's'}, - {L"cpu-time", no_argument, nullptr, 't'}, - {L"process-count", no_argument, nullptr, 'u'}, - {L"virtual-memory-size", no_argument, nullptr, 'v'}, - {L"swap-size", no_argument, nullptr, 'w'}, - {L"realtime-maxtime", no_argument, nullptr, 'y'}, - {L"kernel-queues", no_argument, nullptr, 'K'}, - {L"ptys", no_argument, nullptr, 'P'}, - {L"threads", no_argument, nullptr, 'T'}, - {L"help", no_argument, nullptr, 'h'}, - {}}; + static const struct woption long_options[] = {{L"all", no_argument, 'a'}, + {L"hard", no_argument, 'H'}, + {L"soft", no_argument, 'S'}, + {L"socket-buffers", no_argument, 'b'}, + {L"core-size", no_argument, 'c'}, + {L"data-size", no_argument, 'd'}, + {L"nice", no_argument, 'e'}, + {L"file-size", no_argument, 'f'}, + {L"pending-signals", no_argument, 'i'}, + {L"lock-size", no_argument, 'l'}, + {L"resident-set-size", no_argument, 'm'}, + {L"file-descriptor-count", no_argument, 'n'}, + {L"queue-size", no_argument, 'q'}, + {L"realtime-priority", no_argument, 'r'}, + {L"stack-size", no_argument, 's'}, + {L"cpu-time", no_argument, 't'}, + {L"process-count", no_argument, 'u'}, + {L"virtual-memory-size", no_argument, 'v'}, + {L"swap-size", no_argument, 'w'}, + {L"realtime-maxtime", no_argument, 'y'}, + {L"kernel-queues", no_argument, 'K'}, + {L"ptys", no_argument, 'P'}, + {L"threads", no_argument, 'T'}, + {L"help", no_argument, 'h'}, + {}}; int opt; wgetopter_t w; diff --git a/src/builtins/wait.cpp b/src/builtins/wait.cpp index 51987d934..4f9ad0898 100644 --- a/src/builtins/wait.cpp +++ b/src/builtins/wait.cpp @@ -137,7 +137,7 @@ maybe_t builtin_wait(parser_t &parser, io_streams_t &streams, const wchar_t static const wchar_t *const short_options = L":nh"; static const struct woption long_options[] = { - {L"any", no_argument, nullptr, 'n'}, {L"help", no_argument, nullptr, 'h'}, {}}; + {L"any", no_argument, 'n'}, {L"help", no_argument, 'h'}, {}}; int opt; wgetopter_t w; diff --git a/src/wgetopt.cpp b/src/wgetopt.cpp index 2c7c8ec63..fac5e8e3e 100644 --- a/src/wgetopt.cpp +++ b/src/wgetopt.cpp @@ -292,12 +292,7 @@ void wgetopter_t::_update_long_opt(int argc, string_array_t argv, const struct w nextchar += std::wcslen(nextchar); if (longind != nullptr) *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - *retval = 0; - } else { - *retval = pfound->val; - } + *retval = pfound->val; } // Find a matching long opt. diff --git a/src/wgetopt.h b/src/wgetopt.h index a12674491..0e4ccd0a2 100644 --- a/src/wgetopt.h +++ b/src/wgetopt.h @@ -160,14 +160,12 @@ struct woption { const wchar_t *name{nullptr}; /// Must be one of no_argument, required_argument or optional_argument. woption_argument_t has_arg{}; - /// If non-null, the flag whose value should be set if this switch is encountered. - int *flag{nullptr}; /// If \c flag is non-null, this is the value that flag will be set to. Otherwise, this is the /// return-value of the function call. wchar_t val{L'\0'}; - constexpr woption(const wchar_t *name, woption_argument_t has_arg, int *flag, wchar_t val) - : name(name), has_arg(has_arg), flag(flag), val(val) {} + constexpr woption(const wchar_t *name, woption_argument_t has_arg, wchar_t val) + : name(name), has_arg(has_arg), val(val) {} constexpr woption() = default; };