Reformat all files

This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
This commit is contained in:
Fabian Homborg 2019-05-05 12:09:25 +02:00
parent 90d64194c5
commit c2970f9618
137 changed files with 2885 additions and 2350 deletions

View file

@ -8,7 +8,8 @@ function __fish_describe_command -d "Command used to find descriptions for comma
# TODO: stop interpolating argv into regex, and remove this hack.
string match --quiet --regex '^[a-zA-Z0-9_ ]+$' -- "$argv"
or return
type -q apropos; or return
type -q apropos
or return
apropos $argv 2>/dev/null | awk -v FS=" +- +" '{
split($1, names, ", ");
for (name in names)

View file

@ -73,18 +73,23 @@ function __fish_print_help --description "Print help message for the specified f
# Remove man's bolding
set -l name (string replace -ra '(.)'\b'.' '$1' -- $line)
# We start after we have the name
contains -- $name NAME; and set have_name 1; and continue
contains -- $name NAME
and set have_name 1
and continue
# We ignore the SYNOPSIS header
contains -- $name SYNOPSIS; and continue
contains -- $name SYNOPSIS
and continue
# Everything after COPYRIGHT is useless
contains -- $name COPYRIGHT; and break
contains -- $name COPYRIGHT
and break
# not leading space, and not empty, so must contain a non-space
# in the first column. That makes it a header/footer.
set line_type meta
end
set -q have_name[1]; or continue
set -q have_name[1]
or continue
switch $state
case normal
switch $line_type

View file

@ -1,7 +1,8 @@
# Use --installed to limit to installed packages only
function __fish_print_packages
argparse --name=__fish_print_packages 'i/installed' -- $argv
or return;
or return
set -l only_installed 1
if not set -q _flag_installed

View file

@ -16,7 +16,7 @@ set -g fish_prompt_git_status_renamed '➜'
set -g fish_prompt_git_status_copied '⇒'
set -g fish_prompt_git_status_deleted '✖'
set -g fish_prompt_git_status_untracked '?'
set -g fish_prompt_git_status_unmerged '!'
set -g fish_prompt_git_status_unmerged !
set -g fish_prompt_git_status_order added modified renamed copied deleted untracked unmerged

View file

@ -33,23 +33,30 @@ function _fish_systemctl --description 'Call systemctl with some options from th
help reset-failed list-dependencies list-units revert add-{wants,requires} edit
case enable
# This will only work for "list-unit-files", but won't print an error for "list-units".
set -q _flag_state; or set _flag_state disabled
set -q _flag_state
or set _flag_state disabled
case disable
set -q _flag_state; or set _flag_state enabled
set -q _flag_state
or set _flag_state enabled
case start
# Running `start` on an already started unit isn't an _error_, but useless.
set -q _flag_state; or set _flag_state dead,failed
set -q _flag_state
or set _flag_state dead,failed
case mask
set -q _flag_state; or set _flag_state loaded
set -q _flag_state
or set _flag_state loaded
case unmask
set -q _flag_state; or set _flag_state masked
set -q _flag_state
or set _flag_state masked
case stop kill
# TODO: Is "kill" useful on other unit types?
# Running as the catch-all, "mounted" for .mount units, "active" for .target.
set -q _flag_state; or set _flag_state running,mounted,active
set -q _flag_state
or set _flag_state running,mounted,active
case isolate set-default
# These only take one unit.
set -q argv[1]; and return
set -q argv[1]
and return
case list-sockets
set _flag_type socket
case list-timers
@ -65,11 +72,16 @@ function _fish_systemctl --description 'Call systemctl with some options from th
end
# Add the flags back so we can pass them to our systemctl invocations.
set -q _flag_type; and set passflags $passflags --type=$_flag_type
set -q _flag_state; and set passflags $passflags --state=$_flag_state
set -q _flag_property; and set passflags $passflags --property=$_flag_property
set -q _flag_machine; and set passflags $passflags --machine=$_flag_machine
set -q _flag_host; and set passflags $passflags --host=$_flag_host
set -q _flag_type
and set passflags $passflags --type=$_flag_type
set -q _flag_state
and set passflags $passflags --state=$_flag_state
set -q _flag_property
and set passflags $passflags --property=$_flag_property
set -q _flag_machine
and set passflags $passflags --machine=$_flag_machine
set -q _flag_host
and set passflags $passflags --host=$_flag_host
# Output looks like
# systemd-tmpfiles-clean.timer [more whitespace] loaded active waiting Daily Cleanup[...]

View file

@ -53,12 +53,14 @@ function abbr --description "Manage abbreviations"
else if set -q _flag_query[1]
# "--query": Check if abbrs exist.
# If we don't have an argument, it's an automatic failure.
set -q argv[1]; or return 1
set -q argv[1]
or return 1
set -l escaped _fish_abbr_(string escape --style=var -- $argv)
# We return 0 if any arg exists, whereas `set -q` returns the number of undefined arguments.
# But we should be consistent with `type -q` and `command -q`.
for var in $escaped
set -q $escaped; and return 0
set -q $escaped
and return 0
end
return 1
else

View file

@ -1,7 +1,8 @@
function fish_clipboard_copy
# Copy the current selection, or the entire commandline if that is empty.
set -l cmdline (commandline --current-selection)
test -n "$cmdline"; or set cmdline (commandline)
test -n "$cmdline"
or set cmdline (commandline)
if type -q pbcopy
printf '%s\n' $cmdline | pbcopy
else if type -q xsel

View file

@ -454,7 +454,8 @@ function fish_git_prompt --description "Prompt function for Git"
set b (string replace refs/heads/ '' -- $b)
set -q __fish_git_prompt_shorten_branch_char_suffix
or set -l __fish_git_prompt_shorten_branch_char_suffix "…"
if string match -qr '^\d+$' "$__fish_git_prompt_shorten_branch_len"; and test (string length "$b") -gt $__fish_git_prompt_shorten_branch_len
if string match -qr '^\d+$' "$__fish_git_prompt_shorten_branch_len"
and test (string length "$b") -gt $__fish_git_prompt_shorten_branch_len
set b (string sub -l "$__fish_git_prompt_shorten_branch_len" "$b")"$__fish_git_prompt_shorten_branch_char_suffix"
end
if test -n "$b"
@ -548,7 +549,8 @@ function __fish_git_prompt_informative_status
set -l untrackedfiles (command git ls-files --others --exclude-standard | count)
set -l stashstate 0
set -l stashfile "$argv[1]/logs/refs/stash"
if set -q __fish_git_prompt_showstashstate; and test -e "$stashfile"
if set -q __fish_git_prompt_showstashstate
and test -e "$stashfile"
set stashstate (count < $stashfile)
end

View file

@ -16,7 +16,7 @@ set -g fish_prompt_hg_status_modified '*'
set -g fish_prompt_hg_status_copied '⇒'
set -g fish_prompt_hg_status_deleted '✖'
set -g fish_prompt_hg_status_untracked '?'
set -g fish_prompt_hg_status_unmerged '!'
set -g fish_prompt_hg_status_unmerged !
set -g fish_prompt_hg_status_order added modified copied deleted untracked unmerged

View file

@ -37,7 +37,7 @@ set -g __fish_svn_prompt_char_unversioned_external_color --underline cyan
set -g __fish_svn_prompt_char_unversioned_display '?'
set -g __fish_svn_prompt_char_unversioned_color purple
set -g __fish_svn_prompt_char_missing_display '!'
set -g __fish_svn_prompt_char_missing_display !
set -g __fish_svn_prompt_char_missing_color yellow
set -g __fish_svn_prompt_char_versioned_obstructed_display '~'

View file

@ -69,7 +69,8 @@ function help --description 'Show help for the fish shell'
set fish_browser cygstart
# If xdg-open is available, just use that
# but only if an X session is running
else if type -q xdg-open; and set -q -x DISPLAY
else if type -q xdg-open
and set -q -x DISPLAY
set fish_browser xdg-open
end

View file

@ -61,7 +61,8 @@ function type --description 'Print the type of a command'
switch $func_path
case "n/a"
case "stdin"
break;
break
case "*"
echo $func_path
end

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -13,21 +13,25 @@ from sphinx.errors import SphinxError, SphinxWarning
# -- Helper functions --------------------------------------------------------
def strip_ext(path):
""" Remove the extension from a path. """
return os.path.splitext(path)[0]
# -- Load our Pygments lexer -------------------------------------------------
def setup(app):
from sphinx.highlighting import lexers
this_dir = os.path.dirname(os.path.realpath(__file__))
fish_indent_lexer = pygments.lexers.load_lexer_from_file(
os.path.join(this_dir, 'fish_indent_lexer.py'),
lexername='FishIndentLexer')
lexers['fish-docs-samples'] = fish_indent_lexer
os.path.join(this_dir, "fish_indent_lexer.py"), lexername="FishIndentLexer"
)
lexers["fish-docs-samples"] = fish_indent_lexer
# The default language to assume
highlight_language = 'fish-docs-samples'
highlight_language = "fish-docs-samples"
# -- Path setup --------------------------------------------------------------
@ -42,14 +46,14 @@ highlight_language = 'fish-docs-samples'
# -- Project information -----------------------------------------------------
project = 'fish-shell'
copyright = '2019, fish-shell developers'
author = 'fish-shell developers'
project = "fish-shell"
copyright = "2019, fish-shell developers"
author = "fish-shell developers"
# The short X.Y version
version = '3.1'
version = "3.1"
# The full version, including alpha/beta/rc tags
release = '3.1.0'
release = "3.1.0"
# -- General configuration ---------------------------------------------------
@ -61,20 +65,19 @@ release = '3.1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"
# The master toctree document.
master_doc = 'index'
master_doc = "index"
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -98,7 +101,7 @@ pygments_style = None
# a list of builtin themes.
# !!! If you change this you also need to update the @import at the top
# of _static/fish-syntax-style.css
html_theme = 'nature'
html_theme = "nature"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@ -109,7 +112,7 @@ html_theme = 'nature'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
@ -119,13 +122,13 @@ html_static_path = ['_static']
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
html_sidebars = { '**': ['globaltoc.html', 'localtoc.html', 'searchbox.html'] }
html_sidebars = {"**": ["globaltoc.html", "localtoc.html", "searchbox.html"]}
# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'fish-shelldoc'
htmlhelp_basename = "fish-shelldoc"
# -- Options for LaTeX output ------------------------------------------------
@ -134,15 +137,12 @@ latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
@ -152,34 +152,36 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'fish-shell.tex', 'fish-shell Documentation',
'fish-shell developers', 'manual'),
(
master_doc,
"fish-shell.tex",
"fish-shell Documentation",
"fish-shell developers",
"manual",
)
]
# -- Options for manual page output ------------------------------------------
def get_command_description(path, name):
""" Return the description for a command, by parsing its synopsis line """
with open(path) as fd:
for line in fd:
if line.startswith(name + " - "):
_, desc = line.split(' - ', 1)
_, desc = line.split(" - ", 1)
return desc.strip()
raise SphinxWarning('No description in file %s' % os.path.basename(path))
raise SphinxWarning("No description in file %s" % os.path.basename(path))
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'fish', 'fish-shell Documentation',
[author], 1)
]
for path in sorted(glob.glob('cmds/*')):
man_pages = [(master_doc, "fish", "fish-shell Documentation", [author], 1)]
for path in sorted(glob.glob("cmds/*")):
docname = strip_ext(path)
cmd = os.path.basename(docname)
man_pages.append((docname, cmd, get_command_description(path, cmd), '', 1))
man_pages.append((docname, cmd, get_command_description(path, cmd), "", 1))
# -- Options for Texinfo output ----------------------------------------------
@ -188,9 +190,15 @@ for path in sorted(glob.glob('cmds/*')):
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'fish-shell', 'fish-shell Documentation',
author, 'fish-shell', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"fish-shell",
"fish-shell Documentation",
author,
"fish-shell",
"One line description of project.",
"Miscellaneous",
)
]
@ -209,7 +217,7 @@ epub_title = project
# epub_uid = ''
# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]
# Disable smart-quotes to prevent double dashes from becoming emdashes.
smartquotes = False

View file

@ -91,9 +91,9 @@ def tokenize_fish_command(code, offset):
stdout=subprocess.PIPE,
universal_newlines=False,
)
stdout, _ = proc.communicate(code.encode('utf-8'))
stdout, _ = proc.communicate(code.encode("utf-8"))
result = []
for line in stdout.decode('utf-8').splitlines():
for line in stdout.decode("utf-8").splitlines():
start, end, role = line.split(",")
start, end = int(start), int(end)
value = code[start:end]

View file

@ -19,8 +19,8 @@
#include <errno.h>
#include <stdlib.h>
#include <cstring>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <algorithm>

View file

@ -59,14 +59,11 @@ struct argparse_cmd_opts_t {
};
static const wchar_t *const short_options = L"+:hn:six:N:X:";
static const struct woption long_options[] = {{L"stop-nonopt", no_argument, NULL, 's'},
{L"ignore-unknown", no_argument, NULL, 'i'},
{L"name", required_argument, NULL, 'n'},
{L"exclusive", required_argument, NULL, 'x'},
{L"help", no_argument, NULL, 'h'},
{L"min-args", required_argument, NULL, 'N'},
{L"max-args", required_argument, NULL, 'X'},
{NULL, 0, NULL, 0}};
static const struct woption long_options[] = {
{L"stop-nonopt", no_argument, NULL, 's'}, {L"ignore-unknown", no_argument, NULL, 'i'},
{L"name", required_argument, NULL, 'n'}, {L"exclusive", required_argument, NULL, 'x'},
{L"help", no_argument, NULL, 'h'}, {L"min-args", required_argument, NULL, 'N'},
{L"max-args", required_argument, NULL, 'X'}, {NULL, 0, NULL, 0}};
// Check if any pair of mutually exclusive options was seen. Note that since every option must have
// a short name we only need to check those.
@ -584,12 +581,12 @@ static int argparse_parse_flags(parser_t &parser, argparse_cmd_opts_t &opts,
// A non-option argument.
// We use `-` as the first option-string-char to disable GNU getopt's reordering,
// otherwise we'd get ignored options first and normal arguments later.
// E.g. `argparse -i -- -t tango -w` needs to keep `-t tango -w` in $argv, not `-t -w tango`.
// E.g. `argparse -i -- -t tango -w` needs to keep `-t tango -w` in $argv, not `-t -w
// tango`.
opts.argv.push_back(argv[w.woptind - 1]);
continue;
}
// It's a recognized flag.
auto found = opts.options.find(opt);
assert(found != opts.options.end());
@ -610,7 +607,8 @@ static int argparse_parse_args(argparse_cmd_opts_t &opts, const wcstring_list_t
parser_t &parser, io_streams_t &streams) {
if (args.empty()) return STATUS_CMD_OK;
// "+" means stop at nonopt, "-" means give nonoptions the option character code `1`, and don't reorder.
// "+" means stop at nonopt, "-" means give nonoptions the option character code `1`, and don't
// reorder.
wcstring short_options = opts.stop_nonopt ? L"+:" : L"-";
std::vector<woption> long_options;
populate_option_strings(opts, &short_options, &long_options);

View file

@ -102,8 +102,8 @@ bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bo
// Overload with both kinds of bindings.
// Returns false only if neither exists.
bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset,
io_streams_t &streams) {
bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bool user,
bool preset, io_streams_t &streams) {
bool retval = false;
if (preset) {
retval |= list_one(seq, bind_mode, false, streams);
@ -151,7 +151,8 @@ void builtin_bind_t::function_names(io_streams_t &streams) {
}
/// Wraps input_terminfo_get_sequence(), appending the correct error messages as needed.
bool builtin_bind_t::get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq, io_streams_t &streams) {
bool builtin_bind_t::get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq,
io_streams_t &streams) {
if (input_terminfo_get_sequence(seq, out_seq)) {
return true;
}
@ -159,7 +160,8 @@ bool builtin_bind_t::get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq
wcstring eseq = escape_string(seq, 0);
if (!opts->silent) {
if (errno == ENOENT) {
streams.err.append_format(_(L"%ls: No key with name '%ls' found\n"), L"bind", eseq.c_str());
streams.err.append_format(_(L"%ls: No key with name '%ls' found\n"), L"bind",
eseq.c_str());
} else if (errno == EILSEQ) {
streams.err.append_format(_(L"%ls: Key with name '%ls' does not have any mapping\n"),
L"bind", eseq.c_str());
@ -202,8 +204,8 @@ bool builtin_bind_t::add(const wchar_t *seq, const wchar_t *const *cmds, size_t
/// @param use_terminfo
/// Whether to look use terminfo -k name
///
bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo, bool user,
io_streams_t &streams) {
bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo,
bool user, io_streams_t &streams) {
if (all) {
input_mapping_clear(mode, user);
return false;
@ -228,8 +230,7 @@ bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool us
return res;
}
bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv,
io_streams_t &streams) {
bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int arg_count = argc - optind;
@ -242,7 +243,8 @@ bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv,
} else {
// Inserting both on the other hand makes no sense.
if (opts->have_preset && opts->have_user) {
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd,
streams.err.append_format(
BUILTIN_ERR_COMBO2, cmd,
L"--preset and --user can not be used together when inserting bindings.");
return true;
}

View file

@ -13,23 +13,23 @@ struct bind_cmd_opts_t;
class builtin_bind_t {
public:
int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv);
private:
bind_cmd_opts_t *opts;
void list(const wchar_t *bind_mode, bool user, io_streams_t &streams);
void key_names(bool all, io_streams_t &streams);
void function_names(io_streams_t &streams);
bool add(const wchar_t *seq, const wchar_t *const *cmds, size_t cmds_len,
const wchar_t *mode, const wchar_t *sets_mode, bool terminfo, bool user,
io_streams_t &streams);
bool add(const wchar_t *seq, const wchar_t *const *cmds, size_t cmds_len, const wchar_t *mode,
const wchar_t *sets_mode, bool terminfo, bool user, io_streams_t &streams);
bool erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo, bool user,
io_streams_t &streams);
bool get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq, io_streams_t &streams);
bool insert(int optind, int argc, wchar_t **argv,
io_streams_t &streams);
bool insert(int optind, int argc, wchar_t **argv, io_streams_t &streams);
void list_modes(io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset, io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset,
io_streams_t &streams);
};
inline int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) {

View file

@ -20,8 +20,8 @@ struct builtin_cmd_opts_t {
bool query = false;
};
static const wchar_t *const short_options = L":hnq";
static const struct woption long_options[] = {
{L"help", no_argument, NULL, 'h'}, {L"names", no_argument, NULL, 'n'},
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{L"names", no_argument, NULL, 'n'},
{L"query", no_argument, NULL, 'q'},
{NULL, 0, NULL, 0}};

View file

@ -2,8 +2,8 @@
#ifndef FISH_BUILTIN_COMMANDLINE_H
#define FISH_BUILTIN_COMMANDLINE_H
#include <cwchar>
#include <cstring>
#include <cwchar>
class parser_t;

View file

@ -263,7 +263,6 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Use one left-over arg as the do-complete argument
// to enable `complete -C "git check"`.
if (do_complete && !have_do_complete_param && argc == w.woptind + 1) {
do_complete_param = argv[argc - 1];
have_do_complete_param = true;
} else {

View file

@ -89,7 +89,9 @@ static unsigned int builtin_echo_digit(wchar_t wc, unsigned int base) {
return 6;
case L'7':
return 7;
default: { break; }
default: {
break;
}
}
if (base != 16) return UINT_MAX;
@ -117,7 +119,9 @@ static unsigned int builtin_echo_digit(wchar_t wc, unsigned int base) {
case L'f':
case L'F':
return 15;
default: { break; }
default: {
break;
}
}
return UINT_MAX;

View file

@ -40,13 +40,18 @@ struct functions_cmd_opts_t {
wchar_t *description = NULL;
};
static const wchar_t *const short_options = L":HDacd:ehnqv";
static const struct woption long_options[] = {
{L"erase", no_argument, NULL, 'e'}, {L"description", required_argument, NULL, 'd'},
{L"names", no_argument, NULL, 'n'}, {L"all", no_argument, NULL, 'a'},
{L"help", no_argument, NULL, 'h'}, {L"query", no_argument, NULL, 'q'},
{L"copy", no_argument, NULL, 'c'}, {L"details", no_argument, NULL, 'D'},
{L"verbose", no_argument, NULL, 'v'}, {L"handlers", no_argument, NULL, 'H'},
{L"handlers-type", required_argument, NULL, 't'}, {NULL, 0, NULL, 0}};
static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'},
{L"description", required_argument, NULL, 'd'},
{L"names", no_argument, NULL, 'n'},
{L"all", no_argument, NULL, 'a'},
{L"help", no_argument, NULL, 'h'},
{L"query", no_argument, NULL, 'q'},
{L"copy", no_argument, NULL, 'c'},
{L"details", no_argument, NULL, 'D'},
{L"verbose", no_argument, NULL, 'v'},
{L"handlers", no_argument, NULL, 'H'},
{L"handlers-type", required_argument, NULL, 't'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
@ -328,7 +333,8 @@ int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (opts.handlers_type) {
type_filter = event_type_for_name(opts.handlers_type);
if (!type_filter) {
streams.err.append_format(_(L"%ls: Expected generic | variable | signal | exit | job-id for --handlers-type\n"),
streams.err.append_format(_(L"%ls: Expected generic | variable | signal | exit | "
L"job-id for --handlers-type\n"),
cmd);
return STATUS_INVALID_ARGS;
}

View file

@ -117,8 +117,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int print_last = 0;
static const wchar_t *const short_options = L":cghlpq";
static const struct woption long_options[] = {
{L"command", no_argument, NULL, 'c'},
static const struct woption long_options[] = {{L"command", no_argument, NULL, 'c'},
{L"group", no_argument, NULL, 'g'},
{L"help", no_argument, NULL, 'h'},
{L"last", no_argument, NULL, 'l'},
@ -189,15 +188,16 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int jobId = -1;
jobId = fish_wcstoi(argv[i] + 1);
if (errno || jobId < -1) {
streams.err.append_format(_(L"%ls: '%ls' is not a valid job id"), cmd, argv[i]);
streams.err.append_format(_(L"%ls: '%ls' is not a valid job id"), cmd,
argv[i]);
return STATUS_INVALID_ARGS;
}
j = job_t::from_job_id(jobId);
}
else {
} else {
int pid = fish_wcstoi(argv[i]);
if (errno || pid < 0) {
streams.err.append_format(_(L"%ls: '%ls' is not a valid process id\n"), cmd, argv[i]);
streams.err.append_format(_(L"%ls: '%ls' is not a valid process id\n"), cmd,
argv[i]);
return STATUS_INVALID_ARGS;
}
j = job_t::from_pid(pid);
@ -215,7 +215,8 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
for (const auto &j : jobs()) {
// Ignore unconstructed jobs, i.e. ourself.
if (j->is_visible()) {
builtin_jobs_print(j.get(), mode, !found && !streams.out_is_redirected, streams);
builtin_jobs_print(j.get(), mode, !found && !streams.out_is_redirected,
streams);
found = true;
}
}

View file

@ -54,8 +54,8 @@ static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
} else {
opts.scale = fish_wcstoi(w.woptarg);
if (errno || opts.scale < 0 || opts.scale > 15) {
streams.err.append_format(_(L"%ls: '%ls' is not a valid scale value\n"), cmd,
w.woptarg);
streams.err.append_format(_(L"%ls: '%ls' is not a valid scale value\n"),
cmd, w.woptarg);
return STATUS_INVALID_ARGS;
}
}
@ -133,15 +133,24 @@ static const wchar_t *math_describe_error(te_error_t& error) {
if (error.position == 0) return L"NO ERROR?!?";
switch (error.type) {
case TE_ERROR_NONE: DIE("Error has no position");
case TE_ERROR_UNKNOWN_VARIABLE: return _(L"Unknown variable");
case TE_ERROR_MISSING_CLOSING_PAREN: return _(L"Missing closing parenthesis");
case TE_ERROR_MISSING_OPENING_PAREN: return _(L"Missing opening parenthesis");
case TE_ERROR_TOO_FEW_ARGS: return _(L"Too few arguments");
case TE_ERROR_TOO_MANY_ARGS: return _(L"Too many arguments");
case TE_ERROR_MISSING_OPERATOR: return _(L"Missing operator");
case TE_ERROR_UNKNOWN: return _(L"Expression is bogus");
default: return L"Unknown error";
case TE_ERROR_NONE:
DIE("Error has no position");
case TE_ERROR_UNKNOWN_VARIABLE:
return _(L"Unknown variable");
case TE_ERROR_MISSING_CLOSING_PAREN:
return _(L"Missing closing parenthesis");
case TE_ERROR_MISSING_OPENING_PAREN:
return _(L"Missing opening parenthesis");
case TE_ERROR_TOO_FEW_ARGS:
return _(L"Too few arguments");
case TE_ERROR_TOO_MANY_ARGS:
return _(L"Too many arguments");
case TE_ERROR_MISSING_OPERATOR:
return _(L"Missing operator");
case TE_ERROR_UNKNOWN:
return _(L"Expression is bogus");
default:
return L"Unknown error";
}
}

View file

@ -57,10 +57,10 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <cstring>
#include <sys/types.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#include "builtin.h"
#include "common.h"
@ -93,7 +93,6 @@ struct builtin_printf_state_t {
void nonfatal_error(const wchar_t *fmt, ...);
void fatal_error(const wchar_t *format, ...);
long print_esc(const wchar_t *escstart, bool octal_0);
void print_esc_string(const wchar_t *str);
void print_esc_char(wchar_t c);
@ -161,7 +160,9 @@ static int hex_to_bin(const wchar_t &c) {
case L'F': {
return 15;
}
default: { return -1; }
default: {
return -1;
}
}
}
@ -191,7 +192,9 @@ static int octal_to_bin(wchar_t c) {
case L'7': {
return 7;
}
default: { return -1; }
default: {
return -1;
}
}
}
@ -472,7 +475,9 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
fmt.append(L"l");
break;
}
default: { break; }
default: {
break;
}
}
// Append the conversion itself.

View file

@ -6,8 +6,8 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <algorithm>
@ -55,8 +55,7 @@ struct read_cmd_opts_t {
};
static const wchar_t *const short_options = L":ac:d:ghiLlm:n:p:sSuxzP:UR:LB";
static const struct woption long_options[] = {
{L"array", no_argument, NULL, 'a'},
static const struct woption long_options[] = {{L"array", no_argument, NULL, 'a'},
{L"command", required_argument, NULL, 'c'},
{L"delimiter", required_argument, NULL, 'd'},
{L"export", no_argument, NULL, 'x'},
@ -74,8 +73,7 @@ static const struct woption long_options[] = {
{L"silent", no_argument, NULL, 's'},
{L"unexport", no_argument, NULL, 'u'},
{L"universal", no_argument, NULL, 'U'},
{NULL, 0, NULL, 0}
};
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
@ -98,7 +96,8 @@ static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
break;
}
case 'i': {
streams.err.append_format(_(L"%ls: usage of -i for --silent is deprecated. Please use -s or --silent instead.\n"),
streams.err.append_format(_(L"%ls: usage of -i for --silent is deprecated. Please "
L"use -s or --silent instead.\n"),
cmd);
return STATUS_INVALID_ARGS;
}
@ -350,17 +349,20 @@ static int read_one_char_at_a_time(int fd, wcstring &buff, int nchars, bool spli
static int validate_read_args(const wchar_t *cmd, read_cmd_opts_t &opts, int argc,
const wchar_t *const *argv, parser_t &parser, io_streams_t &streams) {
if (opts.prompt && opts.prompt_str) {
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd, L"-p", L"-P");
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd,
L"-p", L"-P");
builtin_print_error_trailer(parser, streams.err, cmd);
return STATUS_INVALID_ARGS;
}
if (opts.have_delimiter && opts.one_line) {
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd, L"--delimiter", L"--line");
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd,
L"--delimiter", L"--line");
return STATUS_INVALID_ARGS;
}
if (opts.one_line && opts.split_null) {
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd, L"-z", L"--line");
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd,
L"-z", L"--line");
return STATUS_INVALID_ARGS;
}
@ -458,13 +460,14 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
}
};
// Normally, we either consume a line of input or all available input. But if we are reading a line at
// a time, we need a middle ground where we only consume as many lines as we need to fill the given vars.
// Normally, we either consume a line of input or all available input. But if we are reading a
// line at a time, we need a middle ground where we only consume as many lines as we need to
// fill the given vars.
do {
buff.clear();
// TODO: Determine if the original set of conditions for interactive reads should be reinstated:
// if (isatty(0) && streams.stdin_fd == STDIN_FILENO && !split_null) {
// TODO: Determine if the original set of conditions for interactive reads should be
// reinstated: if (isatty(0) && streams.stdin_fd == STDIN_FILENO && !split_null) {
int stream_stdin_is_a_tty = isatty(streams.stdin_fd);
if (stream_stdin_is_a_tty && !opts.split_null) {
// Read interactively using reader_readline(). This does not support splitting on null.
@ -474,7 +477,8 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
lseek(streams.stdin_fd, 0, SEEK_CUR) != -1) {
exit_res = read_in_chunks(streams.stdin_fd, buff, opts.split_null);
} else {
exit_res = read_one_char_at_a_time(streams.stdin_fd, buff, opts.nchars, opts.split_null);
exit_res =
read_one_char_at_a_time(streams.stdin_fd, buff, opts.nchars, opts.split_null);
}
if (exit_res != STATUS_CMD_OK) {
@ -496,7 +500,8 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Every character is a separate token with one wrinkle involving non-array mode where
// the final var gets the remaining characters as a single string.
size_t x = std::max(static_cast<size_t>(1), buff.size());
size_t n_splits = (opts.array || static_cast<size_t>(vars_left()) > x) ? x : vars_left();
size_t n_splits =
(opts.array || static_cast<size_t>(vars_left()) > x) ? x : vars_left();
wcstring_list_t chars;
chars.reserve(n_splits);

View file

@ -4,9 +4,9 @@
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <cstring>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <algorithm>
@ -305,7 +305,6 @@ static bool validate_path_warning_on_colons(const wchar_t *cmd,
static void handle_env_return(int retval, const wchar_t *cmd, const wchar_t *key,
io_streams_t &streams) {
switch (retval) {
case ENV_OK: {
break;
@ -317,19 +316,18 @@ static void handle_env_return(int retval, const wchar_t *cmd, const wchar_t *key
}
case ENV_SCOPE: {
streams.err.append_format(
_(L"%ls: Tried to modify the special variable '%ls' with the wrong scope\n"),
cmd, key);
_(L"%ls: Tried to modify the special variable '%ls' with the wrong scope\n"), cmd,
key);
break;
}
case ENV_INVALID: {
streams.err.append_format(
_(L"%ls: Tried to modify the special variable '%ls' to an invalid value\n"),
cmd, key);
_(L"%ls: Tried to modify the special variable '%ls' to an invalid value\n"), cmd,
key);
break;
}
case ENV_NOT_FOUND: {
streams.err.append_format(
_(L"%ls: The variable '%ls' does not exist\n"), cmd, key);
streams.err.append_format(_(L"%ls: The variable '%ls' does not exist\n"), cmd, key);
break;
}
default: {
@ -579,8 +577,7 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams
if (i >= 50 && i < vals.size() - 50) continue;
}
const wcstring value = vals[i];
const wcstring escaped_val =
escape_string(value, ESCAPE_NO_QUOTED, STRING_STYLE_SCRIPT);
const wcstring escaped_val = escape_string(value, ESCAPE_NO_QUOTED, STRING_STYLE_SCRIPT);
streams.out.append_format(_(L"$%ls[%d]: length=%d value=|%ls|\n"), var_name, i + 1,
value.size(), escaped_val.c_str());
}

View file

@ -69,8 +69,8 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Helps Terminal.app/iTerm
#if __APPLE__
const auto term_prog = parser.vars().get(L"TERM_PROGRAM");
if (!term_prog.missing_or_empty() && (term_prog->as_string() == L"Apple_Terminal"
|| term_prog->as_string() == L"iTerm.app")) {
if (!term_prog.missing_or_empty() &&
(term_prog->as_string() == L"Apple_Terminal" || term_prog->as_string() == L"iTerm.app")) {
const auto term = parser.vars().get(L"TERM");
if (!term.missing_or_empty() && (term->as_string() == L"xterm-256color")) {
enter_italics_mode = sitm_esc;

View file

@ -102,7 +102,8 @@ struct status_cmd_opts_t {
/// least until fish 3.0 and possibly longer to avoid breaking everyones config.fish and other
/// scripts.
static const wchar_t *const short_options = L":L:cbilfnhj:t";
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
static const struct woption long_options[] = {
{L"help", no_argument, NULL, 'h'},
{L"current-filename", no_argument, NULL, 'f'},
{L"current-line-number", no_argument, NULL, 'n'},
{L"filename", no_argument, NULL, 'f'},

View file

@ -11,8 +11,8 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <algorithm>
#include <cwctype>

View file

@ -5,12 +5,12 @@
#include <errno.h>
#include <stdarg.h>
#include <cstring>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#include <cmath>
#include <memory>
@ -24,8 +24,8 @@
#include "parser.h"
#include "wutil.h" // IWYU pragma: keep
using std::unique_ptr;
using std::move;
using std::unique_ptr;
namespace {
namespace test_expressions {
@ -530,7 +530,9 @@ unique_ptr<expression> test_parser::parse_expression(unsigned int start, unsigne
case 4: {
return parse_4_arg_expression(start, end);
}
default: { return parse_combining_expression(start, end); }
default: {
return parse_combining_expression(start, end);
}
}
}
@ -673,8 +675,8 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t
// We could not parse a float or an int.
// Check for special fish_wcsto* value or show standard EINVAL/ERANGE error.
if (errno == -1) {
errors.push_back(format_string(_(L"Integer %lld in '%ls' followed by non-digit"),
integral, argcs));
errors.push_back(
format_string(_(L"Integer %lld in '%ls' followed by non-digit"), integral, argcs));
} else {
errors.push_back(format_string(L"%s: '%ls'", std::strerror(errno), argcs));
}

View file

@ -79,7 +79,9 @@ static int parse_hex_digit(wchar_t x) {
case L'F': {
return 0xF;
}
default: { return -1; }
default: {
return -1;
}
}
}
@ -329,7 +331,9 @@ wcstring rgb_color_t::description() const {
case type_normal: {
return L"normal";
}
default: { break; }
default: {
break;
}
}
DIE("unknown color type");
}

View file

@ -14,13 +14,13 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/stat.h>
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
@ -168,7 +168,9 @@ bool is_windows_subsystem_for_linux() {
if (std::strstr(info.release, "Microsoft") != nullptr) {
const char *dash = std::strchr(info.release, '-');
if (dash == nullptr || strtod(dash + 1, nullptr) < 17763) {
debug(1, "This version of WSL is not supported and fish will probably not work correctly!\n"
debug(1,
"This version of WSL is not supported and fish will probably not work "
"correctly!\n"
"Please upgrade to Windows 10 1809 (17763) or higher to use fish!");
}
@ -187,8 +189,8 @@ bool is_windows_subsystem_for_linux() {
#ifdef HAVE_BACKTRACE_SYMBOLS
// This function produces a stack backtrace with demangled function & method names. It is based on
// https://gist.github.com/fmela/591333 but adapted to the style of the fish project.
[[gnu::noinline]] static const wcstring_list_t
demangled_backtrace(int max_frames, int skip_levels) {
[[gnu::noinline]] static const wcstring_list_t demangled_backtrace(int max_frames,
int skip_levels) {
void *callstack[128];
const int n_max_frames = sizeof(callstack) / sizeof(callstack[0]);
int n_frames = backtrace(callstack, n_max_frames);
@ -653,8 +655,8 @@ static void debug_shared(const wchar_t level, const wcstring &msg) {
std::fwprintf(stderr, L"<%lc> %ls: %ls\n", (unsigned long)level, program_name, msg.c_str());
} else {
current_pid = getpid();
std::fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name, current_pid,
msg.c_str());
std::fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name,
current_pid, msg.c_str());
}
}
@ -1156,8 +1158,9 @@ static wcstring escape_string_pcre2(const wcstring &in) {
case L'}':
case L'\\':
case L'|':
// these two only *need* to be escaped within a character class, and technically it makes
// no sense to ever use process substitution output to compose a character class, but...
// these two only *need* to be escaped within a character class, and technically it
// makes no sense to ever use process substitution output to compose a character class,
// but...
case L'-':
case L']':
out.push_back('\\');
@ -1652,7 +1655,9 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
}
break;
}
default: { break; }
default: {
break;
}
}
}
@ -2232,9 +2237,7 @@ void set_main_thread() {
void configure_thread_assertions_for_testing() { thread_asserts_cfg_for_testing = true; }
bool is_forked_child() {
return is_forked_proc;
}
bool is_forked_child() { return is_forked_proc; }
void setup_fork_guards() {
is_forked_proc = false;
@ -2430,8 +2433,7 @@ std::string get_executable_path(const char *argv0) {
int result = sysctl(name, sizeof(name) / sizeof(int), buff, &buff_size, nullptr, 0);
if (result != 0) {
wperror(L"sysctl KERN_PROC_PATHNAME");
}
else {
} else {
return std::string(buff);
}
#else
@ -2494,9 +2496,10 @@ bool is_console_session() {
const char *TERM = getenv("TERM");
return
// Test that the tty matches /dev/(console|dcons|tty[uv\d])
tty_name && ((strncmp(tty_name, "/dev/tty", len) == 0 &&
(tty_name[len] == 'u' || tty_name[len] == 'v' || isdigit(tty_name[len])))
|| strcmp(tty_name, "/dev/dcons") == 0 || strcmp(tty_name, "/dev/console") == 0)
tty_name &&
((strncmp(tty_name, "/dev/tty", len) == 0 &&
(tty_name[len] == 'u' || tty_name[len] == 'v' || isdigit(tty_name[len]))) ||
strcmp(tty_name, "/dev/dcons") == 0 || strcmp(tty_name, "/dev/console") == 0)
// and that $TERM is simple, e.g. `xterm` or `vt100`, not `xterm-something`
&& (!TERM || !strchr(TERM, '-') || !strcmp(TERM, "sun-color"));
}();

View file

@ -248,7 +248,8 @@ extern const bool has_working_tty_timestamps;
[[noreturn]] void __fish_assert(const char *msg, const char *file, size_t line, int error);
/// Shorthand for wgettext call in situations where a C-style string is needed (e.g., std::fwprintf()).
/// Shorthand for wgettext call in situations where a C-style string is needed (e.g.,
/// std::fwprintf()).
#define _(wstr) wgettext(wstr).c_str()
/// Noop, used to tell xgettext that a string should be translated. Use this when a string cannot be
@ -353,21 +354,17 @@ public:
line_iterator_t(const Collection &coll) : coll(coll), current(coll.cbegin()) {}
/// Access the storage in which the last line was stored.
const Collection &line() const {
return storage;
}
const Collection &line() const { return storage; }
/// Advances to the next line. \return true on success, false if we have exhausted the string.
bool next() {
if (current == coll.end())
return false;
if (current == coll.end()) return false;
auto newline_or_end = std::find(current, coll.cend(), '\n');
storage.assign(current, newline_or_end);
current = newline_or_end;
// Skip the newline.
if (current != coll.cend())
++current;
if (current != coll.cend()) ++current;
return true;
}
};
@ -531,7 +528,9 @@ inline bool bool_from_string(const std::string &x) {
}
}
inline bool bool_from_string(const wcstring &x) { return !x.empty() && std::wcschr(L"YTyt1", x.at(0)); }
inline bool bool_from_string(const wcstring &x) {
return !x.empty() && std::wcschr(L"YTyt1", x.at(0));
}
wchar_t **make_null_terminated_array(const wcstring_list_t &lst);
char **make_null_terminated_array(const std::vector<std::string> &lst);
@ -1016,12 +1015,10 @@ std::string get_executable_path(const char *fallback);
struct cleanup_t {
private:
const std::function<void()> cleanup;
public:
cleanup_t(std::function<void()> exit_actions)
: cleanup{std::move(exit_actions)} {}
~cleanup_t() {
cleanup();
}
cleanup_t(std::function<void()> exit_actions) : cleanup{std::move(exit_actions)} {}
~cleanup_t() { cleanup(); }
};
bool is_console_session();

View file

@ -8,8 +8,8 @@
#include <pthread.h>
#include <pwd.h>
#include <stddef.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <algorithm>
#include <atomic>
@ -180,13 +180,9 @@ static bool compare_completions_by_order(const completion_entry_t &p1,
return p1.order < p2.order;
}
void completion_entry_t::add_option(const complete_entry_opt_t &opt) {
options.push_front(opt);
}
void completion_entry_t::add_option(const complete_entry_opt_t &opt) { options.push_front(opt); }
const option_list_t &completion_entry_t::get_options() const {
return options;
}
const option_list_t &completion_entry_t::get_options() const { return options; }
description_func_t const_desc(const wcstring &s) {
return [=](const wcstring &ignored) {
@ -202,7 +198,8 @@ static complete_flags_t resolve_auto_space(const wcstring &comp, complete_flags_
if (flags & COMPLETE_AUTO_SPACE) {
new_flags &= ~COMPLETE_AUTO_SPACE;
size_t len = comp.size();
if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != 0)) new_flags |= COMPLETE_NO_SPACE;
if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != 0))
new_flags |= COMPLETE_NO_SPACE;
}
return new_flags;
}

View file

@ -195,7 +195,6 @@ void append_completion(std::vector<completion_t> *completions, wcstring comp,
wcstring desc = wcstring(), int flags = 0,
string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact));
/// Support for "wrap targets." A wrap target is a command that completes like another command.
bool complete_add_wrapper(const wcstring &command, const wcstring &wrap_target);
bool complete_remove_wrapper(const wcstring &command, const wcstring &wrap_target);

View file

@ -306,9 +306,7 @@ struct var_stack_t {
}
/// Copy this vars_stack.
var_stack_t clone() const {
return var_stack_t(*this);
}
var_stack_t clone() const { return var_stack_t(*this); }
/// Snapshot this vars_stack. That is, return a new vars_stack that has copies of all local
/// variables. Note that this drops all shadowed nodes: only the currently executing function is
@ -822,7 +820,8 @@ static void env_set_internal_universal(const wcstring &key, wcstring_list_t val,
/// * ENV_SCOPE, the variable cannot be set in the given scope. This applies to readonly/electric
/// variables set from the local or universal scopes, or set as exported.
/// * ENV_INVALID, the variable value was invalid. This applies only to special variables.
int env_stack_t::set_internal(const wcstring &key, env_mode_flags_t input_var_mode, wcstring_list_t val) {
int env_stack_t::set_internal(const wcstring &key, env_mode_flags_t input_var_mode,
wcstring_list_t val) {
ASSERT_IS_MAIN_THREAD();
env_mode_flags_t var_mode = input_var_mode;
bool has_changed_old = vars_stack().has_changed_exported();

View file

@ -241,7 +241,6 @@ class env_stack_t final : public env_scoped_t {
env_stack_t(env_stack_t &&);
public:
/// Sets the variable with the specified name to the given values.
int set(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals);

View file

@ -24,8 +24,8 @@
#include <ncurses/term.h>
#endif
#include <algorithm>
#include <assert.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <string>

View file

@ -43,8 +43,8 @@
#include "path.h"
#include "utf8.h"
#include "util.h" // IWYU pragma: keep
#include "wutil.h"
#include "wcstringutil.h"
#include "wutil.h"
#if __APPLE__
#define FISH_NOTIFYD_AVAILABLE 1
@ -433,7 +433,8 @@ std::string env_universal_t::serialize_with_vars(const var_table_t &vars) {
// variable; soldier on.
const wcstring &key = kv.first;
const env_var_t &var = kv.second;
append_file_entry(var.get_flags(), key, encode_serialized(var.as_list()), &contents, &storage);
append_file_entry(var.get_flags(), key, encode_serialized(var.as_list()), &contents,
&storage);
}
return contents;
}
@ -996,8 +997,9 @@ static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN]) { return
/// Function to get an identifier based on the hostname.
bool get_hostname_identifier(wcstring &result) {
//The behavior of gethostname if the buffer size is insufficient differs by implementation and libc version
//Work around this by using a "guaranteed" sufficient buffer size then truncating the result.
// The behavior of gethostname if the buffer size is insufficient differs by implementation and
// libc version Work around this by using a "guaranteed" sufficient buffer size then truncating
// the result.
bool success = false;
char hostname[256] = {};
if (gethostname(hostname, sizeof(hostname)) == 0) {

View file

@ -64,7 +64,8 @@ public:
return {};
}
// The signal count has changed. Store the new counter and fetch all the signals that are set.
// The signal count has changed. Store the new counter and fetch all the signals that are
// set.
*current = count;
std::bitset<SIGNAL_COUNT> result{};
uint32_t bit = 0;
@ -183,7 +184,9 @@ wcstring event_get_desc(const event_t &evt) {
case event_type_t::generic: {
return format_string(_(L"handler for generic event '%ls'"), ed.str_param1.c_str());
}
case event_type_t::any: { DIE("Unreachable"); }
case event_type_t::any: {
DIE("Unreachable");
}
default:
DIE("Unknown event type");
}
@ -291,8 +294,7 @@ static void event_fire_internal(const event_t &event) {
void event_fire_delayed() {
ASSERT_IS_MAIN_THREAD();
// Do not invoke new event handlers from within event handlers.
if (is_event)
return;
if (is_event) return;
event_list_t to_send;
to_send.swap(blocked);
@ -368,7 +370,6 @@ static const wchar_t *event_name_for_type(event_type_t type) {
return L"";
}
void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
event_handler_list_t tmp = s_event_handlers;
std::sort(tmp.begin(), tmp.end(),
@ -401,8 +402,7 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
}
if (!last_type || *last_type != evt->desc.type) {
if (last_type)
streams.out.append(L"\n");
if (last_type) streams.out.append(L"\n");
last_type = static_cast<event_type_t>(evt->desc.type);
streams.out.append_format(L"Event %ls\n", event_name_for_type(*last_type));
}
@ -421,7 +421,8 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
streams.out.append_format(L"%ls %ls\n", evt->desc.str_param1.c_str(),
evt->function_name.c_str());
break;
case event_type_t::any: DIE("Unreachable");
case event_type_t::any:
DIE("Unreachable");
default:
streams.out.append_format(L"%ls\n", evt->function_name.c_str());
break;

View file

@ -14,9 +14,9 @@
#include <spawn.h>
#endif
#include <stdio.h>
#include <cstring>
#include <sys/wait.h>
#include <unistd.h>
#include <cstring>
#include <stack>
#include <algorithm>
@ -675,8 +675,8 @@ static bool handle_builtin_output(const std::shared_ptr<job_t> &j, process_t *p,
/// Executes an external command.
/// \return true on success, false if there is an exec error.
static bool exec_external_command(env_stack_t &vars, const std::shared_ptr<job_t> &j,
process_t *p, const io_chain_t &proc_io_chain) {
static bool exec_external_command(env_stack_t &vars, const std::shared_ptr<job_t> &j, process_t *p,
const io_chain_t &proc_io_chain) {
assert(p->type == process_type_t::external && "Process is not external");
// Get argv and envv before we fork.
null_terminated_array_t<char> argv_array;
@ -684,8 +684,7 @@ static bool exec_external_command(env_stack_t &vars, const std::shared_ptr<job_t
// Convert our IO chain to a dup2 sequence.
auto dup2s = dup2_list_t::resolve_chain(proc_io_chain);
if (! dup2s)
return false;
if (!dup2s) return false;
// Ensure that stdin is blocking before we hand it off (see issue #176). It's a
// little strange that we only do this with stdin and not with stdout or stderr.

View file

@ -7,10 +7,10 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <cstring>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#ifdef HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h> // IWYU pragma: keep
@ -124,9 +124,7 @@ static void append_cmdsub_error(parse_error_list_t *errors, size_t source_start,
/// Test if the specified string does not contain character which can not be used inside a quoted
/// string.
static bool is_quotable(const wchar_t *str) {
return !std::wcspbrk(str, L"\n\t\r\b\x1B");
}
static bool is_quotable(const wchar_t *str) { return !std::wcspbrk(str, L"\n\t\r\b\x1B"); }
static bool is_quotable(const wcstring &str) { return is_quotable(str.c_str()); }
@ -168,7 +166,8 @@ wcstring expand_escape_variable(const env_var_t &var) {
/// Parse an array slicing specification Returns 0 on success. If a parse error occurs, returns the
/// index of the bad token. Note that 0 can never be a bad index because the string always starts
/// with [.
static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx, size_t array_size) {
static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx,
size_t array_size) {
const long size = (long)array_size;
size_t pos = 1; // skip past the opening square brace
@ -360,7 +359,8 @@ static bool expand_variables(wcstring instr, std::vector<completion_t> *out, siz
} else if (history) {
effective_val_count = history->size();
}
size_t bad_pos = parse_slice(in + slice_start, &slice_end, var_idx_list, effective_val_count);
size_t bad_pos =
parse_slice(in + slice_start, &slice_end, var_idx_list, effective_val_count);
if (bad_pos != 0) {
if (in[slice_start + bad_pos] == L'0') {
append_syntax_error(errors, slice_start + bad_pos,
@ -638,8 +638,7 @@ static bool expand_cmdsubst(wcstring input, parser_t &parser, std::vector<comple
wchar_t *slice_end;
size_t bad_pos;
bad_pos =
parse_slice(slice_begin, &slice_end, slice_idx, sub_res.size());
bad_pos = parse_slice(slice_begin, &slice_end, slice_idx, sub_res.size());
if (bad_pos != 0) {
append_syntax_error(errors, slice_begin - in + bad_pos, L"Invalid index value");
return false;
@ -1140,7 +1139,6 @@ expand_result_t expand_to_command_and_args(const wcstring &instr, const environm
parse_error_list_t *errors) {
// Fast path.
if (expand_is_clean(instr)) {
*out_cmd = instr;
return expand_result_t::ok;
}

View file

@ -14,13 +14,13 @@
#include <stdarg.h> // IWYU pragma: keep
#include <stdio.h> // IWYU pragma: keep
#include <stdlib.h>
#include <cstring>
#include <sys/stat.h> // IWYU pragma: keep
#include <sys/types.h> // IWYU pragma: keep
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
#include <cstring>
#include <cwchar>
#if HAVE_GETTEXT
#include <libintl.h>
#endif
@ -45,8 +45,8 @@
#if defined(TPARM_SOLARIS_KLUDGE)
#undef tparm
char *tparm_solaris_kludge(char *str, long p1, long p2, long p3, long p4,
long p5, long p6, long p7, long p8, long p9) {
char *tparm_solaris_kludge(char *str, long p1, long p2, long p3, long p4, long p5, long p6, long p7,
long p8, long p9) {
return tparm(str, p1, p2, p3, p4, p5, p6, p7, p8, p9);
}
@ -97,8 +97,7 @@ int fish_mkstemp_cloexec(char *name_template) {
return wcscasecmp_fallback(a + 1, b + 1);
}
[[gnu::unused]] static int wcsncasecmp_fallback(const wchar_t *a, const wchar_t *b,
size_t count) {
[[gnu::unused]] static int wcsncasecmp_fallback(const wchar_t *a, const wchar_t *b, size_t count) {
if (count == 0) return 0;
if (*a == 0) {
@ -281,8 +280,10 @@ int fish_wcwidth(wchar_t wc) {
// (width 1) to an emoji (probably width 2). So treat it as width 1 so the sums work. See #2652.
// VS15 selects text presentation.
const wchar_t variation_selector_16 = L'\uFE0F', variation_selector_15 = L'\uFE0E';
if (wc == variation_selector_16) return 1;
else if (wc == variation_selector_15) return 0;
if (wc == variation_selector_16)
return 1;
else if (wc == variation_selector_15)
return 0;
// Korean Hangul Jamo median vowels and final consonants.
// These can either appear in combined form, taking 0 width themselves,

View file

@ -196,8 +196,8 @@ int flock(int fd, int op);
#endif
// NetBSD _has_ wcstod_l, but it's doing some weak linking hullabaloo that I don't get.
// Since it doesn't have uselocale (yes, the standard function isn't there, the non-standard extension is),
// we can't try to use the fallback.
// Since it doesn't have uselocale (yes, the standard function isn't there, the non-standard
// extension is), we can't try to use the fallback.
#if !defined(HAVE_WCSTOD_L) && !defined(__NetBSD__)
// On some platforms if this is incorrectly detected and a system-defined
// defined version of `wcstod_l` exists, calling `wcstod` from our own

View file

@ -27,10 +27,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/resource.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <memory>
@ -130,7 +130,9 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
#ifdef CMAKE_BINARY_DIR
// Detect if we're running right out of the CMAKE build directory
if (string_prefixes_string(CMAKE_BINARY_DIR, exec_path.c_str())) {
debug(2, "Running out of build directory, using paths relative to CMAKE_SOURCE_DIR:\n %s", CMAKE_SOURCE_DIR);
debug(2,
"Running out of build directory, using paths relative to CMAKE_SOURCE_DIR:\n %s",
CMAKE_SOURCE_DIR);
done = true;
paths.data = wcstring{L"" CMAKE_SOURCE_DIR} + L"/share";
@ -339,7 +341,8 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
set_debug_stack_frames((int)tmp);
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"),
optarg);
exit(1);
}
break;

View file

@ -23,15 +23,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#include <memory>
#include <string>
#include <vector>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include "color.h"
#include "common.h"
@ -119,8 +119,8 @@ struct prettifier_t {
line_continuation_indent = is_continuation ? 1 : 0;
}
// Append whitespace as necessary. If we have a newline, append the appropriate indent. Otherwise,
// append a space.
// Append whitespace as necessary. If we have a newline, append the appropriate indent.
// Otherwise, append a space.
void append_whitespace(indent_t node_indent) {
if (needs_continuation_newline) {
append_newline(true);
@ -131,7 +131,6 @@ struct prettifier_t {
output.append((node_indent + line_continuation_indent) * SPACES_PER_INDENT, L' ');
}
}
};
// Dump a parse tree node in a form helpful to someone debugging the behavior of this program.
@ -160,8 +159,9 @@ static void dump_node(indent_t node_indent, const parse_node_t &node, const wcst
nextc_str[2] = nextc + '@';
}
std::fwprintf(stderr, L"{off %4u, len %4u, indent %2u, kw %ls, %ls} [%ls|%ls|%ls]\n",
node.source_start, node.source_length, node_indent, keyword_description(node.keyword),
token_type_description(node.type), prevc_str, source_txt.c_str(), nextc_str);
node.source_start, node.source_length, node_indent,
keyword_description(node.keyword), token_type_description(node.type), prevc_str,
source_txt.c_str(), nextc_str);
}
void prettifier_t::prettify_node(const parse_node_tree_t &tree, node_offset_t node_idx,
@ -187,9 +187,10 @@ void prettifier_t::prettify_node(const parse_node_tree_t &tree, node_offset_t no
const parse_token_type_t prev_node_type =
node_idx > 0 ? tree.at(node_idx - 1).type : token_type_invalid;
// Increment the indent if we are either a root job_list, or root case_item_list, or in an if or
// while header (#1665).
const bool is_root_job_list = node_type == symbol_job_list && parent_type != symbol_job_list;
// Increment the indent if we are either a root job_list, or root case_item_list, or in an
// if or while header (#1665).
const bool is_root_job_list =
node_type == symbol_job_list && parent_type != symbol_job_list;
const bool is_root_case_list =
node_type == symbol_case_item_list && parent_type != symbol_case_item_list;
const bool is_if_while_header =
@ -253,7 +254,8 @@ void prettifier_t::prettify_node(const parse_node_tree_t &tree, node_offset_t no
for (node_offset_t idx = node.child_count; idx > 0; idx--) {
// Note: We pass our type to our child, which becomes its parent node type.
// Note: While node.child_start could be -1 (NODE_OFFSET_INVALID) the addition is safe
// because we won't execute this call in that case since node.child_count should be zero.
// because we won't execute this call in that case since node.child_count should be
// zero.
pending_node_stack.push({node.child_start + (idx - 1), node_indent, node_type});
}
}
@ -435,7 +437,9 @@ static const wchar_t *html_class_name_for_color(highlight_spec_t spec) {
case highlight_role_t::selection: {
return P(selection);
}
default: { return P(other); }
default: {
return P(other);
}
}
}
@ -593,7 +597,8 @@ int main(int argc, char *argv[]) {
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
set_debug_stack_frames((int)tmp);
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"),
optarg);
exit(1);
}
break;
@ -612,7 +617,8 @@ int main(int argc, char *argv[]) {
wcstring src;
if (argc == 0) {
if (output_type == output_type_file) {
std::fwprintf(stderr, _(L"Expected file path to read/write for -w:\n\n $ %ls -w foo.fish\n"),
std::fwprintf(stderr,
_(L"Expected file path to read/write for -w:\n\n $ %ls -w foo.fish\n"),
program_name);
exit(1);
}

View file

@ -14,9 +14,9 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <termios.h>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <memory>
@ -191,7 +191,8 @@ static double output_elapsed_time(double prev_tstamp, bool first_char_seen) {
if (delta_tstamp_us >= 1000000) {
std::fwprintf(stderr, L" ");
} else {
std::fwprintf(stderr, L"(%3lld.%03lld ms) ", delta_tstamp_us / 1000, delta_tstamp_us % 1000);
std::fwprintf(stderr, L"(%3lld.%03lld ms) ", delta_tstamp_us / 1000,
delta_tstamp_us % 1000);
}
return now;
}
@ -293,7 +294,8 @@ static void setup_and_process_keys(bool continuous_mode) {
if (continuous_mode) {
std::fwprintf(stderr, L"\n");
std::fwprintf(stderr, L"To terminate this program type \"exit\" or \"quit\" in this window,\n");
std::fwprintf(stderr,
L"To terminate this program type \"exit\" or \"quit\" in this window,\n");
std::fwprintf(stderr, L"or press [ctrl-%c] or [ctrl-%c] twice in a row.\n",
shell_modes.c_cc[VINTR] + 0x40, shell_modes.c_cc[VEOF] + 0x40);
std::fwprintf(stderr, L"\n");

View file

@ -14,7 +14,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
@ -23,8 +22,9 @@
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#include <thread>
#include <algorithm>
@ -612,7 +612,8 @@ static void test_tokenizer() {
}
if (types[i] != token.type) {
err(L"Tokenization error:");
std::fwprintf(stdout,
std::fwprintf(
stdout,
L"Token number %zu of string \n'%ls'\n, expected type %ld, got token type "
L"%ld\n",
i + 1, str, (long)types[i], (long)token.type);
@ -734,9 +735,7 @@ static void test_pthread() {
say(L"Testing pthreads");
pthread_t result = {};
int val = 3;
bool made = make_pthread(&result, [&val](){
val += 2;
});
bool made = make_pthread(&result, [&val]() { val += 2; });
do_test(made);
void *ignore = nullptr;
int ret = pthread_join(result, &ignore);
@ -1900,18 +1899,20 @@ static void test_abbreviations() {
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// If commands should be expanded.
expanded = reader_expand_abbreviation_in_command(L"if gc", std::wcslen(L"if gc"), vars, &result);
expanded =
reader_expand_abbreviation_in_command(L"if gc", std::wcslen(L"if gc"), vars, &result);
if (!expanded) err(L"gc not expanded on line %ld", (long)__LINE__);
if (result != L"if git checkout")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// Others should not be.
expanded = reader_expand_abbreviation_in_command(L"of gc", std::wcslen(L"of gc"), vars, &result);
expanded =
reader_expand_abbreviation_in_command(L"of gc", std::wcslen(L"of gc"), vars, &result);
if (expanded) err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
// Others should not be.
expanded =
reader_expand_abbreviation_in_command(L"command gc", std::wcslen(L"command gc"), vars, &result);
expanded = reader_expand_abbreviation_in_command(L"command gc", std::wcslen(L"command gc"),
vars, &result);
if (expanded) err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
vars.pop();
@ -2252,8 +2253,7 @@ static bool run_one_test_test(int expected, wcstring_list_t &lst, bool bracket)
io_streams_t streams(0);
int result = builtin_test(parser, streams, argv);
if (expected != result)
err(L"expected builtin_test() to return %d, got %d", expected, result);
if (expected != result) err(L"expected builtin_test() to return %d, got %d", expected, result);
delete[] argv;
@ -2759,8 +2759,8 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command, const wc
bool expects_error = (expected == L"<error>");
if (comps.empty() && !expects_error) {
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
command.c_str());
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n",
line, command.c_str());
do_test_from(!comps.empty(), line);
return;
} else if (!comps.empty() && expects_error) {
@ -2795,8 +2795,8 @@ static void perform_one_completion_cd_test(const wcstring &command, const wcstri
bool expects_error = (expected == L"<error>");
if (comps.empty() && !expects_error) {
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
command.c_str());
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n",
line, command.c_str());
do_test_from(!comps.empty(), line);
return;
} else if (!comps.empty() && expects_error) {
@ -4558,7 +4558,8 @@ static void test_pcre2_escape() {
for (const auto &test : tests) {
auto escaped = escape_string(test[0], 0, STRING_STYLE_REGEX);
if (escaped != test[1]) {
err(L"pcre2_escape error: pcre2_escape(%ls) -> %ls, expected %ls", test[0], escaped.c_str(), test[1]);
err(L"pcre2_escape error: pcre2_escape(%ls) -> %ls, expected %ls", test[0],
escaped.c_str(), test[1]);
}
}
}
@ -5211,8 +5212,8 @@ int main(int argc, char **argv) {
exit(-1);
}
if (!std::strcmp(wd, "/")) {
std::fwprintf(stderr,
L"Unable to find 'tests' directory, which should contain file test.fish\n");
std::fwprintf(
stderr, L"Unable to find 'tests' directory, which should contain file test.fish\n");
exit(EXIT_FAILURE);
}
if (chdir(dirname(wd)) < 0) {

View file

@ -13,7 +13,8 @@ features_t &mutable_fish_features() { return global_features; }
const features_t::metadata_t features_t::metadata[features_t::flag_count] = {
{stderr_nocaret, L"stderr-nocaret", L"3.0", L"^ no longer redirects stderr"},
{qmark_noglob, L"qmark-noglob", L"3.0", L"? no longer globs"},
{string_replace_backslash, L"string-replace-fewer-backslashes", L"3.1", L"string replace -r needs fewer backslashes in the replacement"},
{string_replace_backslash, L"string-replace-fewer-backslashes", L"3.1",
L"string replace -r needs fewer backslashes in the replacement"},
};
const struct features_t::metadata_t *features_t::metadata_for(const wchar_t *name) {

View file

@ -1247,7 +1247,9 @@ const highlighter_t::color_array_t &highlighter_t::highlight() {
this->color_node(node, highlight_role_t::comment);
break;
}
default: { break; }
default: {
break;
}
}
}

View file

@ -8,8 +8,8 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <cstdint>
#include <cstring>
// We need the sys/file.h for the flock() declaration on Linux but not OS X.
#include <sys/file.h> // IWYU pragma: keep
#include <sys/mman.h>
@ -554,7 +554,6 @@ bool history_item_t::merge(const history_item_t &item) {
history_item_t::history_item_t(const wcstring &str, time_t when, history_identifier_t ident)
: creation_timestamp(when), identifier(ident) {
contents = trim(str);
contents_lower.reserve(contents.size());
for (const auto &c : contents) {
@ -1971,7 +1970,6 @@ void history_t::resolve_pending() {
this->has_pending_item = false;
}
static std::atomic<bool> private_mode{false};
void start_private_mode() {
@ -1981,6 +1979,4 @@ void start_private_mode() {
vars.set_one(L"fish_private_mode", ENV_GLOBAL, L"1");
}
bool in_private_mode() {
return private_mode.load();
}
bool in_private_mode() { return private_mode.load(); }

View file

@ -2,8 +2,8 @@
#include "config.h"
#include <errno.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#if HAVE_TERM_H
#include <curses.h>
#include <term.h>
@ -289,7 +289,8 @@ void init_input() {
input_mapping_add(L"\x3", L"commandline ''", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x4", L"exit", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x5", L"bind", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x7f", L"backward-delete-char", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x7f", L"backward-delete-char", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE,
false);
// Arrows - can't have functions, so *-or-search isn't available.
input_mapping_add(L"\x1B[A", L"up-line", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x1B[B", L"down-line", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
@ -498,7 +499,9 @@ char_event_t input_readch(bool allow_commands) {
input_common_next_ch(evt);
return input_readch();
}
default: { return evt; }
default: {
return evt;
}
}
} else if (evt.is_eof()) {
// If we have EOF, we need to immediately quit.
@ -540,8 +543,7 @@ bool input_mapping_erase(const wcstring &sequence, const wcstring &mode, bool us
ASSERT_IS_MAIN_THREAD();
bool result = false;
mapping_list_t &ml = user ? s_mapping_list : s_preset_mapping_list;
for (std::vector<input_mapping_t>::iterator it = ml.begin(), end = ml.end();
it != end; ++it) {
for (std::vector<input_mapping_t>::iterator it = ml.begin(), end = ml.end(); it != end; ++it) {
if (sequence == it->seq && mode == it->mode) {
ml.erase(it);
result = true;
@ -551,8 +553,8 @@ bool input_mapping_erase(const wcstring &sequence, const wcstring &mode, bool us
return result;
}
bool input_mapping_get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds, bool user,
wcstring *out_sets_mode) {
bool input_mapping_get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds,
bool user, wcstring *out_sets_mode) {
bool result = false;
mapping_list_t &ml = user ? s_mapping_list : s_preset_mapping_list;
for (const input_mapping_t &m : ml) {
@ -571,52 +573,21 @@ static std::vector<terminfo_mapping_t> create_input_terminfo() {
assert(curses_initialized);
if (!cur_term) return {}; // setupterm() failed so we can't referency any key definitions
return {
TERMINFO_ADD(key_a1),
TERMINFO_ADD(key_a3),
TERMINFO_ADD(key_b2),
TERMINFO_ADD(key_backspace),
TERMINFO_ADD(key_beg),
TERMINFO_ADD(key_btab),
TERMINFO_ADD(key_c1),
TERMINFO_ADD(key_c3),
TERMINFO_ADD(key_cancel),
TERMINFO_ADD(key_catab),
TERMINFO_ADD(key_clear),
TERMINFO_ADD(key_close),
TERMINFO_ADD(key_command),
TERMINFO_ADD(key_copy),
TERMINFO_ADD(key_create),
TERMINFO_ADD(key_ctab),
TERMINFO_ADD(key_dc),
TERMINFO_ADD(key_dl),
TERMINFO_ADD(key_down),
TERMINFO_ADD(key_eic),
TERMINFO_ADD(key_end),
TERMINFO_ADD(key_enter),
TERMINFO_ADD(key_eol),
TERMINFO_ADD(key_eos),
TERMINFO_ADD(key_exit),
TERMINFO_ADD(key_f0),
TERMINFO_ADD(key_f1),
TERMINFO_ADD(key_f2),
TERMINFO_ADD(key_f3),
TERMINFO_ADD(key_f4),
TERMINFO_ADD(key_f5),
TERMINFO_ADD(key_f6),
TERMINFO_ADD(key_f7),
TERMINFO_ADD(key_f8),
TERMINFO_ADD(key_f9),
TERMINFO_ADD(key_f10),
TERMINFO_ADD(key_f11),
TERMINFO_ADD(key_f12),
TERMINFO_ADD(key_f13),
TERMINFO_ADD(key_f14),
TERMINFO_ADD(key_f15),
TERMINFO_ADD(key_f16),
TERMINFO_ADD(key_f17),
TERMINFO_ADD(key_f18),
TERMINFO_ADD(key_f19),
TERMINFO_ADD(key_f20),
TERMINFO_ADD(key_a1), TERMINFO_ADD(key_a3), TERMINFO_ADD(key_b2),
TERMINFO_ADD(key_backspace), TERMINFO_ADD(key_beg), TERMINFO_ADD(key_btab),
TERMINFO_ADD(key_c1), TERMINFO_ADD(key_c3), TERMINFO_ADD(key_cancel),
TERMINFO_ADD(key_catab), TERMINFO_ADD(key_clear), TERMINFO_ADD(key_close),
TERMINFO_ADD(key_command), TERMINFO_ADD(key_copy), TERMINFO_ADD(key_create),
TERMINFO_ADD(key_ctab), TERMINFO_ADD(key_dc), TERMINFO_ADD(key_dl),
TERMINFO_ADD(key_down), TERMINFO_ADD(key_eic), TERMINFO_ADD(key_end),
TERMINFO_ADD(key_enter), TERMINFO_ADD(key_eol), TERMINFO_ADD(key_eos),
TERMINFO_ADD(key_exit), TERMINFO_ADD(key_f0), TERMINFO_ADD(key_f1),
TERMINFO_ADD(key_f2), TERMINFO_ADD(key_f3), TERMINFO_ADD(key_f4), TERMINFO_ADD(key_f5),
TERMINFO_ADD(key_f6), TERMINFO_ADD(key_f7), TERMINFO_ADD(key_f8), TERMINFO_ADD(key_f9),
TERMINFO_ADD(key_f10), TERMINFO_ADD(key_f11), TERMINFO_ADD(key_f12),
TERMINFO_ADD(key_f13), TERMINFO_ADD(key_f14), TERMINFO_ADD(key_f15),
TERMINFO_ADD(key_f16), TERMINFO_ADD(key_f17), TERMINFO_ADD(key_f18),
TERMINFO_ADD(key_f19), TERMINFO_ADD(key_f20),
#if 0
// I know of no keyboard with more than 20 function keys, so adding the rest here makes very
// little sense, since it will take up a lot of room in any listings (like tab completions),
@ -665,66 +636,26 @@ static std::vector<terminfo_mapping_t> create_input_terminfo() {
TERMINFO_ADD(key_f62),
TERMINFO_ADD(key_f63),
#endif
TERMINFO_ADD(key_find),
TERMINFO_ADD(key_help),
TERMINFO_ADD(key_home),
TERMINFO_ADD(key_ic),
TERMINFO_ADD(key_il),
TERMINFO_ADD(key_left),
TERMINFO_ADD(key_ll),
TERMINFO_ADD(key_mark),
TERMINFO_ADD(key_message),
TERMINFO_ADD(key_move),
TERMINFO_ADD(key_next),
TERMINFO_ADD(key_npage),
TERMINFO_ADD(key_open),
TERMINFO_ADD(key_options),
TERMINFO_ADD(key_ppage),
TERMINFO_ADD(key_previous),
TERMINFO_ADD(key_print),
TERMINFO_ADD(key_redo),
TERMINFO_ADD(key_reference),
TERMINFO_ADD(key_refresh),
TERMINFO_ADD(key_replace),
TERMINFO_ADD(key_restart),
TERMINFO_ADD(key_resume),
TERMINFO_ADD(key_right),
TERMINFO_ADD(key_save),
TERMINFO_ADD(key_sbeg),
TERMINFO_ADD(key_scancel),
TERMINFO_ADD(key_scommand),
TERMINFO_ADD(key_scopy),
TERMINFO_ADD(key_screate),
TERMINFO_ADD(key_sdc),
TERMINFO_ADD(key_sdl),
TERMINFO_ADD(key_select),
TERMINFO_ADD(key_send),
TERMINFO_ADD(key_seol),
TERMINFO_ADD(key_sexit),
TERMINFO_ADD(key_sf),
TERMINFO_ADD(key_sfind),
TERMINFO_ADD(key_shelp),
TERMINFO_ADD(key_shome),
TERMINFO_ADD(key_sic),
TERMINFO_ADD(key_sleft),
TERMINFO_ADD(key_smessage),
TERMINFO_ADD(key_smove),
TERMINFO_ADD(key_snext),
TERMINFO_ADD(key_soptions),
TERMINFO_ADD(key_sprevious),
TERMINFO_ADD(key_sprint),
TERMINFO_ADD(key_sr),
TERMINFO_ADD(key_sredo),
TERMINFO_ADD(key_sreplace),
TERMINFO_ADD(key_sright),
TERMINFO_ADD(key_srsume),
TERMINFO_ADD(key_ssave),
TERMINFO_ADD(key_ssuspend),
TERMINFO_ADD(key_stab),
TERMINFO_ADD(key_sundo),
TERMINFO_ADD(key_suspend),
TERMINFO_ADD(key_undo),
TERMINFO_ADD(key_up)
TERMINFO_ADD(key_find), TERMINFO_ADD(key_help), TERMINFO_ADD(key_home),
TERMINFO_ADD(key_ic), TERMINFO_ADD(key_il), TERMINFO_ADD(key_left),
TERMINFO_ADD(key_ll), TERMINFO_ADD(key_mark), TERMINFO_ADD(key_message),
TERMINFO_ADD(key_move), TERMINFO_ADD(key_next), TERMINFO_ADD(key_npage),
TERMINFO_ADD(key_open), TERMINFO_ADD(key_options), TERMINFO_ADD(key_ppage),
TERMINFO_ADD(key_previous), TERMINFO_ADD(key_print), TERMINFO_ADD(key_redo),
TERMINFO_ADD(key_reference), TERMINFO_ADD(key_refresh), TERMINFO_ADD(key_replace),
TERMINFO_ADD(key_restart), TERMINFO_ADD(key_resume), TERMINFO_ADD(key_right),
TERMINFO_ADD(key_save), TERMINFO_ADD(key_sbeg), TERMINFO_ADD(key_scancel),
TERMINFO_ADD(key_scommand), TERMINFO_ADD(key_scopy), TERMINFO_ADD(key_screate),
TERMINFO_ADD(key_sdc), TERMINFO_ADD(key_sdl), TERMINFO_ADD(key_select),
TERMINFO_ADD(key_send), TERMINFO_ADD(key_seol), TERMINFO_ADD(key_sexit),
TERMINFO_ADD(key_sf), TERMINFO_ADD(key_sfind), TERMINFO_ADD(key_shelp),
TERMINFO_ADD(key_shome), TERMINFO_ADD(key_sic), TERMINFO_ADD(key_sleft),
TERMINFO_ADD(key_smessage), TERMINFO_ADD(key_smove), TERMINFO_ADD(key_snext),
TERMINFO_ADD(key_soptions), TERMINFO_ADD(key_sprevious), TERMINFO_ADD(key_sprint),
TERMINFO_ADD(key_sr), TERMINFO_ADD(key_sredo), TERMINFO_ADD(key_sreplace),
TERMINFO_ADD(key_sright), TERMINFO_ADD(key_srsume), TERMINFO_ADD(key_ssave),
TERMINFO_ADD(key_ssuspend), TERMINFO_ADD(key_stab), TERMINFO_ADD(key_sundo),
TERMINFO_ADD(key_suspend), TERMINFO_ADD(key_undo), TERMINFO_ADD(key_up)
};
}

View file

@ -63,12 +63,13 @@ std::vector<input_mapping_name_t> input_mapping_get_names(bool user = true);
void input_mapping_clear(const wchar_t *mode = NULL, bool user = true);
/// Erase binding for specified key sequence.
bool input_mapping_erase(const wcstring &sequence, const wcstring &mode = DEFAULT_BIND_MODE, bool user = true);
bool input_mapping_erase(const wcstring &sequence, const wcstring &mode = DEFAULT_BIND_MODE,
bool user = true);
/// Gets the command bound to the specified key sequence in the specified mode. Returns true if it
/// exists, false if not.
bool input_mapping_get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds, bool user,
wcstring *out_new_mode);
bool input_mapping_get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds,
bool user, wcstring *out_new_mode);
/// Return the current bind mode.
wcstring input_get_bind_mode(const environment_t &vars);

View file

@ -2,8 +2,8 @@
#include "config.h"
#include <errno.h>
#include <cstring>
#include <unistd.h>
#include <cstring>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
@ -208,7 +208,9 @@ char_event_t input_common_readch() {
case 0: {
return 0;
}
default: { return res; }
default: {
return res;
}
}
}
}

View file

@ -4,8 +4,8 @@
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include "common.h"
@ -49,7 +49,8 @@ void io_buffer_t::run_background_fillthread(autoclose_fd_t readfd) {
// 3. read until EAGAIN (would block), appending
// 4. release the lock
// The purpose of holding the lock around the read calls is to ensure that data from background
// processes isn't weirdly interspersed with data directly transferred (from a builtin to a buffer).
// processes isn't weirdly interspersed with data directly transferred (from a builtin to a
// buffer).
const int fd = readfd.fd();
@ -247,7 +248,6 @@ void io_print(const io_chain_t &chain)
}
#endif
int move_fd_to_unused(int fd, const io_chain_t &io_chain, bool cloexec) {
if (fd < 0 || io_chain.get_io_for_fd(fd).get() == NULL) {
return fd;

View file

@ -96,9 +96,7 @@ public:
discard = true;
}
void reset_discard() {
discard = false;
}
void reset_discard() { discard = false; }
/// Serialize the contents to a single string, where explicitly separated elements have a
/// newline appended.
@ -122,7 +120,8 @@ public:
void append(Iterator begin, Iterator end, separation_type_t sep = separation_type_t::inferred) {
if (!try_add_size(std::distance(begin, end))) return;
// Try merging with the last element.
if (sep == separation_type_t::inferred && !elements_.empty() && !elements_.back().is_explicitly_separated()) {
if (sep == separation_type_t::inferred && !elements_.empty() &&
!elements_.back().is_explicitly_separated()) {
elements_.back().contents.append(begin, end);
} else {
elements_.emplace_back(StringType(begin, end), sep);

View file

@ -4,12 +4,12 @@
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <cstring>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <atomic>
#include <cstring>
#include <condition_variable>
#include <queue>

View file

@ -2,8 +2,8 @@
// IWYU pragma: no_include <cstddef>
#include <stddef.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <algorithm>
#include <numeric>
@ -163,12 +163,11 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s
const wcstring &comp = c->comp.at(i);
if (i > 0) {
comp_remaining -= print_max(PAGER_SPACER_STRING, bg, comp_remaining,
true /* has_more */, &line_data);
comp_remaining -=
print_max(PAGER_SPACER_STRING, bg, comp_remaining, true /* has_more */, &line_data);
}
comp_remaining -=
print_max(prefix, prefix_col, comp_remaining, !comp.empty(), &line_data);
comp_remaining -= print_max(prefix, prefix_col, comp_remaining, !comp.empty(), &line_data);
comp_remaining -=
print_max(comp, comp_col, comp_remaining, i + 1 < c->comp.size(), &line_data);
}

View file

@ -14,8 +14,8 @@
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <algorithm>
#include <memory>

View file

@ -127,7 +127,8 @@ class parse_execution_context_t {
io_chain_t *out_chain);
parse_execution_result_t run_1_job(tnode_t<grammar::job> job, const block_t *associated_block);
parse_execution_result_t run_job_conjunction(tnode_t<grammar::job_conjunction> job_conj, const block_t *associated_block);
parse_execution_result_t run_job_conjunction(tnode_t<grammar::job_conjunction> job_conj,
const block_t *associated_block);
template <typename Type>
parse_execution_result_t run_job_list(tnode_t<Type> job_list_node,
const block_t *associated_block);

View file

@ -214,9 +214,7 @@ DEF_ALT(job_decorator) {
};
// A job_conjunction is a job followed by a continuation.
DEF(job_conjunction) produces_sequence<job, job_conjunction_continuation> {
BODY(job_conjunction)
};
DEF(job_conjunction) produces_sequence<job, job_conjunction_continuation>{BODY(job_conjunction)};
DEF_ALT(job_conjunction_continuation) {
using andands = seq<tok_andand, optional_newlines, job_conjunction>;
@ -279,9 +277,8 @@ DEF_ALT(case_item_list) {
ALT_BODY(case_item_list, empty, case_items, blank_line);
};
DEF(case_item) produces_sequence<keyword<parse_keyword_case>, argument_list, tok_end, job_list> {
BODY(case_item)
};
DEF(case_item)
produces_sequence<keyword<parse_keyword_case>, argument_list, tok_end, job_list>{BODY(case_item)};
DEF(block_statement)
produces_sequence<block_header, job_list, end_command, arguments_or_redirections_list>{
@ -297,9 +294,7 @@ DEF_ALT(block_header) {
DEF(for_header)
produces_sequence<keyword<parse_keyword_for>, tok_string, keyword<parse_keyword_in>, argument_list,
tok_end> {
BODY(for_header)
};
tok_end>{BODY(for_header)};
DEF(while_header)
produces_sequence<keyword<parse_keyword_while>, job_conjunction, tok_end, andor_job_list>{

View file

@ -57,7 +57,9 @@ RESOLVE(job_list) {
case parse_token_type_terminate: {
return production_for<empty>(); // no more commands, just transition to empty
}
default: { return NO_PRODUCTION; }
default: {
return NO_PRODUCTION;
}
}
}
@ -166,7 +168,9 @@ RESOLVE(statement) {
return NO_PRODUCTION;
}
// All other keywords fall through to decorated statement.
default: { return production_for<decorated>(); }
default: {
return production_for<decorated>();
}
}
break;
}
@ -176,7 +180,9 @@ RESOLVE(statement) {
case parse_token_type_terminate: {
return NO_PRODUCTION;
}
default: { return NO_PRODUCTION; }
default: {
return NO_PRODUCTION;
}
}
}
@ -188,7 +194,9 @@ RESOLVE(else_clause) {
case parse_keyword_else: {
return production_for<else_cont>();
}
default: { return production_for<empty>(); }
default: {
return production_for<empty>();
}
}
}
@ -200,7 +208,9 @@ RESOLVE(else_continuation) {
case parse_keyword_if: {
return production_for<else_if>();
}
default: { return production_for<else_only>(); }
default: {
return production_for<else_only>();
}
}
}
@ -252,7 +262,9 @@ RESOLVE(argument_list) {
case parse_token_type_string: {
return production_for<arg>();
}
default: { return production_for<empty>(); }
default: {
return production_for<empty>();
}
}
}
@ -267,7 +279,9 @@ RESOLVE(freestanding_argument_list) {
case parse_token_type_end: {
return production_for<semicolon>();
}
default: { return production_for<empty>(); }
default: {
return production_for<empty>();
}
}
}
@ -288,12 +302,13 @@ RESOLVE(block_header) {
case parse_keyword_begin: {
return production_for<beginh>();
}
default: { return NO_PRODUCTION; }
default: {
return NO_PRODUCTION;
}
}
}
RESOLVE(decorated_statement) {
// If this is e.g. 'command --help' then the command is 'command' and not a decoration. If the
// second token is not a string, then this is a naked 'command' and we should execute it as
// undecorated.
@ -357,7 +372,6 @@ RESOLVE(optional_background) {
}
}
const production_element_t *parse_productions::production_for_token(parse_token_type_t node_type,
const parse_token_t &input1,
const parse_token_t &input2,

View file

@ -178,7 +178,9 @@ static wcstring token_type_user_presentable_description(
return L"end of the statement";
case parse_token_type_terminate:
return L"end of the input";
default: { return format_string(L"a %ls", token_type_description(type)); }
default: {
return format_string(L"a %ls", token_type_description(type));
}
}
}
@ -202,7 +204,9 @@ static wcstring block_type_user_presentable_description(parse_token_type_t type)
case symbol_switch_statement: {
return L"switch statement";
}
default: { return token_type_description(type); }
default: {
return token_type_description(type);
}
}
}
@ -690,8 +694,7 @@ void parse_ll_t::parse_error_failed_production(struct parse_stack_element_t &sta
void parse_ll_t::report_tokenizer_error(const tok_t &tok) {
parse_error_code_t parse_error_code = parse_error_from_tokenizer_error(tok.error);
this->parse_error_at_location(tok.offset, tok.length, tok.offset + tok.error_offset,
parse_error_code, L"%ls",
tokenizer_get_error_message(tok.error));
parse_error_code, L"%ls", tokenizer_get_error_message(tok.error));
}
void parse_ll_t::parse_error_unexpected_token(const wchar_t *expected, parse_token_t token) {
@ -730,7 +733,9 @@ static bool type_is_terminal_type(parse_token_type_t type) {
case parse_token_type_terminate: {
return true;
}
default: { return false; }
default: {
return false;
}
}
}

View file

@ -130,9 +130,7 @@ class parse_node_t {
}
/// Indicate if the node has comment nodes.
bool has_comments() const {
return this->flags & parse_node_flag_has_comments;
}
bool has_comments() const { return this->flags & parse_node_flag_has_comments; }
/// Indicates if we have a preceding escaped newline.
bool has_preceding_escaped_newline() const {

View file

@ -328,7 +328,9 @@ static void job_or_process_extent(const wchar_t *buff, size_t cursor_pos, const
}
break;
}
default: { break; }
default: {
break;
}
}
}
@ -510,7 +512,8 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_
if (offset != 0) {
if (finished) {
while ((cmd_tmp[prev_pos] != 0) && (std::wcschr(L";|", cmd_tmp[prev_pos]) != 0)) prev_pos++;
while ((cmd_tmp[prev_pos] != 0) && (std::wcschr(L";|", cmd_tmp[prev_pos]) != 0))
prev_pos++;
*offset = prev_pos;
} else {
*offset = pos;
@ -674,7 +677,8 @@ std::vector<int> parse_util_compute_indents(const wcstring &src) {
// foo ; cas', we get an invalid parse tree (since 'cas' is not valid) but we indent it as if it
// were a case item list.
parse_node_tree_t tree;
parse_tree_from_string(src, parse_flag_continue_after_error | parse_flag_include_comments |
parse_tree_from_string(src,
parse_flag_continue_after_error | parse_flag_include_comments |
parse_flag_accept_incomplete_tokens,
&tree, NULL /* errors */);
@ -826,7 +830,9 @@ static const wchar_t *error_format_for_character(wchar_t wc) {
case VARIABLE_EXPAND_EMPTY: {
return ERROR_NOT_PID;
}
default: { return ERROR_BAD_VAR_CHAR1; }
default: {
return ERROR_BAD_VAR_CHAR1;
}
}
}

View file

@ -393,7 +393,8 @@ void parser_t::stack_trace_internal(size_t block_idx, wcstring *buff) const {
// We can't quote the arguments because we print this in quotes.
// As a special-case, add the empty argument as "".
if (process->argv(i)[0]) {
tmp.append(escape_string(process->argv(i), ESCAPE_ALL | ESCAPE_NO_QUOTED));
tmp.append(
escape_string(process->argv(i), ESCAPE_ALL | ESCAPE_NO_QUOTED));
} else {
tmp.append(L"\"\"");
}

View file

@ -21,8 +21,7 @@
class io_chain_t;
/// event_blockage_t represents a block on events.
struct event_blockage_t {
};
struct event_blockage_t {};
typedef std::list<event_blockage_t> event_blockage_list_t;

View file

@ -15,21 +15,15 @@ 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"
};
static const wcstring subcommand_keywords[]{L"command", L"builtin", L"while", L"exec",
L"if", L"and", L"or", L"not"};
static const string_set_t block_keywords = {
L"for", L"while", L"if",
L"function", L"switch", L"begin"
};
static const string_set_t block_keywords = {L"for", L"while", L"if",
L"function", L"switch", L"begin"};
static const wcstring reserved_keywords[] = {
L"end", L"case", L"else", L"return",
static const wcstring reserved_keywords[] = {L"end", L"case", L"else", L"return",
L"continue", L"break", L"argparse", L"read",
L"set", L"status", L"test", L"["
};
L"set", L"status", L"test", L"["};
// The lists above are purposely implemented separately from the logic below, so that future
// maintainers may assume the contents of the list based off their names, and not off what the

View file

@ -4,9 +4,9 @@
#include "config.h" // IWYU pragma: keep
#include <errno.h>
#include <cstring>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <memory>

View file

@ -5,8 +5,8 @@
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <cstring>
#include <time.h>
#include <cstring>
#include <memory>
#if FISH_USE_POSIX_SPAWN
#include <spawn.h>
@ -49,18 +49,18 @@ bool child_set_group(job_t *j, process_t *p) {
// Put a cap on how many times we retry so we are never stuck here
if (i < 100) {
if (errno == EPERM) {
// The setpgid(2) man page says that EPERM is returned only if attempts are made to
// move processes into groups across session boundaries (which can never be the case
// in fish, anywhere) or to change the process group ID of a session leader (again,
// can never be the case). I'm pretty sure this is a WSL bug, as we see the same
// with tcsetpgrp(2) in other places and it disappears on retry.
// The setpgid(2) man page says that EPERM is returned only if attempts are made
// to move processes into groups across session boundaries (which can never be
// the case in fish, anywhere) or to change the process group ID of a session
// leader (again, can never be the case). I'm pretty sure this is a WSL bug, as
// we see the same with tcsetpgrp(2) in other places and it disappears on retry.
debug_safe(2, "setpgid(2) returned EPERM. Retrying");
continue;
} else if (errno == EINTR) {
// I don't think signals are blocked here. The parent (fish) redirected the signal
// handlers and `setup_child_process()` calls `signal_reset_handlers()` after we're
// done here (and not `signal_unblock()`). We're already in a loop, so let's just
// handle EINTR just in case.
// I don't think signals are blocked here. The parent (fish) redirected the
// signal handlers and `setup_child_process()` calls `signal_reset_handlers()`
// after we're done here (and not `signal_unblock()`). We're already in a loop,
// so let's just handle EINTR just in case.
continue;
}
}
@ -84,7 +84,9 @@ bool child_set_group(job_t *j, process_t *p) {
pid_buff, argv0, job_id_buff, command, getpgid_buff, job_pgid_buff);
if (is_windows_subsystem_for_linux() && errno == EPERM) {
debug_safe(1, "Please update to Windows 10 1809/17763 or higher to address known issues "
debug_safe(
1,
"Please update to Windows 10 1809/17763 or higher to address known issues "
"with process groups and zombie processes.");
}
@ -107,8 +109,8 @@ bool child_set_group(job_t *j, process_t *p) {
/// if it's to run in the foreground.
bool set_child_group(job_t *j, pid_t child_pid) {
if (j->get_flag(job_flag_t::JOB_CONTROL)) {
assert (j->pgid != INVALID_PID
&& "set_child_group called with JOB_CONTROL before job pgid determined!");
assert(j->pgid != INVALID_PID &&
"set_child_group called with JOB_CONTROL before job pgid determined!");
// The parent sets the child's group. This incurs the well-known unavoidable race with the
// child exiting, so ignore ESRCH and EPERM (in case the pid was recycled).
@ -117,14 +119,13 @@ bool set_child_group(job_t *j, pid_t child_pid) {
if (errno != ESRCH && errno != EPERM && errno != EACCES) {
safe_perror("setpgid");
return false;
}
else {
} else {
// Just in case it's ever not right to ignore the setpgid call, (i.e. if this
// ever leads to a terminal hang due if both this setpgid call AND posix_spawn's
// internal setpgid calls failed), write to the debug log so a future developer
// doesn't go crazy trying to track this down.
debug(2, "Error %d while calling setpgid for child %d (probably harmless)",
errno, child_pid);
debug(2, "Error %d while calling setpgid for child %d (probably harmless)", errno,
child_pid);
}
}
} else {
@ -169,7 +170,6 @@ int setup_child_process(process_t *p, const dup2_list_t &dup2s) {
return 0;
}
int g_fork_count = 0;
/// This function is a wrapper around fork. If the fork calls fails with EAGAIN, it is retried

View file

@ -6,13 +6,13 @@
// IWYU pragma: no_include <__bit_reference>
#include "config.h"
#include <atomic>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <atomic>
#include <cwchar>
#if HAVE_TERM_H
#include <curses.h>
@ -402,7 +402,8 @@ static void process_mark_finished_children(bool block_ok) {
// Poll disowned processes/process groups, but do nothing with the result. Only used to avoid
// zombie processes. Entries have already been converted to negative for process groups.
int status;
s_disowned_pids.erase(std::remove_if(s_disowned_pids.begin(), s_disowned_pids.end(),
s_disowned_pids.erase(
std::remove_if(s_disowned_pids.begin(), s_disowned_pids.end(),
[&status](pid_t pid) { return waitpid(pid, &status, WNOHANG) > 0; }),
s_disowned_pids.end());
}
@ -701,8 +702,8 @@ void proc_update_jiffies() {
}
}
// Return control of the terminal to a job's process group. restore_attrs is true if we are restoring
// a previously-stopped job, in which case we need to restore terminal attributes.
// Return control of the terminal to a job's process group. restore_attrs is true if we are
// restoring a previously-stopped job, in which case we need to restore terminal attributes.
bool terminal_give_to_job(const job_t *j, bool restore_attrs) {
if (j->pgid == 0) {
debug(2, "terminal_give_to_job() returning early due to no process group");

View file

@ -352,8 +352,7 @@ class job_t {
/// untruncated job string when we don't care what the job is, only which of the currently
/// running jobs it is.
wcstring preview() const {
if (processes.empty())
return L"";
if (processes.empty()) return L"";
// Note argv0 may be empty in e.g. a block process.
const wchar_t *argv0 = processes.front()->argv0();
wcstring result = argv0 ? argv0 : L"null";
@ -534,8 +533,9 @@ void hup_background_jobs();
/// Give ownership of the terminal to the specified job.
///
/// \param j The job to give the terminal to.
/// \param restore_attrs If this variable is set, we are giving back control to a job that was previously
/// stopped. In that case, we need to set the terminal attributes to those saved in the job.
/// \param restore_attrs If this variable is set, we are giving back control to a job that was
/// previously stopped. In that case, we need to set the terminal attributes to those saved in the
/// job.
bool terminal_give_to_job(const job_t *j, bool restore_attrs);
/// Given that we are about to run a builtin, acquire the terminal if it is owned by the given job.

View file

@ -32,8 +32,8 @@
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <algorithm>
#include <atomic>
@ -436,9 +436,7 @@ class reader_data_t : public std::enable_shared_from_this<reader_data_t> {
/// Insert the character into the command line buffer and print it to the screen using syntax
/// highlighting, etc.
bool insert_char(editable_line_t *el, wchar_t c) {
return insert_string(el, wcstring{c});
}
bool insert_char(editable_line_t *el, wchar_t c) { return insert_string(el, wcstring{c}); }
void move_word(editable_line_t *el, bool move_right, bool erase, enum move_word_style_t style,
bool newv);
@ -643,8 +641,9 @@ void reader_data_t::repaint() {
size_t cursor_position = focused_on_pager ? pager.cursor_position() : cmd_line->position;
// Prepend the mode prompt to the left prompt.
s_write(&screen, mode_prompt_buff + left_prompt_buff, right_prompt_buff, full_line, cmd_line->size(), colors,
indents, cursor_position, current_page_rendering, focused_on_pager);
s_write(&screen, mode_prompt_buff + left_prompt_buff, right_prompt_buff, full_line,
cmd_line->size(), colors, indents, cursor_position, current_page_rendering,
focused_on_pager);
repaint_needed = false;
}
@ -909,8 +908,7 @@ void reader_data_t::exec_mode_prompt() {
mode_prompt_buff.clear();
if (function_exists(MODE_PROMPT_FUNCTION_NAME, parser())) {
wcstring_list_t mode_indicator_list;
exec_subshell(MODE_PROMPT_FUNCTION_NAME, parser(), mode_indicator_list,
false);
exec_subshell(MODE_PROMPT_FUNCTION_NAME, parser(), mode_indicator_list, false);
// We do not support multiple lines in the mode indicator, so just concatenate all of
// them.
for (size_t i = 0; i < mode_indicator_list.size(); i++) {
@ -1776,7 +1774,6 @@ static void reader_interactive_init() {
signal_set_handlers();
}
// It shouldn't be necessary to place fish in its own process group and force control
// of the terminal, but that works around fish being started with an invalid pgroup,
// such as when launched via firejail (#5295)
@ -2497,7 +2494,8 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
case rl::repaint_mode: {
// Repaint the mode-prompt only if it exists.
// This is an optimization basically exclusively for vi-mode, since the prompt
// may sometimes take a while but when switching the mode all we care about is the mode-prompt.
// may sometimes take a while but when switching the mode all we care about is the
// mode-prompt.
if (function_exists(MODE_PROMPT_FUNCTION_NAME, parser())) {
exec_mode_prompt();
s_reset(&screen, screen_reset_current_line_and_prompt);
@ -2893,16 +2891,16 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
}
case rl::backward_word:
case rl::backward_bigword: {
auto move_style = (c == rl::backward_word) ? move_word_style_punctuation
: move_word_style_whitespace;
auto move_style =
(c == rl::backward_word) ? move_word_style_punctuation : move_word_style_whitespace;
move_word(active_edit_line(), MOVE_DIR_LEFT, false /* do not erase */, move_style,
false);
break;
}
case rl::forward_word:
case rl::forward_bigword: {
auto move_style = (c == rl::forward_word) ? move_word_style_punctuation
: move_word_style_whitespace;
auto move_style =
(c == rl::forward_word) ? move_word_style_punctuation : move_word_style_whitespace;
editable_line_t *el = active_edit_line();
if (el->position < el->size()) {
move_word(el, MOVE_DIR_RIGHT, false /* do not erase */, move_style, false);

View file

@ -62,8 +62,8 @@ class dup2_list_t {
static maybe_t<dup2_list_t> resolve_chain(const io_chain_t &);
/// \return the fd ultimately dup'd to a target fd, or -1 if the target is closed.
/// For example, if target fd is 1, and we have a dup2 chain 5->3 and 3->1, then we will return 5.
/// If the target is not referenced in the chain, returns target.
/// For example, if target fd is 1, and we have a dup2 chain 5->3 and 3->1, then we will
/// return 5. If the target is not referenced in the chain, returns target.
int fd_for_target_fd(int target) const;
};

View file

@ -10,9 +10,9 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <time.h>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#if HAVE_CURSES_H
@ -105,7 +105,8 @@ static bool is_screen_name_escape_seq(const wchar_t *code, size_t *resulting_len
// Consider just <esc>k to be the code.
*resulting_length = 2;
} else {
const wchar_t *escape_sequence_end = screen_name_end + std::wcslen(screen_name_end_sentinel);
const wchar_t *escape_sequence_end =
screen_name_end + std::wcslen(screen_name_end_sentinel);
*resulting_length = escape_sequence_end - code;
}
return true;
@ -191,7 +192,10 @@ static bool is_color_escape_seq(const wchar_t *code, size_t *resulting_length) {
// Detect these terminfo color escapes with parameter value up to max_colors, all of which
// don't move the cursor.
const char *const esc[] = {
set_a_foreground, set_a_background, set_foreground, set_background,
set_a_foreground,
set_a_background,
set_foreground,
set_background,
};
for (size_t p = 0; p < sizeof esc / sizeof *esc; p++) {
@ -218,8 +222,7 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length)
enter_standout_mode, exit_standout_mode, enter_blink_mode, enter_protected_mode,
enter_italics_mode, exit_italics_mode, enter_reverse_mode, enter_shadow_mode,
exit_shadow_mode, enter_standout_mode, exit_standout_mode, enter_secure_mode,
enter_dim_mode, enter_blink_mode, enter_alt_charset_mode, exit_alt_charset_mode
};
enter_dim_mode, enter_blink_mode, enter_alt_charset_mode, exit_alt_charset_mode};
for (size_t p = 0; p < sizeof esc2 / sizeof *esc2; p++) {
if (!esc2[p]) continue;
@ -237,8 +240,8 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length)
}
/// Returns the number of characters in the escape code starting at 'code'. We only handle sequences
/// that begin with \x1B. If it doesn't we return zero. We also return zero if we don't recognize the
/// escape sequence based on querying terminfo and other heuristics.
/// that begin with \x1B. If it doesn't we return zero. We also return zero if we don't recognize
/// the escape sequence based on querying terminfo and other heuristics.
size_t escape_code_length(const wchar_t *code) {
assert(code != NULL);
if (*code != L'\x1B') return 0;
@ -495,8 +498,8 @@ static void s_move(screen_t *s, int new_x, int new_y) {
// Use the bulk ('multi') output for cursor movement if it is supported and it would be shorter
// Note that this is required to avoid some visual glitches in iTerm (issue #1448).
bool use_multi =
multi_str != NULL && multi_str[0] != '\0' && abs(x_steps) * std::strlen(str) > std::strlen(multi_str);
bool use_multi = multi_str != NULL && multi_str[0] != '\0' &&
abs(x_steps) * std::strlen(str) > std::strlen(multi_str);
if (use_multi && cur_term) {
char *multi_param = tparm((char *)multi_str, abs(x_steps));
writembs(outp, multi_param);
@ -1132,8 +1135,8 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) {
abandon_line_string.append(get_omitted_newline_str());
if (cur_term && exit_attribute_mode) {
abandon_line_string.append(
str2wcstring(tparm((char *)exit_attribute_mode))); // normal text ANSI escape sequence
abandon_line_string.append(str2wcstring(
tparm((char *)exit_attribute_mode))); // normal text ANSI escape sequence
}
int newline_glitch_width = term_has_xn ? 0 : 1;

View file

@ -416,4 +416,3 @@ void signal_unblock_all() {
sigemptyset(&iset);
sigprocmask(SIG_SETMASK, &iset, NULL);
}

View file

@ -24,26 +24,36 @@
// This version has been altered and ported to C++ for inclusion in fish.
#include "tinyexpr.h"
#include <stdlib.h>
#include <math.h>
#include <cstring>
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <algorithm>
#include <iterator>
#include <utility>
// TODO: It would be nice not to rely on a typedef for this, especially one that can only do functions with two args.
// TODO: It would be nice not to rely on a typedef for this, especially one that can only do
// functions with two args.
typedef double (*te_fun2)(double, double);
typedef double (*te_fun1)(double);
typedef double (*te_fun0)();
enum {
TE_CONSTANT = 0,
TE_FUNCTION0, TE_FUNCTION1, TE_FUNCTION2, TE_FUNCTION3,
TOK_NULL, TOK_ERROR, TOK_END, TOK_SEP,
TOK_OPEN, TOK_CLOSE, TOK_NUMBER, TOK_INFIX
TE_FUNCTION0,
TE_FUNCTION1,
TE_FUNCTION2,
TE_FUNCTION3,
TOK_NULL,
TOK_ERROR,
TOK_END,
TOK_SEP,
TOK_OPEN,
TOK_CLOSE,
TOK_NUMBER,
TOK_INFIX
};
int get_arity(const int type) {
@ -55,7 +65,10 @@ int get_arity(const int type) {
typedef struct te_expr {
int type;
union {double value; const void *function;};
union {
double value;
const void *function;
};
te_expr *parameters[];
} te_expr;
@ -67,7 +80,10 @@ typedef struct te_builtin {
} te_builtin;
typedef struct state {
union {double value; const void *function;};
union {
double value;
const void *function;
};
const char *start;
const char *next;
int type;
@ -103,7 +119,6 @@ static te_expr *new_expr(const int type, const te_expr *parameters[]) {
return ret;
}
void te_free_parameters(te_expr *n) {
if (!n) return;
int arity = get_arity(n->type);
@ -114,27 +129,22 @@ void te_free_parameters(te_expr *n) {
}
}
void te_free(te_expr *n) {
if (!n) return;
te_free_parameters(n);
free(n);
}
static constexpr double pi() { return M_PI; }
static constexpr double e() { return M_E; }
static double fac(double a) { /* simplest version of fac */
if (a < 0.0)
return NAN;
if (a > UINT_MAX)
return INFINITY;
if (a < 0.0) return NAN;
if (a > UINT_MAX) return INFINITY;
unsigned int ua = (unsigned int)(a);
unsigned long int result = 1, i;
for (i = 1; i <= ua; i++) {
if (i > ULONG_MAX / result)
return INFINITY;
if (i > ULONG_MAX / result) return INFINITY;
result *= i;
}
return (double)result;
@ -147,8 +157,7 @@ static double ncr(double n, double r) {
unsigned long int result = 1;
if (ur > un / 2) ur = un - ur;
for (i = 1; i <= ur; i++) {
if (result > ULONG_MAX / (un - ur + i))
return INFINITY;
if (result > ULONG_MAX / (un - ur + i)) return INFINITY;
result *= un - ur + i;
result /= i;
}
@ -183,14 +192,14 @@ static const te_builtin functions[] = {
{"sinh", (const void *)(te_fun1)sinh, TE_FUNCTION1},
{"sqrt", (const void *)(te_fun1)sqrt, TE_FUNCTION1},
{"tan", (const void *)(te_fun1)tan, TE_FUNCTION1},
{"tanh", (const void *)(te_fun1)tanh, TE_FUNCTION1}
};
{"tanh", (const void *)(te_fun1)tanh, TE_FUNCTION1}};
static const te_builtin *find_builtin(const char *name, int len) {
const auto end = std::end(functions);
const te_builtin *found = std::lower_bound(std::begin(functions), end, name,
[len](const te_builtin &lhs, const char *rhs) {
// The length is important because that's where the parens start
// The length is important because that's where
// the parens start
return std::strncmp(lhs.name, rhs, len) < 0;
});
// We need to compare again because we might have gotten the first "larger" element.
@ -228,19 +237,23 @@ void next_token(state *s) {
if (s->next[0] >= 'a' && s->next[0] <= 'z') {
const char *start;
start = s->next;
while ((s->next[0] >= 'a' && s->next[0] <= 'z') || (s->next[0] >= '0' && s->next[0] <= '9') || (s->next[0] == '_')) s->next++;
while ((s->next[0] >= 'a' && s->next[0] <= 'z') ||
(s->next[0] >= '0' && s->next[0] <= '9') || (s->next[0] == '_'))
s->next++;
const te_builtin *var = find_builtin(start, s->next - start);
if (var) {
switch (var->type) {
case TE_FUNCTION0: case TE_FUNCTION1: case TE_FUNCTION2: case TE_FUNCTION3:
case TE_FUNCTION0:
case TE_FUNCTION1:
case TE_FUNCTION2:
case TE_FUNCTION3:
s->type = var->type;
s->function = var->address;
break;
}
} else if (s->type != TOK_ERROR
|| s->error == TE_ERROR_UNKNOWN) {
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) {
// Our error is more specific, so it takes precedence.
s->type = TOK_ERROR;
s->error = TE_ERROR_UNKNOWN_VARIABLE;
@ -249,29 +262,60 @@ void next_token(state *s) {
/* Look for an operator or special character. */
switch (s->next++ [0]) {
// The "te_fun2" casts are necessary to pick the right overload.
case '+': s->type = TOK_INFIX; s->function = (const void *)(te_fun2) add; break;
case '-': s->type = TOK_INFIX; s->function = (const void *)(te_fun2) sub; break;
case '*': s->type = TOK_INFIX; s->function = (const void *)(te_fun2) mul; break;
case '/': s->type = TOK_INFIX; s->function = (const void *)(te_fun2) divide; break;
case '^': s->type = TOK_INFIX; s->function = (const void *)(te_fun2) pow; break;
case '%': s->type = TOK_INFIX; s->function = (const void *)(te_fun2) fmod; break;
case '(': s->type = TOK_OPEN; break;
case ')': s->type = TOK_CLOSE; break;
case ',': s->type = TOK_SEP; break;
case ' ': case '\t': case '\n': case '\r': break;
default: s->type = TOK_ERROR; s->error = TE_ERROR_MISSING_OPERATOR; break;
case '+':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)add;
break;
case '-':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)sub;
break;
case '*':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)mul;
break;
case '/':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)divide;
break;
case '^':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)pow;
break;
case '%':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)fmod;
break;
case '(':
s->type = TOK_OPEN;
break;
case ')':
s->type = TOK_CLOSE;
break;
case ',':
s->type = TOK_SEP;
break;
case ' ':
case '\t':
case '\n':
case '\r':
break;
default:
s->type = TOK_ERROR;
s->error = TE_ERROR_MISSING_OPERATOR;
break;
}
}
}
} while (s->type == TOK_NULL);
}
static te_expr *expr(state *s);
static te_expr *power(state *s);
static te_expr *base(state *s) {
/* <base> = <constant> | <variable> | <function-0> {"(" ")"} | <function-1> <power> | <function-X> "(" <expr> {"," <expr>} ")" | "(" <list> ")" */
/* <base> = <constant> | <variable> | <function-0> {"(" ")"} | <function-1> <power> |
* <function-X> "(" <expr> {"," <expr>} ")" | "(" <list> ")" */
te_expr *ret;
int arity;
@ -290,8 +334,7 @@ static te_expr *base(state *s) {
next_token(s);
if (s->type == TOK_CLOSE) {
next_token(s);
} else if (s->type != TOK_ERROR
|| s->error == TE_ERROR_UNKNOWN) {
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) {
s->type = TOK_ERROR;
s->error = TE_ERROR_MISSING_CLOSING_PAREN;
}
@ -299,7 +342,8 @@ static te_expr *base(state *s) {
break;
case TE_FUNCTION1:
case TE_FUNCTION2: case TE_FUNCTION3:
case TE_FUNCTION2:
case TE_FUNCTION3:
arity = get_arity(s->type);
ret = new_expr(s->type, 0);
@ -317,14 +361,11 @@ static te_expr *base(state *s) {
}
if (s->type == TOK_CLOSE && i == arity - 1) {
next_token(s);
} else if (s->type != TOK_ERROR
|| s->error == TE_ERROR_UNKNOWN) {
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) {
s->type = TOK_ERROR;
s->error = i < arity ? TE_ERROR_TOO_FEW_ARGS
: TE_ERROR_TOO_MANY_ARGS;
s->error = i < arity ? TE_ERROR_TOO_FEW_ARGS : TE_ERROR_TOO_MANY_ARGS;
}
} else if (s->type != TOK_ERROR
|| s->error == TE_ERROR_UNKNOWN) {
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) {
s->type = TOK_ERROR;
s->error = TE_ERROR_MISSING_OPENING_PAREN;
}
@ -336,8 +377,7 @@ static te_expr *base(state *s) {
ret = expr(s);
if (s->type == TOK_CLOSE) {
next_token(s);
} else if (s->type != TOK_ERROR
|| s->error == TE_ERROR_UNKNOWN) {
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) {
s->type = TOK_ERROR;
s->error = TE_ERROR_MISSING_CLOSING_PAREN;
}
@ -365,7 +405,6 @@ static te_expr *base(state *s) {
return ret;
}
static te_expr *power(state *s) {
/* <power> = {("-" | "+")} <base> */
int sign = 1;
@ -400,12 +439,13 @@ static te_expr *factor(state *s) {
return ret;
}
static te_expr *term(state *s) {
/* <term> = <factor> {("*" | "/" | "%") <factor>} */
te_expr *ret = factor(s);
while (s->type == TOK_INFIX && (s->function == (const void*)(te_fun2)mul || s->function == (const void*)(te_fun2)divide || s->function == (const void*)(te_fun2)fmod)) {
while (s->type == TOK_INFIX && (s->function == (const void *)(te_fun2)mul ||
s->function == (const void *)(te_fun2)divide ||
s->function == (const void *)(te_fun2)fmod)) {
te_fun2 t = (te_fun2)s->function;
next_token(s);
ret = NEW_EXPR(TE_FUNCTION2, ret, factor(s));
@ -415,7 +455,6 @@ static te_expr *term(state *s) {
return ret;
}
static te_expr *expr(state *s) {
/* <expr> = <term> {("+" | "-") <term>} */
te_expr *ret = term(s);
@ -430,16 +469,15 @@ static te_expr *expr(state *s) {
return ret;
}
#define TE_FUN(...) ((double (*)(__VA_ARGS__))n->function)
#define M(e) te_eval(n->parameters[e])
double te_eval(const te_expr *n) {
if (!n) return NAN;
switch (n->type) {
case TE_CONSTANT: return n->value;
case TE_CONSTANT:
return n->value;
case TE_FUNCTION0:
return TE_FUN(void)();
case TE_FUNCTION1:
@ -448,9 +486,9 @@ double te_eval(const te_expr *n) {
return TE_FUN(double, double)(M(0), M(1));
case TE_FUNCTION3:
return TE_FUN(double, double, double)(M(0), M(1), M(2));
default: return NAN;
default:
return NAN;
}
}
#undef TE_FUN
@ -476,7 +514,6 @@ static void optimize(te_expr *n) {
}
}
te_expr *te_compile(const char *expression, te_error_t *error) {
state s;
s.start = s.next = expression;
@ -492,12 +529,11 @@ te_expr *te_compile(const char *expression, te_error_t *error) {
if (s.error != TE_ERROR_NONE) {
error->type = s.error;
} else {
// If we're not at the end but there's no error, then that means we have a superfluous
// token that we have no idea what to do with.
// This occurs in e.g. `2 + 2 4` - the "4" is just not part of the expression.
// We can report either "too many arguments" or "expected operator", but the operator
// should be reported between the "2" and the "4".
// So we report TOO_MANY_ARGS on the "4".
// If we're not at the end but there's no error, then that means we have a
// superfluous token that we have no idea what to do with. This occurs in e.g. `2 +
// 2 4` - the "4" is just not part of the expression. We can report either "too many
// arguments" or "expected operator", but the operator should be reported between
// the "2" and the "4". So we report TOO_MANY_ARGS on the "4".
error->type = TE_ERROR_TOO_MANY_ARGS;
}
}

View file

@ -50,7 +50,8 @@ enum parse_bool_statement_type_t bool_statement_type(tnode_t<grammar::job_decora
return static_cast<parse_bool_statement_type_t>(stmt.tag());
}
enum parse_bool_statement_type_t bool_statement_type(tnode_t<grammar::job_conjunction_continuation> cont) {
enum parse_bool_statement_type_t bool_statement_type(
tnode_t<grammar::job_conjunction_continuation> cont) {
return static_cast<parse_bool_statement_type_t>(cont.tag());
}

View file

@ -239,7 +239,8 @@ parse_statement_decoration_t get_decoration(tnode_t<grammar::plain_statement> st
/// Return the type for a boolean statement.
enum parse_bool_statement_type_t bool_statement_type(tnode_t<grammar::job_decorator> stmt);
enum parse_bool_statement_type_t bool_statement_type(tnode_t<grammar::job_conjunction_continuation> stmt);
enum parse_bool_statement_type_t bool_statement_type(
tnode_t<grammar::job_conjunction_continuation> stmt);
/// Given a redirection, get the redirection type (or none) and target (file path, or fd).
maybe_t<redirection_type_t> redirection_type(tnode_t<grammar::redirection> redirection,

View file

@ -5,8 +5,8 @@
#include <fcntl.h>
#include <limits.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <string>
#include <type_traits>
@ -112,7 +112,9 @@ static bool tok_is_string_character(wchar_t c, bool is_first) {
// Conditional separator.
return !caret_redirs() || !is_first;
}
default: { return true; }
default: {
return true;
}
}
}
@ -629,7 +631,9 @@ bool move_word_state_machine_t::consume_char_punctuation(wchar_t c) {
break;
}
case s_end:
default: { break; }
default: {
break;
}
}
}
return consumed;
@ -697,7 +701,9 @@ bool move_word_state_machine_t::consume_char_path_components(wchar_t c) {
break;
}
case s_end:
default: { break; }
default: {
break;
}
}
}
return consumed;
@ -731,7 +737,9 @@ bool move_word_state_machine_t::consume_char_whitespace(wchar_t c) {
break;
}
case s_end:
default: { break; }
default: {
break;
}
}
}
return consumed;

View file

@ -139,7 +139,9 @@ static int __utf8_forbitten(unsigned char octet) {
case 0xff: {
return -1;
}
default: { return 0; }
default: {
return 0;
}
}
}

View file

@ -4,8 +4,8 @@
#include <errno.h>
#include <stddef.h>
#include <sys/time.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include "common.h"
#include "fallback.h" // IWYU pragma: keep

View file

@ -47,9 +47,7 @@ wcstring truncate(const wcstring &input, int max_len, ellipsis_type etype) {
return output;
}
wcstring trim(const wcstring &input) {
return trim(input, L"\t\v \r\n");
}
wcstring trim(const wcstring &input) { return trim(input, L"\t\v \r\n"); }
wcstring trim(const wcstring &input, const wchar_t *any_of) {
auto begin_offset = input.find_first_not_of(any_of);

View file

@ -63,7 +63,8 @@ enum class ellipsis_type {
Shortest,
};
wcstring truncate(const wcstring &input, int max_len, ellipsis_type etype = ellipsis_type::Prettiest);
wcstring truncate(const wcstring &input, int max_len,
ellipsis_type etype = ellipsis_type::Prettiest);
wcstring trim(const wcstring &input);
wcstring trim(const wcstring &input, const wchar_t *any_of);

View file

@ -39,8 +39,8 @@
#include "config.h" // IWYU pragma: keep
#include <stdio.h>
#include <cwchar>
#include <cstring>
#include <cwchar>
// This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves
// differently for the user, since it allows the user to intersperse the options with the other
@ -263,8 +263,8 @@ void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woptio
else {
if (wopterr) {
if (argv[woptind - 1][1] == '-') // --option
std::fwprintf(stderr, _(L"%ls: Option '--%ls' doesn't allow an argument\n"), argv[0],
pfound->name);
std::fwprintf(stderr, _(L"%ls: Option '--%ls' doesn't allow an argument\n"),
argv[0], pfound->name);
else
// +option or -option
std::fwprintf(stderr, _(L"%ls: Option '%lc%ls' doesn't allow an argument\n"),

View file

@ -336,8 +336,9 @@ bool wildcard_match(const wcstring &str, const wcstring &wc, bool leading_dots_f
/// \param stat_res The result of calling stat on the file
/// \param buf The struct buf output of calling stat on the file
/// \param err The errno value after a failed stat call on the file.
static const wchar_t *file_get_desc(const wcstring &filename, int lstat_res, const struct stat &lbuf,
int stat_res, const struct stat &buf, int err) {
static const wchar_t *file_get_desc(const wcstring &filename, int lstat_res,
const struct stat &lbuf, int stat_res, const struct stat &buf,
int err) {
if (lstat_res) {
return COMPLETE_FILE_DESC;
}

View file

@ -9,8 +9,8 @@
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/stat.h>
#include <cstring>
#if defined(__linux__)
#include <sys/statfs.h>
#endif
@ -18,8 +18,8 @@
#include <sys/statvfs.h>
#include <sys/types.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <atomic>
#include <string>
@ -231,13 +231,9 @@ dir_t::~dir_t() {
}
}
bool dir_t::valid() const {
return this->dir != nullptr;
}
bool dir_t::valid() const { return this->dir != nullptr; }
bool dir_t::read(wcstring &name) {
return wreaddir(this->dir, name);
}
bool dir_t::read(wcstring &name) { return wreaddir(this->dir, name); }
int wstat(const wcstring &file_name, struct stat *buf) {
const cstring tmp = wcs2string(file_name);
@ -289,7 +285,9 @@ int make_fd_blocking(int fd) {
int fd_check_is_remote(int fd) {
#if defined(__linux__)
struct statfs buf{0};
struct statfs buf {
0
};
if (fstatfs(fd, &buf) < 0) {
return -1;
}

View file

@ -3,13 +3,13 @@
#define FISH_WUTIL_H
#include <dirent.h>
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <locale.h>
#include <string>
#include <wctype.h>
#include <string>
#ifdef HAVE_XLOCALE_H
#include <xlocale.h>
@ -190,7 +190,7 @@ namespace std {
return hasher1(f.device) ^ hasher2(f.inode);
}
};
}
} // namespace std
#endif
file_id_t file_id_for_fd(int fd);