From a776b08e849428619740222cc0033e62470706ac Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 24 Sep 2020 17:21:49 +0200 Subject: [PATCH] Use bools, we have the technology --- src/builtin_commandline.cpp | 32 ++++++++++++++++---------------- src/builtin_jobs.cpp | 4 ++-- src/common.cpp | 24 ++++++++++++------------ src/highlight.cpp | 4 ++-- src/output.cpp | 10 +++++----- src/parse_util.cpp | 4 ++-- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index 315f04c51..d927a3513 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -131,20 +131,20 @@ maybe_t builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_ wchar_t *cmd = argv[0]; int buffer_part = 0; - int cut_at_cursor = 0; + bool cut_at_cursor = false; int argc = builtin_count_args(argv); int append_mode = 0; - int function_mode = 0; - int selection_mode = 0; + bool function_mode = false; + bool selection_mode = false; - int tokenize = 0; + bool tokenize = false; - int cursor_mode = 0; - int line_mode = 0; - int search_mode = 0; - int paging_mode = 0; + bool cursor_mode = false; + bool line_mode = false; + bool search_mode = false; + bool paging_mode = false; const wchar_t *begin = nullptr, *end = nullptr; const auto &ld = parser.libdata(); @@ -212,7 +212,7 @@ maybe_t builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_ break; } case 'c': { - cut_at_cursor = 1; + cut_at_cursor = true; break; } case 't': { @@ -228,11 +228,11 @@ maybe_t builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_ break; } case 'f': { - function_mode = 1; + function_mode = true; break; } case 'o': { - tokenize = 1; + tokenize = true; break; } case 'I': { @@ -241,23 +241,23 @@ maybe_t builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_ break; } case 'C': { - cursor_mode = 1; + cursor_mode = true; break; } case 'L': { - line_mode = 1; + line_mode = true; break; } case 'S': { - search_mode = 1; + search_mode = true; break; } case 's': { - selection_mode = 1; + selection_mode = true; break; } case 'P': { - paging_mode = 1; + paging_mode = true; break; } case 'h': { diff --git a/src/builtin_jobs.cpp b/src/builtin_jobs.cpp index f440399e9..92766c0fd 100644 --- a/src/builtin_jobs.cpp +++ b/src/builtin_jobs.cpp @@ -126,7 +126,7 @@ maybe_t builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **arg int argc = builtin_count_args(argv); bool found = false; int mode = JOBS_DEFAULT; - int print_last = 0; + bool print_last = false; static const wchar_t *const short_options = L":cghlpq"; static const struct woption long_options[] = {{L"command", no_argument, nullptr, 'c'}, @@ -159,7 +159,7 @@ maybe_t builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **arg break; } case 'l': { - print_last = 1; + print_last = true; break; } case 'h': { diff --git a/src/common.cpp b/src/common.cpp index 19cec8bc6..58076658d 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -930,8 +930,8 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring const bool no_caret = feature_test(features_t::stderr_nocaret); const bool no_qmark = feature_test(features_t::qmark_noglob); - int need_escape = 0; - int need_complex_escape = 0; + bool need_escape = false; + bool need_complex_escape = false; if (!no_quoted && in_len == 0) { out.assign(L"''"); @@ -951,7 +951,7 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring tmp = val % 16; out += tmp > 9 ? L'a' + (tmp - 10) : L'0' + tmp; - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; } else { wchar_t c = *in; @@ -959,36 +959,36 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring case L'\t': { out += L'\\'; out += L't'; - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; break; } case L'\n': { out += L'\\'; out += L'n'; - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; break; } case L'\b': { out += L'\\'; out += L'b'; - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; break; } case L'\r': { out += L'\\'; out += L'r'; - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; break; } case L'\x1B': { out += L'\\'; out += L'e'; - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; break; } case L'\\': case L'\'': { - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; out += L'\\'; out += *in; break; @@ -1030,7 +1030,7 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring bool char_is_normal = (c == L'~' && no_tilde) || (c == L'^' && no_caret) || (c == L'?' && no_qmark); if (!char_is_normal) { - need_escape = 1; + need_escape = true; if (escape_all) out += L'\\'; } out += *in; @@ -1044,7 +1044,7 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring out += L'c'; out += L'a' + *in - 1; - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; break; } @@ -1053,7 +1053,7 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring out += L'x'; out += ((*in > 15) ? L'1' : L'0'); out += tmp > 9 ? L'a' + (tmp - 10) : L'0' + tmp; - need_escape = need_complex_escape = 1; + need_escape = need_complex_escape = true; } else { out += *in; } diff --git a/src/highlight.cpp b/src/highlight.cpp index f227c62af..ef980e484 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -205,7 +205,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l const bool require_dir = static_cast(flags & PATH_REQUIRE_DIR); wcstring clean_potential_path_fragment; - int has_magic = 0; + bool has_magic = false; wcstring path_with_magic(potential_path_fragment); if (flags & PATH_EXPAND_TILDE) expand_tilde(path_with_magic, ctx.vars); @@ -221,7 +221,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l case ANY_CHAR: case ANY_STRING: case ANY_STRING_RECURSIVE: { - has_magic = 1; + has_magic = true; break; } case INTERNAL_SEPARATOR: { diff --git a/src/output.cpp b/src/output.cpp index 42ecbeb0b..29e43f2e3 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -466,11 +466,11 @@ rgb_color_t best_color(const std::vector &candidates, color_support /// Return the internal color code representing the specified color. /// TODO: This code should be refactored to enable sharing with builtin_set_color. rgb_color_t parse_color(const env_var_t &var, bool is_background) { - int is_bold = 0; - int is_underline = 0; - int is_italics = 0; - int is_dim = 0; - int is_reverse = 0; + bool is_bold = false; + bool is_underline = false; + bool is_italics = false; + bool is_dim = false; + bool is_reverse = false; std::vector candidates; diff --git a/src/parse_util.cpp b/src/parse_util.cpp index 4e004c652..0f0fb705f 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -110,7 +110,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin // open_type is typically ( or [, and close type is the corresponding value. wchar_t *pos; wchar_t prev = 0; - int syntax_error = 0; + bool syntax_error = false; int paran_count = 0; wchar_t *paran_begin = nullptr, *paran_end = nullptr; @@ -142,7 +142,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin } if (paran_count < 0) { - syntax_error = 1; + syntax_error = true; break; } }