time for another make style-all

This commit is contained in:
Kurtis Rader 2016-12-03 20:12:53 -08:00
parent 45d3a705be
commit 9443a415bf
17 changed files with 89 additions and 120 deletions

View file

@ -826,8 +826,10 @@ static int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **ar
w.woptind = 0; w.woptind = 0;
static const struct woption long_options[] = { static const struct woption long_options[] = {{L"quiet", no_argument, NULL, 'q'},
{L"quiet", no_argument, 0, 'q'}, {L"search", no_argument, 0, 's'}, {L"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; {L"search", no_argument, NULL, 's'},
{L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};
while (1) { while (1) {
int opt_index = 0; int opt_index = 0;

View file

@ -310,8 +310,8 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (do_complete) { if (do_complete) {
const wchar_t *token; const wchar_t *token;
parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0,
0, 0); 0);
// Create a scoped transient command line, so that bulitin_commandline will see our // Create a scoped transient command line, so that bulitin_commandline will see our
// argument, not the reader buffer. // argument, not the reader buffer.
@ -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. // just look for the space and clear it.
if (!(next.flags & COMPLETE_NO_SPACE) && if (!(next.flags & COMPLETE_NO_SPACE) &&
string_suffixes_string(L" ", faux_cmdline_with_completion)) { string_suffixes_string(L" ", faux_cmdline_with_completion)) {
faux_cmdline_with_completion.resize(faux_cmdline_with_completion.size() - faux_cmdline_with_completion.resize(faux_cmdline_with_completion.size() - 1);
1);
} }
// The input data is meant to be something like you would have on the command // The input data is meant to be something like you would have on the command

View file

@ -167,7 +167,8 @@ class test_parser {
expression *parse_binary_primary(unsigned int start, unsigned int end); expression *parse_binary_primary(unsigned int start, unsigned int end);
expression *parse_just_a_string(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 { 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. // Empty list and one-arg list should be handled by caller.
assert(args.size() > 1); 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; wcstring_list_t eval_errors;
bool result = expr->evaluate(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"); printf("test returned eval errors:\n");
for (size_t i = 0; i < eval_errors.size(); i++) { for (size_t i = 0; i < eval_errors.size(); i++) {
printf("\t%ls\n", eval_errors.at(i).c_str()); printf("\t%ls\n", eval_errors.at(i).c_str());

View file

@ -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 /// will print the string 'fish: Pi = 3.141', given that debug_level is 1 or higher, and that
/// program_name is 'fish'. /// 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, ...); void __attribute__((noinline)) debug(int level, const wchar_t *msg, ...);
/// Replace special characters with backslash escape sequences. Newline is replaced with \n, etc. /// Replace special characters with backslash escape sequences. Newline is replaced with \n, etc.

View file

@ -1240,9 +1240,8 @@ bool completer_t::try_complete_user(const wcstring &str) {
wcstring name = format_string(L"~%ls", pw_name); wcstring name = format_string(L"~%ls", pw_name);
wcstring desc = format_string(COMPLETE_USER_DESC, pw_name); wcstring desc = format_string(COMPLETE_USER_DESC, pw_name);
append_completion(&this->completions, name, desc, COMPLETE_REPLACES_TOKEN | append_completion(&this->completions, name, desc,
COMPLETE_DONT_ESCAPE | COMPLETE_REPLACES_TOKEN | COMPLETE_DONT_ESCAPE | COMPLETE_NO_SPACE);
COMPLETE_NO_SPACE);
result = true; result = true;
} }
} }

View file

@ -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 // 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. // case we pretend we succeeded. See the comment in save_to_path for the rationale.
if (needs_lock) { if (needs_lock) {
// This is safe in terms of the fallback function implemented in terms of fcntl: only ever // This is safe in terms of the fallback function implemented in terms of fcntl: only
// run on the main thread, and protected by the universal variable lock // ever run on the main thread, and protected by the universal variable lock.
// cppcheck-suppress flockSemanticsWarning // cppcheck-suppress flockSemanticsWarning
while (flock(fd, LOCK_EX) < 0) { while (flock(fd, LOCK_EX) < 0) {
/* error */ /* error */

View file

@ -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. // Not enough room in dst, add NUL and traverse rest of src.
if (n == 0) { if (n == 0) {
if (siz != 0) *d = '\0'; // NUL-terminate dst 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 return s - src - 1; // count does not include NUL
} }
@ -506,7 +507,7 @@ int flock(int fd, int op) {
struct flock fl = {0}; struct flock fl = {0};
switch (op & (LOCK_EX|LOCK_SH|LOCK_UN)) { switch (op & (LOCK_EX | LOCK_SH | LOCK_UN)) {
case LOCK_EX: case LOCK_EX:
fl.l_type = F_WRLCK; fl.l_type = F_WRLCK;
break; break;
@ -527,8 +528,7 @@ int flock(int fd, int op) {
fl.l_whence = SEEK_SET; fl.l_whence = SEEK_SET;
rc = fcntl(fd, op & LOCK_NB ? F_SETLK : F_SETLKW, &fl); rc = fcntl(fd, op & LOCK_NB ? F_SETLK : F_SETLKW, &fl);
if (rc && (errno == EAGAIN)) if (rc && (errno == EAGAIN)) errno = EWOULDBLOCK;
errno = EWOULDBLOCK;
return rc; return rc;
} }

View file

@ -134,10 +134,10 @@ int killpg(int pgr, int sig);
// cppcheck-suppress flockSemanticsWarning // cppcheck-suppress flockSemanticsWarning
int flock(int fd, int op); int flock(int fd, int op);
#define LOCK_SH 1 /* Shared lock. */ #define LOCK_SH 1 // Shared lock.
#define LOCK_EX 2 /* Exclusive lock. */ #define LOCK_EX 2 // Exclusive lock.
#define LOCK_UN 8 /* Unlock. */ #define LOCK_UN 8 // Unlock.
#define LOCK_NB 4 /* Don't block when locking. */ #define LOCK_NB 4 // Don't block when locking.
#endif #endif

View file

@ -1649,7 +1649,8 @@ struct pager_layout_testcase_t {
wcstring text = sd.line(0).to_string(); wcstring text = sd.line(0).to_string();
if (text != expected) { 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); do_test(text == expected);
} }
@ -1666,20 +1667,14 @@ static void test_pager_layout() {
const completion_t c1(L"abcdefghij", L"1234567890"); const completion_t c1(L"abcdefghij", L"1234567890");
pager.set_completions(completion_list_t(1, c1)); pager.set_completions(completion_list_t(1, c1));
const pager_layout_testcase_t testcases1[] = { const pager_layout_testcase_t testcases1[] = {
{26, L"abcdefghij (1234567890)"}, {26, L"abcdefghij (1234567890)"}, {25, L"abcdefghij (1234567890)"},
{25, L"abcdefghij (1234567890)"}, {24, L"abcdefghij (1234567890)"}, {23, L"abcdefghij (12345678…)"},
{24, L"abcdefghij (1234567890)"}, {22, L"abcdefghij (1234567…)"}, {21, L"abcdefghij (123456…)"},
{23, L"abcdefghij (12345678…)"}, {20, L"abcdefghij (12345…)"}, {19, L"abcdefghij (1234…)"},
{22, L"abcdefghij (1234567…)"}, {18, L"abcdefgh… (1234…)"}, {17, L"abcdefg… (1234…)"},
{21, L"abcdefghij (123456…)"}, {16, L"abcdefg… (123…)"}, {0, NULL} // sentinel terminator
{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); testcases1[i].run(pager);
} }
@ -1687,20 +1682,14 @@ static void test_pager_layout() {
const completion_t c2(L"abcdefghijklmnopqrs", L"1"); const completion_t c2(L"abcdefghijklmnopqrs", L"1");
pager.set_completions(completion_list_t(1, c2)); pager.set_completions(completion_list_t(1, c2));
const pager_layout_testcase_t testcases2[] = { const pager_layout_testcase_t testcases2[] = {
{26, L"abcdefghijklmnopqrs (1)"}, {26, L"abcdefghijklmnopqrs (1)"}, {25, L"abcdefghijklmnopqrs (1)"},
{25, L"abcdefghijklmnopqrs (1)"}, {24, L"abcdefghijklmnopqrs (1)"}, {23, L"abcdefghijklmnopq… (1)"},
{24, L"abcdefghijklmnopqrs (1)"}, {22, L"abcdefghijklmnop… (1)"}, {21, L"abcdefghijklmno… (1)"},
{23, L"abcdefghijklmnopq… (1)"}, {20, L"abcdefghijklmn… (1)"}, {19, L"abcdefghijklm… (1)"},
{22, L"abcdefghijklmnop… (1)"}, {18, L"abcdefghijkl… (1)"}, {17, L"abcdefghijk… (1)"},
{21, L"abcdefghijklmno… (1)"}, {16, L"abcdefghij… (1)"}, {0, NULL} // sentinel terminator
{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); testcases2[i].run(pager);
} }
@ -1708,25 +1697,18 @@ static void test_pager_layout() {
const completion_t c3(L"abcdefghijklmnopqrst", L""); const completion_t c3(L"abcdefghijklmnopqrst", L"");
pager.set_completions(completion_list_t(1, c3)); pager.set_completions(completion_list_t(1, c3));
const pager_layout_testcase_t testcases3[] = { const pager_layout_testcase_t testcases3[] = {
{26, L"abcdefghijklmnopqrst"}, {26, L"abcdefghijklmnopqrst"}, {25, L"abcdefghijklmnopqrst"},
{25, L"abcdefghijklmnopqrst"}, {24, L"abcdefghijklmnopqrst"}, {23, L"abcdefghijklmnopqrst"},
{24, L"abcdefghijklmnopqrst"}, {22, L"abcdefghijklmnopqrst"}, {21, L"abcdefghijklmnopqrst"},
{23, L"abcdefghijklmnopqrst"}, {20, L"abcdefghijklmnopqrst"}, {19, L"abcdefghijklmnopqr…"},
{22, L"abcdefghijklmnopqrst"}, {18, L"abcdefghijklmnopq…"}, {17, L"abcdefghijklmnop…"},
{21, L"abcdefghijklmnopqrst"}, {16, L"abcdefghijklmno…"}, {0, NULL} // sentinel terminator
{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); testcases3[i].run(pager);
} }
} }
enum word_motion_t { word_motion_left, word_motion_right }; 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, static void test_1_word_motion(word_motion_t motion, move_word_style_t style,
const wcstring &test) { const wcstring &test) {
@ -4143,7 +4125,8 @@ static void test_illegal_command_exit_code(void) {
int exit_status = res ? STATUS_UNKNOWN_COMMAND : proc_get_last_status(); int exit_status = res ? STATUS_UNKNOWN_COMMAND : proc_get_last_status();
if (exit_status != tests[i].result) { 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);
} }
} }
} }

View file

@ -327,7 +327,8 @@ class history_search_t {
} }
// Default constructor. // 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 // Init history library. The history file won't actually be loaded until the first time a history

View file

@ -75,15 +75,9 @@ class pager_t {
/// On-screen width of the description information. /// On-screen width of the description information.
size_t desc_width; size_t desc_width;
/// Minimum acceptable width. /// Minimum acceptable width.
//size_t min_width; // size_t min_width;
comp_t() comp_t() : comp(), desc(), representative(L""), comp_width(0), desc_width(0) {}
: comp(),
desc(),
representative(L""),
comp_width(0),
desc_width(0)
{}
// Our text looks like this: // Our text looks like this:
// completion (description) // completion (description)
@ -119,8 +113,8 @@ class pager_t {
bool completion_info_passes_filter(const comp_t &info) const; 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, void completion_print(size_t cols, const size_t *width_per_column, size_t row_start,
const wcstring &prefix, const comp_info_list_t &lst, size_t row_stop, const wcstring &prefix, const comp_info_list_t &lst,
page_rendering_t *rendering) const; page_rendering_t *rendering) const;
line_t completion_print_item(const wcstring &prefix, const comp_t *c, size_t row, size_t column, 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, size_t width, bool secondary, bool selected,

View file

@ -136,22 +136,14 @@ enum parse_keyword_t {
} __packed; } __packed;
const enum_map<parse_keyword_t> keyword_enum_map[] = { const enum_map<parse_keyword_t> keyword_enum_map[] = {
{parse_keyword_and, L"and"}, {parse_keyword_and, L"and"}, {parse_keyword_begin, L"begin"},
{parse_keyword_begin, L"begin"}, {parse_keyword_builtin, L"builtin"}, {parse_keyword_case, L"case"},
{parse_keyword_builtin, L"builtin"}, {parse_keyword_command, L"command"}, {parse_keyword_else, L"else"},
{parse_keyword_case, L"case"}, {parse_keyword_end, L"end"}, {parse_keyword_exec, L"exec"},
{parse_keyword_command, L"command"}, {parse_keyword_for, L"for"}, {parse_keyword_function, L"function"},
{parse_keyword_else, L"else"}, {parse_keyword_if, L"if"}, {parse_keyword_in, L"in"},
{parse_keyword_end, L"end"}, {parse_keyword_not, L"not"}, {parse_keyword_or, L"or"},
{parse_keyword_exec, L"exec"}, {parse_keyword_switch, L"switch"}, {parse_keyword_while, L"while"},
{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}}; {parse_keyword_none, NULL}};
#define keyword_enum_map_len (sizeof keyword_enum_map / sizeof *keyword_enum_map) #define keyword_enum_map_len (sizeof keyword_enum_map / sizeof *keyword_enum_map)

View file

@ -708,8 +708,7 @@ parse_execution_result_t parse_execution_context_t::report_errors(
parser->get_backtrace(src, error_list, &backtrace_and_desc); parser->get_backtrace(src, error_list, &backtrace_and_desc);
// Print it. // Print it.
if (! should_suppress_stderr_for_tests()) if (!should_suppress_stderr_for_tests()) fprintf(stderr, "%ls", backtrace_and_desc.c_str());
fprintf(stderr, "%ls", backtrace_and_desc.c_str());
} }
return parse_execution_errored; return parse_execution_errored;
} }

View file

@ -1040,8 +1040,7 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(const parse_node_t
if (out_errors) { if (out_errors) {
// We have something like $$$^.... Back up until we reach the first $. // We have something like $$$^.... Back up until we reach the first $.
size_t first_dollar = idx; size_t first_dollar = idx;
while (first_dollar > 0 && while (first_dollar > 0 && (unesc.at(first_dollar - 1) == VARIABLE_EXPAND ||
(unesc.at(first_dollar - 1) == VARIABLE_EXPAND ||
unesc.at(first_dollar - 1) == VARIABLE_EXPAND_SINGLE)) { unesc.at(first_dollar - 1) == VARIABLE_EXPAND_SINGLE)) {
first_dollar--; first_dollar--;
} }
@ -1174,12 +1173,12 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
parse_bool_statement_type_t bool_type = parse_bool_statement_type_t bool_type =
parse_node_tree_t::statement_boolean_type(*spec_statement); parse_node_tree_t::statement_boolean_type(*spec_statement);
if (bool_type == parse_bool_and) { // this is not allowed if (bool_type == parse_bool_and) { // this is not allowed
errored = append_syntax_error( errored =
&parse_errors, spec_statement->source_start, append_syntax_error(&parse_errors, spec_statement->source_start,
BOOL_AFTER_BACKGROUND_ERROR_MSG, L"and"); BOOL_AFTER_BACKGROUND_ERROR_MSG, L"and");
} else if (bool_type == parse_bool_or) { // this is not allowed } else if (bool_type == parse_bool_or) { // this is not allowed
errored = append_syntax_error( errored =
&parse_errors, spec_statement->source_start, append_syntax_error(&parse_errors, spec_statement->source_start,
BOOL_AFTER_BACKGROUND_ERROR_MSG, L"or"); BOOL_AFTER_BACKGROUND_ERROR_MSG, L"or");
} }
break; break;

View file

@ -123,8 +123,7 @@ static bool is_screen_name_escape_seq(const wchar_t *code, size_t *resulting_len
// Consider just <esc>k to be the code. // Consider just <esc>k to be the code.
*resulting_length = 2; *resulting_length = 2;
} else { } else {
const wchar_t *escape_sequence_end = const wchar_t *escape_sequence_end = screen_name_end + wcslen(screen_name_end_sentinel);
screen_name_end + wcslen(screen_name_end_sentinel);
*resulting_length = escape_sequence_end - code; *resulting_length = escape_sequence_end - code;
} }
return true; return true;

View file

@ -55,9 +55,7 @@ struct line_t {
colors.insert(colors.end(), line.colors.begin(), line.colors.end()); colors.insert(colors.end(), line.colors.begin(), line.colors.end());
} }
wcstring to_string() const { wcstring to_string() const { return wcstring(this->text.begin(), this->text.end()); }
return wcstring(this->text.begin(), this->text.end());
}
}; };
/// A class representing screen contents. /// A class representing screen contents.

View file

@ -490,7 +490,8 @@ class wildcard_expander_t {
void add_expansion_result(const wcstring &result) { void add_expansion_result(const wcstring &result) {
// This function is only for the non-completions case. // This function is only for the non-completions case.
assert(!static_cast<bool>(this->flags & EXPAND_FOR_COMPLETIONS)); //!OCLINT(multiple unary operator) assert(!static_cast<bool>(this->flags &
EXPAND_FOR_COMPLETIONS)); //!OCLINT(multiple unary operator)
if (this->completion_set.insert(result).second) { if (this->completion_set.insert(result).second) {
append_completion(this->resolved_completions, result); append_completion(this->resolved_completions, result);
this->did_add = true; this->did_add = true;