From 4ef14ea6e28ca58d69be3588eb5ac51990588b5c Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Fri, 23 Jun 2017 23:19:09 -0700 Subject: [PATCH] another `make style-all` cleanup --- src/builtin.cpp | 4 +--- src/builtin_function.cpp | 10 ++++++---- src/builtin_status.cpp | 3 ++- src/builtin_string.cpp | 36 ++++++++++++++++++++++-------------- src/common.h | 20 ++++++++------------ src/parse_execution.cpp | 4 ++-- src/parser.h | 4 ++-- 7 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index 2a0bf67d5..1ee4a4bc7 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -488,9 +488,7 @@ bool builtin_exists(const wcstring &cmd) { return static_cast(builtin_look /// Is the command a keyword or a builtin we need to special-case the handling of `-h` and `--help`. static const wcstring_list_t help_builtins({L"for", L"while", L"function", L"if", L"end", L"switch", L"case", L"count", L"printf"}); -static bool cmd_needs_help(const wchar_t *cmd) { - return contains(help_builtins, cmd); -} +static bool cmd_needs_help(const wchar_t *cmd) { return contains(help_builtins, cmd); } /// Execute a builtin command int builtin_run(parser_t &parser, const wchar_t *const *argv, io_streams_t &streams) { diff --git a/src/builtin_function.cpp b/src/builtin_function.cpp index 4d73eed41..6f29d93a2 100644 --- a/src/builtin_function.cpp +++ b/src/builtin_function.cpp @@ -109,7 +109,8 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig } if (job_id == -1) { - streams.err.append_format(_(L"%ls: Cannot find calling job for event handler"), cmd); + streams.err.append_format( + _(L"%ls: Cannot find calling job for event handler"), cmd); return STATUS_INVALID_ARGS; } e.type = EVENT_JOB_ID; @@ -118,7 +119,7 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig pid = fish_wcstoi(w.woptarg); if (errno || pid < 0) { streams.err.append_format(_(L"%ls: Invalid process id '%ls'"), cmd, - w.woptarg); + w.woptarg); return STATUS_INVALID_ARGS; } @@ -181,7 +182,8 @@ static int validate_function_name(int argc, const wchar_t *const *argv, wcstring function_name = argv[1]; if (!valid_func_name(function_name)) { - streams.err.append_format(_(L"%ls: Illegal function name '%ls'"), cmd, function_name.c_str()); + streams.err.append_format(_(L"%ls: Illegal function name '%ls'"), cmd, + function_name.c_str()); return STATUS_INVALID_ARGS; } @@ -235,7 +237,7 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis } } else { streams.err.append_format(_(L"%ls: Unexpected positional argument '%ls'"), cmd, - argv[optind]); + argv[optind]); return STATUS_INVALID_ARGS; } } diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index b646dd2c6..a5b5887a7 100644 --- a/src/builtin_status.cpp +++ b/src/builtin_status.cpp @@ -152,7 +152,8 @@ static int parse_cmd_opts(status_cmd_opts_t &opts, int *optind, //!OCLINT(high case 'L': { opts.level = fish_wcstoi(w.woptarg); if (opts.level < 0 || errno == ERANGE) { - streams.err.append_format(_(L"%ls: Invalid level value '%ls'\n"), argv[0], w.woptarg); + streams.err.append_format(_(L"%ls: Invalid level value '%ls'\n"), argv[0], + w.woptarg); return STATUS_INVALID_ARGS; } else if (errno) { streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, argv[0], w.woptarg); diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index df0ccefa5..e04c78923 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -155,8 +155,7 @@ static int handle_flag_1(wchar_t **argv, parser_t &parser, io_streams_t &streams opts->escape_style = STRING_STYLE_URL; } else if (wcscmp(w.woptarg, L"var") == 0) { opts->escape_style = STRING_STYLE_VAR; - } - else { + } else { string_error(streams, _(L"%ls: Invalid escape style '%ls'\n"), cmd, w.woptarg); return STATUS_INVALID_ARGS; } @@ -367,17 +366,25 @@ 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. -static const struct woption long_options[] = { - {L"all", no_argument, NULL, 'a'}, {L"chars", required_argument, NULL, 'c'}, - {L"count", required_argument, NULL, 'n'}, {L"entire", no_argument, NULL, 'e'}, - {L"filter", no_argument, NULL, 'f'}, {L"ignore-case", no_argument, NULL, 'i'}, - {L"index", no_argument, NULL, 'n'}, {L"invert", no_argument, NULL, 'v'}, - {L"left", no_argument, NULL, 'l'}, {L"length", required_argument, NULL, 'l'}, - {L"max", required_argument, NULL, 'm'}, {L"no-newline", no_argument, NULL, 'N'}, - {L"no-quoted", no_argument, NULL, 'n'}, {L"quiet", no_argument, NULL, 'q'}, - {L"regex", no_argument, NULL, 'r'}, {L"right", no_argument, NULL, 'r'}, - {L"start", required_argument, NULL, 's'}, {L"style", required_argument, NULL, 1}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'}, + {L"chars", required_argument, NULL, 'c'}, + {L"count", required_argument, NULL, 'n'}, + {L"entire", no_argument, NULL, 'e'}, + {L"filter", no_argument, NULL, 'f'}, + {L"ignore-case", no_argument, NULL, 'i'}, + {L"index", no_argument, NULL, 'n'}, + {L"invert", no_argument, NULL, 'v'}, + {L"left", no_argument, NULL, 'l'}, + {L"length", required_argument, NULL, 'l'}, + {L"max", required_argument, NULL, 'm'}, + {L"no-newline", no_argument, NULL, 'N'}, + {L"no-quoted", no_argument, NULL, 'n'}, + {L"quiet", no_argument, NULL, 'q'}, + {L"regex", no_argument, NULL, 'r'}, + {L"right", no_argument, NULL, 'r'}, + {L"start", required_argument, NULL, 's'}, + {L"style", required_argument, NULL, 1}, + {NULL, 0, NULL, 0}}; static std::map flag_to_function = { {'N', handle_flag_N}, {'a', handle_flag_a}, {'c', handle_flag_c}, {'e', handle_flag_e}, @@ -437,7 +444,8 @@ static int parse_opts(options_t *opts, int *optind, int n_req_args, int argc, wc } /// Escape a string so that it can be used in a fish script without further word splitting. -static int string_escape_script(options_t &opts, int optind, wchar_t **argv, io_streams_t &streams) { +static int string_escape_script(options_t &opts, int optind, wchar_t **argv, + io_streams_t &streams) { wcstring storage; int nesc = 0; escape_flags_t flags = ESCAPE_ALL; diff --git a/src/common.h b/src/common.h index f633b24be..49e8fe30c 100644 --- a/src/common.h +++ b/src/common.h @@ -89,11 +89,7 @@ typedef std::vector wcstring_list_t; #define INPUT_COMMON_BASE (wchar_t)0xF700 #define INPUT_COMMON_END (INPUT_COMMON_BASE + 64) -enum escape_string_style_t { - STRING_STYLE_SCRIPT, - STRING_STYLE_URL, - STRING_STYLE_VAR -}; +enum escape_string_style_t { STRING_STYLE_SCRIPT, STRING_STYLE_URL, STRING_STYLE_VAR }; // Flags for unescape_string functions. enum { @@ -227,12 +223,12 @@ extern bool has_working_tty_timestamps; #define DIE_WITH_ERRNO(msg) __fish_assert(msg, __FILE__, __LINE__, errno) /// This macro is meant to be used with functions that return zero on success otherwise return an /// errno value. Most notably the pthread family of functions which we never expect to fail. -#define DIE_ON_FAILURE(e) \ - do { \ - int status = e; \ - if (status != 0) { \ +#define DIE_ON_FAILURE(e) \ + do { \ + int status = e; \ + if (status != 0) { \ __fish_assert(#e, __FILE__, __LINE__, status); \ - } \ + } \ } while (0) [[noreturn]] void __fish_assert(const char *msg, const char *file, size_t line, int error); @@ -698,9 +694,9 @@ ssize_t read_loop(int fd, void *buff, size_t count); /// \param flags Flags to control the escaping /// \return The escaped string wcstring escape_string(const wchar_t *in, escape_flags_t flags, - escape_string_style_t style=STRING_STYLE_SCRIPT); + escape_string_style_t style = STRING_STYLE_SCRIPT); wcstring escape_string(const wcstring &in, escape_flags_t flags, - escape_string_style_t style=STRING_STYLE_SCRIPT); + escape_string_style_t style = STRING_STYLE_SCRIPT); /// Expand backslashed escapes and substitute them with their unescaped counterparts. Also /// optionally change the wildcards, the tilde character and a few more into constants which are diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index f37ded990..958a95ebc 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -389,8 +389,8 @@ parse_execution_result_t parse_execution_context_t::run_function_statement( wcstring(this->src, contents_start, contents_end - contents_start); int definition_line_offset = this->line_offset_of_character_at_offset(contents_start); io_streams_t streams; - int err = builtin_function(*parser, streams, argument_list, contents_str, - definition_line_offset); + int err = + builtin_function(*parser, streams, argument_list, contents_str, definition_line_offset); proc_set_last_status(err); if (!streams.err.empty()) { diff --git a/src/parser.h b/src/parser.h index b64983db1..e92fd9388 100644 --- a/src/parser.h +++ b/src/parser.h @@ -217,7 +217,7 @@ class parser_t { /// Returns the name of the currently evaluated function if we are currently evaluating a /// function, null otherwise. This is tested by moving down the block-scope-stack, checking /// every block if it is of type FUNCTION_CALL. - const wchar_t *is_function(size_t idx=0) const; + const wchar_t *is_function(size_t idx = 0) const; /// Helper for stack_trace(). void stack_trace_internal(size_t block_idx, wcstring *out) const; @@ -308,7 +308,7 @@ class parser_t { const wchar_t *get_block_desc(int block) const; /// Return the function name for the specified stack frame. Default is one (current frame). - const wchar_t *get_function_name(int level=1); + const wchar_t *get_function_name(int level = 1); /// Removes a job. bool job_remove(job_t *job);