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);
@ -1022,11 +1023,11 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
} }
case ':': { case ':': {
string_error(streams, STRING_ERR_MISSING, argv[0]); string_error(streams, STRING_ERR_MISSING, argv[0]);
return BUILTIN_STRING_ERROR; return BUILTIN_STRING_ERROR;
} }
case '?': { case '?': {
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return BUILTIN_STRING_ERROR; return BUILTIN_STRING_ERROR;
} }
default: { default: {
DIE("unexpected opt"); DIE("unexpected opt");
@ -1039,7 +1040,7 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
if (string_args_from_stdin(streams) && argc > i) { if (string_args_from_stdin(streams) && argc > i) {
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]); string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
return BUILTIN_STRING_ERROR; return BUILTIN_STRING_ERROR;
} }
const wchar_t *to_repeat; const wchar_t *to_repeat;
@ -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,9 +1271,10 @@ 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_accept_incomplete_tokens | parse_flag_continue_after_error |
parse_flag_include_comments, parse_flag_accept_incomplete_tokens |
parse_flag_include_comments,
&tree, NULL); &tree, NULL);
// Find the plain statement to operate on. The cursor may be past it (#1261), so backtrack // Find the plain statement to operate on. The cursor may be past it (#1261), so backtrack

View file

@ -191,7 +191,7 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) {
#endif #endif
#endif #endif
#endif // __APPLE__ #endif // __APPLE__
#ifndef HAVE_WCSNDUP #ifndef HAVE_WCSNDUP
wchar_t *wcsndup(const wchar_t *in, size_t c) { wchar_t *wcsndup(const wchar_t *in, size_t c) {

View file

@ -96,24 +96,24 @@ wchar_t *wcsndup(const wchar_t *in, size_t c);
using std::wcsdup; using std::wcsdup;
#else #else
wchar_t *wcsdup(const wchar_t *in); wchar_t *wcsdup(const wchar_t *in);
#endif // HAVE_STD__WCSDUP #endif // HAVE_STD__WCSDUP
#endif // HAVE_WCSDUP #endif // HAVE_WCSDUP
#ifndef HAVE_WCSCASECMP #ifndef HAVE_WCSCASECMP
#ifdef HAVE_STD__WCSCASECMP #ifdef HAVE_STD__WCSCASECMP
using std::wcscasecmp; using std::wcscasecmp;
#else #else
int wcscasecmp(const wchar_t *a, const wchar_t *b); int wcscasecmp(const wchar_t *a, const wchar_t *b);
#endif // HAVE_STD__WCSCASECMP #endif // HAVE_STD__WCSCASECMP
#endif // HAVE_WCSCASECMP #endif // HAVE_WCSCASECMP
#ifndef HAVE_WCSNCASECMP #ifndef HAVE_WCSNCASECMP
#ifdef HAVE_STD__WCSNCASECMP #ifdef HAVE_STD__WCSNCASECMP
using std::wcsncasecmp; using std::wcsncasecmp;
#else #else
int wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n); int wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n);
#endif // HAVE_STD__WCSNCASECMP #endif // HAVE_STD__WCSNCASECMP
#endif // HAVE_WCSNCASECMP #endif // HAVE_WCSNCASECMP
#ifndef HAVE_DIRFD #ifndef HAVE_DIRFD
#ifndef __XOPEN_OR_POSIX #ifndef __XOPEN_OR_POSIX

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);
} }
} }
} }