From 2da81b0ae789c91c196f0ab6f154bf462bafec2d Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 5 May 2013 02:33:17 -0700 Subject: [PATCH] Formatting and style updates --- builtin.cpp | 2 +- builtin_printf.cpp | 88 +++++++++++++++++++++++++++++++--------------- common.cpp | 2 +- complete.h | 2 +- event.h | 2 +- exec.cpp | 5 +-- expand.cpp | 28 +++++++-------- fish.cpp | 2 +- fish_tests.cpp | 4 +-- highlight.cpp | 7 ++-- history.cpp | 10 +++--- input.cpp | 4 +-- input_common.cpp | 2 +- io.h | 12 +++---- proc.cpp | 4 +-- reader.cpp | 8 ++--- wildcard.cpp | 10 +++--- wutil.cpp | 2 +- 18 files changed, 115 insertions(+), 79 deletions(-) diff --git a/builtin.cpp b/builtin.cpp index 890784a37..9796d356f 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -214,7 +214,7 @@ wcstring builtin_help_get(parser_t &parser, const wchar_t *name) /* This won't ever work if no_exec is set */ if (no_exec) return wcstring(); - + wcstring_list_t lst; wcstring out; const wcstring name_esc = escape_string(name, 1); diff --git a/builtin_printf.cpp b/builtin_printf.cpp index 7f1fb4eca..e164f8193 100644 --- a/builtin_printf.cpp +++ b/builtin_printf.cpp @@ -100,23 +100,46 @@ static int hex_to_bin(const wchar_t &c) { switch (c) { - case L'0': return 0; - case L'1': return 1; - case L'2': return 2; - case L'3': return 3; - case L'4': return 4; - case L'5': return 5; - case L'6': return 6; - case L'7': return 7; - case L'8': return 8; - case L'9': return 9; - case L'a': case L'A': return 10; - case L'b': case L'B': return 11; - case L'c': case L'C': return 12; - case L'd': case L'D': return 13; - case L'e': case L'E': return 14; - case L'f': case L'F': return 15; - default: return -1; + case L'0': + return 0; + case L'1': + return 1; + case L'2': + return 2; + case L'3': + return 3; + case L'4': + return 4; + case L'5': + return 5; + case L'6': + return 6; + case L'7': + return 7; + case L'8': + return 8; + case L'9': + return 9; + case L'a': + case L'A': + return 10; + case L'b': + case L'B': + return 11; + case L'c': + case L'C': + return 12; + case L'd': + case L'D': + return 13; + case L'e': + case L'E': + return 14; + case L'f': + case L'F': + return 15; + default: + return -1; } } @@ -124,15 +147,24 @@ static int octal_to_bin(wchar_t c) { switch (c) { - case L'0': return 0; - case L'1': return 1; - case L'2': return 2; - case L'3': return 3; - case L'4': return 4; - case L'5': return 5; - case L'6': return 6; - case L'7': return 7; - default: return -1; + case L'0': + return 0; + case L'1': + return 1; + case L'2': + return 2; + case L'3': + return 3; + case L'4': + return 4; + case L'5': + return 5; + case L'6': + return 6; + case L'7': + return 7; + default: + return -1; } } @@ -358,9 +390,9 @@ long builtin_printf_state_t::print_esc(const wchar_t *escstart, bool octal_0) uni_value = uni_value * 16 + hex_to_bin(*p); p++; } - + /* PCA GNU printf respects the limitations described in ISO N717, about which universal characters "shall not" be specified. I believe this limitation is for the benefit of compilers; I see no reason to impose it in builtin_printf. - + If __STDC_ISO_10646__ is defined, then it means wchar_t can and does hold Unicode code points, so just use that. If not defined, use the %lc printf conversion; this probably won't do anything good if your wide character set is not Unicode, but such platforms are exceedingly rare. */ if (uni_value > 0x10FFFF) diff --git a/common.cpp b/common.cpp index 75a44ceb2..0ac84361c 100644 --- a/common.cpp +++ b/common.cpp @@ -568,7 +568,7 @@ wcstring wsetlocale(int category, const wchar_t *locale) // U+23CE is the "return" character omitted_newline_char = unicode ? L'\x23CE' : L'~'; - + if (!res) return wcstring(); else diff --git a/complete.h b/complete.h index 5af677035..42416b5c2 100644 --- a/complete.h +++ b/complete.h @@ -89,7 +89,7 @@ enum /** This completion should be inserted as-is, without escaping. */ COMPLETE_DONT_ESCAPE = 1 << 4, - + /** If you do escape, don't escape tildes */ COMPLETE_DONT_ESCAPE_TILDES = 1 << 5 }; diff --git a/event.h b/event.h index 5bcf28a5f..645eeda46 100644 --- a/event.h +++ b/event.h @@ -49,7 +49,7 @@ enum */ struct event_t { - public: +public: /** Type of event */ int type; diff --git a/exec.cpp b/exec.cpp index 3c5d74ed0..82261b18a 100644 --- a/exec.cpp +++ b/exec.cpp @@ -590,7 +590,8 @@ void exec(parser_t &parser, job_t *j) CHECK(j,); CHECK_BLOCK(); - if (no_exec) { + if (no_exec) + { exec_no_exec(parser, j); return; } @@ -1312,7 +1313,7 @@ void exec(parser_t &parser, job_t *j) /* Get argv and envv before we fork */ null_terminated_array_t argv_array; convert_wide_array_to_narrow(p->get_argv_array(), &argv_array); - + /* Ensure that stdin is blocking before we hand it off (see issue #176). It's a little strange that we only do this with stdin and not with stdout or stderr. However in practice, setting or clearing O_NONBLOCK on stdin also sets it for the other two fds, presumably because they refer to the same underlying file (/dev/tty?) */ make_fd_blocking(STDIN_FILENO); diff --git a/expand.cpp b/expand.cpp index 8ff6de262..74e501027 100644 --- a/expand.cpp +++ b/expand.cpp @@ -1490,7 +1490,7 @@ static void expand_home_directory(wcstring &input) { size_t tail_idx; wcstring username = get_home_directory_name(input, &tail_idx); - + bool tilde_error = false; wcstring home; if (username.empty()) @@ -1539,7 +1539,7 @@ static void unexpand_tildes(const wcstring &input, std::vector *co // If it does not, there's nothing to do if (input.empty() || input.at(0) != L'~') return; - + // We only operate on completions that replace their contents // If we don't have any, we're done. // In particular, empty vectors are common. @@ -1554,15 +1554,15 @@ static void unexpand_tildes(const wcstring &input, std::vector *co } if (! has_candidate_completion) return; - + size_t tail_idx; wcstring username_with_tilde = L"~"; username_with_tilde.append(get_home_directory_name(input, &tail_idx)); - + // Expand username_with_tilde wcstring home = username_with_tilde; expand_tilde(home); - + // Now for each completion that starts with home, replace it with the username_with_tilde for (size_t i=0; i < completions->size(); i++) { @@ -1570,7 +1570,7 @@ static void unexpand_tildes(const wcstring &input, std::vector *co if ((comp.flags & COMPLETE_REPLACES_TOKEN) && string_prefixes_string(home, comp.completion)) { comp.completion.replace(0, home.size(), username_with_tilde); - + // And mark that our tilde is literal, so it doesn't try to escape it comp.flags |= COMPLETE_DONT_ESCAPE_TILDES; } @@ -1607,9 +1607,9 @@ static void remove_internal_separator(wcstring &str, bool conv) int expand_string(const wcstring &input, std::vector &output, expand_flags_t flags) -{ +{ parser_t parser(PARSER_TYPE_ERRORS_ONLY, true /* show errors */); - + size_t i; int res = EXPAND_OK; @@ -1618,7 +1618,7 @@ int expand_string(const wcstring &input, std::vector &output, expa output.push_back(completion_t(input)); return EXPAND_OK; } - + std::vector clist1, clist2; std::vector *in = &clist1, *out = &clist2; @@ -1642,7 +1642,7 @@ int expand_string(const wcstring &input, std::vector &output, expa if (! cmdsubst_ok) return EXPAND_ERROR; } - + for (i=0; i < in->size(); i++) { /* @@ -1785,19 +1785,19 @@ int expand_string(const wcstring &input, std::vector &output, expa } else { - if (! (flags & ACCEPT_INCOMPLETE)) + if (!(flags & ACCEPT_INCOMPLETE)) { out->push_back(completion_t(next_str)); } } } - + // Hack to un-expand tildes (see #647) - if (! (flags & EXPAND_SKIP_HOME_DIRECTORIES)) + if (!(flags & EXPAND_SKIP_HOME_DIRECTORIES)) { unexpand_tildes(input, out); } - + // Return our output output.insert(output.end(), out->begin(), out->end()); diff --git a/fish.cpp b/fish.cpp index 4a6466f9e..abefa8985 100644 --- a/fish.cpp +++ b/fish.cpp @@ -462,7 +462,7 @@ int main(int argc, char **argv) { /* Stop the exit status of any initialization commands (#635) */ proc_set_last_status(STATUS_BUILTIN_OK); - + /* Run the commands specified as arguments, if any */ if (! cmds.empty()) { diff --git a/fish_tests.cpp b/fish_tests.cpp index c02ca8abc..d9dd3d845 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -1701,7 +1701,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); srand(time(0)); configure_thread_assertions_for_testing(); - + program_name=L"(ignore)"; say(L"Testing low-level functionality"); @@ -1714,7 +1714,7 @@ int main(int argc, char **argv) builtin_init(); reader_init(); env_init(); - + test_format(); test_escape(); test_convert(); diff --git a/highlight.cpp b/highlight.cpp index e9f8a9f42..8ea0989e6 100644 --- a/highlight.cpp +++ b/highlight.cpp @@ -1377,9 +1377,12 @@ void highlight_shell(const wcstring &buff, std::vector &color, size_t pos, for (size_t i=0; i < buff.size(); i++) { int ¤t_val = color.at(i); - if (current_val >= 0) { + if (current_val >= 0) + { last_val = current_val; - } else { + } + else + { current_val = last_val; //note - this writes into the vector } } diff --git a/history.cpp b/history.cpp index 83caec805..8e3772d21 100644 --- a/history.cpp +++ b/history.cpp @@ -70,7 +70,7 @@ class history_output_buffer_t return s ? strlen(s) : 0; } - public: +public: /* Add a bit more to HISTORY_OUTPUT_BUFFER_SIZE because we flush once we've exceeded that size */ history_output_buffer_t() : buffer(HISTORY_OUTPUT_BUFFER_SIZE + 128, '\0'), offset(0) @@ -1070,14 +1070,14 @@ bool history_search_t::go_backwards() return false; const bool main_thread = is_main_thread(); - + while (++idx < max_idx) { if (main_thread ? reader_interrupted() : reader_thread_job_is_stale()) { return false; } - + const history_item_t item = history->item_at_index(idx); /* We're done if it's empty or we cancelled */ if (item.empty()) @@ -1165,7 +1165,7 @@ static void unescape_yaml(std::string &str) { // Operate on a const version of str, to avoid needless COWs that at() does. const std::string &const_str = str; - + // Look for a backslash size_t backslash = const_str.find('\\', cursor); if (backslash == std::string::npos || backslash + 1 >= size) @@ -1429,7 +1429,7 @@ bool history_t::save_internal_via_appending() */ /* So far so good. Write all items at or after first_unwritten_new_item_index */ - + bool errored = false; history_output_buffer_t buffer; while (first_unwritten_new_item_index < new_items.size()) diff --git a/input.cpp b/input.cpp index eddcc545f..f786b26ea 100644 --- a/input.cpp +++ b/input.cpp @@ -796,8 +796,8 @@ bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq) { errno = err; return false; - } - + } + *out_seq = format_string(L"%s", res); return true; diff --git a/input_common.cpp b/input_common.cpp index 0f9fa52bd..77c8f168a 100644 --- a/input_common.cpp +++ b/input_common.cpp @@ -287,7 +287,7 @@ static void input_flush_callbacks(void) /* Nothing to do if nothing to do */ if (callback_queue.empty()) return; - + /* We move the queue into a local variable, so that events queued up during a callback don't get fired until next round. */ callback_queue_t local_queue; std::swap(local_queue, callback_queue); diff --git a/io.h b/io.h index 32205b4ca..6a98f380d 100644 --- a/io.h +++ b/io.h @@ -3,13 +3,13 @@ #include #if __cplusplus > 199711L - // C++11 - #include - using std::shared_ptr; +// C++11 +#include +using std::shared_ptr; #else - // C++03 - #include - using std::tr1::shared_ptr; +// C++03 +#include +using std::tr1::shared_ptr; #endif /** diff --git a/proc.cpp b/proc.cpp index f444a7be1..749f38c2c 100644 --- a/proc.cpp +++ b/proc.cpp @@ -1060,7 +1060,7 @@ void job_continue(job_t *j, bool cont) { /* Put the job into the foreground. Hack: ensure that stdin is marked as blocking first (#176). */ make_fd_blocking(STDIN_FILENO); - + signal_block(); bool ok = terminal_give_to_job(j, cont); @@ -1202,7 +1202,7 @@ void job_continue(job_t *j, bool cont) } } } - + /* Put the shell back in the foreground. */ if (job_get_flag(j, JOB_TERMINAL) && job_get_flag(j, JOB_FOREGROUND)) { diff --git a/reader.cpp b/reader.cpp index fae46011c..f7f92e584 100644 --- a/reader.cpp +++ b/reader.cpp @@ -874,7 +874,7 @@ void reader_react_to_color_change() { if (! data) return; - + if (! data->repaint_needed || ! data->screen_reset_needed) { data->repaint_needed = true; @@ -1006,7 +1006,7 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag if (do_escape) { /* Respect COMPLETE_DONT_ESCAPE_TILDES */ - bool no_tilde = !! (flags & COMPLETE_DONT_ESCAPE_TILDES); + bool no_tilde = !!(flags & COMPLETE_DONT_ESCAPE_TILDES); escaped = escape(val, ESCAPE_ALL | ESCAPE_NO_QUOTED | (no_tilde ? ESCAPE_NO_TILDE : 0)); sb.append(escaped); move_cursor = wcslen(escaped); @@ -1328,7 +1328,7 @@ struct autosuggestion_context_t this->autosuggestion = special_suggestion; return 1; } - + /* Maybe cancel here */ if (reader_thread_job_is_stale()) return 0; @@ -3087,7 +3087,7 @@ const wchar_t *reader_readline(void) /* Start the cycle at the beginning */ completion_cycle_idx = (size_t)(-1); - + /* Repaint */ reader_repaint_if_needed(); } diff --git a/wildcard.cpp b/wildcard.cpp index 07ffe409e..5514023b6 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -729,7 +729,7 @@ static int wildcard_expand_internal(const wchar_t *wc, debug(2, L"Got null string on line %d of file %s", __LINE__, __FILE__); return 0; } - + const size_t base_dir_len = wcslen(base_dir); if (flags & ACCEPT_INCOMPLETE) @@ -897,7 +897,7 @@ static int wildcard_expand_internal(const wchar_t *wc, /* new_dir is a scratch area containing the full path to a file/directory we are iterating over */ wcstring new_dir = base_dir; - + wcstring name_str; while (wreaddir(dir, name_str)) { @@ -926,11 +926,11 @@ static int wildcard_expand_internal(const wchar_t *wc, { struct stat buf; int new_res; - + // new_dir is base_dir + some other path components // Replace everything after base_dir with the new path component new_dir.replace(base_dir_len, wcstring::npos, name_str); - + int stat_res = wstat(new_dir, &buf); if (!stat_res) @@ -942,7 +942,7 @@ static int wildcard_expand_internal(const wchar_t *wc, if (S_ISDIR(buf.st_mode) && (visited_files.insert(file_id).second || ! is_recursive)) { new_dir.push_back(L'/'); - + /* Regular matching */ diff --git a/wutil.cpp b/wutil.cpp index 03b55c89a..fa9ebc40e 100644 --- a/wutil.cpp +++ b/wutil.cpp @@ -294,7 +294,7 @@ int make_fd_nonblocking(int fd) { int flags = fcntl(fd, F_GETFL, 0); int err = 0; - if (! (flags & O_NONBLOCK)) + if (!(flags & O_NONBLOCK)) { err = fcntl(fd, F_SETFL, flags | O_NONBLOCK); }