From 464187491f910ab2cb8bb0a1bdc6013f10fcd319 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 2 Jun 2013 01:14:26 -0700 Subject: [PATCH] Formatting --- common.cpp | 12 ++++++------ common.h | 18 +++++++++--------- complete.cpp | 24 ++++++++++++------------ complete.h | 2 +- expand.h | 2 +- fish_tests.cpp | 6 +++--- reader.cpp | 45 +++++++++++++++++++++++---------------------- wildcard.cpp | 17 +++++++++-------- 8 files changed, 64 insertions(+), 62 deletions(-) diff --git a/common.cpp b/common.cpp index 158b9e83a..797398e8e 100644 --- a/common.cpp +++ b/common.cpp @@ -1772,13 +1772,13 @@ static bool subsequence_in_string(const wcstring &seq, const wcstring &str) { return false; } - + /* Empty strings are considered to be subsequences of everything */ if (seq.empty()) { return true; } - + size_t str_idx, seq_idx; for (seq_idx = str_idx = 0; seq_idx < seq.size() && str_idx < str.size(); seq_idx++) { @@ -1795,16 +1795,16 @@ static bool subsequence_in_string(const wcstring &seq, const wcstring &str) str_idx = char_loc + 1; } } - + /* We succeeded if we exhausted our sequence */ assert(seq_idx <= seq.size()); return seq_idx == seq.size(); } string_fuzzy_match_t::string_fuzzy_match_t(enum fuzzy_match_type_t t, size_t distance_first, size_t distance_second) : - type(t), - match_distance_first(distance_first), - match_distance_second(distance_second) + type(t), + match_distance_first(distance_first), + match_distance_second(distance_second) { } diff --git a/common.h b/common.h index 735867bcf..57fe7fa1a 100644 --- a/common.h +++ b/common.h @@ -250,22 +250,22 @@ enum fuzzy_match_type_t { /* We match the string exactly: FOOBAR matches FOOBAR */ fuzzy_match_exact = 0, - + /* We match a prefix of the string: FO matches FOOBAR */ fuzzy_match_prefix, - + /* We match the string exactly, but in a case insensitive way: foobar matches FOOBAR */ fuzzy_match_case_insensitive, - + /* We match a prefix of the string, in a case insensitive way: foo matches FOOBAR */ fuzzy_match_prefix_case_insensitive, - + /* We match a substring of the string: OOBA matches FOOBAR */ fuzzy_match_substring, - + /* A subsequence match with insertions only: FBR matches FOOBAR */ fuzzy_match_subsequence_insertions_only, - + /* We don't match the string */ fuzzy_match_none }; @@ -302,14 +302,14 @@ static inline bool match_type_shares_prefix(fuzzy_match_type_t t) struct string_fuzzy_match_t { enum fuzzy_match_type_t type; - + /* Strength of the match. The value depends on the type. Lower is stronger. */ size_t match_distance_first; size_t match_distance_second; - + /* Constructor */ string_fuzzy_match_t(enum fuzzy_match_type_t t, size_t distance_first = 0, size_t distance_second = 0); - + /* Return -1, 0, 1 if this match is (respectively) better than, equal to, or worse than rhs */ int compare(const string_fuzzy_match_t &rhs) const; }; diff --git a/complete.cpp b/complete.cpp index 001fe37b3..8fbcb1d34 100644 --- a/complete.cpp +++ b/complete.cpp @@ -375,7 +375,7 @@ class completer_t { return !!(flags & COMPLETION_REQUEST_FUZZY_MATCH); } - + fuzzy_match_type_t max_fuzzy_match_type() const { /* If we are doing fuzzy matching, request all types; if not request only prefix matching */ @@ -439,11 +439,11 @@ public: expand_flags_t result = 0; if (this->type() == COMPLETE_AUTOSUGGEST) result |= EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_JOBS; - + /* Allow fuzzy matching */ if (this->fuzzy()) result |= EXPAND_FUZZY_MATCH; - + return result; } @@ -1207,7 +1207,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool this->complete_cmd_desc(str_cmd); } } - + if (use_function) { //function_get_names( &possible_comp, cmd[0] == L'_' ); @@ -1658,22 +1658,22 @@ bool completer_t::complete_variable(const wcstring &str, size_t start_offset) const wchar_t *var = &whole_var[start_offset]; size_t varlen = wcslen(var); bool res = false; - + const wcstring_list_t names = complete_get_variable_names(); for (size_t i=0; imax_fuzzy_match_type()); if (match.type == fuzzy_match_none) { // No match continue; } - + wcstring comp; int flags = 0; - + if (! match_type_requires_full_replacement(match.type)) { // Take only the suffix @@ -1685,21 +1685,21 @@ bool completer_t::complete_variable(const wcstring &str, size_t start_offset) comp.append(env_name); flags = COMPLETE_REPLACES_TOKEN | COMPLETE_DONT_ESCAPE; } - + wcstring desc; if (this->wants_descriptions()) { env_var_t value_unescaped = env_get_string(env_name); if (value_unescaped.missing()) continue; - + wcstring value = expand_escape_variable(value_unescaped); if (this->type() != COMPLETE_AUTOSUGGEST) desc = format_string(COMPLETE_VAR_DESC_VAL, value.c_str()); } - + append_completion(this->completions, comp.c_str(), desc.c_str(), flags, match); - + res = true; } diff --git a/complete.h b/complete.h index 4fdfc63f8..da94bacdc 100644 --- a/complete.h +++ b/complete.h @@ -122,7 +122,7 @@ public: is case insensitive. */ int flags; - + /* Construction. Note: defining these so that they are not inlined reduces the executable size. */ completion_t(const wcstring &comp, const wcstring &desc = L"", string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact), int flags_val = 0); completion_t(const completion_t &); diff --git a/expand.h b/expand.h index 701695d29..1968e0ee5 100644 --- a/expand.h +++ b/expand.h @@ -57,7 +57,7 @@ enum /** Don't expand home directories */ EXPAND_SKIP_HOME_DIRECTORIES = 1 << 9, - + /** Allow fuzzy matching */ EXPAND_FUZZY_MATCH = 1 << 10 }; diff --git a/fish_tests.cpp b/fish_tests.cpp index 5146e88e0..2572e8d6a 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -988,18 +988,18 @@ static void test_complete(void) assert(completions.at(0).completion == L"oo1"); assert(completions.at(1).completion == L"oo2"); assert(completions.at(2).completion == L"oo3"); - + completions.clear(); complete(L"$1", completions, COMPLETION_REQUEST_DEFAULT); assert(completions.empty()); - + completions.clear(); complete(L"$1", completions, COMPLETION_REQUEST_DEFAULT | COMPLETION_REQUEST_FUZZY_MATCH); assert(completions.size() == 2); assert(completions.at(0).completion == L"$Foo1"); assert(completions.at(1).completion == L"$Bar1"); - + complete_set_variable_names(NULL); } diff --git a/reader.cpp b/reader.cpp index 8bf359d9c..9b2eea14e 100644 --- a/reader.cpp +++ b/reader.cpp @@ -1139,12 +1139,12 @@ static void run_pager(const wcstring &prefix, int is_quoted, const std::vector &comp) if (el.match.type < best_type) best_type = el.match.type; } - + /* Throw out completions whose match types are not the best. */ i = comp.size(); while (i--) @@ -1508,7 +1508,7 @@ static void prioritize_completions(std::vector &comp) comp.erase(comp.begin() + i); } } - + /* Sort the remainder */ sort(comp.begin(), comp.end(), compare_completions_by_match_type); } @@ -1536,7 +1536,7 @@ static const completion_t *cycle_competions(const std::vector &com const completion_t &c = comp.at(idx); /* Try this completion */ - if (! (c.flags & COMPLETE_REPLACES_TOKEN) || reader_can_replace(command_line, c.flags)) + if (!(c.flags & COMPLETE_REPLACES_TOKEN) || reader_can_replace(command_line, c.flags)) { /* Success */ result = &c; @@ -1605,7 +1605,7 @@ static bool handle_completions(const std::vector &comp) the token doesn't contain evil operators like {} */ - if (! (c.flags & COMPLETE_REPLACES_TOKEN) || reader_can_replace(tok, c.flags)) + if (!(c.flags & COMPLETE_REPLACES_TOKEN) || reader_can_replace(tok, c.flags)) { completion_insert(c.completion.c_str(), c.flags); } @@ -1618,7 +1618,7 @@ static bool handle_completions(const std::vector &comp) if (!done) { - + /* Determine the type of the best match(es) */ fuzzy_match_type_t best_match_type = fuzzy_match_none; for (size_t i=0; i < comp.size(); i++) @@ -1629,19 +1629,19 @@ static bool handle_completions(const std::vector &comp) best_match_type = el.match.type; } } - + /* Determine whether we are going to replace the token or not. If any commands of the best type do not require replacement, then ignore all those that want to use replacement */ bool will_replace_token = true; for (size_t i=0; i< comp.size(); i++) { const completion_t &el = comp.at(i); - if (el.match.type == best_match_type && ! (el.flags & COMPLETE_REPLACES_TOKEN)) + if (el.match.type == best_match_type && !(el.flags & COMPLETE_REPLACES_TOKEN)) { will_replace_token = false; break; } } - + /* Decide which completions survived. There may be a lot of them; it would be nice if we could figure out how to avoid copying them here */ std::vector surviving_completions; for (size_t i=0; i < comp.size(); i++) @@ -1650,21 +1650,21 @@ static bool handle_completions(const std::vector &comp) /* Only use completions with the best match type */ if (el.match.type != best_match_type) continue; - + /* Only use completions that match replace_token */ - bool completion_replace_token = !! (el.flags & COMPLETE_REPLACES_TOKEN); + bool completion_replace_token = !!(el.flags & COMPLETE_REPLACES_TOKEN); if (completion_replace_token != will_replace_token) continue; - + /* Don't use completions that want to replace, if we cannot replace them */ if (completion_replace_token && ! reader_can_replace(tok, el.flags)) continue; - + /* This completion survived */ surviving_completions.push_back(el); } - - + + /* Try to find a common prefix to insert among the surviving completions */ wcstring common_prefix; complete_flags_t flags = 0; @@ -1682,7 +1682,8 @@ static bool handle_completions(const std::vector &comp) { /* Determine the shared prefix length. */ size_t idx, max = mini(common_prefix.size(), el.completion.size()); - for (idx=0; idx < max; idx++) { + for (idx=0; idx < max; idx++) + { wchar_t ac = common_prefix.at(idx), bc = el.completion.at(idx); bool matches = (ac == bc); /* If we are replacing the token, allow case to vary */ @@ -1694,17 +1695,17 @@ static bool handle_completions(const std::vector &comp) if (! matches) break; } - + /* idx is now the length of the new common prefix */ common_prefix.resize(idx); prefix_is_partial_completion = true; - + /* Early out if we decide there's no common prefix */ if (idx == 0) break; } } - + if (! common_prefix.empty()) { /* We got something. If more than one completion contributed, then it means we have a prefix; don't insert a space after it */ @@ -1722,7 +1723,7 @@ static bool handle_completions(const std::vector &comp) assert(data->buff_pos >= prefix_start); len = data->buff_pos - prefix_start; - + if (match_type_requires_full_replacement(best_match_type)) { // No prefix @@ -1751,7 +1752,7 @@ static bool handle_completions(const std::vector &comp) reader_repaint_without_autosuggestion(); write_loop(1, "\n", 1); - + run_pager(prefix, is_quoted, surviving_completions); } s_reset(&data->screen, screen_reset_abandon_line); diff --git a/wildcard.cpp b/wildcard.cpp index fffe662a4..0edcfa85c 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -217,12 +217,12 @@ static bool wildcard_complete_internal(const wcstring &orig, debug(2, L"Got null string on line %d of file %s", __LINE__, __FILE__); return 0; } - + bool has_match = false; string_fuzzy_match_t fuzzy_match(fuzzy_match_exact); const bool at_end_of_wildcard = (*wc == L'\0'); const wchar_t *completion_string = NULL; - + // Hack hack hack // Implement EXPAND_FUZZY_MATCH by short-circuiting everything if there are no remaining wildcards if ((expand_flags & EXPAND_FUZZY_MATCH) && ! at_end_of_wildcard && ! wildcard_has(wc, true)) @@ -231,7 +231,7 @@ static bool wildcard_complete_internal(const wcstring &orig, if (fuzzy_match.type != fuzzy_match_none) { has_match = true; - + /* If we're not a prefix or exact match, then we need to replace the token. Note that in this case we're not going to call ourselves recursively, so these modified flags won't "leak" except into the completion. */ if (match_type_requires_full_replacement(fuzzy_match.type)) { @@ -247,9 +247,10 @@ static bool wildcard_complete_internal(const wcstring &orig, } } } - + /* Maybe we satisfied the wildcard normally */ - if (! has_match) { + if (! has_match) + { bool file_has_leading_dot = (is_first && str[0] == L'.'); if (at_end_of_wildcard && ! file_has_leading_dot) { @@ -264,7 +265,7 @@ static bool wildcard_complete_internal(const wcstring &orig, } } } - + if (has_match) { /* Wildcard complete */ @@ -281,7 +282,7 @@ static bool wildcard_complete_internal(const wcstring &orig, } else { - if (desc_func && ! (expand_flags & EXPAND_NO_DESCRIPTIONS)) + if (desc_func && !(expand_flags & EXPAND_NO_DESCRIPTIONS)) { /* A description generating function is specified, call @@ -299,7 +300,7 @@ static bool wildcard_complete_internal(const wcstring &orig, append_completion(out, out_completion, out_desc, flags, fuzzy_match); return true; } - + if (*wc == ANY_STRING) { bool res=false;