time for another make style-all

Gotta keep the entropy (i.e., disorder) from increasing.
This commit is contained in:
Kurtis Rader 2017-01-26 20:00:43 -08:00
parent 05d569ee44
commit 5b6cc5af6d
29 changed files with 200 additions and 213 deletions

View file

@ -160,8 +160,11 @@ if set -q MANPATH
end
set __fish_tmp_manpath $__fish_tmp_manpath[-1..1]
end
test -r /etc/manpaths ; and __fish_load_manpath_helper_manpaths < /etc/manpaths
for manpathfile in /etc/manpaths.d/* ; __fish_load_manpath_helper_manpaths < $manpathfile ; end
test -r /etc/manpaths
and __fish_load_manpath_helper_manpaths </etc/manpaths
for manpathfile in /etc/manpaths.d/*
__fish_load_manpath_helper_manpaths <$manpathfile
end
set -xg MANPATH $__fish_tmp_manpath
set -e __fish_tmp_manpath
functions -e __fish_load_manpath_helper_manpaths

View file

@ -28,43 +28,43 @@ function __fish_complete_man
if test -n "$token"
# Do the actual search
apropos $token ^/dev/null | awk '
BEGIN { FS="[\t ]- "; OFS="\t"; }
# BSD/Darwin
/^[^( \t]+\('$section'\)/ {
split($1, pages, ", ");
for (i in pages) {
page = pages[i];
sub(/[ \t]+/, "", page);
paren = index(page, "(");
name = substr(page, 1, paren - 1);
sect = substr(page, paren + 1, length(page) - paren - 1);
print name, sect ": " $2;
}
}
# man-db
/^[^( \t]+ +\('$section'\)/ {
split($1, t, " ");
sect = substr(t[2], 2, length(t[2]) - 2);
print t[1], sect ": " $2;
}
# man-db RHEL 5 with [aliases]
/^[^( \t]+ +\[.*\] +\('$section'\)/ {
split($1, t, " ");
sect = substr(t[3], 2, length(t[3]) - 2);
print t[1], sect ": " $2;
}
# Solaris 11
# Does not display descriptions
# Solaris apropos outputs embedded backspace in descriptions
/^[0-9]+\. [^( \t]*\('$section'\) / {
split($1, t, " ")
paren = index(t[2], "(");
name = substr(t[2], 1, paren - 1);
sect = substr(t[2], paren + 1, length(t[2]) - paren - 1);
print name, sect
}
'
BEGIN { FS="[\t ]- "; OFS="\t"; }
# BSD/Darwin
/^[^( \t]+\('$section'\)/ {
split($1, pages, ", ");
for (i in pages) {
page = pages[i];
sub(/[ \t]+/, "", page);
paren = index(page, "(");
name = substr(page, 1, paren - 1);
sect = substr(page, paren + 1, length(page) - paren - 1);
print name, sect ": " $2;
}
}
# man-db
/^[^( \t]+ +\('$section'\)/ {
split($1, t, " ");
sect = substr(t[2], 2, length(t[2]) - 2);
print t[1], sect ": " $2;
}
# man-db RHEL 5 with [aliases]
/^[^( \t]+ +\[.*\] +\('$section'\)/ {
split($1, t, " ");
sect = substr(t[3], 2, length(t[3]) - 2);
print t[1], sect ": " $2;
}
# Solaris 11
# Does not display descriptions
# Solaris apropos outputs embedded backspace in descriptions
/^[0-9]+\. [^( \t]*\('$section'\) / {
split($1, t, " ")
paren = index(t[2], "(");
name = substr(t[2], 1, paren - 1);
sect = substr(t[2], paren + 1, length(t[2]) - paren - 1);
print name, sect
}
'
# Fish commands are not given by apropos
set -l files $__fish_datadir/man/man1/*.1
string replace -r '.*/([^/]+)\.1$' '$1\tFish command' -- $files

View file

@ -1046,7 +1046,7 @@ static wcstring functions_def(const wcstring &name) {
}
static int report_function_metadata(const wchar_t *funcname, bool verbose, io_streams_t &streams,
bool metadata_as_comments) {
bool metadata_as_comments) {
const wchar_t *path = L"n/a";
const wchar_t *autoloaded = L"n/a";
const wchar_t *shadows_scope = L"n/a";
@ -1201,7 +1201,7 @@ static int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **
} else if (report_metadata) {
if (argc - w.woptind != 1) {
streams.err.append_format(
_(L"%ls: Expected exactly one function name for --metadata\n"), argv[0]);
_(L"%ls: Expected exactly one function name for --metadata\n"), argv[0]);
return STATUS_BUILTIN_ERROR;
}
@ -2025,7 +2025,7 @@ static int read_in_chunks(int fd, wcstring &buff, bool split_null) {
}
const char *end = std::find(inbuf, inbuf + bytes_read, split_null ? L'\0' : L'\n');
long bytes_consumed = end - inbuf; // note: must be signed for use in lseek
long bytes_consumed = end - inbuf; // note: must be signed for use in lseek
assert(bytes_consumed <= bytes_read);
str.append(inbuf, bytes_consumed);
if (bytes_consumed < bytes_read) {

View file

@ -143,7 +143,8 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
fgcolors.push_back(fg);
}
if (fgcolors.empty() && bgcolor == NULL && !bold && !underline && !italics && !dim && !reverse) {
if (fgcolors.empty() && bgcolor == NULL && !bold && !underline && !italics && !dim &&
!reverse) {
streams.err.append_format(_(L"%ls: Expected an argument\n"), argv[0]);
return STATUS_BUILTIN_ERROR;
}

View file

@ -170,8 +170,7 @@ class test_parser {
unique_ptr<expression> parse_binary_primary(unsigned int start, unsigned int end);
unique_ptr<expression> parse_just_a_string(unsigned int start, unsigned int end);
static unique_ptr<expression> parse_args(const wcstring_list_t &args,
wcstring &err,
static unique_ptr<expression> parse_args(const wcstring_list_t &args, wcstring &err,
wchar_t *program_name);
};
@ -280,7 +279,8 @@ unique_ptr<expression> test_parser::parse_unary_expression(unsigned int start, u
if (tok == test_bang) {
unique_ptr<expression> subject(parse_unary_expression(start + 1, end));
if (subject.get()) {
return make_unique<unary_operator>(tok, range_t(start, subject->range.end), move(subject));
return make_unique<unary_operator>(tok, range_t(start, subject->range.end),
move(subject));
}
return NULL;
}
@ -288,7 +288,8 @@ unique_ptr<expression> test_parser::parse_unary_expression(unsigned int start, u
}
/// Parse a combining expression (AND, OR).
unique_ptr<expression> test_parser::parse_combining_expression(unsigned int start, unsigned int end) {
unique_ptr<expression> test_parser::parse_combining_expression(unsigned int start,
unsigned int end) {
if (start >= end) return NULL;
std::vector<unique_ptr<expression>> subjects;
@ -333,7 +334,8 @@ unique_ptr<expression> test_parser::parse_combining_expression(unsigned int star
}
// Our new expression takes ownership of all expressions we created. The token we pass is
// irrelevant.
return make_unique<combining_expression>(test_combine_and, range_t(start, idx), move(subjects), move(combiners));
return make_unique<combining_expression>(test_combine_and, range_t(start, idx), move(subjects),
move(combiners));
}
unique_ptr<expression> test_parser::parse_unary_primary(unsigned int start, unsigned int end) {
@ -383,7 +385,8 @@ unique_ptr<expression> test_parser::parse_binary_primary(unsigned int start, uns
const token_info_t *info = token_for_string(arg(start + 1));
if (!(info->flags & BINARY_PRIMARY)) return NULL;
return make_unique<binary_primary>(info->tok, range_t(start, start + 3), arg(start), arg(start + 2));
return make_unique<binary_primary>(info->tok, range_t(start, start + 3), arg(start),
arg(start + 2));
}
unique_ptr<expression> test_parser::parse_parenthentical(unsigned int start, unsigned int end) {
@ -410,7 +413,8 @@ unique_ptr<expression> test_parser::parse_parenthentical(unsigned int start, uns
}
// Success.
return make_unique<parenthetical_expression>(test_paren_open, range_t(start, close_index + 1), move(subexpr));
return make_unique<parenthetical_expression>(test_paren_open, range_t(start, close_index + 1),
move(subexpr));
}
unique_ptr<expression> test_parser::parse_primary(unsigned int start, unsigned int end) {
@ -444,8 +448,7 @@ unique_ptr<expression> test_parser::parse_3_arg_expression(unsigned int start, u
subjects.push_back(move(left));
subjects.push_back(move(right));
result = make_unique<combining_expression>(center_token->tok, range_t(start, end),
move(subjects),
move(combiners));
move(subjects), move(combiners));
}
} else {
result = parse_unary_expression(start, end);
@ -461,7 +464,8 @@ unique_ptr<expression> test_parser::parse_4_arg_expression(unsigned int start, u
if (first_token == test_bang) {
unique_ptr<expression> subject(parse_3_arg_expression(start + 1, end));
if (subject.get()) {
result = make_unique<unary_operator>(first_token, range_t(start, subject->range.end), move(subject));
result = make_unique<unary_operator>(first_token, range_t(start, subject->range.end),
move(subject));
}
} else if (first_token == test_paren_open) {
result = parse_parenthentical(start, end);
@ -499,7 +503,7 @@ unique_ptr<expression> test_parser::parse_expression(unsigned int start, unsigne
}
unique_ptr<expression> test_parser::parse_args(const wcstring_list_t &args, wcstring &err,
wchar_t *program_name) {
wchar_t *program_name) {
// Empty list and one-arg list should be handled by caller.
assert(args.size() > 1);

View file

@ -19,7 +19,13 @@ class rgb_color_t {
unsigned char type : 4;
// Flags
enum { flag_bold = 1 << 0, flag_underline = 1 << 1, flag_italics = 1 << 2, flag_dim = 1 << 3, flag_reverse = 1 << 4 };
enum {
flag_bold = 1 << 0,
flag_underline = 1 << 1,
flag_italics = 1 << 2,
flag_dim = 1 << 3,
flag_reverse = 1 << 4
};
unsigned char flags : 5;
union {

View file

@ -640,8 +640,8 @@ void append_formatv(wcstring &str, const wchar_t *format, va_list ap);
using std::make_unique;
#else
/// make_unique implementation
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args &&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
#endif
@ -683,7 +683,6 @@ ssize_t write_loop(int fd, const char *buff, size_t count);
/// error.
ssize_t read_loop(int fd, void *buff, size_t count);
/// Replace special characters with backslash escape sequences. Newline is replaced with \n, etc.
///
/// \param in The string to be escaped

View file

@ -673,8 +673,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool
// updated with choices for the user.
expand_error_t ignore =
expand_string(str_cmd, &this->completions,
EXPAND_FOR_COMPLETIONS | DIRECTORIES_ONLY | this->expand_flags(),
NULL);
EXPAND_FOR_COMPLETIONS | DIRECTORIES_ONLY | this->expand_flags(), NULL);
USE(ignore);
}
@ -864,9 +863,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop
} else if (this->type() == COMPLETE_AUTOSUGGEST &&
!completion_autoloader.has_tried_loading(cmd)) {
// Load this command (on the main thread)
iothread_perform_on_main([&](){
complete_load(cmd, false);
});
iothread_perform_on_main([&]() { complete_load(cmd, false); });
}
// Make a list of lists of all options that we care about.
@ -1454,7 +1451,8 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> *out_c
wcstring faux_cmdline = cmd;
faux_cmdline.replace(cmd_node->source_start,
cmd_node->source_length, wrap_chain.at(i));
transient_cmd = make_unique<builtin_commandline_scoped_transient_t>(faux_cmdline);
transient_cmd = make_unique<builtin_commandline_scoped_transient_t>(
faux_cmdline);
}
if (!completer.complete_param(wrap_chain.at(i),
previous_argument_unescape,

View file

@ -76,8 +76,7 @@ class env_node_t {
friend struct var_stack_t;
env_node_t(bool is_new_scope) : new_scope(is_new_scope) {}
public:
public:
/// Variable table.
var_table_t env;
/// Does this node imply a new variable scope? If yes, all non-global variables below this one
@ -122,9 +121,7 @@ struct var_stack_t {
void mark_changed_exported() { has_changed_exported = true; }
void update_export_array_if_necessary();
var_stack_t() : top(new env_node_t(false)) {
this->global_env = this->top.get();
}
var_stack_t() : top(new env_node_t(false)) { this->global_env = this->top.get(); }
// Pushes a new node onto our stack
// Optionally creates a new scope for the node
@ -177,9 +174,9 @@ void var_stack_t::pop() {
}
}
// Actually do the pop!
// Move the top pointer into a local variable, then replace the top pointer with the next pointer
// afterwards we should have a node with no next pointer, and our top should be non-null
// Actually do the pop! Move the top pointer into a local variable, then replace the top pointer
// with the next pointer afterwards we should have a node with no next pointer, and our top
// should be non-null.
std::unique_ptr<env_node_t> old_top = std::move(this->top);
this->top = std::move(old_top->next);
old_top->next.reset();
@ -194,7 +191,7 @@ void var_stack_t::pop() {
break;
}
}
// TODO: move this to something general
// TODO: Move this to something general.
if (locale_changed) handle_locale(locale_changed);
}
@ -348,9 +345,7 @@ static bool var_is_curses(const wcstring &key) {
static bool can_set_term_title = false;
/// Returns true if we think the terminal supports setting its title.
bool term_supports_setting_title() {
return can_set_term_title;
}
bool term_supports_setting_title() { return can_set_term_title; }
/// This is a pretty lame heuristic for detecting terminals that do not support setting the
/// title. If we recognise the terminal name as that of a virtual terminal, we assume it supports
@ -381,9 +376,7 @@ static bool does_term_support_setting_title() {
}
/// Handle changes to the TERM env var that do not involves the curses subsystem.
static void handle_term() {
can_set_term_title = does_term_support_setting_title();
}
static void handle_term() { can_set_term_title = does_term_support_setting_title(); }
/// Push all curses/terminfo env vars into the global environment where they can be found by those
/// libraries.
@ -1039,13 +1032,9 @@ static bool local_scope_exports(const env_node_t *n) {
return local_scope_exports(n->next.get());
}
void env_push(bool new_scope) {
vars_stack().push(new_scope);
}
void env_push(bool new_scope) { vars_stack().push(new_scope); }
void env_pop() {
vars_stack().pop();
}
void env_pop() { vars_stack().pop(); }
/// Function used with to insert keys of one table into a set::set<wcstring>.
static void add_key_to_string_set(const var_table_t &envs, std::set<wcstring> *str_set,
@ -1161,7 +1150,7 @@ static void export_func(const std::map<wcstring, wcstring> &envs, std::vector<st
}
void var_stack_t::update_export_array_if_necessary() {
if (! this->has_changed_exported) {
if (!this->has_changed_exported) {
return;
}
std::map<wcstring, wcstring> vals;

View file

@ -153,7 +153,7 @@ class env_vars_snapshot_t {
std::map<wcstring, wcstring> vars;
bool is_current() const;
public:
public:
env_vars_snapshot_t(const env_vars_snapshot_t &) = default;
env_vars_snapshot_t &operator=(const env_vars_snapshot_t &) = default;

View file

@ -46,7 +46,7 @@
#ifdef __HAIKU__
#define _BSD_SOURCE
#include <bsd/ifaddrs.h>
#endif //Haiku
#endif // Haiku
// NAME_MAX is not defined on Solaris and suggests the use of pathconf()
// There is no obvious sensible pathconf() for shared memory and _XPG_NAME_MAX
@ -864,8 +864,8 @@ void env_universal_t::parse_message_internal(const wcstring &msgstr, var_table_t
#ifdef SIOCGIFHWADDR
// Linux
#include <sys/socket.h>
#include <net/if.h>
#include <sys/socket.h>
static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN],
const char *interface = "eth0") {
bool result = false;
@ -886,9 +886,9 @@ static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN],
#elif defined(HAVE_GETIFADDRS)
// OS X and BSD
#include <sys/socket.h>
#include <ifaddrs.h>
#include <net/if_dl.h>
#include <sys/socket.h>
static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN],
const char *interface = "en0") {
// BSD, Mac OS X

View file

@ -136,8 +136,8 @@ class universal_notifier_t {
virtual ~universal_notifier_t();
// Factory constructor.
static std::unique_ptr<universal_notifier_t> new_notifier_for_strategy(notifier_strategy_t strat,
const wchar_t *test_path = NULL);
static std::unique_ptr<universal_notifier_t> new_notifier_for_strategy(
notifier_strategy_t strat, const wchar_t *test_path = NULL);
// Default instance. Other instances are possible for testing.
static universal_notifier_t &default_notifier();

View file

@ -263,7 +263,7 @@ void event_remove(const event_t &criterion) {
event_list_t::iterator iter = s_event_handlers.begin();
while (iter != s_event_handlers.end()) {
const event_t *n = iter->get();
if (! event_match(criterion, *n)) {
if (!event_match(criterion, *n)) {
++iter;
continue;
}
@ -323,7 +323,7 @@ static void event_fire_internal(const event_t &event) {
if (signal_is_blocked()) {
// Fix for https://github.com/fish-shell/fish-shell/issues/608. Don't run event handlers
// while signals are blocked.
input_common_add_callback([event](){
input_common_add_callback([event]() {
ASSERT_IS_MAIN_THREAD();
event_fire(&event);
});
@ -333,9 +333,8 @@ static void event_fire_internal(const event_t &event) {
// Iterate over our list of matching events.
for (shared_ptr<event_t> &criterion : fire) {
// Only fire if this event is still present
if (std::find(s_event_handlers.begin(),
s_event_handlers.end(),
criterion) == s_event_handlers.end()) {
if (std::find(s_event_handlers.begin(), s_event_handlers.end(), criterion) ==
s_event_handlers.end()) {
continue;
}
@ -445,9 +444,7 @@ void event_fire(const event_t *event) {
void event_init() {}
void event_destroy() {
s_event_handlers.clear();
}
void event_destroy() { s_event_handlers.clear(); }
void event_fire_generic(const wchar_t *name, wcstring_list_t *args) {
CHECK(name, );

View file

@ -455,7 +455,7 @@ void exec_job(parser_t &parser, job_t *j) {
if (j->get_flag(JOB_CONTROL) && !exec_error) {
for (const process_ptr_t &p : j->processes) {
if (p->type != EXTERNAL) {
if (! p->is_last_in_job || ! p->is_first_in_job) {
if (!p->is_last_in_job || !p->is_first_in_job) {
needs_keepalive = true;
break;
}
@ -498,7 +498,7 @@ void exec_job(parser_t &parser, job_t *j) {
if (exec_error) {
break;
}
process_t * const p = unique_p.get();
process_t *const p = unique_p.get();
// The IO chain for this process. It starts with the block IO, then pipes, and then gets any
// from the process.
io_chain_t process_net_io_chain = j->block_io_chain();
@ -509,7 +509,7 @@ void exec_job(parser_t &parser, job_t *j) {
pipe_next_read = -1;
// See if we need a pipe.
const bool pipes_to_next_command = ! p->is_last_in_job;
const bool pipes_to_next_command = !p->is_last_in_job;
// The pipes the current process write to and read from. Unfortunately these can't be just
// allocated on the stack, since j->io wants shared_ptr.
@ -554,7 +554,7 @@ void exec_job(parser_t &parser, job_t *j) {
process_net_io_chain.append(p->io_chain());
// Read pipe goes last.
if (! p->is_first_in_job) {
if (!p->is_first_in_job) {
pipe_read.reset(new io_pipe_t(p->pipe_read_fd, true));
// Record the current read in pipe_read.
pipe_read->pipe_fd[0] = pipe_current_read;
@ -568,7 +568,7 @@ void exec_job(parser_t &parser, job_t *j) {
// uniprocessor systems.
if (p->type == EXTERNAL) {
// Apply universal barrier so we have the most recent uvar changes
if (! get_proc_had_barrier()) {
if (!get_proc_had_barrier()) {
set_proc_had_barrier(true);
env_universal_barrier();
}
@ -637,7 +637,8 @@ void exec_job(parser_t &parser, job_t *j) {
break;
}
function_block_t *fb = parser.push_block<function_block_t>(p, func_name, shadow_scope);
function_block_t *fb =
parser.push_block<function_block_t>(p, func_name, shadow_scope);
// Setting variables might trigger an event handler, hence we need to unblock
// signals.
@ -647,7 +648,7 @@ void exec_job(parser_t &parser, job_t *j) {
parser.forbid_function(func_name);
if (! p->is_last_in_job) {
if (!p->is_last_in_job) {
// Be careful to handle failure, e.g. too many open fds.
block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios);
if (block_output_io_buffer.get() == NULL) {
@ -674,7 +675,7 @@ void exec_job(parser_t &parser, job_t *j) {
}
case INTERNAL_BLOCK_NODE: {
if (! p->is_last_in_job) {
if (!p->is_last_in_job) {
block_output_io_buffer = io_buffer_t::create(STDOUT_FILENO, all_ios);
if (block_output_io_buffer.get() == NULL) {
// We failed (e.g. no more fds could be created).
@ -764,7 +765,7 @@ void exec_job(parser_t &parser, job_t *j) {
} else {
// Determine if we have a "direct" redirection for stdin.
bool stdin_is_directly_redirected;
if (! p->is_first_in_job) {
if (!p->is_first_in_job) {
// We must have a pipe
stdin_is_directly_redirected = true;
} else {

View file

@ -430,9 +430,10 @@ bool process_iterator_t::next_process(wcstring *out_str, pid_t *out_pid) {
#endif
/// The following function is invoked on the main thread, because the job list is not thread safe.
/// It should search the job list for something matching the given proc, and then return true to stop
/// the search, false to continue it.
static bool find_job(const wchar_t *proc, expand_flags_t flags, std::vector<completion_t> *completions) {
/// It should search the job list for something matching the given proc, and then return true to
/// stop the search, false to continue it.
static bool find_job(const wchar_t *proc, expand_flags_t flags,
std::vector<completion_t> *completions) {
ASSERT_IS_MAIN_THREAD();
bool found = false;
@ -540,9 +541,7 @@ static void find_process(const wchar_t *proc, expand_flags_t flags,
std::vector<completion_t> *out) {
if (!(flags & EXPAND_SKIP_JOBS)) {
bool found = false;
iothread_perform_on_main([&](){
found = find_job(proc, flags, out);
});
iothread_perform_on_main([&]() { found = find_job(proc, flags, out); });
if (found) {
return;
}

View file

@ -170,7 +170,7 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) {
return wcsncasecmp_fallback(a, b, n);
}
#endif // __DARWIN_C_LEVEL >= 200809L
#else // __APPLE__
#else // __APPLE__
/// These functions are missing from Solaris 10
#ifndef HAVE_WCSDUP

View file

@ -514,7 +514,7 @@ static void test_tokenizer() {
// Little function that runs in a background thread, bouncing to the main.
static int test_iothread_thread_call(int *addr) {
int before = *addr;
iothread_perform_on_main([=](){ *addr += 1; });
iothread_perform_on_main([=]() { *addr += 1; });
int after = *addr;
// Must have incremented it at least once.
@ -531,7 +531,7 @@ static void test_iothread(void) {
int max_achieved_thread_count = 0;
double start = timef();
for (int i = 0; i < iterations; i++) {
int thread_count = iothread_perform([&](){ test_iothread_thread_call(int_ptr.get());});
int thread_count = iothread_perform([&]() { test_iothread_thread_call(int_ptr.get()); });
max_achieved_thread_count = std::max(max_achieved_thread_count, thread_count);
}
@ -718,7 +718,7 @@ static void test_1_cancellation(const wchar_t *src) {
const io_chain_t io_chain(out_buff);
pthread_t thread = pthread_self();
double delay = 0.25 /* seconds */;
iothread_perform([=](){
iothread_perform([=]() {
/// Wait a while and then SIGINT the main thread.
usleep(delay * 1E6);
pthread_kill(thread, SIGINT);
@ -2460,7 +2460,7 @@ static void test_universal() {
const int threads = 16;
for (int i = 0; i < threads; i++) {
iothread_perform([=](){test_universal_helper(i);});
iothread_perform([=]() { test_universal_helper(i); });
}
iothread_drain_all();
@ -2898,7 +2898,8 @@ void history_tests_t::test_history_merge(void) {
say(L"Testing history merge");
const size_t count = 3;
const wcstring name = L"merge_test";
std::unique_ptr<history_t> hists[count] = {make_unique<history_t>(name), make_unique<history_t>(name), make_unique<history_t>(name)};
std::unique_ptr<history_t> hists[count] = {
make_unique<history_t>(name), make_unique<history_t>(name), make_unique<history_t>(name)};
const wcstring texts[count] = {L"History 1", L"History 2", L"History 3"};
const wcstring alt_texts[count] = {L"History Alt 1", L"History Alt 2", L"History Alt 3"};
@ -4056,16 +4057,11 @@ static void test_illegal_command_exit_code(void) {
};
const command_result_tuple_t tests[] = {
{L"echo -n", STATUS_BUILTIN_OK},
{L"pwd", STATUS_BUILTIN_OK},
{L")", STATUS_ILLEGAL_CMD},
{L") ", STATUS_ILLEGAL_CMD},
{L"*", STATUS_ILLEGAL_CMD},
{L"**", STATUS_ILLEGAL_CMD},
{L"%", STATUS_ILLEGAL_CMD},
{L"%test", STATUS_ILLEGAL_CMD},
{L"?", STATUS_ILLEGAL_CMD},
{L"abc?def", STATUS_ILLEGAL_CMD},
{L"echo -n", STATUS_BUILTIN_OK}, {L"pwd", STATUS_BUILTIN_OK},
{L")", STATUS_ILLEGAL_CMD}, {L") ", STATUS_ILLEGAL_CMD},
{L"*", STATUS_ILLEGAL_CMD}, {L"**", STATUS_ILLEGAL_CMD},
{L"%", STATUS_ILLEGAL_CMD}, {L"%test", STATUS_ILLEGAL_CMD},
{L"?", STATUS_ILLEGAL_CMD}, {L"abc?def", STATUS_ILLEGAL_CMD},
{L") ", STATUS_ILLEGAL_CMD}};
int res = 0;

View file

@ -1675,7 +1675,7 @@ path_list_t valid_paths(const path_list_t &paths, const wcstring &working_direct
bool all_paths_are_valid(const path_list_t &paths, const wcstring &working_directory) {
ASSERT_IS_BACKGROUND_THREAD();
for (const wcstring &path : paths) {
if (! path_is_valid(path, working_directory)) {
if (!path_is_valid(path, working_directory)) {
return false;
}
}
@ -1742,12 +1742,11 @@ void history_t::add_pending_with_file_detection(const wcstring &str) {
// Check for which paths are valid on a background thread,
// then on the main thread update our history item
const wcstring wd = env_get_pwd_slash();
iothread_perform([=](){
return valid_paths(potential_paths, wd);
}, [=](path_list_t validated_paths){
this->set_valid_file_paths(validated_paths, identifier);
this->enable_automatic_saving();
});
iothread_perform([=]() { return valid_paths(potential_paths, wd); },
[=](path_list_t validated_paths) {
this->set_valid_file_paths(validated_paths, identifier);
this->enable_automatic_saving();
});
}
// Actually add the item to the history.

View file

@ -2,8 +2,8 @@
#ifndef INPUT_COMMON_H
#define INPUT_COMMON_H
#include <functional>
#include <stddef.h>
#include <functional>
#include "common.h"

View file

@ -39,13 +39,10 @@ struct spawn_request_t {
void_function_t handler;
void_function_t completion;
spawn_request_t()
{}
spawn_request_t() {}
spawn_request_t(void_function_t f, void_function_t comp) :
handler(std::move(f)),
completion(std::move(comp))
{}
spawn_request_t(void_function_t f, void_function_t comp)
: handler(std::move(f)), completion(std::move(comp)) {}
// Move-only
spawn_request_t &operator=(const spawn_request_t &) = delete;
@ -77,9 +74,11 @@ static pthread_mutex_t s_result_queue_lock = PTHREAD_MUTEX_INITIALIZER;
static std::queue<spawn_request_t> s_result_queue;
// "Do on main thread" support.
static pthread_mutex_t s_main_thread_performer_lock = PTHREAD_MUTEX_INITIALIZER; // protects the main thread requests
static pthread_cond_t s_main_thread_performer_cond; // protects the main thread requests
static pthread_mutex_t s_main_thread_request_q_lock = PTHREAD_MUTEX_INITIALIZER; // protects the queue
static pthread_mutex_t s_main_thread_performer_lock =
PTHREAD_MUTEX_INITIALIZER; // protects the main thread requests
static pthread_cond_t s_main_thread_performer_cond; // protects the main thread requests
static pthread_mutex_t s_main_thread_request_q_lock =
PTHREAD_MUTEX_INITIALIZER; // protects the queue
static std::queue<main_thread_request_t *> s_main_thread_request_queue;
// Notifying pipes.
@ -194,7 +193,7 @@ int iothread_perform_impl(void_function_t &&func, void_function_t &&completion)
ASSERT_IS_MAIN_THREAD();
ASSERT_IS_NOT_FORKED_CHILD();
iothread_init();
struct spawn_request_t req(std::move(func), std::move(completion));
int local_thread_count = -1;
bool spawn_new_thread = false;
@ -366,7 +365,7 @@ void iothread_perform_on_main(void_function_t &&func) {
// It would be nice to support checking for cancellation here, but the clients need a
// deterministic way to clean up to avoid leaks
VOMIT_ON_FAILURE(
pthread_cond_wait(&s_main_thread_performer_cond, &s_main_thread_performer_lock));
pthread_cond_wait(&s_main_thread_performer_cond, &s_main_thread_performer_lock));
}
// Ok, the request must now be done.

View file

@ -27,8 +27,7 @@ void iothread_service_completion(void);
void iothread_drain_all(void);
// Internal implementation
int iothread_perform_impl(std::function<void(void)> &&func,
std::function<void(void)> &&completion);
int iothread_perform_impl(std::function<void(void)> &&func, std::function<void(void)> &&completion);
// Template helpers
// This is the glue part of the handler-completion handoff
@ -36,21 +35,23 @@ int iothread_perform_impl(std::function<void(void)> &&func,
// and then call the completion with that object. However if our type is void,
// this won't work (new void() fails!). So we have to use this template.
// The type T is the return type of HANDLER and the argument to COMPLETION
template<typename T>
template <typename T>
struct _iothread_trampoline {
template<typename HANDLER, typename COMPLETION>
template <typename HANDLER, typename COMPLETION>
static int perform(const HANDLER &handler, const COMPLETION &completion) {
T *result = new T(); // TODO: placement new?
return iothread_perform_impl([=](){ *result = handler(); },
[=](){ completion(std::move(*result)); delete result; });
T *result = new T(); // TODO: placement new?
return iothread_perform_impl([=]() { *result = handler(); },
[=]() {
completion(std::move(*result));
delete result;
});
}
};
// Void specialization
template<>
template <>
struct _iothread_trampoline<void> {
template<typename HANDLER, typename COMPLETION>
template <typename HANDLER, typename COMPLETION>
static int perform(const HANDLER &handler, const COMPLETION &completion) {
return iothread_perform_impl(handler, completion);
}
@ -60,15 +61,14 @@ struct _iothread_trampoline<void> {
// on the main thread. The value returned from the handler is passed to the completion.
// In other words, this is like COMPLETION(HANDLER()) except the handler part is invoked
// on a background thread.
template<typename HANDLER, typename COMPLETION>
template <typename HANDLER, typename COMPLETION>
int iothread_perform(const HANDLER &handler, const COMPLETION &completion) {
return _iothread_trampoline<decltype(handler())>::perform(handler, completion);
}
// variant of iothread_perform without a completion handler
inline int iothread_perform(std::function<void(void)> &&func) {
return iothread_perform_impl(std::move(func),
std::function<void(void)>());
return iothread_perform_impl(std::move(func), std::function<void(void)>());
}
/// Performs a function on the main thread, blocking until it completes.

View file

@ -230,7 +230,7 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
was_reverse = false;
}
if (was_dim && !is_dim ) {
if (was_dim && !is_dim) {
// Only way to exit dim mode is a reset of all attributes.
writembs(exit_attribute_mode);
last_color = normal;
@ -242,7 +242,7 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
was_reverse = false;
}
if (was_reverse && !is_reverse ) {
if (was_reverse && !is_reverse) {
// Only way to exit reverse mode is a reset of all attributes.
writembs(exit_attribute_mode);
last_color = normal;

View file

@ -75,9 +75,8 @@ static wcstring profiling_cmd_name_for_redirectable_block(const parse_node_t &no
return result;
}
parse_execution_context_t::parse_execution_context_t(parse_node_tree_t t,
const wcstring &s, parser_t *p,
int initial_eval_level)
parse_execution_context_t::parse_execution_context_t(parse_node_tree_t t, const wcstring &s,
parser_t *p, int initial_eval_level)
: tree(std::move(t)),
src(s),
parser(p),
@ -1264,14 +1263,15 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t
shared_ptr<job_t> job = std::make_shared<job_t>(acquire_job_id(), block_io);
job->tmodes = tmodes;
job->set_flag(JOB_CONTROL,
(job_control_mode == JOB_CONTROL_ALL) ||
((job_control_mode == JOB_CONTROL_INTERACTIVE) && shell_is_interactive()));
(job_control_mode == JOB_CONTROL_ALL) ||
((job_control_mode == JOB_CONTROL_INTERACTIVE) && shell_is_interactive()));
job->set_flag(JOB_FOREGROUND, !tree.job_should_be_backgrounded(job_node));
job->set_flag(JOB_TERMINAL, job->get_flag(JOB_CONTROL) && !is_subshell && !is_event);
job->set_flag(JOB_SKIP_NOTIFICATION, is_subshell || is_block || is_event || !shell_is_interactive());
job->set_flag(JOB_SKIP_NOTIFICATION,
is_subshell || is_block || is_event || !shell_is_interactive());
// Tell the current block what its job is. This has to happen before we populate it (#1394).
parser->current_block()->job = job;

View file

@ -124,7 +124,6 @@ const wchar_t *token_type_description(parse_token_type_t type) {
const wchar_t *description = enum_to_str(type, token_enum_map);
if (description) return description;
return L"unknown_token_type";
}
const wchar_t *keyword_description(parse_keyword_t type) {

View file

@ -142,8 +142,8 @@ class parse_node_tree_t : public std::vector<parse_node_t> {
parse_node_tree_t() {}
parse_node_tree_t(parse_node_tree_t &&) = default;
parse_node_tree_t &operator=(parse_node_tree_t &&) = default;
parse_node_tree_t(const parse_node_tree_t &) = delete; // no copying
parse_node_tree_t &operator=(const parse_node_tree_t &) = delete; // no copying
parse_node_tree_t(const parse_node_tree_t &) = delete; // no copying
parse_node_tree_t &operator=(const parse_node_tree_t &) = delete; // no copying
// Get the node corresponding to a child of the given node, or NULL if there is no such child.
// If expected_type is provided, assert that the node has that type.

View file

@ -525,7 +525,7 @@ wcstring parser_t::current_line() {
void parser_t::job_add(shared_ptr<job_t> job) {
assert(job != NULL);
assert(! job->processes.empty());
assert(!job->processes.empty());
this->my_job_list.push_front(std::move(job));
}
@ -596,7 +596,8 @@ int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t
return this->eval(cmd, io, block_type, std::move(tree));
}
int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type, parse_node_tree_t tree) {
int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type,
parse_node_tree_t tree) {
CHECK_BLOCK(1);
assert(block_type == TOP || block_type == SUBST);
@ -612,8 +613,8 @@ int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t
(execution_contexts.empty() ? -1 : execution_contexts.back()->current_eval_level());
// Append to the execution context stack.
execution_contexts.push_back(make_unique<parse_execution_context_t>(std::move(tree), cmd,
this, exec_eval_level));
execution_contexts.push_back(
make_unique<parse_execution_context_t>(std::move(tree), cmd, this, exec_eval_level));
const parse_execution_context_t *ctx = execution_contexts.back().get();
// Execute the first node.

View file

@ -244,7 +244,8 @@ class parser_t {
int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type);
/// Evaluate the expressions contained in cmd, which has been parsed into the given parse tree.
int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type, parse_node_tree_t t);
int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type,
parse_node_tree_t t);
/// Evaluates a block node at the given node offset in the topmost execution context.
int eval_block_node(node_offset_t node_idx, const io_chain_t &io, enum block_type_t block_type);
@ -288,8 +289,8 @@ class parser_t {
/// Pushes a new block created with the given arguments
/// Returns a pointer to the block. The pointer is valid
/// until the call to pop_block()
template<typename BLOCKTYPE, typename... Args>
BLOCKTYPE *push_block(Args&&... args) {
template <typename BLOCKTYPE, typename... Args>
BLOCKTYPE *push_block(Args &&... args) {
BLOCKTYPE *ret = new BLOCKTYPE(std::forward<Args>(args)...);
this->push_block_int(ret);
return ret;

View file

@ -220,7 +220,7 @@ int job_is_stopped(const job_t *j) {
///
/// \param j the job to test
bool job_is_completed(const job_t *j) {
assert(! j->processes.empty());
assert(!j->processes.empty());
bool result = true;
for (const process_ptr_t &p : j->processes) {
if (!p->completed) {
@ -239,9 +239,7 @@ void job_t::set_flag(job_flag_t flag, bool set) {
}
}
bool job_t::get_flag(job_flag_t flag) const {
return !! (this->flags & flag);
}
bool job_t::get_flag(job_flag_t flag) const { return !!(this->flags & flag); }
int job_signal(job_t *j, int signal) {
pid_t my_pid = getpid();
@ -368,9 +366,7 @@ process_t::process_t()
job_t::job_t(job_id_t jobid, const io_chain_t &bio)
: block_io(bio), pgid(0), tmodes(), job_id(jobid), flags(0) {}
job_t::~job_t() {
release_job_id(job_id);
}
job_t::~job_t() { release_job_id(job_id); }
/// Return all the IO redirections. Start with the block IO, then walk over the processes.
io_chain_t job_t::all_io_redirections() const {
@ -798,17 +794,18 @@ static bool terminal_give_to_job(job_t *j, int cont) {
}
if (cont) {
int result = -1;
errno = EINTR;
while (result == -1 && errno == EINTR) {
result = tcsetattr(STDIN_FILENO, TCSADRAIN, &j->tmodes);
}
if (result == -1) {
if (errno == ENOTTY) redirect_tty_output();
debug(1, _(L"terminal_give_to_job(): Could not send job %d ('%ls') to foreground"), j->job_id, j->command_wcstr());
wperror(L"tcsetattr");
return false;
}
int result = -1;
errno = EINTR;
while (result == -1 && errno == EINTR) {
result = tcsetattr(STDIN_FILENO, TCSADRAIN, &j->tmodes);
}
if (result == -1) {
if (errno == ENOTTY) redirect_tty_output();
debug(1, _(L"terminal_give_to_job(): Could not send job %d ('%ls') to foreground"),
j->job_id, j->command_wcstr());
wperror(L"tcsetattr");
return false;
}
}
return true;
@ -985,7 +982,6 @@ void proc_sanity_check() {
while (const job_t *j = jobs.next()) {
if (!j->get_flag(JOB_CONSTRUCTED)) continue;
// More than one foreground job?
if (j->get_flag(JOB_FOREGROUND) && !(job_is_stopped(j) || job_is_completed(j))) {
if (fg_job) {
@ -1013,7 +1009,6 @@ void proc_sanity_check() {
j->command_wcstr(), p->argv0(), p->completed);
sanity_lose();
}
}
}
}

View file

@ -37,8 +37,8 @@
#include <wctype.h>
#include <algorithm>
#include <stack>
#include <memory>
#include <stack>
#include "color.h"
#include "common.h"
@ -1118,8 +1118,8 @@ struct autosuggestion_result_t {
// Returns a function that can be invoked (potentially
// on a background thread) to determine the autosuggestion
static std::function<autosuggestion_result_t(void)>
get_autosuggestion_performer(const wcstring &search_string, size_t cursor_pos, history_t *history) {
static std::function<autosuggestion_result_t(void)> get_autosuggestion_performer(
const wcstring &search_string, size_t cursor_pos, history_t *history) {
const unsigned int generation_count = s_generation_count;
const wcstring working_directory(env_get_pwd_slash());
env_vars_snapshot_t vars(env_vars_snapshot_t::highlighting_keys);
@ -1135,8 +1135,8 @@ get_autosuggestion_performer(const wcstring &search_string, size_t cursor_pos, h
return nothing;
}
VOMIT_ON_FAILURE(pthread_setspecific(generation_count_key,
(void *)(uintptr_t)generation_count));
VOMIT_ON_FAILURE(
pthread_setspecific(generation_count_key, (void *)(uintptr_t)generation_count));
// Let's make sure we aren't using the empty string.
if (search_string.empty()) {
@ -1176,9 +1176,8 @@ get_autosuggestion_performer(const wcstring &search_string, size_t cursor_pos, h
if (!completions.empty()) {
const completion_t &comp = completions.at(0);
size_t cursor = cursor_pos;
wcstring suggestion = completion_apply_to_command_line(comp.completion, comp.flags,
search_string, &cursor,
true /* append only */);
wcstring suggestion = completion_apply_to_command_line(
comp.completion, comp.flags, search_string, &cursor, true /* append only */);
return {std::move(suggestion), search_string};
}
@ -1197,8 +1196,7 @@ static bool can_autosuggest(void) {
// Called after an autosuggestion has been computed on a background thread
static void autosuggest_completed(autosuggestion_result_t result) {
if (! result.suggestion.empty() &&
can_autosuggest() &&
if (!result.suggestion.empty() && can_autosuggest() &&
result.search_string == data->command_line.text &&
string_prefixes_string_case_insensitive(result.search_string, result.suggestion)) {
// Autosuggestion is active and the search term has not changed, so we're good to go.
@ -2104,7 +2102,8 @@ static void highlight_complete(highlight_result_t result) {
// Given text, bracket matching position, and whether IO is allowed,
// return a function that performs highlighting. The function may be invoked on a background thread.
static std::function<highlight_result_t(void)> get_highlight_performer(const wcstring &text,
long match_highlight_pos, bool no_io) {
long match_highlight_pos,
bool no_io) {
env_vars_snapshot_t vars(env_vars_snapshot_t::highlighting_keys);
unsigned int generation_count = s_generation_count;
highlight_function_t highlight_func = no_io ? highlight_shell_no_io : data->highlight_function;
@ -2116,7 +2115,8 @@ static std::function<highlight_result_t(void)> get_highlight_performer(const wcs
if (text.empty()) {
return {};
}
VOMIT_ON_FAILURE(pthread_setspecific(generation_count_key, (void *)(uintptr_t)generation_count));
VOMIT_ON_FAILURE(
pthread_setspecific(generation_count_key, (void *)(uintptr_t)generation_count));
std::vector<highlight_spec_t> colors(text.size(), 0);
highlight_func(text, colors, match_highlight_pos, NULL /* error */, vars);
return {std::move(colors), text};