From 9dd6873e5855f69b01f2e3705a49a4231c992e71 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 3 Apr 2016 19:02:46 -0700 Subject: [PATCH] lint: remove or comment out unused functions Cppcheck has identified a lot of unused functions. This removes funcs that are unlikely to ever be used. Others that might be useful for debugging I've commented out with "#if 0". --- src/builtin.cpp | 4 ++++ src/common.cpp | 5 ----- src/common.h | 3 --- src/expand.cpp | 56 ---------------------------------------------- src/expand.h | 1 - src/fish_tests.cpp | 8 ++++--- src/io.cpp | 4 ++++ src/io.h | 4 +++- src/parser.cpp | 2 -- src/proc.cpp | 12 +++++++--- 10 files changed, 25 insertions(+), 74 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index f4de72c73..dd67817a3 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -3925,6 +3925,8 @@ static int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **ar return STATUS_BUILTIN_ERROR; } +#if 0 +// Disabled for the 2.2.0 release: https://github.com/fish-shell/fish-shell/issues/1809. int builtin_parse(parser_t &parser, io_streams_t &streams, wchar_t **argv) { struct sigaction act; @@ -3966,6 +3968,7 @@ int builtin_parse(parser_t &parser, io_streams_t &streams, wchar_t **argv) } return STATUS_BUILTIN_OK; } +#endif int builtin_true(parser_t &parser, io_streams_t &streams, wchar_t **argv) { @@ -3992,6 +3995,7 @@ static const builtin_data_t builtin_datas[]= { { L"[", &builtin_test, N_(L"Test a condition") }, #if 0 + // Disabled for the 2.2.0 release: https://github.com/fish-shell/fish-shell/issues/1809. { L"__fish_parse", &builtin_parse, N_(L"Try out the new parser") }, #endif { L"and", &builtin_generic, N_(L"Execute command if previous command suceeded") }, diff --git a/src/common.cpp b/src/common.cpp index a796baca1..84c3de65a 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -689,11 +689,6 @@ void debug(int level, const char *msg, ...) errno = errno_old; } -void print_stderr(const wcstring &str) -{ - fprintf(stderr, "%ls\n", str.c_str()); -} - void read_ignore(int fd, void *buff, size_t count) { size_t ignore __attribute__((unused)); diff --git a/src/common.h b/src/common.h index 74640988c..d6eb01910 100644 --- a/src/common.h +++ b/src/common.h @@ -811,9 +811,6 @@ ssize_t read_loop(int fd, void *buff, size_t count); void debug(int level, const char *msg, ...); void debug(int level, const wchar_t *msg, ...); -/** Writes a string to stderr, followed by a newline */ -void print_stderr(const wcstring &str); - /** Replace special characters with backslash escape sequences. Newline is replaced with \n, etc. diff --git a/src/expand.cpp b/src/expand.cpp index c2b4258c8..de67ffa84 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -1998,62 +1998,6 @@ bool fish_xdm_login_hack_hack_hack_hack(std::vector *cmds, int argc return result; } -bool fish_openSUSE_dbus_hack_hack_hack_hack(std::vector *args) -{ - static signed char isSUSE = -1; - if (isSUSE == 0) - return false; - - bool result = false; - if (args && ! args->empty()) - { - const wcstring &cmd = args->at(0).completion; - if (cmd.find(L"DBUS_SESSION_BUS_") != wcstring::npos) - { - /* See if we are SUSE */ - if (isSUSE < 0) - { - struct stat buf = {}; - isSUSE = (0 == stat("/etc/SuSE-release", &buf)); - } - - if (isSUSE) - { - /* Look for an equal sign */ - size_t where = cmd.find(L'='); - if (where != wcstring::npos) - { - /* Oh my. It's presumably of the form foo=bar; find the = and split */ - const wcstring key = wcstring(cmd, 0, where); - - /* Trim whitespace and semicolon */ - wcstring val = wcstring(cmd, where+1); - size_t last_good = val.find_last_not_of(L"\n ;"); - if (last_good != wcstring::npos) - val.resize(last_good + 1); - - args->clear(); - append_completion(args, L"set"); - if (key == L"DBUS_SESSION_BUS_ADDRESS") - append_completion(args, L"-x"); - append_completion(args, key); - append_completion(args, val); - result = true; - } - else if (string_prefixes_string(L"export DBUS_SESSION_BUS_ADDRESS;", cmd)) - { - /* Nothing, we already exported it */ - args->clear(); - append_completion(args, L"echo"); - append_completion(args, L"-n"); - result = true; - } - } - } - } - return result; -} - bool expand_abbreviation(const wcstring &src, wcstring *output) { if (src.empty()) diff --git a/src/expand.h b/src/expand.h index 731acd711..6ae91cca3 100644 --- a/src/expand.h +++ b/src/expand.h @@ -168,7 +168,6 @@ bool expand_abbreviation(const wcstring &src, wcstring *output); /* Terrible hacks */ bool fish_xdm_login_hack_hack_hack_hack(std::vector *cmds, int argc, const char * const *argv); -bool fish_openSUSE_dbus_hack_hack_hack_hack(std::vector *args); #endif diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 5bacab80e..9afb43441 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2887,8 +2887,7 @@ public: static void test_history(void); static void test_history_merge(void); static void test_history_formats(void); - static void test_history_speed(void); - + // static void test_history_speed(void); static void test_history_races(void); static void test_history_races_pound_on_history(); }; @@ -3378,6 +3377,8 @@ void history_tests_t::test_history_formats(void) } } +#if 0 +// This test isn't run at this time. It was added by commit b9283d48 but not actually enabled. void history_tests_t::test_history_speed(void) { say(L"Testing history speed (pid is %d)", getpid()); @@ -3403,6 +3404,7 @@ void history_tests_t::test_history_speed(void) hist->clear(); delete hist; } +#endif static void test_new_parser_correctness(void) { @@ -4483,8 +4485,8 @@ int main(int argc, char **argv) if (should_test_function("history_merge")) history_tests_t::test_history_merge(); if (should_test_function("history_races")) history_tests_t::test_history_races(); if (should_test_function("history_formats")) history_tests_t::test_history_formats(); - //history_tests_t::test_history_speed(); if (should_test_function("string")) test_string(); + // history_tests_t::test_history_speed(); say(L"Encountered %d errors in low-level tests", err_count); if (s_test_run_count == 0) diff --git a/src/io.cpp b/src/io.cpp index da326f559..614528305 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -183,6 +183,9 @@ void io_chain_t::append(const io_chain_t &chain) this->insert(this->end(), chain.begin(), chain.end()); } +#if 0 +// This isn't used so the lint tools were complaining about its presence. I'm keeping it in the +// source because it could be useful for debugging. void io_print(const io_chain_t &chain) { if (chain.empty()) @@ -206,6 +209,7 @@ void io_print(const io_chain_t &chain) } } } +#endif /* If the given fd is used by the io chain, duplicates it repeatedly until an fd not used in the io chain is found, or we run out. If we return a new fd or an error, closes the old one. Any fd created is marked close-on-exec. Returns -1 on failure (in which case the given fd is still closed). */ static int move_fd_to_unused(int fd, const io_chain_t &io_chain) diff --git a/src/io.h b/src/io.h index adc59be17..181099adf 100644 --- a/src/io.h +++ b/src/io.h @@ -304,7 +304,9 @@ struct io_streams_t } }; -/** Print debug information about the specified IO redirection chain to stderr. */ +#if 0 +// Print debug information about the specified IO redirection chain to stderr. void io_print(const io_chain_t &chain); +#endif #endif diff --git a/src/parser.cpp b/src/parser.cpp index 2097aecf6..2862df609 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -842,8 +842,6 @@ int parser_t::eval_acquiring_tree(const wcstring &cmd, const io_chain_t &io, enu return 0; } - //print_stderr(block_stack_description()); - /* Determine the initial eval level. If this is the first context, it's -1; otherwise it's the eval level of the top context. This is sort of wonky because we're stitching together a global notion of eval level from these separate objects. A better approach would be some profile object that all contexts share, and that tracks the eval levels on its own. */ int exec_eval_level = (execution_contexts.empty() ? -1 : execution_contexts.back()->current_eval_level()); diff --git a/src/proc.cpp b/src/proc.cpp index f5c833e2a..1a0d64792 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -94,15 +94,21 @@ size_t job_iterator_t::count() const return this->job_list->size(); } +#if 0 +// This isn't used so the lint tools were complaining about its presence. I'm keeping it in the +// source because it could be useful for debugging. However, it would probably be better to add a +// verbose or debug option to the builtin `jobs` command. void print_jobs(void) { job_iterator_t jobs; job_t *j; - while ((j = jobs.next())) - { - printf("%p -> %ls -> (foreground %d, complete %d, stopped %d, constructed %d)\n", j, j->command_wcstr(), job_get_flag(j, JOB_FOREGROUND), job_is_completed(j), job_is_stopped(j), job_get_flag(j, JOB_CONSTRUCTED)); + while (j = jobs.next()) { + printf("%p -> %ls -> (foreground %d, complete %d, stopped %d, constructed %d)\n", + j, j->command_wcstr(), job_get_flag(j, JOB_FOREGROUND), job_is_completed(j), + job_is_stopped(j), job_get_flag(j, JOB_CONSTRUCTED)); } } +#endif int is_interactive_session=0; int is_subshell=0;