style cleanups

Time for another `make style-all`.
This commit is contained in:
Kurtis Rader 2017-05-01 21:44:30 -07:00
parent 46d86766c4
commit 48d5342601
17 changed files with 99 additions and 86 deletions

View file

@ -97,9 +97,10 @@ int autoload_t::load(const wcstring &cmd, bool reload) {
// on the main thread. // on the main thread.
if (!inserted) { if (!inserted) {
// We failed to insert. // We failed to insert.
debug(0, _(L"Could not autoload item '%ls', it is already being autoloaded. " const wchar_t *fmt =
L"This is a circular dependency in the autoloading scripts, please remove it."), _(L"Could not autoload item '%ls', it is already being autoloaded. "
cmd.c_str()); L"This is a circular dependency in the autoloading scripts, please remove it.");
debug(0, fmt, cmd.c_str());
return 1; return 1;
} }
// Try loading it. // Try loading it.

View file

@ -3046,9 +3046,9 @@ static int disown_job(parser_t &parser, io_streams_t &streams, job_t *j) {
// Stopped disowned jobs must be manually signalled; explain how to do so // Stopped disowned jobs must be manually signalled; explain how to do so
if (job_is_stopped(j)) { if (job_is_stopped(j)) {
killpg(j->pgid, SIGCONT); killpg(j->pgid, SIGCONT);
streams.err.append_format( const wchar_t *fmt =
_(L"%ls: job %d ('%ls') was stopped and has been signalled to continue.\n"), _(L"%ls: job %d ('%ls') was stopped and has been signalled to continue.\n");
L"disown", j->job_id, j->command_wcstr()); streams.err.append_format(fmt, L"disown", j->job_id, j->command_wcstr());
} }
if (parser.job_remove(j)) { if (parser.job_remove(j)) {

View file

@ -730,7 +730,7 @@ static bool unary_primary_evaluate(test_expressions::token_t token, const wcstri
} }
} }
} }
}; }; // namespace test_expressions
/// Evaluate a conditional expression given the arguments. If fromtest is set, the caller is the /// Evaluate a conditional expression given the arguments. If fromtest is set, the caller is the
/// test or [ builtin; with the pointer giving the name of the command. for POSIX conformance this /// test or [ builtin; with the pointer giving the name of the command. for POSIX conformance this

View file

@ -807,7 +807,8 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
// Some `su`s keep $USER when changing to root. // Some `su`s keep $USER when changing to root.
// This leads to issues later on (and e.g. in prompts), // This leads to issues later on (and e.g. in prompts),
// so we work around it by resetting $USER. // so we work around it by resetting $USER.
// TODO: Figure out if that su actually checks if username == "root"(as the man page says) or UID == 0. // TODO: Figure out if that su actually checks if username == "root"(as the man page says) or
// UID == 0.
uid_t uid = getuid(); uid_t uid = getuid();
setup_user(uid == 0); setup_user(uid == 0);

View file

@ -53,8 +53,8 @@ struct event_t {
/// The type-specific parameter. The int types are one of the following: /// The type-specific parameter. The int types are one of the following:
/// ///
/// signal: Signal number for signal-type events.Use EVENT_ANY_SIGNAL to match any signal /// signal: Signal number for signal-type events.Use EVENT_ANY_SIGNAL to match any signal
/// pid: Process id for process-type events. Use EVENT_ANY_PID to match any pid. (Negative values are used for PGIDs). /// pid: Process id for process-type events. Use EVENT_ANY_PID to match any pid. (Negative
/// job_id: Job id for EVENT_JOB_ID type events /// values are used for PGIDs). job_id: Job id for EVENT_JOB_ID type events
union { union {
int signal; int signal;
int job_id; int job_id;

View file

@ -2134,7 +2134,6 @@ static void test_complete(void) {
complete(L"echo \\$Foo", &completions, COMPLETION_REQUEST_DEFAULT, vars); complete(L"echo \\$Foo", &completions, COMPLETION_REQUEST_DEFAULT, vars);
do_test(completions.empty()); do_test(completions.empty());
// File completions. // File completions.
completions.clear(); completions.clear();
complete(L"cat test/complete_test/te", &completions, COMPLETION_REQUEST_DEFAULT, vars); complete(L"cat test/complete_test/te", &completions, COMPLETION_REQUEST_DEFAULT, vars);

View file

@ -41,16 +41,25 @@
/// The environment variables used to specify the color of different tokens. This matches the order /// The environment variables used to specify the color of different tokens. This matches the order
/// in highlight_spec_t. /// in highlight_spec_t.
static const wchar_t *const highlight_var[] = { static const wchar_t *const highlight_var[] = {L"fish_color_normal",
L"fish_color_normal", L"fish_color_error", L"fish_color_command", L"fish_color_end", L"fish_color_error",
L"fish_color_param", L"fish_color_comment", L"fish_color_match", L"fish_color_search_match", L"fish_color_command",
L"fish_color_operator", L"fish_color_escape", L"fish_color_quote", L"fish_color_redirection", L"fish_color_end",
L"fish_color_autosuggestion", L"fish_color_selection", L"fish_color_param",
L"fish_color_comment",
L"fish_pager_color_prefix", L"fish_pager_color_completion", L"fish_pager_color_description", L"fish_color_match",
L"fish_pager_color_progress", L"fish_pager_color_secondary" L"fish_color_search_match",
L"fish_color_operator",
}; L"fish_color_escape",
L"fish_color_quote",
L"fish_color_redirection",
L"fish_color_autosuggestion",
L"fish_color_selection",
L"fish_pager_color_prefix",
L"fish_pager_color_completion",
L"fish_pager_color_description",
L"fish_pager_color_progress",
L"fish_pager_color_secondary"};
/// Determine if the filesystem containing the given fd is case insensitive for lookups regardless /// Determine if the filesystem containing the given fd is case insensitive for lookups regardless
/// of whether it preserves the case when saving a pathname. /// of whether it preserves the case when saving a pathname.
@ -843,9 +852,8 @@ 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( auto hl = redirect_type == TOK_NONE ? highlight_spec_error : highlight_spec_redirection;
*redirection_primitive, this->color_node(*redirection_primitive, hl);
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.
@ -942,9 +950,8 @@ void highlighter_t::color_redirection(const parse_node_t &redirection_node) {
} }
if (redirection_target != NULL) { if (redirection_target != NULL) {
this->color_node( auto hl = target_is_valid ? highlight_spec_redirection : highlight_spec_error;
*redirection_target, this->color_node(*redirection_target, hl);
target_is_valid ? highlight_spec_redirection : highlight_spec_error);
} }
} }
} }

View file

@ -53,9 +53,9 @@ void io_buffer_t::read() {
// never block. But a broken pipe seems to cause some flags to reset, causing the // never block. But a broken pipe seems to cause some flags to reset, causing the
// EOF flag to not be set. Therefore, EAGAIN is ignored and we exit anyway. // EOF flag to not be set. Therefore, EAGAIN is ignored and we exit anyway.
if (errno != EAGAIN) { if (errno != EAGAIN) {
debug(1, _(L"An error occured while reading output from code block on file " const wchar_t *fmt =
L"descriptor %d"), _(L"An error occured while reading output from code block on fd %d");
pipe_fd[0]); debug(1, fmt, pipe_fd[0]);
wperror(L"io_buffer_t::read"); wperror(L"io_buffer_t::read");
} }

View file

@ -555,8 +555,9 @@ void writembs_check(char *mbs, const char *mbs_name, const char *file, long line
tputs(mbs, 1, &writeb); tputs(mbs, 1, &writeb);
} else { } else {
env_var_t term = env_get_string(L"TERM"); env_var_t term = env_get_string(L"TERM");
debug(0, _(L"Tried to use terminfo string %s on line %ld of %s, which is undefined in " const wchar_t *fmt =
L"terminal of type \"%ls\". Please report this error to %s"), _(L"Tried to use terminfo string %s on line %ld of %s, which is "
mbs_name, line, file, term.c_str(), PACKAGE_BUGREPORT); L"undefined in terminal of type \"%ls\". Please report this error to %s");
debug(0, fmt, mbs_name, line, file, term.c_str(), PACKAGE_BUGREPORT);
} }
} }

View file

@ -767,10 +767,11 @@ parse_execution_result_t parse_execution_context_t::handle_command_not_found(
} }
} else if (wcschr(cmd, L'$') || wcschr(cmd, VARIABLE_EXPAND_SINGLE) || } else if (wcschr(cmd, L'$') || wcschr(cmd, VARIABLE_EXPAND_SINGLE) ||
wcschr(cmd, VARIABLE_EXPAND)) { wcschr(cmd, VARIABLE_EXPAND)) {
const wchar_t *msg =
_(L"Variables may not be used as commands. In fish, "
L"please define a function or use 'eval %ls'.");
wcstring eval_cmd = reconstruct_orig_str(cmd_str); wcstring eval_cmd = reconstruct_orig_str(cmd_str);
this->report_error(statement_node, _(L"Variables may not be used as commands. In fish, " this->report_error(statement_node, msg, eval_cmd.c_str());
L"please define a function or use 'eval %ls'."),
eval_cmd.c_str());
} else if (err_code != ENOENT) { } else if (err_code != ENOENT) {
this->report_error(statement_node, _(L"The file '%ls' is not executable by this user"), this->report_error(statement_node, _(L"The file '%ls' is not executable by this user"),
cmd ? cmd : L"UNKNOWN"); cmd ? cmd : L"UNKNOWN");
@ -998,10 +999,10 @@ bool parse_execution_context_t::determine_io_chain(const parse_node_t &statement
} else { } else {
int old_fd = fish_wcstoi(target.c_str()); int old_fd = fish_wcstoi(target.c_str());
if (errno || old_fd < 0) { if (errno || old_fd < 0) {
errored = const wchar_t *fmt =
report_error(redirect_node, _(L"Requested redirection to '%ls', which " _(L"Requested redirection to '%ls', "
L"is not a valid file descriptor"), L"which is not a valid file descriptor");
target.c_str()); errored = report_error(redirect_node, fmt, target.c_str());
} else { } else {
new_io.reset(new io_fd_t(source_fd, old_fd, true)); new_io.reset(new io_fd_t(source_fd, old_fd, true));
} }

View file

@ -44,6 +44,6 @@ inline bool production_element_is_valid(production_element_t elem) {
const production_element_t *production_for_token(parse_token_type_t node_type, const production_element_t *production_for_token(parse_token_type_t node_type,
const parse_token_t &input1, const parse_token_t &input1,
const parse_token_t &input2, uint8_t *out_tag); const parse_token_t &input2, uint8_t *out_tag);
} } // namespace parse_productions
#endif #endif

View file

@ -440,9 +440,7 @@ const wchar_t *parser_t::is_function() const {
return result; return result;
} }
const wchar_t *parser_t::get_function_name() { const wchar_t *parser_t::get_function_name() { return this->is_function(); }
return this->is_function();
}
int parser_t::get_lineno() const { int parser_t::get_lineno() const {
int lineno = -1; int lineno = -1;

View file

@ -233,8 +233,7 @@ static void maybe_issue_path_warning(const wcstring &which_dir, const wcstring &
debug(0, custom_error_msg.c_str()); debug(0, custom_error_msg.c_str());
if (path.empty()) { if (path.empty()) {
debug(0, _(L"Unable to locate the %ls directory."), which_dir.c_str()); debug(0, _(L"Unable to locate the %ls directory."), which_dir.c_str());
debug(0, _(L"Please set the %ls or HOME environment variable " debug(0, _(L"Please set the %ls or HOME environment variable before starting fish."),
L"before starting fish."),
xdg_var.c_str()); xdg_var.c_str());
} else { } else {
const wchar_t *env_var = using_xdg ? xdg_var.c_str() : L"HOME"; const wchar_t *env_var = using_xdg ? xdg_var.c_str() : L"HOME";

View file

@ -326,7 +326,7 @@ bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr,
// set_child_group puts each job into its own process group // set_child_group puts each job into its own process group
// do the same here if there is no PGID yet (i.e. PGID == -2) // do the same here if there is no PGID yet (i.e. PGID == -2)
desired_process_group_id = j->pgid; desired_process_group_id = j->pgid;
if (desired_process_group_id == -2 ) { if (desired_process_group_id == -2) {
desired_process_group_id = 0; desired_process_group_id = 0;
} }
} }

View file

@ -597,9 +597,9 @@ int job_reap(bool allow_interactive) {
} else { } else {
const wcstring job_number_desc = const wcstring job_number_desc =
(job_count == 1) ? wcstring() : format_string(L"from job %d, ", j->job_id); (job_count == 1) ? wcstring() : format_string(L"from job %d, ", j->job_id);
fwprintf(stdout, _(L"%ls: Process %d, \'%ls\' %ls\'%ls\' " const wchar_t *fmt =
L"terminated by signal %ls (%ls)"), _(L"%ls: Process %d, \'%ls\' %ls\'%ls\' terminated by signal %ls (%ls)");
program_name, p->pid, p->argv0(), job_number_desc.c_str(), fwprintf(stdout, fmt, program_name, p->pid, p->argv0(), job_number_desc.c_str(),
truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)), truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)),
signal_get_desc(WTERMSIG(p->status))); signal_get_desc(WTERMSIG(p->status)));
} }

View file

@ -447,9 +447,9 @@ static void reader_repaint() {
bool focused_on_pager = data->active_edit_line() == &data->pager.search_field_line; bool focused_on_pager = data->active_edit_line() == &data->pager.search_field_line;
size_t cursor_position = focused_on_pager ? data->pager.cursor_position() : cmd_line->position; size_t cursor_position = focused_on_pager ? data->pager.cursor_position() : cmd_line->position;
s_write(&data->screen, data->left_prompt_buff, data->right_prompt_buff, full_line, cmd_line->size(), s_write(&data->screen, data->left_prompt_buff, data->right_prompt_buff, full_line,
&colors[0], &indents[0], cursor_position, data->current_page_rendering, cmd_line->size(), &colors[0], &indents[0], cursor_position,
focused_on_pager); data->current_page_rendering, focused_on_pager);
data->repaint_needed = false; data->repaint_needed = false;
} }
@ -1603,9 +1603,10 @@ static void reader_interactive_init() {
} else { } else {
if (check_for_orphaned_process(loop_count, shell_pgid)) { if (check_for_orphaned_process(loop_count, shell_pgid)) {
// We're orphaned, so we just die. Another sad statistic. // We're orphaned, so we just die. Another sad statistic.
debug(1, _(L"I appear to be an orphaned process, so I am quitting politely. My " const wchar_t *fmt =
L"pid is %d."), _(L"I appear to be an orphaned process, so I am quitting politely. "
(int)getpid()); L"My pid is %d.");
debug(1, fmt, (int)getpid());
exit_without_destructors(1); exit_without_destructors(1);
} }

View file

@ -1020,23 +1020,27 @@ static screen_layout_t compute_layout(screen_t *s, size_t screen_width,
// the right prompt? The issue is resizing: if you resize the window smaller, then the right // the right prompt? The issue is resizing: if you resize the window smaller, then the right
// prompt will wrap to the next line. This means that we can't go back to the line that we were // prompt will wrap to the next line. This means that we can't go back to the line that we were
// on, and things turn to chaos very quickly. // on, and things turn to chaos very quickly.
size_t calculated_width;
bool done = false; bool done = false;
// Case 1 // Case 1
if (!done && if (!done) {
left_prompt_width + right_prompt_width + first_command_line_width + calculated_width = left_prompt_width + right_prompt_width + first_command_line_width +
autosuggest_total_width < autosuggest_total_width;
screen_width) { if (calculated_width < screen_width) {
result.left_prompt = left_prompt; result.left_prompt = left_prompt;
result.left_prompt_space = left_prompt_width; result.left_prompt_space = left_prompt_width;
result.right_prompt = right_prompt; result.right_prompt = right_prompt;
result.autosuggestion = autosuggestion; result.autosuggestion = autosuggestion;
done = true; done = true;
} }
}
// Case 2. Note that we require strict inequality so that there's always at least one space // Case 2. Note that we require strict inequality so that there's always at least one space
// between the left edge and the rprompt. // between the left edge and the rprompt.
if (!done && left_prompt_width + right_prompt_width + first_command_line_width < screen_width) { if (!done) {
calculated_width = left_prompt_width + right_prompt_width + first_command_line_width;
if (calculated_width < screen_width) {
result.left_prompt = left_prompt; result.left_prompt = left_prompt;
result.left_prompt_space = left_prompt_width; result.left_prompt_space = left_prompt_width;
result.right_prompt = right_prompt; result.right_prompt = right_prompt;
@ -1045,20 +1049,24 @@ static screen_layout_t compute_layout(screen_t *s, size_t screen_width,
size_t available_autosuggest_space = size_t available_autosuggest_space =
screen_width - (left_prompt_width + right_prompt_width + first_command_line_width); screen_width - (left_prompt_width + right_prompt_width + first_command_line_width);
if (autosuggest_total_width > 0 && available_autosuggest_space > 2) { if (autosuggest_total_width > 0 && available_autosuggest_space > 2) {
size_t truncation_offset = truncation_offset_for_width(autosuggest_truncated_widths, size_t truncation_offset = truncation_offset_for_width(
available_autosuggest_space - 2); autosuggest_truncated_widths, available_autosuggest_space - 2);
result.autosuggestion = wcstring(autosuggestion, truncation_offset); result.autosuggestion = wcstring(autosuggestion, truncation_offset);
result.autosuggestion.push_back(ellipsis_char); result.autosuggestion.push_back(ellipsis_char);
} }
done = true; done = true;
} }
}
// Case 3 // Case 3
if (!done && left_prompt_width + first_command_line_width < screen_width) { if (!done) {
calculated_width = left_prompt_width + first_command_line_width;
if (calculated_width < screen_width) {
result.left_prompt = left_prompt; result.left_prompt = left_prompt;
result.left_prompt_space = left_prompt_width; result.left_prompt_space = left_prompt_width;
done = true; done = true;
} }
}
// Case 4 // Case 4
if (!done) { if (!done) {
@ -1072,11 +1080,8 @@ static screen_layout_t compute_layout(screen_t *s, size_t screen_width,
prompt_percent_width > 33) { prompt_percent_width > 33) {
result.prompts_get_own_line = true; result.prompts_get_own_line = true;
} }
done = true;
} }
assert(done);
return result; return result;
} }