mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
clang-format C++ files
This commit is contained in:
parent
3d9c0d3c69
commit
9f7972a08b
10 changed files with 76 additions and 69 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "config.h" // IWYU pragma: keep
|
||||
|
||||
#include "builtin_read.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -403,16 +404,14 @@ static int validate_read_args(const wchar_t *cmd, read_cmd_opts_t &opts, int arg
|
|||
}
|
||||
|
||||
if (opts.tokenize && opts.have_delimiter) {
|
||||
streams.err.append_format(
|
||||
BUILTIN_ERR_COMBO2, cmd,
|
||||
L"--delimiter and --tokenize can not be used together");
|
||||
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd,
|
||||
L"--delimiter and --tokenize can not be used together");
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (opts.tokenize && opts.one_line) {
|
||||
streams.err.append_format(
|
||||
BUILTIN_ERR_COMBO2, cmd,
|
||||
L"--line and --tokenize can not be used together");
|
||||
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd,
|
||||
L"--line and --tokenize can not be used together");
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
|
|
|
@ -483,7 +483,8 @@ static int builtin_set_list(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
|
|||
if (!names_only) {
|
||||
wcstring val;
|
||||
if (opts.shorten_ok && key == L"history") {
|
||||
history_t *history = &history_t::history_with_name(history_session_id(env_stack_t::principal()));
|
||||
history_t *history =
|
||||
&history_t::history_with_name(history_session_id(env_stack_t::principal()));
|
||||
for (size_t i = 1; i < history->size() && val.size() < 64; i++) {
|
||||
if (i > 1) val += L' ';
|
||||
val += expand_escape_string(history->item_at_index(i).str());
|
||||
|
|
|
@ -39,9 +39,9 @@
|
|||
#include "history.h"
|
||||
#include "iothread.h"
|
||||
#include "parse_constants.h"
|
||||
#include "parser_keywords.h"
|
||||
#include "parse_util.h"
|
||||
#include "parser.h"
|
||||
#include "parser_keywords.h"
|
||||
#include "path.h"
|
||||
#include "proc.h"
|
||||
#include "reader.h"
|
||||
|
@ -1193,9 +1193,11 @@ bool completer_t::complete_variable(const wcstring &str, size_t start_offset) {
|
|||
wcstring desc;
|
||||
if (this->wants_descriptions()) {
|
||||
if (this->type() != COMPLETE_AUTOSUGGEST) {
|
||||
// $history can be huge, don't put all of it in the completion description; see #6288.
|
||||
// $history can be huge, don't put all of it in the completion description; see
|
||||
// #6288.
|
||||
if (env_name == L"history") {
|
||||
history_t *history = &history_t::history_with_name(history_session_id(env_stack_t::principal()));
|
||||
history_t *history =
|
||||
&history_t::history_with_name(history_session_id(env_stack_t::principal()));
|
||||
for (size_t i = 1; i < history->size() && desc.size() < 64; i++) {
|
||||
if (i > 1) desc += L' ';
|
||||
desc += expand_escape_string(history->item_at_index(i).str());
|
||||
|
|
1
src/io.h
1
src/io.h
|
@ -457,5 +457,4 @@ struct io_streams_t {
|
|||
explicit io_streams_t(size_t read_limit) : out(read_limit), err(read_limit), stdin_fd(-1) {}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1356,7 +1356,8 @@ eval_result_t parse_execution_context_t::run_job_conjunction(
|
|||
if (continuation) {
|
||||
// Check the conjunction type.
|
||||
parse_job_decoration_t conj = bool_statement_type(continuation);
|
||||
assert((conj == parse_job_decoration_and || conj == parse_job_decoration_or) && "Unexpected conjunction");
|
||||
assert((conj == parse_job_decoration_and || conj == parse_job_decoration_or) &&
|
||||
"Unexpected conjunction");
|
||||
skip = should_skip(conj);
|
||||
}
|
||||
if (!skip) {
|
||||
|
|
|
@ -16,9 +16,8 @@ static const wcstring skip_keywords[]{
|
|||
L"begin",
|
||||
};
|
||||
|
||||
static const wcstring subcommand_keywords[]{L"command", L"builtin", L"while", L"exec",
|
||||
L"if", L"and", L"or", L"not",
|
||||
L"time", L"begin"};
|
||||
static const wcstring subcommand_keywords[]{L"command", L"builtin", L"while", L"exec", L"if",
|
||||
L"and", L"or", L"not", L"time", L"begin"};
|
||||
|
||||
static const string_set_t block_keywords = {L"for", L"while", L"if",
|
||||
L"function", L"switch", L"begin"};
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
// Functions for executing the time builtin.
|
||||
#include "config.h" // IWYU pragma: keep
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <ctime>
|
||||
|
||||
#include "common.h"
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
#include "exec.h"
|
||||
#include "fallback.h" // IWYU pragma: keep
|
||||
#include "io.h"
|
||||
#include "parser.h"
|
||||
#include "proc.h"
|
||||
#include "timer.h"
|
||||
#include "wgetopt.h"
|
||||
#include "wutil.h" // IWYU pragma: keep
|
||||
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
|
||||
// Measuring time is always complicated with many caveats. Quite apart from the typical
|
||||
// gotchas faced by developers attempting to choose between monotonic vs non-monotonic and system vs
|
||||
// cpu clocks, the fact that we are executing as a shell further complicates matters: we can't just
|
||||
|
@ -60,7 +61,6 @@ static int64_t micros(const std::chrono::duration<D1, D2> &d) {
|
|||
return std::chrono::duration_cast<std::chrono::microseconds>(d).count();
|
||||
};
|
||||
|
||||
|
||||
timer_snapshot_t timer_snapshot_t::take() {
|
||||
timer_snapshot_t snapshot;
|
||||
|
||||
|
@ -71,8 +71,8 @@ timer_snapshot_t timer_snapshot_t::take() {
|
|||
return snapshot;
|
||||
}
|
||||
|
||||
wcstring
|
||||
timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool verbose /* = true */) {
|
||||
wcstring timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2,
|
||||
bool verbose /* = true */) {
|
||||
int64_t fish_sys_micros = micros(t2.cpu_fish.ru_stime) - micros(t1.cpu_fish.ru_stime);
|
||||
int64_t fish_usr_micros = micros(t2.cpu_fish.ru_utime) - micros(t1.cpu_fish.ru_utime);
|
||||
int64_t child_sys_micros = micros(t2.cpu_children.ru_stime) - micros(t1.cpu_children.ru_stime);
|
||||
|
@ -112,10 +112,14 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver
|
|||
|
||||
auto unit_name = [](tunit unit) {
|
||||
switch (unit) {
|
||||
case tunit::minutes: return "minutes";
|
||||
case tunit::seconds: return "seconds";
|
||||
case tunit::milliseconds: return "milliseconds";
|
||||
case tunit::microseconds: return "microseconds";
|
||||
case tunit::minutes:
|
||||
return "minutes";
|
||||
case tunit::seconds:
|
||||
return "seconds";
|
||||
case tunit::milliseconds:
|
||||
return "milliseconds";
|
||||
case tunit::microseconds:
|
||||
return "microseconds";
|
||||
}
|
||||
// GCC does not recognize the exhaustive switch above
|
||||
return "";
|
||||
|
@ -123,10 +127,14 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver
|
|||
|
||||
auto unit_short_name = [](tunit unit) {
|
||||
switch (unit) {
|
||||
case tunit::minutes: return "mins";
|
||||
case tunit::seconds: return "secs";
|
||||
case tunit::milliseconds: return "millis";
|
||||
case tunit::microseconds: return "micros";
|
||||
case tunit::minutes:
|
||||
return "mins";
|
||||
case tunit::seconds:
|
||||
return "secs";
|
||||
case tunit::milliseconds:
|
||||
return "millis";
|
||||
case tunit::microseconds:
|
||||
return "micros";
|
||||
}
|
||||
// GCC does not recognize the exhaustive switch above
|
||||
return "";
|
||||
|
@ -134,10 +142,14 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver
|
|||
|
||||
auto convert = [](int64_t micros, tunit unit) {
|
||||
switch (unit) {
|
||||
case tunit::minutes: return micros / 1.0E6 / 60.0;
|
||||
case tunit::seconds: return micros / 1.0E6;
|
||||
case tunit::milliseconds: return micros / 1.0E3;
|
||||
case tunit::microseconds: return micros / 1.0;
|
||||
case tunit::minutes:
|
||||
return micros / 1.0E6 / 60.0;
|
||||
case tunit::seconds:
|
||||
return micros / 1.0E6;
|
||||
case tunit::milliseconds:
|
||||
return micros / 1.0E3;
|
||||
case tunit::microseconds:
|
||||
return micros / 1.0;
|
||||
}
|
||||
// GCC does not recognize the exhaustive switch above
|
||||
return 0.0;
|
||||
|
@ -152,15 +164,13 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver
|
|||
wcstring output;
|
||||
if (!verbose) {
|
||||
append_format(output,
|
||||
L"\n_______________________________" \
|
||||
L"\nExecuted in %6.2F %s" \
|
||||
L"\n usr time %6.2F %s" \
|
||||
L"\n sys time %6.2F %s" \
|
||||
L"\n",
|
||||
wall_time, unit_name(wall_unit),
|
||||
usr_time, unit_name(cpu_unit),
|
||||
sys_time, unit_name(cpu_unit)
|
||||
);
|
||||
L"\n_______________________________"
|
||||
L"\nExecuted in %6.2F %s"
|
||||
L"\n usr time %6.2F %s"
|
||||
L"\n sys time %6.2F %s"
|
||||
L"\n",
|
||||
wall_time, unit_name(wall_unit), usr_time, unit_name(cpu_unit), sys_time,
|
||||
unit_name(cpu_unit));
|
||||
} else {
|
||||
auto fish_unit = get_unit((fish_sys_micros + fish_usr_micros) / 2);
|
||||
auto child_unit = get_unit((child_sys_micros + child_usr_micros) / 2);
|
||||
|
@ -170,22 +180,17 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver
|
|||
auto child_sys_time = convert(child_sys_micros, child_unit);
|
||||
|
||||
append_format(output,
|
||||
L"\n________________________________________________________" \
|
||||
L"\nExecuted in %6.2F %s %*s %*s " \
|
||||
L"\n usr time %6.2F %s %6.2F %s %6.2F %s " \
|
||||
L"\n sys time %6.2F %s %6.2F %s %6.2F %s " \
|
||||
L"\n",
|
||||
wall_time, unit_short_name(wall_unit),
|
||||
strlen(unit_short_name(wall_unit)) - 1, "fish",
|
||||
strlen(unit_short_name(fish_unit)) - 1, "external",
|
||||
usr_time, unit_short_name(cpu_unit),
|
||||
fish_usr_time, unit_short_name(fish_unit),
|
||||
child_usr_time, unit_short_name(child_unit),
|
||||
sys_time, unit_short_name(cpu_unit),
|
||||
fish_sys_time, unit_short_name(fish_unit),
|
||||
child_sys_time, unit_short_name(child_unit)
|
||||
);
|
||||
|
||||
L"\n________________________________________________________"
|
||||
L"\nExecuted in %6.2F %s %*s %*s "
|
||||
L"\n usr time %6.2F %s %6.2F %s %6.2F %s "
|
||||
L"\n sys time %6.2F %s %6.2F %s %6.2F %s "
|
||||
L"\n",
|
||||
wall_time, unit_short_name(wall_unit), strlen(unit_short_name(wall_unit)) - 1,
|
||||
"fish", strlen(unit_short_name(fish_unit)) - 1, "external", usr_time,
|
||||
unit_short_name(cpu_unit), fish_usr_time, unit_short_name(fish_unit),
|
||||
child_usr_time, unit_short_name(child_unit), sys_time,
|
||||
unit_short_name(cpu_unit), fish_sys_time, unit_short_name(fish_unit),
|
||||
child_sys_time, unit_short_name(child_unit));
|
||||
}
|
||||
|
||||
return output;
|
||||
|
|
11
src/timer.h
11
src/timer.h
|
@ -2,10 +2,11 @@
|
|||
#ifndef FISH_TIMER_H
|
||||
#define FISH_TIMER_H
|
||||
|
||||
#include <chrono>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
@ -13,7 +14,7 @@ class parser_t;
|
|||
struct io_streams_t;
|
||||
|
||||
struct timer_snapshot_t {
|
||||
public:
|
||||
public:
|
||||
struct rusage cpu_fish;
|
||||
struct rusage cpu_children;
|
||||
std::chrono::time_point<std::chrono::steady_clock> wall;
|
||||
|
@ -21,7 +22,7 @@ public:
|
|||
static timer_snapshot_t take();
|
||||
static wcstring print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool verbose = false);
|
||||
|
||||
private:
|
||||
private:
|
||||
timer_snapshot_t() {}
|
||||
};
|
||||
|
||||
|
|
|
@ -235,8 +235,7 @@ parse_statement_decoration_t get_decoration(tnode_t<grammar::plain_statement> st
|
|||
/// Return the type for a boolean statement.
|
||||
parse_job_decoration_t bool_statement_type(tnode_t<grammar::job_decorator> stmt);
|
||||
|
||||
parse_job_decoration_t bool_statement_type(
|
||||
tnode_t<grammar::job_conjunction_continuation> cont);
|
||||
parse_job_decoration_t bool_statement_type(tnode_t<grammar::job_conjunction_continuation> cont);
|
||||
|
||||
/// Given a redirection node, get the parsed redirection and target of the redirection (file path,
|
||||
/// or fd).
|
||||
|
|
|
@ -155,7 +155,8 @@ generation_list_t topic_monitor_t::await_gens(const generation_list_t &input_gen
|
|||
#endif
|
||||
uint8_t ignored[PIPE_BUF];
|
||||
auto unused = read(fd, ignored, sizeof ignored);
|
||||
if (unused) {}
|
||||
if (unused) {
|
||||
}
|
||||
|
||||
// We are finished reading. We must stop being the reader, and post on the condition
|
||||
// variable to wake up any other threads waiting for us to finish reading.
|
||||
|
|
Loading…
Reference in a new issue