diff --git a/src/builtin.cpp b/src/builtin.cpp index 7dd35f1c7..f735c2996 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -93,10 +93,10 @@ int builtin_count_args(const wchar_t *const *argv) { /// This function works like wperror, but it prints its result into the streams.err string instead /// to stderr. Used by the builtin commands. -void builtin_wperror(const wchar_t *s, io_streams_t &streams) { +void builtin_wperror(const wchar_t *program_name, io_streams_t &streams) { char *err = std::strerror(errno); - if (s != nullptr) { - streams.err.append(s); + if (program_name != nullptr) { + streams.err.append(program_name); streams.err.append(L": "); } if (err != nullptr) { @@ -319,21 +319,21 @@ static maybe_t builtin_breakpoint(parser_t &parser, io_streams_t &streams, return parser.get_last_status(); } -maybe_t builtin_true(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { +static maybe_t builtin_true(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { UNUSED(parser); UNUSED(streams); UNUSED(argv); return STATUS_CMD_OK; } -maybe_t builtin_false(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { +static maybe_t builtin_false(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { UNUSED(parser); UNUSED(streams); UNUSED(argv); return STATUS_CMD_ERROR; } -maybe_t builtin_gettext(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { +static maybe_t builtin_gettext(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { UNUSED(parser); UNUSED(streams); for (int i = 1; i < builtin_count_args(argv); i++) { diff --git a/src/builtin.h b/src/builtin.h index c13568ceb..1d6e35704 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -101,7 +101,7 @@ void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wch void builtin_print_error_trailer(parser_t &parser, output_stream_t &b, const wchar_t *cmd); -void builtin_wperror(const wchar_t *s, io_streams_t &streams); +void builtin_wperror(const wchar_t *program_name, io_streams_t &streams); struct help_only_cmd_opts_t { bool print_help = false; diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index c56aa364c..01ea013fd 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -17,6 +17,7 @@ #include #include "builtin.h" +#include "builtin_set.h" #include "common.h" #include "env.h" #include "expand.h" @@ -313,7 +314,7 @@ struct split_var_t { /// Returns: /// a split var on success, none() on error, in which case an error will have been printed. /// If no index is found, this leaves indexes empty. -maybe_t split_var_and_indexes(const wchar_t *arg, env_mode_flags_t mode, +static maybe_t split_var_and_indexes(const wchar_t *arg, env_mode_flags_t mode, const environment_t &vars, io_streams_t &streams) { split_var_t res{}; const wchar_t *open_bracket = std::wcschr(arg, L'['); diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index 60271db18..be20ffddf 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -124,7 +124,7 @@ struct token_info_t { unsigned int flags; }; -const token_info_t *token_for_string(const wcstring &str) { +static const token_info_t *token_for_string(const wcstring &str) { static const std::map token_infos = { {L"", {test_unknown, 0}}, {L"!", {test_bang, 0}}, diff --git a/src/function.cpp b/src/function.cpp index df12ec156..455f22557 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -77,7 +77,7 @@ bool function_set_t::allow_autoload(const wcstring &name) const { } // namespace /// \return a copy of some function props, in a new shared_ptr. -std::shared_ptr copy_props(const function_properties_ref_t &props) { +static std::shared_ptr copy_props(const function_properties_ref_t &props) { assert(props && "Null props"); return std::make_shared(*props); } diff --git a/src/parse_constants.h b/src/parse_constants.h index a495f6e35..904e75ad5 100644 --- a/src/parse_constants.h +++ b/src/parse_constants.h @@ -109,7 +109,7 @@ const enum_map keyword_enum_map[] = {{parse_keyword_t::kw_excla #define keyword_enum_map_len (sizeof keyword_enum_map / sizeof *keyword_enum_map) // Statement decorations like 'command' or 'exec'. -enum class statement_decoration_t { +enum class statement_decoration_t : uint8_t { none, command, builtin, @@ -117,7 +117,7 @@ enum class statement_decoration_t { }; // Parse error code list. -enum parse_error_code_t { +enum parse_error_code_t : uint8_t { parse_error_none, // Matching values from enum parser_error. @@ -159,10 +159,10 @@ enum { /// Indicate that extra semis should be generated. parse_flag_show_extra_semis = 1 << 5, }; -typedef unsigned int parse_tree_flags_t; +using parse_tree_flags_t = uint8_t; enum { PARSER_TEST_ERROR = 1, PARSER_TEST_INCOMPLETE = 2 }; -typedef unsigned int parser_test_error_bits_t; +using parser_test_error_bits_t = uint8_t; struct parse_error_t { /// Text of the error. @@ -193,7 +193,7 @@ wcstring token_type_user_presentable_description(parse_token_type_t type, void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt); // The location of a pipeline. -enum class pipeline_position_t { +enum class pipeline_position_t : uint8_t { none, // not part of a pipeline first, // first command in a pipeline subsequent // second or further command in a pipeline diff --git a/src/path.cpp b/src/path.cpp index 963a308ad..5f3cd991a 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -98,7 +98,7 @@ bool path_get_path(const wcstring &cmd, wcstring *out_path, const environment_t return path_get_path_core(cmd, out_path, vars.get(L"PATH")); } -bool path_is_executable(const std::string &path) { +static bool path_is_executable(const std::string &path) { if (access(path.c_str(), X_OK)) return false; struct stat buff; if (stat(path.c_str(), &buff) == -1) { @@ -221,11 +221,11 @@ maybe_t path_get_cdpath(const wcstring &dir, const wcstring &wd, assert(!wd.empty() && wd.back() == L'/'); auto paths = path_apply_cdpath(dir, wd, env_vars); - for (const wcstring &dir : paths) { + for (const wcstring &a_dir : paths) { struct stat buf; - if (wstat(dir, &buf) == 0) { + if (wstat(a_dir, &buf) == 0) { if (S_ISDIR(buf.st_mode)) { - return dir; + return a_dir; } err = ENOTDIR; } diff --git a/src/proc.h b/src/proc.h index 37ac8b950..cb0fe0894 100644 --- a/src/proc.h +++ b/src/proc.h @@ -24,7 +24,7 @@ #include "wait_handle.h" /// Types of processes. -enum class process_type_t { +enum class process_type_t : uint8_t { /// A regular external command. external, /// A builtin command. @@ -37,7 +37,7 @@ enum class process_type_t { exec, }; -enum class job_control_t { +enum class job_control_t : uint8_t { all, interactive, none, diff --git a/src/reader.cpp b/src/reader.cpp index bc0176bae..edb3c7bdf 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -930,7 +930,7 @@ void term_copy_modes() { } /// Grab control of terminal. -void term_steal() { +static void term_steal() { term_copy_modes(); while (true) { if (tcsetattr(STDIN_FILENO, TCSANOW, &shell_modes) == -1) { @@ -4184,7 +4184,7 @@ void reader_queue_ch(const char_event_t &ch) { } /// Sets the command line contents, clearing the pager. -void reader_set_buffer(const wcstring &b, size_t pos) { +static void reader_set_buffer(const wcstring &b, size_t pos) { reader_data_t *data = current_data_or_null(); if (!data) return;