Skip to content

Commit

Permalink
Update style and formatting to conform to fish style guide.
Browse files Browse the repository at this point in the history
  • Loading branch information
ridiculousfish committed Jan 15, 2014
1 parent e2fe873 commit 5381498
Show file tree
Hide file tree
Showing 28 changed files with 703 additions and 683 deletions.
40 changes: 20 additions & 20 deletions builtin.cpp
Expand Up @@ -1038,14 +1038,14 @@ static int builtin_emit(parser_t &parser, wchar_t **argv)
static int builtin_generic(parser_t &parser, wchar_t **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 */
if (argc == 1)
{
builtin_print_help(parser, argv[0], stdout_buffer);
return STATUS_BUILTIN_ERROR;
}

woptind=0;

static const struct woption
Expand Down Expand Up @@ -1754,16 +1754,16 @@ static int builtin_pwd(parser_t &parser, wchar_t **argv)
int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstring &contents, wcstring *out_err)
{
assert(out_err != NULL);

/* wgetopt expects 'function' as the first argument. Make a new wcstring_list with that property. */
wcstring_list_t args;
args.push_back(L"function");
args.insert(args.end(), c_args.begin(), c_args.end());

/* Hackish const_cast matches the one in builtin_run */
const null_terminated_array_t<wchar_t> argv_array(args);
wchar_t **argv = const_cast<wchar_t **>(argv_array.get());

int argc = builtin_count_args(argv);
int res=STATUS_BUILTIN_OK;
wchar_t *desc=0;
Expand Down Expand Up @@ -1806,9 +1806,9 @@ int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstr
case 0:
if (long_options[opt_index].flag != 0)
break;



append_format(*out_err,
BUILTIN_ERR_UNKNOWN,
argv[0],
Expand Down Expand Up @@ -1876,15 +1876,15 @@ int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstr
if (is_subshell)
{
size_t block_idx = 0;

/* Find the outermost substitution block */
for (block_idx = 0; ; block_idx++)
{
const block_t *b = parser.block_at_index(block_idx);
if (b == NULL || b->type() == SUBST)
break;
}

/* Go one step beyond that, to get to the caller */
const block_t *caller_block = parser.block_at_index(block_idx + 1);
if (caller_block != NULL && caller_block->job != NULL)
Expand Down Expand Up @@ -2046,9 +2046,9 @@ int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstr
event_t &e = d.events.at(i);
e.function_name = d.name;
}

d.definition = contents.c_str();

// TODO: fix def_offset inside function_add
function_add(d, parser);
}
Expand All @@ -2068,7 +2068,7 @@ static int builtin_function(parser_t &parser, wchar_t **argv)
builtin_print_help(parser, argv[0], stdout_buffer);
return STATUS_BUILTIN_OK;
}

int argc = builtin_count_args(argv);
int res=STATUS_BUILTIN_OK;
wchar_t *desc=0;
Expand Down Expand Up @@ -2181,15 +2181,15 @@ static int builtin_function(parser_t &parser, wchar_t **argv)
if (is_subshell)
{
size_t block_idx = 0;

/* Find the outermost substitution block */
for (block_idx = 0; ; block_idx++)
{
const block_t *b = parser.block_at_index(block_idx);
if (b == NULL || b->type() == SUBST)
break;
}

/* Go one step beyond that, to get to the caller */
const block_t *caller_block = parser.block_at_index(block_idx + 1);
if (caller_block != NULL && caller_block->job != NULL)
Expand Down Expand Up @@ -3965,7 +3965,7 @@ static int builtin_break_continue(parser_t &parser, wchar_t **argv)
{
parser.block_at_index(block_idx)->skip = true;
}

/* Skip the loop itself */
block_t *loop_block = parser.block_at_index(loop_idx);
loop_block->skip = true;
Expand Down Expand Up @@ -4043,7 +4043,7 @@ static int builtin_return(parser_t &parser, wchar_t **argv)
builtin_print_help(parser, argv[0], stderr_buffer);
return STATUS_BUILTIN_ERROR;
}

/* Skip everything up to (and then including) the function block */
for (size_t i=0; i < function_block_idx; i++)
{
Expand All @@ -4063,8 +4063,8 @@ static int builtin_switch(parser_t &parser, wchar_t **argv)
{
int res=STATUS_BUILTIN_OK;
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)
{
builtin_print_help(parser, argv[0], stdout_buffer);
Expand Down Expand Up @@ -4307,7 +4307,7 @@ int builtin_parse(parser_t &parser, wchar_t **argv)
stdout_buffer.append(errors.at(i).describe(src));
stdout_buffer.push_back(L'\n');
}

stdout_buffer.append(L"(Reparsed with continue after error)\n");
parse_tree.clear();
errors.clear();
Expand Down
2 changes: 1 addition & 1 deletion builtin_set.cpp
Expand Up @@ -712,7 +712,7 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
retcode = 1;
break;
}

size_t idx_count = indexes.size();
size_t val_count = argc-woptind-1;

Expand Down
6 changes: 3 additions & 3 deletions common.cpp
Expand Up @@ -1130,7 +1130,7 @@ static size_t read_unquoted_escape(const wchar_t *input, wcstring *result, bool
switch (c)
{

/* A null character after a backslash is an error */
/* A null character after a backslash is an error */
case L'\0':
{
/* Adjust in_pos to only include the backslash */
Expand Down Expand Up @@ -1177,11 +1177,11 @@ static size_t read_unquoted_escape(const wchar_t *input, wcstring *result, bool
{
chars=8;
max_val = WCHAR_MAX;

// Don't exceed the largest Unicode code point - see #1107
if (0x10FFFF < max_val)
max_val = (wchar_t)0x10FFFF;

break;
}

Expand Down
58 changes: 29 additions & 29 deletions complete.cpp
Expand Up @@ -472,7 +472,7 @@ void completion_autoload_t::command_removed(const wcstring &cmd)
void append_completion(std::vector<completion_t> &completions, const wcstring &comp, const wcstring &desc, complete_flags_t flags, string_fuzzy_match_t match)
{
/* If we just constructed the completion and used push_back, we would get two string copies. Try to avoid that by making a stubby completion in the vector first, and then copying our string in. Note that completion_t's constructor will munge 'flags' so it's important that we pass those to the constructor.
Nasty hack for #1241 - since the constructor needs the completion string to resolve AUTO_SPACE, and we aren't providing it with the completion, we have to do the resolution ourselves. We should get this resolving out of the constructor.
*/
const wcstring empty;
Expand Down Expand Up @@ -1811,56 +1811,56 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
parse_util_cmdsubst_extent(cmd_with_subcmds.c_str(), cmd_with_subcmds.size(), &cmdsubst_begin, &cmdsubst_end);
assert(cmdsubst_begin != NULL && cmdsubst_end != NULL && cmdsubst_end >= cmdsubst_begin);
const wcstring cmd = wcstring(cmdsubst_begin, cmdsubst_end - cmdsubst_begin);

/* Make our completer */
completer_t completer(cmd, flags);

wcstring current_command;
const size_t pos = cmd.size();
bool done=false;
bool use_command = 1;
bool use_function = 1;
bool use_builtin = 1;

// debug( 1, L"Complete '%ls'", cmd );

const wchar_t *cmd_cstr = cmd.c_str();
const wchar_t *tok_begin = NULL, *prev_begin = NULL, *prev_end = NULL;
parse_util_token_extent(cmd_cstr, cmd.size(), &tok_begin, NULL, &prev_begin, &prev_end);

/**
If we are completing a variable name or a tilde expansion user
name, we do that and return. No need for any other completions.
*/

const wcstring current_token = tok_begin;

if (!done)
{
done = completer.try_complete_variable(current_token) || completer.try_complete_user(current_token);
}

if (!done)
{
//const size_t prev_token_len = (prev_begin ? prev_end - prev_begin : 0);
//const wcstring prev_token(prev_begin, prev_token_len);

parse_node_tree_t tree;
parse_tree_from_string(cmd, parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens, &tree, NULL);

/* Find the plain statement that contains the position */
const parse_node_t *plain_statement = tree.find_node_matching_source_location(symbol_plain_statement, pos, NULL);
if (plain_statement != NULL)
{
assert(plain_statement->has_source() && plain_statement->type == symbol_plain_statement);

/* Get the command node */
const parse_node_t *cmd_node = tree.get_child(*plain_statement, 0, parse_token_type_string);

/* Get the actual command string */
if (cmd_node != NULL)
current_command = cmd_node->get_source(cmd);

/* Check the decoration */
switch (tree.decoration_for_plain_statement(*plain_statement))
{
Expand All @@ -1869,20 +1869,20 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
use_function = true;
use_builtin = true;
break;

case parse_statement_decoration_command:
use_command = true;
use_function = false;
use_builtin = false;
break;

case parse_statement_decoration_builtin:
use_command = false;
use_function = false;
use_builtin = true;
break;
}

if (cmd_node && cmd_node->location_in_or_at_end_of_source_range(pos))
{
/* Complete command filename */
Expand All @@ -1892,7 +1892,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
{
/* Get all the arguments */
const parse_node_tree_t::parse_node_list_t all_arguments = tree.find_nodes(*plain_statement, symbol_argument);

/* See whether we are in an argument. We may also be in a redirection, or nothing at all. */
size_t matching_arg_index = -1;
for (size_t i=0; i < all_arguments.size(); i++)
Expand All @@ -1904,17 +1904,17 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
break;
}
}

bool had_ddash = false;
wcstring current_argument, previous_argument;
if (matching_arg_index != (size_t)(-1))
{
/* Get the current argument and the previous argument, if we have one */
current_argument = all_arguments.at(matching_arg_index)->get_source(cmd);

if (matching_arg_index > 0)
previous_argument = all_arguments.at(matching_arg_index - 1)->get_source(cmd);

/* Check to see if we have a preceding double-dash */
for (size_t i=0; i < matching_arg_index; i++)
{
Expand All @@ -1925,34 +1925,34 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
}
}
}

bool do_file = false;

wcstring current_command_unescape, previous_argument_unescape, current_argument_unescape;
if (unescape_string(current_command, &current_command_unescape, UNESCAPE_DEFAULT) &&
unescape_string(previous_argument, &previous_argument_unescape, UNESCAPE_DEFAULT) &&
unescape_string(current_argument, &current_argument_unescape, UNESCAPE_INCOMPLETE))
unescape_string(previous_argument, &previous_argument_unescape, UNESCAPE_DEFAULT) &&
unescape_string(current_argument, &current_argument_unescape, UNESCAPE_INCOMPLETE))
{
do_file = completer.complete_param(current_command_unescape,
previous_argument_unescape,
current_argument_unescape,
!had_ddash);
}

/* If we have found no command specific completions at all, fall back to using file completions. */
if (completer.empty())
do_file = true;

/* And if we're autosuggesting, and the token is empty, don't do file suggestions */
if ((flags & COMPLETION_REQUEST_AUTOSUGGESTION) && current_argument_unescape.empty())
do_file = false;

/* This function wants the unescaped string */
completer.complete_param_expand(current_token, do_file);
}
}
}

comps = completer.get_completions();
}

Expand Down
8 changes: 4 additions & 4 deletions env_universal.cpp
Expand Up @@ -132,12 +132,12 @@ static int try_get_socket_once(void)
if (connect(s, (struct sockaddr *)&local, sizeof local) == -1)
{
close(s);

/* If it fails on first try, it's probably no serious error, but fishd hasn't been launched yet.
This happens (at least) on the first concurrent session. */
if (get_socket_count > 1)
wperror(L"connect");

return -1;
}

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

if (!msg)
{
Expand Down
4 changes: 2 additions & 2 deletions event.cpp
Expand Up @@ -146,13 +146,13 @@ static int event_is_blocked(const event_t &e)
{
const block_t *block;
parser_t &parser = parser_t::principal_parser();

size_t idx = 0;
while ((block = parser.block_at_index(idx++)))
{
if (event_block_list_blocks_type(block->event_blocks, e.type))
return true;

}
return event_block_list_blocks_type(parser.global_event_blocks, e.type);
}
Expand Down

0 comments on commit 5381498

Please sign in to comment.