Use bools, we have the technology

This commit is contained in:
Fabian Homborg 2020-09-24 17:21:49 +02:00
parent 4cb9f3224c
commit a776b08e84
6 changed files with 39 additions and 39 deletions

View file

@ -131,20 +131,20 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int buffer_part = 0; int buffer_part = 0;
int cut_at_cursor = 0; bool cut_at_cursor = false;
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
int append_mode = 0; int append_mode = 0;
int function_mode = 0; bool function_mode = false;
int selection_mode = 0; bool selection_mode = false;
int tokenize = 0; bool tokenize = false;
int cursor_mode = 0; bool cursor_mode = false;
int line_mode = 0; bool line_mode = false;
int search_mode = 0; bool search_mode = false;
int paging_mode = 0; bool paging_mode = false;
const wchar_t *begin = nullptr, *end = nullptr; const wchar_t *begin = nullptr, *end = nullptr;
const auto &ld = parser.libdata(); const auto &ld = parser.libdata();
@ -212,7 +212,7 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_
break; break;
} }
case 'c': { case 'c': {
cut_at_cursor = 1; cut_at_cursor = true;
break; break;
} }
case 't': { case 't': {
@ -228,11 +228,11 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_
break; break;
} }
case 'f': { case 'f': {
function_mode = 1; function_mode = true;
break; break;
} }
case 'o': { case 'o': {
tokenize = 1; tokenize = true;
break; break;
} }
case 'I': { case 'I': {
@ -241,23 +241,23 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_
break; break;
} }
case 'C': { case 'C': {
cursor_mode = 1; cursor_mode = true;
break; break;
} }
case 'L': { case 'L': {
line_mode = 1; line_mode = true;
break; break;
} }
case 'S': { case 'S': {
search_mode = 1; search_mode = true;
break; break;
} }
case 's': { case 's': {
selection_mode = 1; selection_mode = true;
break; break;
} }
case 'P': { case 'P': {
paging_mode = 1; paging_mode = true;
break; break;
} }
case 'h': { case 'h': {

View file

@ -126,7 +126,7 @@ maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **arg
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
bool found = false; bool found = false;
int mode = JOBS_DEFAULT; int mode = JOBS_DEFAULT;
int print_last = 0; bool print_last = false;
static const wchar_t *const short_options = L":cghlpq"; static const wchar_t *const short_options = L":cghlpq";
static const struct woption long_options[] = {{L"command", no_argument, nullptr, 'c'}, static const struct woption long_options[] = {{L"command", no_argument, nullptr, 'c'},
@ -159,7 +159,7 @@ maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **arg
break; break;
} }
case 'l': { case 'l': {
print_last = 1; print_last = true;
break; break;
} }
case 'h': { case 'h': {

View file

@ -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_caret = feature_test(features_t::stderr_nocaret);
const bool no_qmark = feature_test(features_t::qmark_noglob); const bool no_qmark = feature_test(features_t::qmark_noglob);
int need_escape = 0; bool need_escape = false;
int need_complex_escape = 0; bool need_complex_escape = false;
if (!no_quoted && in_len == 0) { if (!no_quoted && in_len == 0) {
out.assign(L"''"); 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; tmp = val % 16;
out += tmp > 9 ? L'a' + (tmp - 10) : L'0' + tmp; out += tmp > 9 ? L'a' + (tmp - 10) : L'0' + tmp;
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
} else { } else {
wchar_t c = *in; 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': { case L'\t': {
out += L'\\'; out += L'\\';
out += L't'; out += L't';
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
break; break;
} }
case L'\n': { case L'\n': {
out += L'\\'; out += L'\\';
out += L'n'; out += L'n';
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
break; break;
} }
case L'\b': { case L'\b': {
out += L'\\'; out += L'\\';
out += L'b'; out += L'b';
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
break; break;
} }
case L'\r': { case L'\r': {
out += L'\\'; out += L'\\';
out += L'r'; out += L'r';
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
break; break;
} }
case L'\x1B': { case L'\x1B': {
out += L'\\'; out += L'\\';
out += L'e'; out += L'e';
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
break; break;
} }
case L'\\': case L'\\':
case L'\'': { case L'\'': {
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
out += L'\\'; out += L'\\';
out += *in; out += *in;
break; 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) || bool char_is_normal = (c == L'~' && no_tilde) || (c == L'^' && no_caret) ||
(c == L'?' && no_qmark); (c == L'?' && no_qmark);
if (!char_is_normal) { if (!char_is_normal) {
need_escape = 1; need_escape = true;
if (escape_all) out += L'\\'; if (escape_all) out += L'\\';
} }
out += *in; 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'c';
out += L'a' + *in - 1; out += L'a' + *in - 1;
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
break; break;
} }
@ -1053,7 +1053,7 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring
out += L'x'; out += L'x';
out += ((*in > 15) ? L'1' : L'0'); out += ((*in > 15) ? L'1' : L'0');
out += tmp > 9 ? L'a' + (tmp - 10) : L'0' + tmp; out += tmp > 9 ? L'a' + (tmp - 10) : L'0' + tmp;
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = true;
} else { } else {
out += *in; out += *in;
} }

View file

@ -205,7 +205,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
const bool require_dir = static_cast<bool>(flags & PATH_REQUIRE_DIR); const bool require_dir = static_cast<bool>(flags & PATH_REQUIRE_DIR);
wcstring clean_potential_path_fragment; wcstring clean_potential_path_fragment;
int has_magic = 0; bool has_magic = false;
wcstring path_with_magic(potential_path_fragment); wcstring path_with_magic(potential_path_fragment);
if (flags & PATH_EXPAND_TILDE) expand_tilde(path_with_magic, ctx.vars); 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_CHAR:
case ANY_STRING: case ANY_STRING:
case ANY_STRING_RECURSIVE: { case ANY_STRING_RECURSIVE: {
has_magic = 1; has_magic = true;
break; break;
} }
case INTERNAL_SEPARATOR: { case INTERNAL_SEPARATOR: {

View file

@ -466,11 +466,11 @@ rgb_color_t best_color(const std::vector<rgb_color_t> &candidates, color_support
/// Return the internal color code representing the specified color. /// Return the internal color code representing the specified color.
/// TODO: This code should be refactored to enable sharing with builtin_set_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) { rgb_color_t parse_color(const env_var_t &var, bool is_background) {
int is_bold = 0; bool is_bold = false;
int is_underline = 0; bool is_underline = false;
int is_italics = 0; bool is_italics = false;
int is_dim = 0; bool is_dim = false;
int is_reverse = 0; bool is_reverse = false;
std::vector<rgb_color_t> candidates; std::vector<rgb_color_t> candidates;

View file

@ -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. // open_type is typically ( or [, and close type is the corresponding value.
wchar_t *pos; wchar_t *pos;
wchar_t prev = 0; wchar_t prev = 0;
int syntax_error = 0; bool syntax_error = false;
int paran_count = 0; int paran_count = 0;
wchar_t *paran_begin = nullptr, *paran_end = nullptr; 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) { if (paran_count < 0) {
syntax_error = 1; syntax_error = true;
break; break;
} }
} }