Update style and formatting to conform to fish style guide.

This commit is contained in:
ridiculousfish 2014-01-15 01:40:40 -08:00
parent e2fe873049
commit 53814983ff
28 changed files with 703 additions and 683 deletions

View file

@ -4064,7 +4064,7 @@ static int builtin_switch(parser_t &parser, wchar_t **argv)
int res=STATUS_BUILTIN_OK; int res=STATUS_BUILTIN_OK;
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
/* Hackish - if we have no arguments other than the command, we are a "naked invocation" and we just print help */ /* Hackish - if we have no arguments other than the command, we are a "naked invocation" and we just print help */
if (argc == 1) if (argc == 1)
{ {
builtin_print_help(parser, argv[0], stdout_buffer); builtin_print_help(parser, argv[0], stdout_buffer);

View file

@ -1130,7 +1130,7 @@ static size_t read_unquoted_escape(const wchar_t *input, wcstring *result, bool
switch (c) switch (c)
{ {
/* A null character after a backslash is an error */ /* A null character after a backslash is an error */
case L'\0': case L'\0':
{ {
/* Adjust in_pos to only include the backslash */ /* Adjust in_pos to only include the backslash */

View file

@ -1930,8 +1930,8 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
wcstring current_command_unescape, previous_argument_unescape, current_argument_unescape; wcstring current_command_unescape, previous_argument_unescape, current_argument_unescape;
if (unescape_string(current_command, &current_command_unescape, UNESCAPE_DEFAULT) && if (unescape_string(current_command, &current_command_unescape, UNESCAPE_DEFAULT) &&
unescape_string(previous_argument, &previous_argument_unescape, UNESCAPE_DEFAULT) && unescape_string(previous_argument, &previous_argument_unescape, UNESCAPE_DEFAULT) &&
unescape_string(current_argument, &current_argument_unescape, UNESCAPE_INCOMPLETE)) unescape_string(current_argument, &current_argument_unescape, UNESCAPE_INCOMPLETE))
{ {
do_file = completer.complete_param(current_command_unescape, do_file = completer.complete_param(current_command_unescape,
previous_argument_unescape, previous_argument_unescape,

View file

@ -438,8 +438,8 @@ void env_universal_set(const wcstring &name, const wcstring &value, bool exportv
else else
{ {
message_t *msg = create_message(exportv?SET_EXPORT:SET, message_t *msg = create_message(exportv?SET_EXPORT:SET,
name.c_str(), name.c_str(),
value.c_str()); value.c_str());
if (!msg) if (!msg)
{ {

View file

@ -149,7 +149,11 @@ static void err(const wchar_t *blah, ...)
/* Test sane escapes */ /* Test sane escapes */
static void test_unescape_sane() static void test_unescape_sane()
{ {
const struct test_t {const wchar_t * input; const wchar_t * expected;} tests[] = const struct test_t
{
const wchar_t * input;
const wchar_t * expected;
} tests[] =
{ {
{L"abcd", L"abcd"}, {L"abcd", L"abcd"},
{L"'abcd'", L"abcd"}, {L"'abcd'", L"abcd"},
@ -754,7 +758,8 @@ static void test_indents()
say(L"Testing indents"); say(L"Testing indents");
// Here are the components of our source and the indents we expect those to be // Here are the components of our source and the indents we expect those to be
struct indent_component_t { struct indent_component_t
{
const wchar_t *txt; const wchar_t *txt;
int indent; int indent;
}; };
@ -2539,7 +2544,8 @@ static void test_highlighting(void)
if (system("touch /tmp/fish_highlight_test/bar")) err(L"touch failed"); if (system("touch /tmp/fish_highlight_test/bar")) err(L"touch failed");
// Here are the components of our source and the colors we expect those to be // Here are the components of our source and the colors we expect those to be
struct highlight_component_t { struct highlight_component_t
{
const wchar_t *txt; const wchar_t *txt;
int color; int color;
}; };

View file

@ -1700,7 +1700,7 @@ class highlighter_t
/* Colors the source range of a node with a given color */ /* Colors the source range of a node with a given color */
void color_node(const parse_node_t &node, int color); void color_node(const parse_node_t &node, int color);
public: public:
/* Constructor */ /* Constructor */
highlighter_t(const wcstring &str, size_t pos, const env_vars_snapshot_t &ev, const wcstring &wd) : buff(str), cursor_pos(pos), vars(ev), working_directory(wd), color_array(str.size()) highlighter_t(const wcstring &str, size_t pos, const env_vars_snapshot_t &ev, const wcstring &wd) : buff(str), cursor_pos(pos), vars(ev), working_directory(wd), color_array(str.size())
@ -1947,7 +1947,7 @@ void highlighter_t::color_redirection(const parse_node_t &redirection_node)
} }
/* NOCLOB means that we must not overwrite files that exist */ /* NOCLOB means that we must not overwrite files that exist */
target_is_valid = file_is_writable && ! (file_exists && redirect_type == TOK_REDIRECT_NOCLOB); target_is_valid = file_is_writable && !(file_exists && redirect_type == TOK_REDIRECT_NOCLOB);
} }
break; break;

View file

@ -128,9 +128,10 @@ enum parse_error_code_t
parse_error_double_background // foo && bar, has special error message parse_error_double_background // foo && bar, has special error message
}; };
enum { enum
PARSER_TEST_ERROR = 1, {
PARSER_TEST_INCOMPLETE = 2 PARSER_TEST_ERROR = 1,
PARSER_TEST_INCOMPLETE = 2
}; };
typedef unsigned int parser_test_error_bits_t; typedef unsigned int parser_test_error_bits_t;

View file

@ -325,7 +325,7 @@ parse_execution_result_t parse_execution_context_t::run_begin_statement(const pa
parser->pop_block(sb); parser->pop_block(sb);
return ret; return ret;
} }
/* Define a function */ /* Define a function */
parse_execution_result_t parse_execution_context_t::run_function_statement(const parse_node_t &header, const parse_node_t &contents) parse_execution_result_t parse_execution_context_t::run_function_statement(const parse_node_t &header, const parse_node_t &contents)
@ -484,8 +484,8 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p
case EXPAND_ERROR: case EXPAND_ERROR:
{ {
result = report_error(switch_value_node, result = report_error(switch_value_node,
_(L"Could not expand string '%ls'"), _(L"Could not expand string '%ls'"),
switch_value.c_str()); switch_value.c_str());
break; break;
} }
@ -506,9 +506,9 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p
if (result == parse_execution_success && switch_values_expanded.size() != 1) if (result == parse_execution_success && switch_values_expanded.size() != 1)
{ {
result = report_error(switch_value_node, result = report_error(switch_value_node,
_(L"switch: Expected exactly one argument, got %lu\n"), _(L"switch: Expected exactly one argument, got %lu\n"),
switch_values_expanded.size()); switch_values_expanded.size());
} }
const wcstring &switch_value_expanded = switch_values_expanded.at(0).completion; const wcstring &switch_value_expanded = switch_values_expanded.at(0).completion;
@ -919,8 +919,8 @@ wcstring_list_t parse_execution_context_t::determine_arguments(const parse_node_
case EXPAND_ERROR: case EXPAND_ERROR:
{ {
this->report_error(arg_node, this->report_error(arg_node,
_(L"Could not expand string '%ls'"), _(L"Could not expand string '%ls'"),
arg_str.c_str()); arg_str.c_str());
break; break;
} }
@ -987,8 +987,8 @@ bool parse_execution_context_t::determine_io_chain(const parse_node_t &statement
{ {
/* Should improve this error message */ /* Should improve this error message */
errored = report_error(redirect_node, errored = report_error(redirect_node,
_(L"Invalid redirection target: %ls"), _(L"Invalid redirection target: %ls"),
target.c_str()); target.c_str());
} }
@ -1011,8 +1011,8 @@ bool parse_execution_context_t::determine_io_chain(const parse_node_t &statement
if (old_fd < 0 || errno || *end) if (old_fd < 0 || errno || *end)
{ {
errored = report_error(redirect_node, errored = report_error(redirect_node,
_(L"Requested redirection to '%ls', which is not a valid file descriptor"), _(L"Requested redirection to '%ls', which is not a valid file descriptor"),
target.c_str()); target.c_str());
} }
else else
{ {
@ -1063,7 +1063,7 @@ parse_execution_result_t parse_execution_context_t::populate_boolean_process(job
assert(bool_statement.type == symbol_boolean_statement); assert(bool_statement.type == symbol_boolean_statement);
switch (bool_statement.production_idx) switch (bool_statement.production_idx)
{ {
// These magic numbers correspond to productions for boolean_statement // These magic numbers correspond to productions for boolean_statement
case 0: case 0:
// AND. Skip if the last job failed. // AND. Skip if the last job failed.
skip_job = (proc_get_last_status() != 0); skip_job = (proc_get_last_status() != 0);

View file

@ -32,7 +32,7 @@ enum parse_execution_result_t
class parse_execution_context_t class parse_execution_context_t
{ {
private: private:
const parse_node_tree_t tree; const parse_node_tree_t tree;
const wcstring src; const wcstring src;
io_chain_t block_io; io_chain_t block_io;
@ -102,7 +102,7 @@ class parse_execution_context_t
parse_execution_result_t run_job_list(const parse_node_t &job_list_node, const block_t *associated_block); parse_execution_result_t run_job_list(const parse_node_t &job_list_node, const block_t *associated_block);
parse_execution_result_t populate_job_from_job_node(job_t *j, const parse_node_t &job_node, const block_t *associated_block); parse_execution_result_t populate_job_from_job_node(job_t *j, const parse_node_t &job_node, const block_t *associated_block);
public: public:
parse_execution_context_t(const parse_node_tree_t &t, const wcstring &s, parser_t *p); parse_execution_context_t(const parse_node_tree_t &t, const wcstring &s, parser_t *p);
/* Start executing at the given node offset. Returns 0 if there was no error, 1 if there was an error */ /* Start executing at the given node offset. Returns 0 if there was no error, 1 if there was an error */

View file

@ -250,7 +250,7 @@ static wcstring token_type_user_presentable_description(parse_token_type_t type,
switch (type) switch (type)
{ {
/* Hackish. We only support the following types. */ /* Hackish. We only support the following types. */
case symbol_statement: case symbol_statement:
return L"a command"; return L"a command";
@ -569,7 +569,7 @@ class parse_ll_t
} }
} }
public: public:
/* Constructor */ /* Constructor */
parse_ll_t() : fatal_errored(false), should_generate_error_messages(true) parse_ll_t() : fatal_errored(false), should_generate_error_messages(true)
@ -905,7 +905,7 @@ bool parse_ll_t::top_node_handle_terminal_types(parse_token_t token)
// Check to see which keyword we got which was considered wrong // Check to see which keyword we got which was considered wrong
switch (token.keyword) switch (token.keyword)
{ {
// Some keywords are only valid in certain contexts. If this cascaded all the way down through the outermost job_list, it was not in a valid context. // Some keywords are only valid in certain contexts. If this cascaded all the way down through the outermost job_list, it was not in a valid context.
case parse_keyword_case: case parse_keyword_case:
case parse_keyword_end: case parse_keyword_end:
case parse_keyword_else: case parse_keyword_else:

View file

@ -41,11 +41,11 @@ int parse_util_locate_cmdsubst(const wchar_t *in,
*/ */
int parse_util_locate_cmdsubst_range(const wcstring &str, int parse_util_locate_cmdsubst_range(const wcstring &str,
size_t *inout_cursor_offset, size_t *inout_cursor_offset,
wcstring *out_contents, wcstring *out_contents,
size_t *out_start, size_t *out_start,
size_t *out_end, size_t *out_end,
bool accept_incomplete); bool accept_incomplete);
/** /**
Find the beginning and end of the command substitution under the Find the beginning and end of the command substitution under the

View file

@ -1215,7 +1215,8 @@ static screen_layout_t compute_layout(screen_t *s,
// If the command wraps, and the prompt is not short, place the command on its own line. // If the command wraps, and the prompt is not short, place the command on its own line.
// A short prompt is 33% or less of the terminal's width. // A short prompt is 33% or less of the terminal's width.
const size_t prompt_percent_width = (100 * left_prompt_width) / screen_width; const size_t prompt_percent_width = (100 * left_prompt_width) / screen_width;
if (left_prompt_width + first_command_line_width + 1 > screen_width && prompt_percent_width > 33) { if (left_prompt_width + first_command_line_width + 1 > screen_width && prompt_percent_width > 33)
{
result.prompts_get_own_line = true; result.prompts_get_own_line = true;
} }

View file

@ -458,10 +458,18 @@ static size_t read_redirection_or_fd_pipe(const wchar_t *buff, enum token_type *
/* We did not find a leading digit, so there's no explicit fd. Infer it from the type */ /* We did not find a leading digit, so there's no explicit fd. Infer it from the type */
switch (buff[idx]) switch (buff[idx])
{ {
case L'>': fd = STDOUT_FILENO; break; case L'>':
case L'<': fd = STDIN_FILENO; break; fd = STDOUT_FILENO;
case L'^': fd = STDERR_FILENO; break; break;
default: errored = true; break; case L'<':
fd = STDIN_FILENO;
break;
case L'^':
fd = STDERR_FILENO;
break;
default:
errored = true;
break;
} }
} }
@ -556,10 +564,14 @@ int oflags_for_redirection_type(enum token_type type)
{ {
switch (type) switch (type)
{ {
case TOK_REDIRECT_APPEND: return O_CREAT | O_APPEND | O_WRONLY; case TOK_REDIRECT_APPEND:
case TOK_REDIRECT_OUT: return O_CREAT | O_WRONLY | O_TRUNC; return O_CREAT | O_APPEND | O_WRONLY;
case TOK_REDIRECT_NOCLOB: return O_CREAT | O_EXCL | O_WRONLY; case TOK_REDIRECT_OUT:
case TOK_REDIRECT_IN: return O_RDONLY; return O_CREAT | O_WRONLY | O_TRUNC;
case TOK_REDIRECT_NOCLOB:
return O_CREAT | O_EXCL | O_WRONLY;
case TOK_REDIRECT_IN:
return O_RDONLY;
default: default:
return -1; return -1;