From 7ac593273e25d5ce39104dc1752660a43a29f61d Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 31 Oct 2014 01:15:50 -0700 Subject: [PATCH] Remove a bunch of dead code identified by cppcheck --- complete.cpp | 4 +- env_universal_common.cpp | 36 ----------- history.cpp | 8 +-- history.h | 3 - input.cpp | 2 +- output.cpp | 128 --------------------------------------- output.h | 12 ---- pager.h | 2 - parse_tree.cpp | 5 -- parse_util.cpp | 5 -- parser.cpp | 2 +- parser.h | 21 +++---- parser_keywords.cpp | 17 ------ parser_keywords.h | 19 ------ path.cpp | 79 ------------------------ reader.cpp | 31 ---------- tokenizer.cpp | 37 ----------- tokenizer.h | 13 ---- wutil.cpp | 35 ----------- wutil.h | 17 ------ 20 files changed, 14 insertions(+), 462 deletions(-) diff --git a/complete.cpp b/complete.cpp index 07bc7cc01..cfd040efb 100644 --- a/complete.cpp +++ b/complete.cpp @@ -1588,14 +1588,14 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop wcstring completion = format_string(L"%ls=", whole_opt.c_str()+offset); append_completion(this->completions, completion, - C_(o->desc.c_str()), + C_(o->desc), flags); } append_completion(this->completions, whole_opt.c_str() + offset, - C_(o->desc.c_str()), + C_(o->desc), flags); } } diff --git a/env_universal_common.cpp b/env_universal_common.cpp index 07d325238..88ec7749b 100644 --- a/env_universal_common.cpp +++ b/env_universal_common.cpp @@ -79,24 +79,6 @@ static wcstring default_vars_path() return str2wcstring(machine_id_path); } -/** - The table of all universal variables -*/ -static env_universal_t &default_universal_vars() -{ - static env_universal_t s_default_vars(L""); - return s_default_vars; -} - -static void (*callback)(fish_message_type_t type, - const wchar_t *key, - const wchar_t *val); - -void env_universal_common_init(void (*cb)(fish_message_type_t type, const wchar_t *key, const wchar_t *val)) -{ - callback = cb; -} - /** Test if the message msg contains the command cmd */ @@ -1614,24 +1596,6 @@ static bool bool_from_env_var(const char *name, bool default_value) return var ? from_string(var) : default_value; } -static bool initialize_synchronizes_via_fishd() -{ - if (program_name && ! wcscmp(program_name, L"fishd")) - { - /* fishd always wants to use fishd */ - return true; - } - - return bool_from_env_var(UNIVERSAL_USE_FISHD, false); -} - -bool synchronizes_via_fishd() -{ - /* Note that in general we can't change this once it's been set, so we only load it once */ - static bool result = initialize_synchronizes_via_fishd(); - return result; -} - bool universal_log_enabled() { return bool_from_env_var(UNIVERSAL_LOGGING_ENV_NAME, false); diff --git a/history.cpp b/history.cpp index 2a367cd22..a3ef0ee90 100644 --- a/history.cpp +++ b/history.cpp @@ -656,7 +656,7 @@ void history_t::set_valid_file_paths(const wcstring_list_t &valid_file_paths, hi scoped_lock locker(lock); /* Look for an item with the given identifier. It is likely to be at the end of new_items */ - for (history_item_list_t::reverse_iterator iter = new_items.rbegin(); iter != new_items.rend(); iter++) + for (history_item_list_t::reverse_iterator iter = new_items.rbegin(); iter != new_items.rend(); ++iter) { if (iter->identifier == ident) { @@ -1565,12 +1565,6 @@ void history_t::save(void) this->save_internal(false); } -void history_t::save_and_vacuum(void) -{ - scoped_lock locker(lock); - this->save_internal(true); -} - void history_t::disable_automatic_saving() { scoped_lock locker(lock); diff --git a/history.h b/history.h index 921f09c54..c0e0f433d 100644 --- a/history.h +++ b/history.h @@ -220,9 +220,6 @@ public: /** Saves history */ void save(); - /** Performs a full (non-incremental) save */ - void save_and_vacuum(); - /** Enable / disable automatic saving. Main thread only! */ void disable_automatic_saving(); void enable_automatic_saving(); diff --git a/input.cpp b/input.cpp index 088793812..136c68c5f 100644 --- a/input.cpp +++ b/input.cpp @@ -608,7 +608,7 @@ static void input_mapping_execute(const input_mapping_t &m, bool allow_commands) } } - input_set_bind_mode(m.sets_mode.c_str()); + input_set_bind_mode(m.sets_mode); } diff --git a/output.cpp b/output.cpp index aea0a9073..d5aefc166 100644 --- a/output.cpp +++ b/output.cpp @@ -527,134 +527,6 @@ void writestr(const wchar_t *str) delete[] buffer; } - -void writestr_ellipsis(const wchar_t *str, int max_width) -{ - int written=0; - int tot; - - CHECK(str,); - - tot = fish_wcswidth(str); - - if (tot <= max_width) - { - writestr(str); - return; - } - - while (*str != 0) - { - int w = fish_wcwidth(*str); - if (written+w+fish_wcwidth(ellipsis_char)>max_width) - { - break; - } - written+=w; - writech(*(str++)); - } - - written += fish_wcwidth(ellipsis_char); - writech(ellipsis_char); - - while (written < max_width) - { - written++; - writestr(L" "); - } -} - -int write_escaped_str(const wchar_t *str, int max_len) -{ - - int i; - int written=0; - - CHECK(str, 0); - - wcstring out = escape(str, ESCAPE_ALL); - int len = fish_wcswidth(out); - - if (max_len && (max_len < len)) - { - for (i=0; (written+fish_wcwidth(out[i]))<=(max_len-1); i++) - { - writech(out[i]); - written += fish_wcwidth(out[i]); - } - writech(ellipsis_char); - written += fish_wcwidth(ellipsis_char); - - for (i=written; ipager.select_next_completion_in_direction(dir, data->current_page_rendering); if (selection_changed) { @@ -4151,36 +4150,6 @@ int reader_has_pager_contents() return ! data->current_page_rendering.screen_data.empty(); } -void reader_selected_completion_changed(pager_t *pager) -{ - /* Only interested in the top level pager */ - if (data == NULL || pager != &data->pager) - return; - - const completion_t *completion = pager->selected_completion(data->current_page_rendering); - - /* Update the cursor and command line */ - size_t cursor_pos = data->cycle_cursor_pos; - wcstring new_cmd_line; - - if (completion == NULL) - { - new_cmd_line = data->cycle_command_line; - } - else - { - new_cmd_line = completion_apply_to_command_line(completion->completion, completion->flags, data->cycle_command_line, &cursor_pos, false); - } - reader_set_buffer_maintaining_pager(new_cmd_line, cursor_pos); - - /* Since we just inserted a completion, don't immediately do a new autosuggestion */ - data->suppress_autosuggestion = true; - - /* Trigger repaint (see #765) */ - reader_repaint_needed(); -} - - /** Read non-interactively. Read input from stdin without displaying the prompt, using syntax highlighting. This is used for reading diff --git a/tokenizer.cpp b/tokenizer.cpp index 980cac4cb..dca22281e 100644 --- a/tokenizer.cpp +++ b/tokenizer.cpp @@ -542,13 +542,6 @@ int oflags_for_redirection_type(enum token_type type) } } -wchar_t tok_last_quote(tokenizer_t *tok) -{ - CHECK(tok, 0); - - return tok->last_quote; -} - /** Test if a character is whitespace. Differs from iswspace in that it does not consider a newline to be whitespace. @@ -706,36 +699,6 @@ void tok_next(tokenizer_t *tok) } -enum token_type tok_peek_next(tokenizer_t *tok, wcstring *out_next_string) -{ - if (out_next_string != NULL) - { - out_next_string->clear(); - } - - enum token_type result = TOK_END; - if (tok_has_next(tok)) - { - int saved = tok_get_pos(tok); - tok_next(tok); - result = tok_last_type(tok); - - if (out_next_string != NULL) - { - const wchar_t *last = tok_last(tok); - out_next_string->assign(last ? last : L""); - } - - tok_set_pos(tok, saved); - } - return result; -} - -const wchar_t *tok_string(tokenizer_t *tok) -{ - return tok?tok->orig_buff:0; -} - wcstring tok_first(const wchar_t *str) { wcstring result; diff --git a/tokenizer.h b/tokenizer.h index dcd355a3f..525afb464 100644 --- a/tokenizer.h +++ b/tokenizer.h @@ -126,11 +126,6 @@ enum token_type tok_last_type(tokenizer_t *tok); */ const wchar_t *tok_last(tokenizer_t *tok); -/** - Returns the type of quote from the last TOK_QSTRING -*/ -wchar_t tok_last_quote(tokenizer_t *tok); - /** Returns true as long as there are more tokens left */ @@ -144,14 +139,6 @@ int tok_get_pos(const tokenizer_t *tok); /** Returns the extent of the current token */ size_t tok_get_extent(const tokenizer_t *tok); -/** Returns the token type after the current one, without adjusting the position. Optionally returns the next string by reference. */ -enum token_type tok_peek_next(tokenizer_t *tok, wcstring *out_next_string); - -/** - Returns the original string to tokenizer - */ -const wchar_t *tok_string(tokenizer_t *tok); - /** Returns only the first token from the specified string. This is a convenience function, used to retrieve the first token of a diff --git a/wutil.cpp b/wutil.cpp index 25c0cec0a..903131983 100644 --- a/wutil.cpp +++ b/wutil.cpp @@ -188,12 +188,6 @@ FILE *wfopen(const wcstring &path, const char *mode) return result; } -FILE *wfreopen(const wcstring &path, const char *mode, FILE *stream) -{ - cstring tmp = wcs2string(path); - return freopen(tmp.c_str(), mode, stream); -} - bool set_cloexec(int fd) { int flags = fcntl(fd, F_GETFD, 0); @@ -232,26 +226,12 @@ static int wopen_internal(const wcstring &pathname, int flags, mode_t mode, bool return fd; } -int wopen(const wcstring &pathname, int flags, mode_t mode) -{ - // off the main thread, always use wopen_cloexec - ASSERT_IS_MAIN_THREAD(); - ASSERT_IS_NOT_FORKED_CHILD(); - return wopen_internal(pathname, flags, mode, false); -} int wopen_cloexec(const wcstring &pathname, int flags, mode_t mode) { return wopen_internal(pathname, flags, mode, true); } - -int wcreat(const wcstring &pathname, mode_t mode) -{ - const cstring tmp = wcs2string(pathname); - return creat(tmp.c_str(), mode); -} - DIR *wopendir(const wcstring &name) { const cstring tmp = wcs2string(name); @@ -488,21 +468,6 @@ const wchar_t *wgettext(const wchar_t *in) return val->c_str(); //looks dangerous but is safe, since the string is stored in the map } -const wchar_t *wgetenv(const wcstring &name) -{ - ASSERT_IS_MAIN_THREAD(); - cstring name_narrow = wcs2string(name); - char *res_narrow = getenv(name_narrow.c_str()); - static wcstring out; - - if (!res_narrow) - return 0; - - out = format_string(L"%s", res_narrow); - return out.c_str(); - -} - int wmkdir(const wcstring &name, int mode) { cstring name_narrow = wcs2string(name); diff --git a/wutil.h b/wutil.h index 36d6d0754..a1945c07b 100644 --- a/wutil.h +++ b/wutil.h @@ -38,14 +38,6 @@ FILE *wfopen(const wcstring &path, const char *mode); /** Sets CLO_EXEC on a given fd */ bool set_cloexec(int fd); -/** - Wide character version of freopen(). -*/ -FILE *wfreopen(const wcstring &path, const char *mode, FILE *stream); - -/** Wide character version of open(). */ -int wopen(const wcstring &pathname, int flags, mode_t mode = 0); - /** Wide character version of open() that also sets the close-on-exec flag (atomically when possible). */ int wopen_cloexec(const wcstring &pathname, int flags, mode_t mode = 0); @@ -55,10 +47,6 @@ int make_fd_nonblocking(int fd); /** Mark an fd as blocking; returns errno or 0 on success */ int make_fd_blocking(int fd); -/** Wide character version of creat(). */ -int wcreat(const wcstring &pathname, mode_t mode); - - /** Wide character version of opendir(). Note that opendir() is guaranteed to set close-on-exec by POSIX (hooray). */ DIR *wopendir(const wcstring &name); @@ -141,11 +129,6 @@ std::wstring wbasename(const std::wstring &path); */ const wchar_t *wgettext(const wchar_t *in); -/** - Wide character version of getenv -*/ -const wchar_t *wgetenv(const wcstring &name); - /** Wide character version of mkdir */