diff --git a/src/builtin.cpp b/src/builtin.cpp index f4ee07b10..d8d10c5e2 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -826,8 +826,10 @@ static int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **ar w.woptind = 0; - static const struct woption long_options[] = { - {L"quiet", no_argument, 0, 'q'}, {L"search", no_argument, 0, 's'}, {L"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; + static const struct woption long_options[] = {{L"quiet", no_argument, NULL, 'q'}, + {L"search", no_argument, NULL, 's'}, + {L"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0}}; while (1) { int opt_index = 0; diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp index a08fd032d..434b5a118 100644 --- a/src/builtin_complete.cpp +++ b/src/builtin_complete.cpp @@ -310,8 +310,8 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (do_complete) { const wchar_t *token; - parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, - 0, 0); + parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0, + 0); // Create a scoped transient command line, so that bulitin_commandline will see our // argument, not the reader buffer. @@ -322,7 +322,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { std::vector comp; complete(do_complete_param, &comp, COMPLETION_REQUEST_DEFAULT, - env_vars_snapshot_t::current()); + env_vars_snapshot_t::current()); for (size_t i = 0; i < comp.size(); i++) { const completion_t &next = comp.at(i); @@ -339,8 +339,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // just look for the space and clear it. if (!(next.flags & COMPLETE_NO_SPACE) && string_suffixes_string(L" ", faux_cmdline_with_completion)) { - faux_cmdline_with_completion.resize(faux_cmdline_with_completion.size() - - 1); + faux_cmdline_with_completion.resize(faux_cmdline_with_completion.size() - 1); } // The input data is meant to be something like you would have on the command diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index 05313353d..6b457b994 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -167,7 +167,8 @@ class test_parser { expression *parse_binary_primary(unsigned int start, unsigned int end); expression *parse_just_a_string(unsigned int start, unsigned int end); - static expression *parse_args(const wcstring_list_t &args, wcstring &err, wchar_t *program_name); + static expression *parse_args(const wcstring_list_t &args, wcstring &err, + wchar_t *program_name); }; struct range_t { @@ -538,7 +539,8 @@ expression *test_parser::parse_expression(unsigned int start, unsigned int end) } } -expression *test_parser::parse_args(const wcstring_list_t &args, wcstring &err, wchar_t *program_name) { +expression *test_parser::parse_args(const wcstring_list_t &args, wcstring &err, + wchar_t *program_name) { // Empty list and one-arg list should be handled by caller. assert(args.size() > 1); @@ -820,7 +822,7 @@ int builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv) { wcstring_list_t eval_errors; bool result = expr->evaluate(eval_errors); - if (!eval_errors.empty() && ! should_suppress_stderr_for_tests()) { + if (!eval_errors.empty() && !should_suppress_stderr_for_tests()) { printf("test returned eval errors:\n"); for (size_t i = 0; i < eval_errors.size(); i++) { printf("\t%ls\n", eval_errors.at(i).c_str()); diff --git a/src/common.h b/src/common.h index 303605fb6..6d324aca9 100644 --- a/src/common.h +++ b/src/common.h @@ -675,7 +675,8 @@ ssize_t read_loop(int fd, void *buff, size_t count); /// /// will print the string 'fish: Pi = 3.141', given that debug_level is 1 or higher, and that /// program_name is 'fish'. -void __attribute__((noinline)) debug(int level, const char *msg, ...) __attribute__ ((format (printf, 2, 3))); +void __attribute__((noinline)) debug(int level, const char *msg, ...) + __attribute__((format(printf, 2, 3))); void __attribute__((noinline)) debug(int level, const wchar_t *msg, ...); /// Replace special characters with backslash escape sequences. Newline is replaced with \n, etc. diff --git a/src/complete.cpp b/src/complete.cpp index 34bf0ca2d..aecf346e6 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -676,7 +676,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool NULL); if (result != EXPAND_ERROR && this->wants_descriptions()) { this->complete_cmd_desc(str_cmd); - } + } } if (use_implicit_cd) { @@ -961,7 +961,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop } for (option_list_t::const_iterator oiter = options.begin(); oiter != options.end(); - ++oiter) { + ++oiter) { const complete_entry_opt_t *o = &*oiter; // If this entry is for the base command, check if any of the arguments match. if (!this->condition_test(o->condition)) continue; @@ -1240,9 +1240,8 @@ bool completer_t::try_complete_user(const wcstring &str) { wcstring name = format_string(L"~%ls", pw_name); wcstring desc = format_string(COMPLETE_USER_DESC, pw_name); - append_completion(&this->completions, name, desc, COMPLETE_REPLACES_TOKEN | - COMPLETE_DONT_ESCAPE | - COMPLETE_NO_SPACE); + append_completion(&this->completions, name, desc, + COMPLETE_REPLACES_TOKEN | COMPLETE_DONT_ESCAPE | COMPLETE_NO_SPACE); result = true; } } diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index c182e7f4a..09f9ddb5d 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -595,8 +595,8 @@ bool env_universal_t::open_and_acquire_lock(const wcstring &path, int *out_fd) { // Try taking the lock, if necessary. If we failed, we may be on lockless NFS, etc.; in that // case we pretend we succeeded. See the comment in save_to_path for the rationale. if (needs_lock) { - // This is safe in terms of the fallback function implemented in terms of fcntl: only ever - // run on the main thread, and protected by the universal variable lock + // This is safe in terms of the fallback function implemented in terms of fcntl: only + // ever run on the main thread, and protected by the universal variable lock. // cppcheck-suppress flockSemanticsWarning while (flock(fd, LOCK_EX) < 0) { /* error */ diff --git a/src/fallback.cpp b/src/fallback.cpp index aac1cecac..e1ed88477 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -204,7 +204,8 @@ size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) { // Not enough room in dst, add NUL and traverse rest of src. if (n == 0) { if (siz != 0) *d = '\0'; // NUL-terminate dst - while (*s++) ; // ignore rest of src + while (*s++) + ; // ignore rest of src } return s - src - 1; // count does not include NUL } @@ -506,7 +507,7 @@ int flock(int fd, int op) { struct flock fl = {0}; - switch (op & (LOCK_EX|LOCK_SH|LOCK_UN)) { + switch (op & (LOCK_EX | LOCK_SH | LOCK_UN)) { case LOCK_EX: fl.l_type = F_WRLCK; break; @@ -527,10 +528,9 @@ int flock(int fd, int op) { fl.l_whence = SEEK_SET; rc = fcntl(fd, op & LOCK_NB ? F_SETLK : F_SETLKW, &fl); - if (rc && (errno == EAGAIN)) - errno = EWOULDBLOCK; + if (rc && (errno == EAGAIN)) errno = EWOULDBLOCK; return rc; } -#endif // HAVE_FLOCK +#endif // HAVE_FLOCK diff --git a/src/fallback.h b/src/fallback.h index 6e60a34fa..946b4e3a0 100644 --- a/src/fallback.h +++ b/src/fallback.h @@ -134,10 +134,10 @@ int killpg(int pgr, int sig); // cppcheck-suppress flockSemanticsWarning int flock(int fd, int op); -#define LOCK_SH 1 /* Shared lock. */ -#define LOCK_EX 2 /* Exclusive lock. */ -#define LOCK_UN 8 /* Unlock. */ -#define LOCK_NB 4 /* Don't block when locking. */ +#define LOCK_SH 1 // Shared lock. +#define LOCK_EX 2 // Exclusive lock. +#define LOCK_UN 8 // Unlock. +#define LOCK_NB 4 // Don't block when locking. #endif diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 9bfb52efe..c09e72720 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1649,7 +1649,8 @@ struct pager_layout_testcase_t { wcstring text = sd.line(0).to_string(); if (text != expected) { - fprintf(stderr, "width %lu got <%ls>, expected <%ls>\n", this->width, text.c_str(), expected.c_str()); + fprintf(stderr, "width %lu got <%ls>, expected <%ls>\n", this->width, text.c_str(), + expected.c_str()); } do_test(text == expected); } @@ -1666,20 +1667,14 @@ static void test_pager_layout() { const completion_t c1(L"abcdefghij", L"1234567890"); pager.set_completions(completion_list_t(1, c1)); const pager_layout_testcase_t testcases1[] = { - {26, L"abcdefghij (1234567890)"}, - {25, L"abcdefghij (1234567890)"}, - {24, L"abcdefghij (1234567890)"}, - {23, L"abcdefghij (12345678…)"}, - {22, L"abcdefghij (1234567…)"}, - {21, L"abcdefghij (123456…)"}, - {20, L"abcdefghij (12345…)"}, - {19, L"abcdefghij (1234…)"}, - {18, L"abcdefgh… (1234…)"}, - {17, L"abcdefg… (1234…)"}, - {16, L"abcdefg… (123…)"}, - {0, NULL} // sentinel terminator + {26, L"abcdefghij (1234567890)"}, {25, L"abcdefghij (1234567890)"}, + {24, L"abcdefghij (1234567890)"}, {23, L"abcdefghij (12345678…)"}, + {22, L"abcdefghij (1234567…)"}, {21, L"abcdefghij (123456…)"}, + {20, L"abcdefghij (12345…)"}, {19, L"abcdefghij (1234…)"}, + {18, L"abcdefgh… (1234…)"}, {17, L"abcdefg… (1234…)"}, + {16, L"abcdefg… (123…)"}, {0, NULL} // sentinel terminator }; - for (size_t i=0; testcases1[i].expected != NULL; i++) { + for (size_t i = 0; testcases1[i].expected != NULL; i++) { testcases1[i].run(pager); } @@ -1687,20 +1682,14 @@ static void test_pager_layout() { const completion_t c2(L"abcdefghijklmnopqrs", L"1"); pager.set_completions(completion_list_t(1, c2)); const pager_layout_testcase_t testcases2[] = { - {26, L"abcdefghijklmnopqrs (1)"}, - {25, L"abcdefghijklmnopqrs (1)"}, - {24, L"abcdefghijklmnopqrs (1)"}, - {23, L"abcdefghijklmnopq… (1)"}, - {22, L"abcdefghijklmnop… (1)"}, - {21, L"abcdefghijklmno… (1)"}, - {20, L"abcdefghijklmn… (1)"}, - {19, L"abcdefghijklm… (1)"}, - {18, L"abcdefghijkl… (1)"}, - {17, L"abcdefghijk… (1)"}, - {16, L"abcdefghij… (1)"}, - {0, NULL} // sentinel terminator + {26, L"abcdefghijklmnopqrs (1)"}, {25, L"abcdefghijklmnopqrs (1)"}, + {24, L"abcdefghijklmnopqrs (1)"}, {23, L"abcdefghijklmnopq… (1)"}, + {22, L"abcdefghijklmnop… (1)"}, {21, L"abcdefghijklmno… (1)"}, + {20, L"abcdefghijklmn… (1)"}, {19, L"abcdefghijklm… (1)"}, + {18, L"abcdefghijkl… (1)"}, {17, L"abcdefghijk… (1)"}, + {16, L"abcdefghij… (1)"}, {0, NULL} // sentinel terminator }; - for (size_t i=0; testcases2[i].expected != NULL; i++) { + for (size_t i = 0; testcases2[i].expected != NULL; i++) { testcases2[i].run(pager); } @@ -1708,25 +1697,18 @@ static void test_pager_layout() { const completion_t c3(L"abcdefghijklmnopqrst", L""); pager.set_completions(completion_list_t(1, c3)); const pager_layout_testcase_t testcases3[] = { - {26, L"abcdefghijklmnopqrst"}, - {25, L"abcdefghijklmnopqrst"}, - {24, L"abcdefghijklmnopqrst"}, - {23, L"abcdefghijklmnopqrst"}, - {22, L"abcdefghijklmnopqrst"}, - {21, L"abcdefghijklmnopqrst"}, - {20, L"abcdefghijklmnopqrst"}, - {19, L"abcdefghijklmnopqr…"}, - {18, L"abcdefghijklmnopq…"}, - {17, L"abcdefghijklmnop…"}, - {16, L"abcdefghijklmno…"}, - {0, NULL} // sentinel terminator + {26, L"abcdefghijklmnopqrst"}, {25, L"abcdefghijklmnopqrst"}, + {24, L"abcdefghijklmnopqrst"}, {23, L"abcdefghijklmnopqrst"}, + {22, L"abcdefghijklmnopqrst"}, {21, L"abcdefghijklmnopqrst"}, + {20, L"abcdefghijklmnopqrst"}, {19, L"abcdefghijklmnopqr…"}, + {18, L"abcdefghijklmnopq…"}, {17, L"abcdefghijklmnop…"}, + {16, L"abcdefghijklmno…"}, {0, NULL} // sentinel terminator }; - for (size_t i=0; testcases3[i].expected != NULL; i++) { + for (size_t i = 0; testcases3[i].expected != NULL; i++) { testcases3[i].run(pager); } } - enum word_motion_t { word_motion_left, word_motion_right }; static void test_1_word_motion(word_motion_t motion, move_word_style_t style, const wcstring &test) { @@ -4127,10 +4109,10 @@ static void test_illegal_command_exit_code(void) { {L"**", STATUS_ILLEGAL_CMD}, {L"%", STATUS_ILLEGAL_CMD}, {L"%test", STATUS_ILLEGAL_CMD}, - // the following two inputs cause errors during tests for unknown reasons - // ("terminate called after throwing an instance of 'std::bad_alloc'") - // {L"?", STATUS_ILLEGAL_CMD}, - // {L"abc?def", STATUS_ILLEGAL_CMD}, + // the following two inputs cause errors during tests for unknown reasons + // ("terminate called after throwing an instance of 'std::bad_alloc'") + // {L"?", STATUS_ILLEGAL_CMD}, + // {L"abc?def", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD}}; int res = 0; @@ -4143,7 +4125,8 @@ static void test_illegal_command_exit_code(void) { int exit_status = res ? STATUS_UNKNOWN_COMMAND : proc_get_last_status(); if (exit_status != tests[i].result) { - err(L"command '%ls': expected exit code %d , got %d", tests[i].txt, tests[i].result, exit_status); + err(L"command '%ls': expected exit code %d , got %d", tests[i].txt, tests[i].result, + exit_status); } } } diff --git a/src/history.h b/src/history.h index c6f55a679..1cb9e0bf7 100644 --- a/src/history.h +++ b/src/history.h @@ -327,7 +327,8 @@ class history_search_t { } // Default constructor. - history_search_t() : history(), term(), search_type(HISTORY_SEARCH_TYPE_CONTAINS), case_sensitive(true) {} + history_search_t() + : history(), term(), search_type(HISTORY_SEARCH_TYPE_CONTAINS), case_sensitive(true) {} }; // Init history library. The history file won't actually be loaded until the first time a history diff --git a/src/pager.h b/src/pager.h index 0498b0803..74b9e9ce0 100644 --- a/src/pager.h +++ b/src/pager.h @@ -75,15 +75,9 @@ class pager_t { /// On-screen width of the description information. size_t desc_width; /// Minimum acceptable width. - //size_t min_width; + // size_t min_width; - comp_t() - : comp(), - desc(), - representative(L""), - comp_width(0), - desc_width(0) - {} + comp_t() : comp(), desc(), representative(L""), comp_width(0), desc_width(0) {} // Our text looks like this: // completion (description) @@ -119,8 +113,8 @@ class pager_t { bool completion_info_passes_filter(const comp_t &info) const; - void completion_print(size_t cols, const size_t *width_per_column, size_t row_start, size_t row_stop, - const wcstring &prefix, const comp_info_list_t &lst, + void completion_print(size_t cols, const size_t *width_per_column, size_t row_start, + size_t row_stop, const wcstring &prefix, const comp_info_list_t &lst, page_rendering_t *rendering) const; line_t completion_print_item(const wcstring &prefix, const comp_t *c, size_t row, size_t column, size_t width, bool secondary, bool selected, diff --git a/src/parse_constants.h b/src/parse_constants.h index 84a3f9828..642a569ee 100644 --- a/src/parse_constants.h +++ b/src/parse_constants.h @@ -136,22 +136,14 @@ enum parse_keyword_t { } __packed; const enum_map keyword_enum_map[] = { - {parse_keyword_and, L"and"}, - {parse_keyword_begin, L"begin"}, - {parse_keyword_builtin, L"builtin"}, - {parse_keyword_case, L"case"}, - {parse_keyword_command, L"command"}, - {parse_keyword_else, L"else"}, - {parse_keyword_end, L"end"}, - {parse_keyword_exec, L"exec"}, - {parse_keyword_for, L"for"}, - {parse_keyword_function, L"function"}, - {parse_keyword_if, L"if"}, - {parse_keyword_in, L"in"}, - {parse_keyword_not, L"not"}, - {parse_keyword_or, L"or"}, - {parse_keyword_switch, L"switch"}, - {parse_keyword_while, L"while"}, + {parse_keyword_and, L"and"}, {parse_keyword_begin, L"begin"}, + {parse_keyword_builtin, L"builtin"}, {parse_keyword_case, L"case"}, + {parse_keyword_command, L"command"}, {parse_keyword_else, L"else"}, + {parse_keyword_end, L"end"}, {parse_keyword_exec, L"exec"}, + {parse_keyword_for, L"for"}, {parse_keyword_function, L"function"}, + {parse_keyword_if, L"if"}, {parse_keyword_in, L"in"}, + {parse_keyword_not, L"not"}, {parse_keyword_or, L"or"}, + {parse_keyword_switch, L"switch"}, {parse_keyword_while, L"while"}, {parse_keyword_none, NULL}}; #define keyword_enum_map_len (sizeof keyword_enum_map / sizeof *keyword_enum_map) diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 936b78ab9..6408c361b 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -708,8 +708,7 @@ parse_execution_result_t parse_execution_context_t::report_errors( parser->get_backtrace(src, error_list, &backtrace_and_desc); // Print it. - if (! should_suppress_stderr_for_tests()) - fprintf(stderr, "%ls", backtrace_and_desc.c_str()); + if (!should_suppress_stderr_for_tests()) fprintf(stderr, "%ls", backtrace_and_desc.c_str()); } return parse_execution_errored; } diff --git a/src/parse_util.cpp b/src/parse_util.cpp index 35ccbcaa4..43321d372 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -204,9 +204,9 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c // The command substitutions must not be NULL and must be in the valid pointer range, and // the end must be bigger than the beginning. assert(bracket_range_begin != NULL && bracket_range_begin >= valid_range_start && - bracket_range_begin <= valid_range_end); + bracket_range_begin <= valid_range_end); assert(bracket_range_end != NULL && bracket_range_end > bracket_range_begin && - bracket_range_end >= valid_range_start && bracket_range_end <= valid_range_end); + bracket_range_end >= valid_range_start && bracket_range_end <= valid_range_end); // Assign the substring to the out_contents. const wchar_t *interior_begin = bracket_range_begin + 1; @@ -1040,13 +1040,12 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t if (out_errors) { // We have something like $$$^.... Back up until we reach the first $. size_t first_dollar = idx; - while (first_dollar > 0 && - (unesc.at(first_dollar - 1) == VARIABLE_EXPAND || - unesc.at(first_dollar - 1) == VARIABLE_EXPAND_SINGLE)) { + while (first_dollar > 0 && (unesc.at(first_dollar - 1) == VARIABLE_EXPAND || + unesc.at(first_dollar - 1) == VARIABLE_EXPAND_SINGLE)) { first_dollar--; } parse_util_expand_variable_error(unesc, node.source_start, first_dollar, - out_errors); + out_errors); } } } @@ -1174,13 +1173,13 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, parse_bool_statement_type_t bool_type = parse_node_tree_t::statement_boolean_type(*spec_statement); if (bool_type == parse_bool_and) { // this is not allowed - errored = append_syntax_error( - &parse_errors, spec_statement->source_start, - BOOL_AFTER_BACKGROUND_ERROR_MSG, L"and"); + errored = + append_syntax_error(&parse_errors, spec_statement->source_start, + BOOL_AFTER_BACKGROUND_ERROR_MSG, L"and"); } else if (bool_type == parse_bool_or) { // this is not allowed - errored = append_syntax_error( - &parse_errors, spec_statement->source_start, - BOOL_AFTER_BACKGROUND_ERROR_MSG, L"or"); + errored = + append_syntax_error(&parse_errors, spec_statement->source_start, + BOOL_AFTER_BACKGROUND_ERROR_MSG, L"or"); } break; } diff --git a/src/screen.cpp b/src/screen.cpp index 4fc38d691..19836a14d 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -123,8 +123,7 @@ static bool is_screen_name_escape_seq(const wchar_t *code, size_t *resulting_len // Consider just k to be the code. *resulting_length = 2; } else { - const wchar_t *escape_sequence_end = - screen_name_end + wcslen(screen_name_end_sentinel); + const wchar_t *escape_sequence_end = screen_name_end + wcslen(screen_name_end_sentinel); *resulting_length = escape_sequence_end - code; } return true; diff --git a/src/screen.h b/src/screen.h index 4dabeeb52..c4eb257f1 100644 --- a/src/screen.h +++ b/src/screen.h @@ -55,9 +55,7 @@ struct line_t { colors.insert(colors.end(), line.colors.begin(), line.colors.end()); } - wcstring to_string() const { - return wcstring(this->text.begin(), this->text.end()); - } + wcstring to_string() const { return wcstring(this->text.begin(), this->text.end()); } }; /// A class representing screen contents. diff --git a/src/wildcard.cpp b/src/wildcard.cpp index cd8cb226d..15fbe59de 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -490,7 +490,8 @@ class wildcard_expander_t { void add_expansion_result(const wcstring &result) { // This function is only for the non-completions case. - assert(!static_cast(this->flags & EXPAND_FOR_COMPLETIONS)); //!OCLINT(multiple unary operator) + assert(!static_cast(this->flags & + EXPAND_FOR_COMPLETIONS)); //!OCLINT(multiple unary operator) if (this->completion_set.insert(result).second) { append_completion(this->resolved_completions, result); this->did_add = true;