style cleanups

This commit is contained in:
Kurtis Rader 2017-03-15 14:06:58 -07:00
parent f0469d829a
commit 84cf391faa
7 changed files with 41 additions and 51 deletions

View file

@ -991,7 +991,8 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
case 'n': { case 'n': {
long lcount = fish_wcstol(w.woptarg); long lcount = fish_wcstol(w.woptarg);
if (lcount < 0 || errno == ERANGE) { if (lcount < 0 || errno == ERANGE) {
string_error(streams, _(L"%ls: Invalid count value '%ls'\n"), argv[0], w.woptarg); string_error(streams, _(L"%ls: Invalid count value '%ls'\n"), argv[0],
w.woptarg);
return BUILTIN_STRING_ERROR; return BUILTIN_STRING_ERROR;
} else if (errno) { } else if (errno) {
string_error(streams, BUILTIN_ERR_NOT_NUMBER, argv[0], w.woptarg); string_error(streams, BUILTIN_ERR_NOT_NUMBER, argv[0], w.woptarg);
@ -1048,7 +1049,7 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
if ((to_repeat = string_get_arg(&i, argv, &storage, streams)) != NULL && *to_repeat) { if ((to_repeat = string_get_arg(&i, argv, &storage, streams)) != NULL && *to_repeat) {
const wcstring word(to_repeat); const wcstring word(to_repeat);
const bool rep_until = (0 < max && word.length()*count > max) || !count; const bool rep_until = (0 < max && word.length() * count > max) || !count;
const wcstring repeated = rep_until ? wcsrepeat_until(word, max) : wcsrepeat(word, count); const wcstring repeated = rep_until ? wcsrepeat_until(word, max) : wcsrepeat(word, count);
is_empty = repeated.empty(); is_empty = repeated.empty();
@ -1266,11 +1267,11 @@ static const struct string_subcommand {
wchar_t **argv); //!OCLINT(unused param) wchar_t **argv); //!OCLINT(unused param)
} }
string_subcommands[] = { string_subcommands[] = {{L"escape", &string_escape}, {L"join", &string_join},
{L"escape", &string_escape}, {L"join", &string_join}, {L"length", &string_length}, {L"length", &string_length}, {L"match", &string_match},
{L"match", &string_match}, {L"replace", &string_replace}, {L"split", &string_split}, {L"replace", &string_replace}, {L"split", &string_split},
{L"sub", &string_sub}, {L"trim", &string_trim}, {L"repeat", &string_repeat}, {L"sub", &string_sub}, {L"trim", &string_trim},
{0, 0}}; {L"repeat", &string_repeat}, {0, 0}};
/// The string builtin, for manipulating strings. /// The string builtin, for manipulating strings.
int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) {

View file

@ -153,28 +153,17 @@ struct named_color_t {
}; };
static const named_color_t named_colors[] = { static const named_color_t named_colors[] = {
{L"black", 0, {0x00, 0x00, 0x00}, false}, {L"black", 0, {0x00, 0x00, 0x00}, false}, {L"red", 1, {0x80, 0x00, 0x00}, false},
{L"red", 1, {0x80, 0x00, 0x00}, false}, {L"green", 2, {0x00, 0x80, 0x00}, false}, {L"brown", 3, {0x72, 0x50, 0x00}, true},
{L"green", 2, {0x00, 0x80, 0x00}, false}, {L"yellow", 3, {0x80, 0x80, 0x00}, false}, {L"blue", 4, {0x00, 0x00, 0x80}, false},
{L"brown", 3, {0x72, 0x50, 0x00}, true}, {L"magenta", 5, {0x80, 0x00, 0x80}, false}, {L"purple", 5, {0x80, 0x00, 0x80}, true},
{L"yellow", 3, {0x80, 0x80, 0x00}, false}, {L"cyan", 6, {0x00, 0x80, 0x80}, false}, {L"white", 7, {0xC0, 0xC0, 0xC0}, false},
{L"blue", 4, {0x00, 0x00, 0x80}, false}, {L"grey", 7, {0xE5, 0xE5, 0xE5}, true}, {L"brblack", 8, {0x80, 0x80, 0x80}, false},
{L"magenta", 5, {0x80, 0x00, 0x80}, false}, {L"brgrey", 8, {0x55, 0x55, 0x55}, true}, {L"brred", 9, {0xFF, 0x00, 0x00}, false},
{L"purple", 5, {0x80, 0x00, 0x80}, true}, {L"brgreen", 10, {0x00, 0xFF, 0x00}, false}, {L"brbrown", 11, {0xFF, 0xFF, 0x00}, true},
{L"cyan", 6, {0x00, 0x80, 0x80}, false}, {L"bryellow", 11, {0xFF, 0xFF, 0x00}, false}, {L"brblue", 12, {0x00, 0x00, 0xFF}, false},
{L"white", 7, {0xC0, 0xC0, 0xC0}, false}, {L"brmagenta", 13, {0xFF, 0x00, 0xFF}, false}, {L"brpurple", 13, {0xFF, 0x00, 0xFF}, true},
{L"grey", 7, {0xE5, 0xE5, 0xE5}, true}, {L"brcyan", 14, {0x00, 0xFF, 0xFF}, false}, {L"brwhite", 15, {0xFF, 0xFF, 0xFF}, false},
{L"brblack", 8, {0x80, 0x80, 0x80}, false},
{L"brgrey", 8, {0x55, 0x55, 0x55}, true},
{L"brred", 9, {0xFF, 0x00, 0x00}, false},
{L"brgreen", 10, {0x00, 0xFF, 0x00}, false},
{L"brbrown", 11, {0xFF, 0xFF, 0x00}, true},
{L"bryellow", 11, {0xFF, 0xFF, 0x00}, false},
{L"brblue", 12, {0x00, 0x00, 0xFF}, false},
{L"brmagenta", 13, {0xFF, 0x00, 0xFF}, false},
{L"brpurple", 13, {0xFF, 0x00, 0xFF}, true},
{L"brcyan", 14, {0x00, 0xFF, 0xFF}, false},
{L"brwhite", 15, {0xFF, 0xFF, 0xFF}, false},
}; };
wcstring_list_t rgb_color_t::named_color_names(void) { wcstring_list_t rgb_color_t::named_color_names(void) {
@ -340,8 +329,6 @@ wcstring rgb_color_t::description() const {
case type_normal: { case type_normal: {
return L"normal"; return L"normal";
} }
default: { default: { DIE("unknown color type"); }
DIE("unknown color type");
}
} }
} }

View file

@ -852,7 +852,7 @@ static void escape_string_internal(const wchar_t *orig_in, size_t in_len, wcstri
case L'\\': case L'\\':
case L'\'': { case L'\'': {
need_escape = need_complex_escape = 1; need_escape = need_complex_escape = 1;
//WTF if (escape_all) out += L'\\'; // WTF if (escape_all) out += L'\\';
out += L'\\'; out += L'\\';
out += *in; out += *in;
break; break;

View file

@ -1271,7 +1271,8 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> *out_c
if (!done) { if (!done) {
parse_node_tree_t tree; parse_node_tree_t tree;
parse_tree_from_string(cmd, parse_flag_continue_after_error | parse_tree_from_string(cmd,
parse_flag_continue_after_error |
parse_flag_accept_incomplete_tokens | parse_flag_accept_incomplete_tokens |
parse_flag_include_comments, parse_flag_include_comments,
&tree, NULL); &tree, NULL);

View file

@ -842,9 +842,9 @@ void highlighter_t::color_redirection(const parse_node_t &redirection_node) {
this->parse_tree.type_for_redirection(redirection_node, this->buff, NULL, &target); this->parse_tree.type_for_redirection(redirection_node, this->buff, NULL, &target);
// We may get a TOK_NONE redirection type, e.g. if the redirection is invalid. // We may get a TOK_NONE redirection type, e.g. if the redirection is invalid.
this->color_node(*redirection_primitive, redirect_type == TOK_NONE this->color_node(
? highlight_spec_error *redirection_primitive,
: highlight_spec_redirection); redirect_type == TOK_NONE ? highlight_spec_error : highlight_spec_redirection);
// Check if the argument contains a command substitution. If so, highlight it as a param // Check if the argument contains a command substitution. If so, highlight it as a param
// even though it's a command redirection, and don't try to do any other validation. // even though it's a command redirection, and don't try to do any other validation.
@ -941,8 +941,9 @@ void highlighter_t::color_redirection(const parse_node_t &redirection_node) {
} }
if (redirection_target != NULL) { if (redirection_target != NULL) {
this->color_node(*redirection_target, target_is_valid ? highlight_spec_redirection this->color_node(
: highlight_spec_error); *redirection_target,
target_is_valid ? highlight_spec_redirection : highlight_spec_error);
} }
} }
} }