clang-format C++ builtins

This commit is contained in:
Johannes Altmanninger 2023-04-20 18:27:26 +02:00
parent 33f51b45e4
commit 82a797db9c
5 changed files with 31 additions and 20 deletions

View file

@ -33,10 +33,11 @@
/// Silly function. /// Silly function.
static void builtin_complete_add2(const wcstring &cmd, bool cmd_is_path, const wchar_t *short_opt, static void builtin_complete_add2(const wcstring &cmd, bool cmd_is_path, const wchar_t *short_opt,
const std::vector<wcstring> &gnu_opts, const std::vector<wcstring> &old_opts, const std::vector<wcstring> &gnu_opts,
completion_mode_t result_mode, const std::vector<wcstring> &condition, const std::vector<wcstring> &old_opts,
const wchar_t *comp, const wchar_t *desc, completion_mode_t result_mode,
complete_flags_t flags) { const std::vector<wcstring> &condition, const wchar_t *comp,
const wchar_t *desc, complete_flags_t flags) {
for (const wchar_t *s = short_opt; *s; s++) { for (const wchar_t *s = short_opt; *s; s++) {
complete_add(cmd, cmd_is_path, wcstring{*s}, option_type_short, result_mode, condition, complete_add(cmd, cmd_is_path, wcstring{*s}, option_type_short, result_mode, condition,
comp, desc, flags); comp, desc, flags);
@ -59,9 +60,11 @@ static void builtin_complete_add2(const wcstring &cmd, bool cmd_is_path, const w
} }
/// Silly function. /// Silly function.
static void builtin_complete_add(const std::vector<wcstring> &cmds, const std::vector<wcstring> &paths, static void builtin_complete_add(const std::vector<wcstring> &cmds,
const wchar_t *short_opt, const std::vector<wcstring> &gnu_opt, const std::vector<wcstring> &paths, const wchar_t *short_opt,
const std::vector<wcstring> &old_opt, completion_mode_t result_mode, const std::vector<wcstring> &gnu_opt,
const std::vector<wcstring> &old_opt,
completion_mode_t result_mode,
const std::vector<wcstring> &condition, const wchar_t *comp, const std::vector<wcstring> &condition, const wchar_t *comp,
const wchar_t *desc, complete_flags_t flags) { const wchar_t *desc, complete_flags_t flags) {
for (const wcstring &cmd : cmds) { for (const wcstring &cmd : cmds) {
@ -76,7 +79,8 @@ static void builtin_complete_add(const std::vector<wcstring> &cmds, const std::v
} }
static void builtin_complete_remove_cmd(const wcstring &cmd, bool cmd_is_path, static void builtin_complete_remove_cmd(const wcstring &cmd, bool cmd_is_path,
const wchar_t *short_opt, const std::vector<wcstring> &gnu_opt, const wchar_t *short_opt,
const std::vector<wcstring> &gnu_opt,
const std::vector<wcstring> &old_opt) { const std::vector<wcstring> &old_opt) {
bool removed = false; bool removed = false;
for (const wchar_t *s = short_opt; *s; s++) { for (const wchar_t *s = short_opt; *s; s++) {
@ -100,8 +104,9 @@ static void builtin_complete_remove_cmd(const wcstring &cmd, bool cmd_is_path,
} }
} }
static void builtin_complete_remove(const std::vector<wcstring> &cmds, const std::vector<wcstring> &paths, static void builtin_complete_remove(const std::vector<wcstring> &cmds,
const wchar_t *short_opt, const std::vector<wcstring> &gnu_opt, const std::vector<wcstring> &paths, const wchar_t *short_opt,
const std::vector<wcstring> &gnu_opt,
const std::vector<wcstring> &old_opt) { const std::vector<wcstring> &old_opt) {
for (const wcstring &cmd : cmds) { for (const wcstring &cmd : cmds) {
builtin_complete_remove_cmd(cmd, false /* not path */, short_opt, gnu_opt, old_opt); builtin_complete_remove_cmd(cmd, false /* not path */, short_opt, gnu_opt, old_opt);

View file

@ -88,7 +88,8 @@ static bool set_hist_cmd(const wchar_t *cmd, hist_cmd_t *hist_cmd, hist_cmd_t su
} }
static bool check_for_unexpected_hist_args(const history_cmd_opts_t &opts, const wchar_t *cmd, static bool check_for_unexpected_hist_args(const history_cmd_opts_t &opts, const wchar_t *cmd,
const std::vector<wcstring> &args, io_streams_t &streams) { const std::vector<wcstring> &args,
io_streams_t &streams) {
if (opts.history_search_type_defined || opts.show_time_format || opts.null_terminate) { if (opts.history_search_type_defined || opts.show_time_format || opts.null_terminate) {
const wchar_t *subcmd_str = enum_to_str(opts.hist_cmd, hist_enum_map); const wchar_t *subcmd_str = enum_to_str(opts.hist_cmd, hist_enum_map);
streams.err.append_format(_(L"%ls: %ls: subcommand takes no options\n"), cmd, subcmd_str); streams.err.append_format(_(L"%ls: %ls: subcommand takes no options\n"), cmd, subcmd_str);

View file

@ -622,7 +622,8 @@ maybe_t<int> builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t
// We're using IFS, so tokenize the buffer using each IFS char. This is for backward // We're using IFS, so tokenize the buffer using each IFS char. This is for backward
// compatibility with old versions of fish. // compatibility with old versions of fish.
// Note the final variable gets any remaining text. // Note the final variable gets any remaining text.
std::vector<wcstring> var_vals = split_string_tok(buff, opts.delimiter, vars_left()); std::vector<wcstring> var_vals =
split_string_tok(buff, opts.delimiter, vars_left());
size_t val_idx = 0; size_t val_idx = 0;
while (vars_left()) { while (vars_left()) {
wcstring val; wcstring val;

View file

@ -301,7 +301,8 @@ static void handle_env_return(int retval, const wchar_t *cmd, const wcstring &ke
/// Call vars.set. If this is a path variable, e.g. PATH, validate the elements. On error, print a /// Call vars.set. If this is a path variable, e.g. PATH, validate the elements. On error, print a
/// description of the problem to stderr. /// description of the problem to stderr.
static int env_set_reporting_errors(const wchar_t *cmd, const wcstring &key, int scope, static int env_set_reporting_errors(const wchar_t *cmd, const wcstring &key, int scope,
std::vector<wcstring> list, io_streams_t &streams, parser_t &parser) { std::vector<wcstring> list, io_streams_t &streams,
parser_t &parser) {
int retval = parser.set_var_and_fire(key, scope | ENV_USER, std::move(list)); int retval = parser.set_var_and_fire(key, scope | ENV_USER, std::move(list));
// If this returned OK, the parser already fired the event. // If this returned OK, the parser already fired the event.
handle_env_return(retval, cmd, key, streams); handle_env_return(retval, cmd, key, streams);
@ -396,7 +397,8 @@ static maybe_t<split_var_t> split_var_and_indexes(const wchar_t *arg, env_mode_f
/// Given a list of values and 1-based indexes, return a new list with those elements removed. /// Given a list of values and 1-based indexes, return a new list with those elements removed.
/// Note this deliberately accepts both args by value, as it modifies them both. /// Note this deliberately accepts both args by value, as it modifies them both.
static std::vector<wcstring> erased_at_indexes(std::vector<wcstring> input, std::vector<long> indexes) { static std::vector<wcstring> erased_at_indexes(std::vector<wcstring> input,
std::vector<long> indexes) {
// Sort our indexes into *descending* order. // Sort our indexes into *descending* order.
std::sort(indexes.begin(), indexes.end(), std::greater<long>()); std::sort(indexes.begin(), indexes.end(), std::greater<long>());
@ -656,7 +658,8 @@ static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
} }
} else { // remove just the specified indexes of the var } else { // remove just the specified indexes of the var
if (!split->var) return STATUS_CMD_ERROR; if (!split->var) return STATUS_CMD_ERROR;
std::vector<wcstring> result = erased_at_indexes(split->var->as_list(), split->indexes); std::vector<wcstring> result =
erased_at_indexes(split->var->as_list(), split->indexes);
retval = env_set_reporting_errors(cmd, split->varname, scope, std::move(result), retval = env_set_reporting_errors(cmd, split->varname, scope, std::move(result),
streams, parser); streams, parser);
} }
@ -674,8 +677,9 @@ static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
/// Return a list of new values for the variable \p varname, respecting the \p opts. /// Return a list of new values for the variable \p varname, respecting the \p opts.
/// The arguments are given as the argc, argv pair. /// The arguments are given as the argc, argv pair.
/// This handles the simple case where there are no indexes. /// This handles the simple case where there are no indexes.
static std::vector<wcstring> new_var_values(const wcstring &varname, const set_cmd_opts_t &opts, int argc, static std::vector<wcstring> new_var_values(const wcstring &varname, const set_cmd_opts_t &opts,
const wchar_t *const *argv, const environment_t &vars) { int argc, const wchar_t *const *argv,
const environment_t &vars) {
std::vector<wcstring> result; std::vector<wcstring> result;
if (!opts.prepend && !opts.append) { if (!opts.prepend && !opts.append) {
// Not prepending or appending. // Not prepending or appending.
@ -705,7 +709,7 @@ static std::vector<wcstring> new_var_values(const wcstring &varname, const set_c
/// This handles the more difficult case of setting individual slices of a var. /// This handles the more difficult case of setting individual slices of a var.
static std::vector<wcstring> new_var_values_by_index(const split_var_t &split, int argc, static std::vector<wcstring> new_var_values_by_index(const split_var_t &split, int argc,
const wchar_t *const *argv) { const wchar_t *const *argv) {
assert(static_cast<size_t>(argc) == split.indexes.size() && assert(static_cast<size_t>(argc) == split.indexes.size() &&
"Must have the same number of indexes as arguments"); "Must have the same number of indexes as arguments");

View file

@ -65,8 +65,8 @@ static void print_modifiers(outputter_t &outp, bool bold, bool underline, bool i
} }
} }
static void print_colors(io_streams_t &streams, std::vector<wcstring> args, bool bold, bool underline, static void print_colors(io_streams_t &streams, std::vector<wcstring> args, bool bold,
bool italics, bool dim, bool reverse, rgb_color_t bg) { bool underline, bool italics, bool dim, bool reverse, rgb_color_t bg) {
outputter_t outp; outputter_t outp;
if (args.empty()) args = rgb_color_t::named_color_names(); if (args.empty()) args = rgb_color_t::named_color_names();
for (const auto &color_name : args) { for (const auto &color_name : args) {