mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
[clang-tidy] Replace NULL with nullptr
Found with modernize-use-nullptr Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
8d54e928cd
commit
1055ff321c
80 changed files with 721 additions and 710 deletions
|
@ -89,11 +89,11 @@ bool builtin_data_t::operator<(const builtin_data_t *other) const {
|
||||||
/// Counts the number of arguments in the specified null-terminated array
|
/// Counts the number of arguments in the specified null-terminated array
|
||||||
int builtin_count_args(const wchar_t *const *argv) {
|
int builtin_count_args(const wchar_t *const *argv) {
|
||||||
int argc;
|
int argc;
|
||||||
for (argc = 1; argv[argc] != NULL;) {
|
for (argc = 1; argv[argc] != nullptr;) {
|
||||||
argc++;
|
argc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(argv[argc] == NULL);
|
assert(argv[argc] == nullptr);
|
||||||
return argc;
|
return argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,11 +101,11 @@ int builtin_count_args(const wchar_t *const *argv) {
|
||||||
/// to stderr. Used by the builtin commands.
|
/// to stderr. Used by the builtin commands.
|
||||||
void builtin_wperror(const wchar_t *s, io_streams_t &streams) {
|
void builtin_wperror(const wchar_t *s, io_streams_t &streams) {
|
||||||
char *err = std::strerror(errno);
|
char *err = std::strerror(errno);
|
||||||
if (s != NULL) {
|
if (s != nullptr) {
|
||||||
streams.err.append(s);
|
streams.err.append(s);
|
||||||
streams.err.append(L": ");
|
streams.err.append(L": ");
|
||||||
}
|
}
|
||||||
if (err != NULL) {
|
if (err != nullptr) {
|
||||||
const wcstring werr = str2wcstring(err);
|
const wcstring werr = str2wcstring(err);
|
||||||
streams.err.append(werr);
|
streams.err.append(werr);
|
||||||
streams.err.push_back(L'\n');
|
streams.err.push_back(L'\n');
|
||||||
|
@ -113,15 +113,15 @@ void builtin_wperror(const wchar_t *s, io_streams_t &streams) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const wchar_t *const short_options = L"+:h";
|
static const wchar_t *const short_options = L"+:h";
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int argc,
|
int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int argc,
|
||||||
wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) { //!OCLINT(too few branches)
|
switch (opt) { //!OCLINT(too few branches)
|
||||||
case 'h': {
|
case 'h': {
|
||||||
opts.print_help = true;
|
opts.print_help = true;
|
||||||
|
@ -283,7 +283,7 @@ static int builtin_break_continue(parser_t &parser, io_streams_t &streams, wchar
|
||||||
/// Implementation of the builtin breakpoint command, used to launch the interactive debugger.
|
/// Implementation of the builtin breakpoint command, used to launch the interactive debugger.
|
||||||
static int builtin_breakpoint(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
static int builtin_breakpoint(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
if (argv[1] != NULL) {
|
if (argv[1] != nullptr) {
|
||||||
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, cmd, 0, builtin_count_args(argv) - 1);
|
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, cmd, 0, builtin_count_args(argv) - 1);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ static int builtin_breakpoint(parser_t &parser, io_streams_t &streams, wchar_t *
|
||||||
int builtin_true(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
int builtin_true(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
UNUSED(parser);
|
UNUSED(parser);
|
||||||
UNUSED(streams);
|
UNUSED(streams);
|
||||||
if (argv[1] != NULL) {
|
if (argv[1] != nullptr) {
|
||||||
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, argv[0], 0, builtin_count_args(argv) - 1);
|
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, argv[0], 0, builtin_count_args(argv) - 1);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ int builtin_true(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
int builtin_false(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
int builtin_false(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
UNUSED(parser);
|
UNUSED(parser);
|
||||||
UNUSED(streams);
|
UNUSED(streams);
|
||||||
if (argv[1] != NULL) {
|
if (argv[1] != nullptr) {
|
||||||
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, argv[0], 0, builtin_count_args(argv) - 1);
|
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, argv[0], 0, builtin_count_args(argv) - 1);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ static const builtin_data_t *builtin_lookup(const wcstring &name) {
|
||||||
if (found != array_end && name == found->name) {
|
if (found != array_end && name == found->name) {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize builtin data.
|
/// Initialize builtin data.
|
||||||
|
@ -433,7 +433,8 @@ static bool cmd_needs_help(const wchar_t *cmd) { return contains(help_builtins,
|
||||||
proc_status_t builtin_run(parser_t &parser, int job_pgid, wchar_t **argv, io_streams_t &streams) {
|
proc_status_t builtin_run(parser_t &parser, int job_pgid, wchar_t **argv, io_streams_t &streams) {
|
||||||
UNUSED(parser);
|
UNUSED(parser);
|
||||||
UNUSED(streams);
|
UNUSED(streams);
|
||||||
if (argv == NULL || argv[0] == NULL) return proc_status_t::from_exit_code(STATUS_INVALID_ARGS);
|
if (argv == nullptr || argv[0] == nullptr)
|
||||||
|
return proc_status_t::from_exit_code(STATUS_INVALID_ARGS);
|
||||||
|
|
||||||
// We can be handed a keyword by the parser as if it was a command. This happens when the user
|
// We can be handed a keyword by the parser as if it was a command. This happens when the user
|
||||||
// follows the keyword by `-h` or `--help`. Since it isn't really a builtin command we need to
|
// follows the keyword by `-h` or `--help`. Since it isn't really a builtin command we need to
|
||||||
|
@ -471,7 +472,7 @@ wcstring_list_t builtin_get_names() {
|
||||||
|
|
||||||
/// Insert all builtin names into list.
|
/// Insert all builtin names into list.
|
||||||
void builtin_get_names(std::vector<completion_t> *list) {
|
void builtin_get_names(std::vector<completion_t> *list) {
|
||||||
assert(list != NULL);
|
assert(list != nullptr);
|
||||||
list->reserve(list->size() + BUILTIN_COUNT);
|
list->reserve(list->size() + BUILTIN_COUNT);
|
||||||
for (size_t i = 0; i < BUILTIN_COUNT; i++) {
|
for (size_t i = 0; i < BUILTIN_COUNT; i++) {
|
||||||
append_completion(list, builtin_datas[i].name);
|
append_completion(list, builtin_datas[i].name);
|
||||||
|
|
|
@ -60,10 +60,10 @@ struct argparse_cmd_opts_t {
|
||||||
|
|
||||||
static const wchar_t *const short_options = L"+:hn:six:N:X:";
|
static const wchar_t *const short_options = L"+:hn:six:N:X:";
|
||||||
static const struct woption long_options[] = {
|
static const struct woption long_options[] = {
|
||||||
{L"stop-nonopt", no_argument, NULL, 's'}, {L"ignore-unknown", no_argument, NULL, 'i'},
|
{L"stop-nonopt", no_argument, nullptr, 's'}, {L"ignore-unknown", no_argument, nullptr, 'i'},
|
||||||
{L"name", required_argument, NULL, 'n'}, {L"exclusive", required_argument, NULL, 'x'},
|
{L"name", required_argument, nullptr, 'n'}, {L"exclusive", required_argument, nullptr, 'x'},
|
||||||
{L"help", no_argument, NULL, 'h'}, {L"min-args", required_argument, NULL, 'N'},
|
{L"help", no_argument, nullptr, 'h'}, {L"min-args", required_argument, nullptr, 'N'},
|
||||||
{L"max-args", required_argument, NULL, 'X'}, {NULL, 0, NULL, 0}};
|
{L"max-args", required_argument, nullptr, 'X'}, {nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
// Check if any pair of mutually exclusive options was seen. Note that since every option must have
|
// 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.
|
// a short name we only need to check those.
|
||||||
|
@ -343,7 +343,7 @@ static int parse_cmd_opts(argparse_cmd_opts_t &opts, int *optind, //!OCLINT(hig
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'n': {
|
case 'n': {
|
||||||
opts.name = w.woptarg;
|
opts.name = w.woptarg;
|
||||||
|
@ -440,10 +440,10 @@ static void populate_option_strings(const argparse_cmd_opts_t &opts, wcstring *s
|
||||||
|
|
||||||
if (!opt_spec->long_flag.empty()) {
|
if (!opt_spec->long_flag.empty()) {
|
||||||
long_options->push_back(
|
long_options->push_back(
|
||||||
{opt_spec->long_flag.c_str(), arg_type, NULL, opt_spec->short_flag});
|
{opt_spec->long_flag.c_str(), arg_type, nullptr, opt_spec->short_flag});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long_options->push_back({NULL, 0, NULL, 0});
|
long_options->push_back({nullptr, 0, nullptr, 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
static int validate_arg(parser_t &parser, const argparse_cmd_opts_t &opts, option_spec_t *opt_spec,
|
static int validate_arg(parser_t &parser, const argparse_cmd_opts_t &opts, option_spec_t *opt_spec,
|
||||||
|
@ -501,7 +501,7 @@ static int validate_and_store_implicit_int(parser_t &parser, const argparse_cmd_
|
||||||
opt_spec->vals.clear();
|
opt_spec->vals.clear();
|
||||||
opt_spec->vals.push_back(wcstring(val));
|
opt_spec->vals.push_back(wcstring(val));
|
||||||
opt_spec->num_seen++;
|
opt_spec->num_seen++;
|
||||||
w.nextchar = NULL;
|
w.nextchar = nullptr;
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
/// Helper function for builtin_bg().
|
/// Helper function for builtin_bg().
|
||||||
static int send_to_bg(parser_t &parser, io_streams_t &streams, job_t *j) {
|
static int send_to_bg(parser_t &parser, io_streams_t &streams, job_t *j) {
|
||||||
assert(j != NULL);
|
assert(j != nullptr);
|
||||||
if (!j->wants_job_control()) {
|
if (!j->wants_job_control()) {
|
||||||
wcstring error_message = format_string(
|
wcstring error_message = format_string(
|
||||||
_(L"%ls: Can't put job %d, '%ls' to background because it is not under job control\n"),
|
_(L"%ls: Can't put job %d, '%ls' to background because it is not under job control\n"),
|
||||||
|
|
|
@ -211,7 +211,7 @@ bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool us
|
||||||
}
|
}
|
||||||
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
if (mode == NULL) mode = DEFAULT_BIND_MODE; //!OCLINT(parameter reassignment)
|
if (mode == nullptr) mode = DEFAULT_BIND_MODE; //!OCLINT(parameter reassignment)
|
||||||
|
|
||||||
while (*seq) {
|
while (*seq) {
|
||||||
if (use_terminfo) {
|
if (use_terminfo) {
|
||||||
|
@ -253,10 +253,10 @@ bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv, io_streams_t &
|
||||||
// We don't overload this with user and def because we want them to be grouped.
|
// We don't overload this with user and def because we want them to be grouped.
|
||||||
// First the presets, then the users (because of scrolling).
|
// First the presets, then the users (because of scrolling).
|
||||||
if (opts->preset) {
|
if (opts->preset) {
|
||||||
list(opts->bind_mode_given ? opts->bind_mode : NULL, false, streams);
|
list(opts->bind_mode_given ? opts->bind_mode : nullptr, false, streams);
|
||||||
}
|
}
|
||||||
if (opts->user) {
|
if (opts->user) {
|
||||||
list(opts->bind_mode_given ? opts->bind_mode : NULL, true, streams);
|
list(opts->bind_mode_given ? opts->bind_mode : nullptr, true, streams);
|
||||||
}
|
}
|
||||||
} else if (arg_count == 1) {
|
} else if (arg_count == 1) {
|
||||||
wcstring seq;
|
wcstring seq;
|
||||||
|
@ -318,23 +318,23 @@ int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss meth
|
||||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
static const wchar_t *const short_options = L":aehkKfM:Lm:s";
|
static const wchar_t *const short_options = L":aehkKfM:Lm:s";
|
||||||
static const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'},
|
static const struct woption long_options[] = {{L"all", no_argument, nullptr, 'a'},
|
||||||
{L"erase", no_argument, NULL, 'e'},
|
{L"erase", no_argument, nullptr, 'e'},
|
||||||
{L"function-names", no_argument, NULL, 'f'},
|
{L"function-names", no_argument, nullptr, 'f'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"key", no_argument, NULL, 'k'},
|
{L"key", no_argument, nullptr, 'k'},
|
||||||
{L"key-names", no_argument, NULL, 'K'},
|
{L"key-names", no_argument, nullptr, 'K'},
|
||||||
{L"list-modes", no_argument, NULL, 'L'},
|
{L"list-modes", no_argument, nullptr, 'L'},
|
||||||
{L"mode", required_argument, NULL, 'M'},
|
{L"mode", required_argument, nullptr, 'M'},
|
||||||
{L"preset", no_argument, NULL, 'p'},
|
{L"preset", no_argument, nullptr, 'p'},
|
||||||
{L"sets-mode", required_argument, NULL, 'm'},
|
{L"sets-mode", required_argument, nullptr, 'm'},
|
||||||
{L"silent", no_argument, NULL, 's'},
|
{L"silent", no_argument, nullptr, 's'},
|
||||||
{L"user", no_argument, NULL, 'u'},
|
{L"user", no_argument, nullptr, 'u'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case L'a': {
|
case L'a': {
|
||||||
opts.all = true;
|
opts.all = true;
|
||||||
|
@ -438,7 +438,7 @@ int builtin_bind_t::builtin_bind(parser_t &parser, io_streams_t &streams, wchar_
|
||||||
if (!opts.have_preset && !opts.have_user) opts.user = true;
|
if (!opts.have_preset && !opts.have_user) opts.user = true;
|
||||||
switch (opts.mode) {
|
switch (opts.mode) {
|
||||||
case BIND_ERASE: {
|
case BIND_ERASE: {
|
||||||
const wchar_t *bind_mode = opts.bind_mode_given ? opts.bind_mode : NULL;
|
const wchar_t *bind_mode = opts.bind_mode_given ? opts.bind_mode : nullptr;
|
||||||
// If we get both, we erase both.
|
// If we get both, we erase both.
|
||||||
if (opts.user) {
|
if (opts.user) {
|
||||||
if (erase(&argv[optind], opts.all, bind_mode, opts.use_terminfo, /* user */ true,
|
if (erase(&argv[optind], opts.all, bind_mode, opts.use_terminfo, /* user */ true,
|
||||||
|
|
|
@ -25,15 +25,15 @@ static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high n
|
||||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
static const wchar_t *const short_options = L":eghl";
|
static const wchar_t *const short_options = L":eghl";
|
||||||
static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'},
|
static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'},
|
||||||
{L"local", no_argument, NULL, 'l'},
|
{L"local", no_argument, nullptr, 'l'},
|
||||||
{L"global", no_argument, NULL, 'g'},
|
{L"global", no_argument, nullptr, 'g'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h': {
|
case 'h': {
|
||||||
opts.print_help = true;
|
opts.print_help = true;
|
||||||
|
@ -108,16 +108,16 @@ int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
case LOCAL: {
|
case LOCAL: {
|
||||||
// If this is the outermost block, then we're global
|
// If this is the outermost block, then we're global
|
||||||
if (block_idx + 1 >= parser.block_count()) {
|
if (block_idx + 1 >= parser.block_count()) {
|
||||||
block = NULL;
|
block = nullptr;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GLOBAL: {
|
case GLOBAL: {
|
||||||
block = NULL;
|
block = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UNSET: {
|
case UNSET: {
|
||||||
while (block != NULL && block->type() != FUNCTION_CALL &&
|
while (block != nullptr && block->type() != FUNCTION_CALL &&
|
||||||
block->type() != FUNCTION_CALL_NO_SHADOW) {
|
block->type() != FUNCTION_CALL_NO_SHADOW) {
|
||||||
// Set it in function scope
|
// Set it in function scope
|
||||||
block = parser.block_at_index(++block_idx);
|
block = parser.block_at_index(++block_idx);
|
||||||
|
|
|
@ -20,17 +20,17 @@ struct builtin_cmd_opts_t {
|
||||||
bool query = false;
|
bool query = false;
|
||||||
};
|
};
|
||||||
static const wchar_t *const short_options = L":hnq";
|
static const wchar_t *const short_options = L":hnq";
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"names", no_argument, NULL, 'n'},
|
{L"names", no_argument, nullptr, 'n'},
|
||||||
{L"query", no_argument, NULL, 'q'},
|
{L"query", no_argument, nullptr, 'q'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
||||||
parser_t &parser, io_streams_t &streams) {
|
parser_t &parser, io_streams_t &streams) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h': {
|
case 'h': {
|
||||||
opts.print_help = true;
|
opts.print_help = true;
|
||||||
|
|
|
@ -23,18 +23,18 @@ struct command_cmd_opts_t {
|
||||||
bool all_paths = false;
|
bool all_paths = false;
|
||||||
};
|
};
|
||||||
static const wchar_t *const short_options = L":ahqsv";
|
static const wchar_t *const short_options = L":ahqsv";
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"all", no_argument, NULL, 'a'},
|
{L"all", no_argument, nullptr, 'a'},
|
||||||
{L"quiet", no_argument, NULL, 'q'},
|
{L"quiet", no_argument, nullptr, 'q'},
|
||||||
{L"search", no_argument, NULL, 's'},
|
{L"search", no_argument, nullptr, 's'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(command_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
static int parse_cmd_opts(command_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
||||||
parser_t &parser, io_streams_t &streams) {
|
parser_t &parser, io_streams_t &streams) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a': {
|
case 'a': {
|
||||||
opts.all_paths = true;
|
opts.all_paths = true;
|
||||||
|
|
|
@ -125,7 +125,7 @@ static void write_part(const wchar_t *begin, const wchar_t *end, int cut_at_curs
|
||||||
int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
// Pointer to what the commandline builtin considers to be the current contents of the command
|
// Pointer to what the commandline builtin considers to be the current contents of the command
|
||||||
// line buffer.
|
// line buffer.
|
||||||
const wchar_t *current_buffer = 0;
|
const wchar_t *current_buffer = nullptr;
|
||||||
|
|
||||||
// What the commandline builtin considers to be the current cursor position.
|
// What the commandline builtin considers to be the current cursor position.
|
||||||
auto current_cursor_pos = static_cast<size_t>(-1);
|
auto current_cursor_pos = static_cast<size_t>(-1);
|
||||||
|
@ -146,7 +146,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
int line_mode = 0;
|
int line_mode = 0;
|
||||||
int search_mode = 0;
|
int search_mode = 0;
|
||||||
int paging_mode = 0;
|
int paging_mode = 0;
|
||||||
const wchar_t *begin = NULL, *end = NULL;
|
const wchar_t *begin = nullptr, *end = nullptr;
|
||||||
|
|
||||||
const auto &ld = parser.libdata();
|
const auto &ld = parser.libdata();
|
||||||
wcstring transient_commandline;
|
wcstring transient_commandline;
|
||||||
|
@ -173,28 +173,28 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const wchar_t *const short_options = L":abijpctforhI:CLSsP";
|
static const wchar_t *const short_options = L":abijpctforhI:CLSsP";
|
||||||
static const struct woption long_options[] = {{L"append", no_argument, NULL, 'a'},
|
static const struct woption long_options[] = {{L"append", no_argument, nullptr, 'a'},
|
||||||
{L"insert", no_argument, NULL, 'i'},
|
{L"insert", no_argument, nullptr, 'i'},
|
||||||
{L"replace", no_argument, NULL, 'r'},
|
{L"replace", no_argument, nullptr, 'r'},
|
||||||
{L"current-buffer", no_argument, NULL, 'b'},
|
{L"current-buffer", no_argument, nullptr, 'b'},
|
||||||
{L"current-job", no_argument, NULL, 'j'},
|
{L"current-job", no_argument, nullptr, 'j'},
|
||||||
{L"current-process", no_argument, NULL, 'p'},
|
{L"current-process", no_argument, nullptr, 'p'},
|
||||||
{L"current-selection", no_argument, NULL, 's'},
|
{L"current-selection", no_argument, nullptr, 's'},
|
||||||
{L"current-token", no_argument, NULL, 't'},
|
{L"current-token", no_argument, nullptr, 't'},
|
||||||
{L"cut-at-cursor", no_argument, NULL, 'c'},
|
{L"cut-at-cursor", no_argument, nullptr, 'c'},
|
||||||
{L"function", no_argument, NULL, 'f'},
|
{L"function", no_argument, nullptr, 'f'},
|
||||||
{L"tokenize", no_argument, NULL, 'o'},
|
{L"tokenize", no_argument, nullptr, 'o'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"input", required_argument, NULL, 'I'},
|
{L"input", required_argument, nullptr, 'I'},
|
||||||
{L"cursor", no_argument, NULL, 'C'},
|
{L"cursor", no_argument, nullptr, 'C'},
|
||||||
{L"line", no_argument, NULL, 'L'},
|
{L"line", no_argument, nullptr, 'L'},
|
||||||
{L"search-mode", no_argument, NULL, 'S'},
|
{L"search-mode", no_argument, nullptr, 'S'},
|
||||||
{L"paging-mode", no_argument, NULL, 'P'},
|
{L"paging-mode", no_argument, nullptr, 'P'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case L'a': {
|
case L'a': {
|
||||||
append_mode = APPEND_MODE;
|
append_mode = APPEND_MODE;
|
||||||
|
@ -408,7 +408,8 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TOKEN_MODE: {
|
case TOKEN_MODE: {
|
||||||
parse_util_token_extent(current_buffer, current_cursor_pos, &begin, &end, 0, 0);
|
parse_util_token_extent(current_buffer, current_cursor_pos, &begin, &end, nullptr,
|
||||||
|
nullptr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -128,30 +128,31 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
bool preserve_order = false;
|
bool preserve_order = false;
|
||||||
|
|
||||||
static const wchar_t *const short_options = L":a:c:p:s:l:o:d:fFrxeuAn:C::w:hk";
|
static const wchar_t *const short_options = L":a:c:p:s:l:o:d:fFrxeuAn:C::w:hk";
|
||||||
static const struct woption long_options[] = {{L"exclusive", no_argument, NULL, 'x'},
|
static const struct woption long_options[] = {
|
||||||
{L"no-files", no_argument, NULL, 'f'},
|
{L"exclusive", no_argument, nullptr, 'x'},
|
||||||
{L"force-files", no_argument, NULL, 'F'},
|
{L"no-files", no_argument, nullptr, 'f'},
|
||||||
{L"require-parameter", no_argument, NULL, 'r'},
|
{L"force-files", no_argument, nullptr, 'F'},
|
||||||
{L"path", required_argument, NULL, 'p'},
|
{L"require-parameter", no_argument, nullptr, 'r'},
|
||||||
{L"command", required_argument, NULL, 'c'},
|
{L"path", required_argument, nullptr, 'p'},
|
||||||
{L"short-option", required_argument, NULL, 's'},
|
{L"command", required_argument, nullptr, 'c'},
|
||||||
{L"long-option", required_argument, NULL, 'l'},
|
{L"short-option", required_argument, nullptr, 's'},
|
||||||
{L"old-option", required_argument, NULL, 'o'},
|
{L"long-option", required_argument, nullptr, 'l'},
|
||||||
{L"description", required_argument, NULL, 'd'},
|
{L"old-option", required_argument, nullptr, 'o'},
|
||||||
{L"arguments", required_argument, NULL, 'a'},
|
{L"description", required_argument, nullptr, 'd'},
|
||||||
{L"erase", no_argument, NULL, 'e'},
|
{L"arguments", required_argument, nullptr, 'a'},
|
||||||
{L"unauthoritative", no_argument, NULL, 'u'},
|
{L"erase", no_argument, nullptr, 'e'},
|
||||||
{L"authoritative", no_argument, NULL, 'A'},
|
{L"unauthoritative", no_argument, nullptr, 'u'},
|
||||||
{L"condition", required_argument, NULL, 'n'},
|
{L"authoritative", no_argument, nullptr, 'A'},
|
||||||
{L"wraps", required_argument, NULL, 'w'},
|
{L"condition", required_argument, nullptr, 'n'},
|
||||||
{L"do-complete", optional_argument, NULL, 'C'},
|
{L"wraps", required_argument, nullptr, 'w'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"do-complete", optional_argument, nullptr, 'C'},
|
||||||
{L"keep-order", no_argument, NULL, 'k'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{L"keep-order", no_argument, nullptr, 'k'},
|
||||||
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'x': {
|
case 'x': {
|
||||||
result_mode.no_files = true;
|
result_mode.no_files = true;
|
||||||
|
@ -241,7 +242,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
}
|
}
|
||||||
case 'C': {
|
case 'C': {
|
||||||
do_complete = true;
|
do_complete = true;
|
||||||
have_do_complete_param = w.woptarg != NULL;
|
have_do_complete_param = w.woptarg != nullptr;
|
||||||
if (have_do_complete_param) do_complete_param = w.woptarg;
|
if (have_do_complete_param) do_complete_param = w.woptarg;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +318,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
if (!have_do_complete_param) {
|
if (!have_do_complete_param) {
|
||||||
// No argument given, try to use the current commandline.
|
// No argument given, try to use the current commandline.
|
||||||
const wchar_t *cmd = reader_get_buffer();
|
const wchar_t *cmd = reader_get_buffer();
|
||||||
if (cmd == NULL) {
|
if (cmd == nullptr) {
|
||||||
// This corresponds to using 'complete -C' in non-interactive mode.
|
// This corresponds to using 'complete -C' in non-interactive mode.
|
||||||
// See #2361 .
|
// See #2361 .
|
||||||
builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]);
|
builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]);
|
||||||
|
@ -327,8 +328,8 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
}
|
}
|
||||||
const wchar_t *token;
|
const wchar_t *token;
|
||||||
|
|
||||||
parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0,
|
parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token,
|
||||||
0);
|
nullptr, nullptr, nullptr);
|
||||||
|
|
||||||
// Create a scoped transient command line, so that builtin_commandline will see our
|
// Create a scoped transient command line, so that builtin_commandline will see our
|
||||||
// argument, not the reader buffer.
|
// argument, not the reader buffer.
|
||||||
|
|
|
@ -19,15 +19,16 @@ struct contains_cmd_opts_t {
|
||||||
bool print_index = false;
|
bool print_index = false;
|
||||||
};
|
};
|
||||||
static const wchar_t *const short_options = L"+:hi";
|
static const wchar_t *const short_options = L"+:hi";
|
||||||
static const struct woption long_options[] = {
|
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"help", no_argument, NULL, 'h'}, {L"index", no_argument, NULL, 'i'}, {NULL, 0, NULL, 0}};
|
{L"index", no_argument, nullptr, 'i'},
|
||||||
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(contains_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
static int parse_cmd_opts(contains_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
||||||
parser_t &parser, io_streams_t &streams) {
|
parser_t &parser, io_streams_t &streams) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h': {
|
case 'h': {
|
||||||
opts.print_help = true;
|
opts.print_help = true;
|
||||||
|
|
|
@ -55,7 +55,7 @@ int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv[1] == 0) {
|
if (argv[1] == nullptr) {
|
||||||
// Select last constructed job (ie first job in the job queue) that is possible to disown.
|
// Select last constructed job (ie first job in the job queue) that is possible to disown.
|
||||||
// Stopped jobs can be disowned (they will be continued).
|
// Stopped jobs can be disowned (they will be continued).
|
||||||
// Foreground jobs can be disowned.
|
// Foreground jobs can be disowned.
|
||||||
|
|
|
@ -19,7 +19,7 @@ struct echo_cmd_opts_t {
|
||||||
bool interpret_special_chars = false;
|
bool interpret_special_chars = false;
|
||||||
};
|
};
|
||||||
static const wchar_t *const short_options = L"+:Eens";
|
static const wchar_t *const short_options = L"+:Eens";
|
||||||
static const struct woption *const long_options = NULL;
|
static const struct woption *const long_options = nullptr;
|
||||||
|
|
||||||
static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
||||||
parser_t &parser, io_streams_t &streams) {
|
parser_t &parser, io_streams_t &streams) {
|
||||||
|
@ -28,7 +28,7 @@ static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'n': {
|
case 'n': {
|
||||||
opts.print_newline = false;
|
opts.print_newline = false;
|
||||||
|
@ -194,7 +194,7 @@ int builtin_echo(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
bool continue_output = true;
|
bool continue_output = true;
|
||||||
|
|
||||||
const wchar_t *const *args_to_echo = argv + optind;
|
const wchar_t *const *args_to_echo = argv + optind;
|
||||||
for (size_t idx = 0; continue_output && args_to_echo[idx] != NULL; idx++) {
|
for (size_t idx = 0; continue_output && args_to_echo[idx] != nullptr; idx++) {
|
||||||
if (opts.print_spaces && idx > 0) {
|
if (opts.print_spaces && idx > 0) {
|
||||||
streams.out.push_back(' ');
|
streams.out.push_back(' ');
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ struct exit_cmd_opts_t {
|
||||||
bool print_help = false;
|
bool print_help = false;
|
||||||
};
|
};
|
||||||
static const wchar_t *const short_options = L":h";
|
static const wchar_t *const short_options = L":h";
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
|
@ -30,7 +30,7 @@ static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) { //!OCLINT(too few branches)
|
switch (opt) { //!OCLINT(too few branches)
|
||||||
case 'h': {
|
case 'h': {
|
||||||
opts.print_help = true;
|
opts.print_help = true;
|
||||||
|
|
|
@ -39,18 +39,19 @@ struct function_cmd_opts_t {
|
||||||
// This command is atypical in using the "-" (RETURN_IN_ORDER) option for flag parsing.
|
// This command is atypical in using the "-" (RETURN_IN_ORDER) option for flag parsing.
|
||||||
// This is needed due to the semantics of the -a/--argument-names flag.
|
// This is needed due to the semantics of the -a/--argument-names flag.
|
||||||
static const wchar_t *const short_options = L"-:a:d:e:hj:p:s:v:w:SV:";
|
static const wchar_t *const short_options = L"-:a:d:e:hj:p:s:v:w:SV:";
|
||||||
static const struct woption long_options[] = {{L"description", required_argument, NULL, 'd'},
|
static const struct woption long_options[] = {
|
||||||
{L"on-signal", required_argument, NULL, 's'},
|
{L"description", required_argument, nullptr, 'd'},
|
||||||
{L"on-job-exit", required_argument, NULL, 'j'},
|
{L"on-signal", required_argument, nullptr, 's'},
|
||||||
{L"on-process-exit", required_argument, NULL, 'p'},
|
{L"on-job-exit", required_argument, nullptr, 'j'},
|
||||||
{L"on-variable", required_argument, NULL, 'v'},
|
{L"on-process-exit", required_argument, nullptr, 'p'},
|
||||||
{L"on-event", required_argument, NULL, 'e'},
|
{L"on-variable", required_argument, nullptr, 'v'},
|
||||||
{L"wraps", required_argument, NULL, 'w'},
|
{L"on-event", required_argument, nullptr, 'e'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"wraps", required_argument, nullptr, 'w'},
|
||||||
{L"argument-names", required_argument, NULL, 'a'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"no-scope-shadowing", no_argument, NULL, 'S'},
|
{L"argument-names", required_argument, nullptr, 'a'},
|
||||||
{L"inherit-variable", required_argument, NULL, 'V'},
|
{L"no-scope-shadowing", no_argument, nullptr, 'S'},
|
||||||
{NULL, 0, NULL, 0}};
|
{L"inherit-variable", required_argument, nullptr, 'V'},
|
||||||
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
|
@ -58,7 +59,7 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
bool handling_named_arguments = false;
|
bool handling_named_arguments = false;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
if (opt != 'a' && opt != 1) handling_named_arguments = false;
|
if (opt != 'a' && opt != 1) handling_named_arguments = false;
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 1: {
|
case 1: {
|
||||||
|
|
|
@ -39,29 +39,29 @@ struct functions_cmd_opts_t {
|
||||||
bool report_metadata = false;
|
bool report_metadata = false;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
bool handlers = false;
|
bool handlers = false;
|
||||||
wchar_t *handlers_type = NULL;
|
wchar_t *handlers_type = nullptr;
|
||||||
wchar_t *description = NULL;
|
wchar_t *description = nullptr;
|
||||||
};
|
};
|
||||||
static const wchar_t *const short_options = L":HDacd:ehnqv";
|
static const wchar_t *const short_options = L":HDacd:ehnqv";
|
||||||
static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'},
|
static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'},
|
||||||
{L"description", required_argument, NULL, 'd'},
|
{L"description", required_argument, nullptr, 'd'},
|
||||||
{L"names", no_argument, NULL, 'n'},
|
{L"names", no_argument, nullptr, 'n'},
|
||||||
{L"all", no_argument, NULL, 'a'},
|
{L"all", no_argument, nullptr, 'a'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"query", no_argument, NULL, 'q'},
|
{L"query", no_argument, nullptr, 'q'},
|
||||||
{L"copy", no_argument, NULL, 'c'},
|
{L"copy", no_argument, nullptr, 'c'},
|
||||||
{L"details", no_argument, NULL, 'D'},
|
{L"details", no_argument, nullptr, 'D'},
|
||||||
{L"verbose", no_argument, NULL, 'v'},
|
{L"verbose", no_argument, nullptr, 'v'},
|
||||||
{L"handlers", no_argument, NULL, 'H'},
|
{L"handlers", no_argument, nullptr, 'H'},
|
||||||
{L"handlers-type", required_argument, NULL, 't'},
|
{L"handlers-type", required_argument, nullptr, 't'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
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) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'v': {
|
case 'v': {
|
||||||
opts.verbose = true;
|
opts.verbose = true;
|
||||||
|
|
|
@ -25,12 +25,12 @@ enum hist_cmd_t { HIST_SEARCH = 1, HIST_DELETE, HIST_CLEAR, HIST_MERGE, HIST_SAV
|
||||||
// Must be sorted by string, not enum or random.
|
// Must be sorted by string, not enum or random.
|
||||||
static const enum_map<hist_cmd_t> hist_enum_map[] = {
|
static const enum_map<hist_cmd_t> hist_enum_map[] = {
|
||||||
{HIST_CLEAR, L"clear"}, {HIST_DELETE, L"delete"}, {HIST_MERGE, L"merge"},
|
{HIST_CLEAR, L"clear"}, {HIST_DELETE, L"delete"}, {HIST_MERGE, L"merge"},
|
||||||
{HIST_SAVE, L"save"}, {HIST_SEARCH, L"search"}, {HIST_UNDEF, NULL}};
|
{HIST_SAVE, L"save"}, {HIST_SEARCH, L"search"}, {HIST_UNDEF, nullptr}};
|
||||||
|
|
||||||
struct history_cmd_opts_t {
|
struct history_cmd_opts_t {
|
||||||
hist_cmd_t hist_cmd = HIST_UNDEF;
|
hist_cmd_t hist_cmd = HIST_UNDEF;
|
||||||
history_search_type_t search_type = static_cast<history_search_type_t>(-1);
|
history_search_type_t search_type = static_cast<history_search_type_t>(-1);
|
||||||
const wchar_t *show_time_format = NULL;
|
const wchar_t *show_time_format = nullptr;
|
||||||
size_t max_items = SIZE_MAX;
|
size_t max_items = SIZE_MAX;
|
||||||
bool print_help = false;
|
bool print_help = false;
|
||||||
bool history_search_type_defined = false;
|
bool history_search_type_defined = false;
|
||||||
|
@ -44,21 +44,21 @@ struct history_cmd_opts_t {
|
||||||
/// supported at least until fish 3.0 and possibly longer to avoid breaking everyones
|
/// supported at least until fish 3.0 and possibly longer to avoid breaking everyones
|
||||||
/// config.fish and other scripts.
|
/// config.fish and other scripts.
|
||||||
static const wchar_t *const short_options = L":CRcehmn:pt::z";
|
static const wchar_t *const short_options = L":CRcehmn:pt::z";
|
||||||
static const struct woption long_options[] = {{L"prefix", no_argument, NULL, 'p'},
|
static const struct woption long_options[] = {{L"prefix", no_argument, nullptr, 'p'},
|
||||||
{L"contains", no_argument, NULL, 'c'},
|
{L"contains", no_argument, nullptr, 'c'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"show-time", optional_argument, NULL, 't'},
|
{L"show-time", optional_argument, nullptr, 't'},
|
||||||
{L"exact", no_argument, NULL, 'e'},
|
{L"exact", no_argument, nullptr, 'e'},
|
||||||
{L"max", required_argument, NULL, 'n'},
|
{L"max", required_argument, nullptr, 'n'},
|
||||||
{L"null", no_argument, NULL, 'z'},
|
{L"null", no_argument, nullptr, 'z'},
|
||||||
{L"case-sensitive", no_argument, NULL, 'C'},
|
{L"case-sensitive", no_argument, nullptr, 'C'},
|
||||||
{L"delete", no_argument, NULL, 1},
|
{L"delete", no_argument, nullptr, 1},
|
||||||
{L"search", no_argument, NULL, 2},
|
{L"search", no_argument, nullptr, 2},
|
||||||
{L"save", no_argument, NULL, 3},
|
{L"save", no_argument, nullptr, 3},
|
||||||
{L"clear", no_argument, NULL, 4},
|
{L"clear", no_argument, nullptr, 4},
|
||||||
{L"merge", no_argument, NULL, 5},
|
{L"merge", no_argument, nullptr, 5},
|
||||||
{L"reverse", no_argument, NULL, 'R'},
|
{L"reverse", no_argument, nullptr, 'R'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
/// Remember the history subcommand and disallow selecting more than one history subcommand.
|
/// Remember the history subcommand and disallow selecting more than one history subcommand.
|
||||||
static bool set_hist_cmd(wchar_t *const cmd, hist_cmd_t *hist_cmd, hist_cmd_t sub_cmd,
|
static bool set_hist_cmd(wchar_t *const cmd, hist_cmd_t *hist_cmd, hist_cmd_t sub_cmd,
|
||||||
|
@ -99,7 +99,7 @@ static int parse_cmd_opts(history_cmd_opts_t &opts, int *optind, //!OCLINT(high
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 1: {
|
case 1: {
|
||||||
if (!set_hist_cmd(cmd, &opts.hist_cmd, HIST_DELETE, streams)) {
|
if (!set_hist_cmd(cmd, &opts.hist_cmd, HIST_DELETE, streams)) {
|
||||||
|
@ -186,7 +186,7 @@ static int parse_cmd_opts(history_cmd_opts_t &opts, int *optind, //!OCLINT(high
|
||||||
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
|
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
w.nextchar = NULL;
|
w.nextchar = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -33,7 +33,7 @@ static int cpu_use(const job_t *j) {
|
||||||
for (const process_ptr_t &p : j->processes) {
|
for (const process_ptr_t &p : j->processes) {
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
int jiffies;
|
int jiffies;
|
||||||
gettimeofday(&t, 0);
|
gettimeofday(&t, nullptr);
|
||||||
jiffies = proc_get_jiffies(p.get());
|
jiffies = proc_get_jiffies(p.get());
|
||||||
|
|
||||||
double t1 = 1000000.0 * p->last_time.tv_sec + p->last_time.tv_usec;
|
double t1 = 1000000.0 * p->last_time.tv_sec + p->last_time.tv_usec;
|
||||||
|
@ -119,17 +119,17 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
int print_last = 0;
|
int print_last = 0;
|
||||||
|
|
||||||
static const wchar_t *const short_options = L":cghlpq";
|
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, nullptr, 'c'},
|
||||||
{L"group", no_argument, NULL, 'g'},
|
{L"group", no_argument, nullptr, 'g'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"last", no_argument, NULL, 'l'},
|
{L"last", no_argument, nullptr, 'l'},
|
||||||
{L"pid", no_argument, NULL, 'p'},
|
{L"pid", no_argument, nullptr, 'p'},
|
||||||
{L"quiet", no_argument, NULL, 'q'},
|
{L"quiet", no_argument, nullptr, 'q'},
|
||||||
{nullptr, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'p': {
|
case 'p': {
|
||||||
mode = JOBS_PRINT_PID;
|
mode = JOBS_PRINT_PID;
|
||||||
|
|
|
@ -35,16 +35,16 @@ struct math_cmd_opts_t {
|
||||||
// This command is atypical in using the "+" (REQUIRE_ORDER) option for flag parsing.
|
// This command is atypical in using the "+" (REQUIRE_ORDER) option for flag parsing.
|
||||||
// This is needed because of the minus, `-`, operator in math expressions.
|
// This is needed because of the minus, `-`, operator in math expressions.
|
||||||
static const wchar_t *const short_options = L"+:hs:";
|
static const wchar_t *const short_options = L"+:hs:";
|
||||||
static const struct woption long_options[] = {{L"scale", required_argument, NULL, 's'},
|
static const struct woption long_options[] = {{L"scale", required_argument, nullptr, 's'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
const wchar_t *cmd = L"math";
|
const wchar_t *cmd = L"math";
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's': {
|
case 's': {
|
||||||
// "max" is the special value that tells us to pick the maximum scale.
|
// "max" is the special value that tells us to pick the maximum scale.
|
||||||
|
@ -97,10 +97,10 @@ static const wchar_t *math_get_arg_stdin(wcstring *storage, const io_streams_t &
|
||||||
char ch = '\0';
|
char ch = '\0';
|
||||||
long rc = read_blocked(streams.stdin_fd, &ch, 1);
|
long rc = read_blocked(streams.stdin_fd, &ch, 1);
|
||||||
|
|
||||||
if (rc < 0) return NULL; // failure
|
if (rc < 0) return nullptr; // failure
|
||||||
|
|
||||||
if (rc == 0) { // EOF
|
if (rc == 0) { // EOF
|
||||||
if (arg.empty()) return NULL;
|
if (arg.empty()) return nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ static const wchar_t *math_get_arg_stdin(wcstring *storage, const io_streams_t &
|
||||||
|
|
||||||
/// Return the next argument from argv.
|
/// Return the next argument from argv.
|
||||||
static const wchar_t *math_get_arg_argv(int *argidx, wchar_t **argv) {
|
static const wchar_t *math_get_arg_argv(int *argidx, wchar_t **argv) {
|
||||||
return argv && argv[*argidx] ? argv[(*argidx)++] : NULL;
|
return argv && argv[*argidx] ? argv[(*argidx)++] : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the arguments from argv or stdin based on the execution context. This mimics how builtin
|
/// Get the arguments from argv or stdin based on the execution context. This mimics how builtin
|
||||||
|
@ -196,7 +196,7 @@ static int evaluate_expression(const wchar_t *cmd, parser_t &parser, io_streams_
|
||||||
// Switch locale while computing stuff.
|
// Switch locale while computing stuff.
|
||||||
// This means that the "." is always the radix character,
|
// This means that the "." is always the radix character,
|
||||||
// so numbers work the same across locales.
|
// so numbers work the same across locales.
|
||||||
char *saved_locale = strdup(setlocale(LC_NUMERIC, NULL));
|
char *saved_locale = strdup(setlocale(LC_NUMERIC, nullptr));
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
double v = te_interp(narrow_str.c_str(), &error);
|
double v = te_interp(narrow_str.c_str(), &error);
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ static int evaluate_expression(const wchar_t *cmd, parser_t &parser, io_streams_
|
||||||
// TODO: Really, this should be done in tinyexpr
|
// TODO: Really, this should be done in tinyexpr
|
||||||
// (e.g. infinite is the result of "x / 0"),
|
// (e.g. infinite is the result of "x / 0"),
|
||||||
// but that's much more work.
|
// but that's much more work.
|
||||||
const char *error_message = NULL;
|
const char *error_message = nullptr;
|
||||||
if (std::isinf(v)) {
|
if (std::isinf(v)) {
|
||||||
error_message = "Result is infinite";
|
error_message = "Result is infinite";
|
||||||
} else if (std::isnan(v)) {
|
} else if (std::isnan(v)) {
|
||||||
|
|
|
@ -304,7 +304,7 @@ static T string_to_scalar_type(const wchar_t *s, builtin_printf_state_t *state)
|
||||||
wchar_t ch = *++s;
|
wchar_t ch = *++s;
|
||||||
val = ch;
|
val = ch;
|
||||||
} else {
|
} else {
|
||||||
wchar_t *end = NULL;
|
wchar_t *end = nullptr;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
val = raw_string_to_scalar_type<T>(s, &end);
|
val = raw_string_to_scalar_type<T>(s, &end);
|
||||||
state->verify_numeric(s, end, errno);
|
state->verify_numeric(s, end, errno);
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
/// The pwd builtin. Respect -P to resolve symbolic links. Respect -L to not do that (the default).
|
/// The pwd builtin. Respect -P to resolve symbolic links. Respect -L to not do that (the default).
|
||||||
static const wchar_t *const short_options = L"LPh";
|
static const wchar_t *const short_options = L"LPh";
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
UNUSED(parser);
|
UNUSED(parser);
|
||||||
const wchar_t *cmd = argv[0];
|
const wchar_t *cmd = argv[0];
|
||||||
|
@ -24,7 +24,7 @@ int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
bool resolve_symlinks = false;
|
bool resolve_symlinks = false;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'L':
|
case 'L':
|
||||||
resolve_symlinks = false;
|
resolve_symlinks = false;
|
||||||
|
|
|
@ -38,8 +38,8 @@ struct read_cmd_opts_t {
|
||||||
bool print_help = false;
|
bool print_help = false;
|
||||||
int place = ENV_USER;
|
int place = ENV_USER;
|
||||||
wcstring prompt_cmd;
|
wcstring prompt_cmd;
|
||||||
const wchar_t *prompt = NULL;
|
const wchar_t *prompt = nullptr;
|
||||||
const wchar_t *prompt_str = NULL;
|
const wchar_t *prompt_str = nullptr;
|
||||||
const wchar_t *right_prompt = L"";
|
const wchar_t *right_prompt = L"";
|
||||||
const wchar_t *commandline = L"";
|
const wchar_t *commandline = L"";
|
||||||
// If a delimiter was given. Used to distinguish between the default
|
// If a delimiter was given. Used to distinguish between the default
|
||||||
|
@ -56,32 +56,32 @@ struct read_cmd_opts_t {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const wchar_t *const short_options = L":ac:d:ghiLlm:n:p:sSuxzP:UR:LB";
|
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, nullptr, 'a'},
|
||||||
{L"command", required_argument, NULL, 'c'},
|
{L"command", required_argument, nullptr, 'c'},
|
||||||
{L"delimiter", required_argument, NULL, 'd'},
|
{L"delimiter", required_argument, nullptr, 'd'},
|
||||||
{L"export", no_argument, NULL, 'x'},
|
{L"export", no_argument, nullptr, 'x'},
|
||||||
{L"global", no_argument, NULL, 'g'},
|
{L"global", no_argument, nullptr, 'g'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"line", no_argument, NULL, 'L'},
|
{L"line", no_argument, nullptr, 'L'},
|
||||||
{L"list", no_argument, NULL, 'a'},
|
{L"list", no_argument, nullptr, 'a'},
|
||||||
{L"local", no_argument, NULL, 'l'},
|
{L"local", no_argument, nullptr, 'l'},
|
||||||
{L"nchars", required_argument, NULL, 'n'},
|
{L"nchars", required_argument, nullptr, 'n'},
|
||||||
{L"null", no_argument, NULL, 'z'},
|
{L"null", no_argument, nullptr, 'z'},
|
||||||
{L"prompt", required_argument, NULL, 'p'},
|
{L"prompt", required_argument, nullptr, 'p'},
|
||||||
{L"prompt-str", required_argument, NULL, 'P'},
|
{L"prompt-str", required_argument, nullptr, 'P'},
|
||||||
{L"right-prompt", required_argument, NULL, 'R'},
|
{L"right-prompt", required_argument, nullptr, 'R'},
|
||||||
{L"shell", no_argument, NULL, 'S'},
|
{L"shell", no_argument, nullptr, 'S'},
|
||||||
{L"silent", no_argument, NULL, 's'},
|
{L"silent", no_argument, nullptr, 's'},
|
||||||
{L"unexport", no_argument, NULL, 'u'},
|
{L"unexport", no_argument, nullptr, 'u'},
|
||||||
{L"universal", no_argument, NULL, 'U'},
|
{L"universal", no_argument, nullptr, 'U'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
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) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a': {
|
case 'a': {
|
||||||
opts.array = true;
|
opts.array = true;
|
||||||
|
|
|
@ -19,8 +19,8 @@ struct return_cmd_opts_t {
|
||||||
bool print_help = false;
|
bool print_help = false;
|
||||||
};
|
};
|
||||||
static const wchar_t *const short_options = L":h";
|
static const wchar_t *const short_options = L":h";
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
|
@ -29,7 +29,7 @@ static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) { //!OCLINT(too few branches)
|
switch (opt) { //!OCLINT(too few branches)
|
||||||
case 'h': {
|
case 'h': {
|
||||||
opts.print_help = true;
|
opts.print_help = true;
|
||||||
|
|
|
@ -58,14 +58,14 @@ enum {
|
||||||
// we stop scanning for flags when the first non-flag argument is seen.
|
// we stop scanning for flags when the first non-flag argument is seen.
|
||||||
static const wchar_t *const short_options = L"+:LSUaeghlnpqux";
|
static const wchar_t *const short_options = L"+:LSUaeghlnpqux";
|
||||||
static const struct woption long_options[] = {
|
static const struct woption long_options[] = {
|
||||||
{L"export", no_argument, NULL, 'x'}, {L"global", no_argument, NULL, 'g'},
|
{L"export", no_argument, nullptr, 'x'}, {L"global", no_argument, nullptr, 'g'},
|
||||||
{L"local", no_argument, NULL, 'l'}, {L"erase", no_argument, NULL, 'e'},
|
{L"local", no_argument, nullptr, 'l'}, {L"erase", no_argument, nullptr, 'e'},
|
||||||
{L"names", no_argument, NULL, 'n'}, {L"unexport", no_argument, NULL, 'u'},
|
{L"names", no_argument, nullptr, 'n'}, {L"unexport", no_argument, nullptr, 'u'},
|
||||||
{L"universal", no_argument, NULL, 'U'}, {L"long", no_argument, NULL, 'L'},
|
{L"universal", no_argument, nullptr, 'U'}, {L"long", no_argument, nullptr, 'L'},
|
||||||
{L"query", no_argument, NULL, 'q'}, {L"show", no_argument, NULL, 'S'},
|
{L"query", no_argument, nullptr, 'q'}, {L"show", no_argument, nullptr, 'S'},
|
||||||
{L"append", no_argument, NULL, 'a'}, {L"prepend", no_argument, NULL, 'p'},
|
{L"append", no_argument, nullptr, 'a'}, {L"prepend", no_argument, nullptr, 'p'},
|
||||||
{L"path", no_argument, NULL, opt_path}, {L"unpath", no_argument, NULL, opt_unpath},
|
{L"path", no_argument, nullptr, opt_path}, {L"unpath", no_argument, nullptr, opt_unpath},
|
||||||
{L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}};
|
{L"help", no_argument, nullptr, 'h'}, {nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
// Hint for invalid path operation with a colon.
|
// Hint for invalid path operation with a colon.
|
||||||
#define BUILTIN_SET_PATH_ERROR _(L"%ls: Warning: $%ls entry \"%ls\" is not valid (%s)\n")
|
#define BUILTIN_SET_PATH_ERROR _(L"%ls: Warning: $%ls entry \"%ls\" is not valid (%s)\n")
|
||||||
|
@ -86,7 +86,7 @@ static int parse_cmd_opts(set_cmd_opts_t &opts, int *optind, //!OCLINT(high ncs
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a': {
|
case 'a': {
|
||||||
opts.append = true;
|
opts.append = true;
|
||||||
|
|
|
@ -49,16 +49,16 @@ static void print_colors(io_streams_t &streams) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const wchar_t *const short_options = L":b:hvoidrcu";
|
static const wchar_t *const short_options = L":b:hvoidrcu";
|
||||||
static const struct woption long_options[] = {{L"background", required_argument, NULL, 'b'},
|
static const struct woption long_options[] = {{L"background", required_argument, nullptr, 'b'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"bold", no_argument, NULL, 'o'},
|
{L"bold", no_argument, nullptr, 'o'},
|
||||||
{L"underline", no_argument, NULL, 'u'},
|
{L"underline", no_argument, nullptr, 'u'},
|
||||||
{L"italics", no_argument, NULL, 'i'},
|
{L"italics", no_argument, nullptr, 'i'},
|
||||||
{L"dim", no_argument, NULL, 'd'},
|
{L"dim", no_argument, nullptr, 'd'},
|
||||||
{L"reverse", no_argument, NULL, 'r'},
|
{L"reverse", no_argument, nullptr, 'r'},
|
||||||
{L"version", no_argument, NULL, 'v'},
|
{L"version", no_argument, nullptr, 'v'},
|
||||||
{L"print-colors", no_argument, NULL, 'c'},
|
{L"print-colors", no_argument, nullptr, 'c'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
static char sitm_esc[] = "\x1B[3m";
|
static char sitm_esc[] = "\x1B[3m";
|
||||||
|
@ -96,13 +96,13 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *bgcolor = NULL;
|
const wchar_t *bgcolor = nullptr;
|
||||||
bool bold = false, underline = false, italics = false, dim = false, reverse = false;
|
bool bold = false, underline = false, italics = false, dim = false, reverse = false;
|
||||||
|
|
||||||
// Parse options to obtain the requested operation and the modifiers.
|
// Parse options to obtain the requested operation and the modifiers.
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'b': {
|
case 'b': {
|
||||||
bgcolor = w.woptarg;
|
bgcolor = w.woptarg;
|
||||||
|
@ -161,7 +161,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
fgcolors.push_back(fg);
|
fgcolors.push_back(fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgcolors.empty() && bgcolor == NULL && !bold && !underline && !italics && !dim &&
|
if (fgcolors.empty() && bgcolor == nullptr && !bold && !underline && !italics && !dim &&
|
||||||
!reverse) {
|
!reverse) {
|
||||||
streams.err.append_format(_(L"%ls: Expected an argument\n"), argv[0]);
|
streams.err.append_format(_(L"%ls: Expected an argument\n"), argv[0]);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
|
@ -180,7 +180,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
|
|
||||||
// Test if we have at least basic support for setting fonts, colors and related bits - otherwise
|
// Test if we have at least basic support for setting fonts, colors and related bits - otherwise
|
||||||
// just give up...
|
// just give up...
|
||||||
if (cur_term == NULL || !exit_attribute_mode) {
|
if (cur_term == nullptr || !exit_attribute_mode) {
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
outputter_t outp;
|
outputter_t outp;
|
||||||
|
@ -207,7 +207,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
writembs_nofail(outp, enter_standout_mode);
|
writembs_nofail(outp, enter_standout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bgcolor != NULL && bg.is_normal()) {
|
if (bgcolor != nullptr && bg.is_normal()) {
|
||||||
writembs_nofail(outp, tparm((char *)exit_attribute_mode));
|
writembs_nofail(outp, tparm((char *)exit_attribute_mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bgcolor != NULL && !bg.is_normal() && !bg.is_reset()) {
|
if (bgcolor != nullptr && !bg.is_normal() && !bg.is_reset()) {
|
||||||
outp.write_color(bg, false /* not is_fg */);
|
outp.write_color(bg, false /* not is_fg */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ const enum_map<status_cmd_t> status_enum_map[] = {
|
||||||
{STATUS_STACK_TRACE, L"print-stack-trace"},
|
{STATUS_STACK_TRACE, L"print-stack-trace"},
|
||||||
{STATUS_STACK_TRACE, L"stack-trace"},
|
{STATUS_STACK_TRACE, L"stack-trace"},
|
||||||
{STATUS_TEST_FEATURE, L"test-feature"},
|
{STATUS_TEST_FEATURE, L"test-feature"},
|
||||||
{STATUS_UNDEF, NULL}};
|
{STATUS_UNDEF, nullptr}};
|
||||||
#define status_enum_map_len (sizeof status_enum_map / sizeof *status_enum_map)
|
#define status_enum_map_len (sizeof status_enum_map / sizeof *status_enum_map)
|
||||||
|
|
||||||
#define CHECK_FOR_UNEXPECTED_STATUS_ARGS(status_cmd) \
|
#define CHECK_FOR_UNEXPECTED_STATUS_ARGS(status_cmd) \
|
||||||
|
@ -103,24 +103,24 @@ struct status_cmd_opts_t {
|
||||||
/// scripts.
|
/// scripts.
|
||||||
static const wchar_t *const short_options = L":L:cbilfnhj:t";
|
static const wchar_t *const short_options = L":L:cbilfnhj:t";
|
||||||
static const struct woption long_options[] = {
|
static const struct woption long_options[] = {
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{L"current-filename", no_argument, NULL, 'f'},
|
{L"current-filename", no_argument, nullptr, 'f'},
|
||||||
{L"current-line-number", no_argument, NULL, 'n'},
|
{L"current-line-number", no_argument, nullptr, 'n'},
|
||||||
{L"filename", no_argument, NULL, 'f'},
|
{L"filename", no_argument, nullptr, 'f'},
|
||||||
{L"fish-path", no_argument, NULL, STATUS_FISH_PATH},
|
{L"fish-path", no_argument, nullptr, STATUS_FISH_PATH},
|
||||||
{L"is-block", no_argument, NULL, 'b'},
|
{L"is-block", no_argument, nullptr, 'b'},
|
||||||
{L"is-command-substitution", no_argument, NULL, 'c'},
|
{L"is-command-substitution", no_argument, nullptr, 'c'},
|
||||||
{L"is-full-job-control", no_argument, NULL, STATUS_IS_FULL_JOB_CTRL},
|
{L"is-full-job-control", no_argument, nullptr, STATUS_IS_FULL_JOB_CTRL},
|
||||||
{L"is-interactive", no_argument, NULL, 'i'},
|
{L"is-interactive", no_argument, nullptr, 'i'},
|
||||||
{L"is-interactive-job-control", no_argument, NULL, STATUS_IS_INTERACTIVE_JOB_CTRL},
|
{L"is-interactive-job-control", no_argument, nullptr, STATUS_IS_INTERACTIVE_JOB_CTRL},
|
||||||
{L"is-login", no_argument, NULL, 'l'},
|
{L"is-login", no_argument, nullptr, 'l'},
|
||||||
{L"is-no-job-control", no_argument, NULL, STATUS_IS_NO_JOB_CTRL},
|
{L"is-no-job-control", no_argument, nullptr, STATUS_IS_NO_JOB_CTRL},
|
||||||
{L"job-control", required_argument, NULL, 'j'},
|
{L"job-control", required_argument, nullptr, 'j'},
|
||||||
{L"level", required_argument, NULL, 'L'},
|
{L"level", required_argument, nullptr, 'L'},
|
||||||
{L"line", no_argument, NULL, 'n'},
|
{L"line", no_argument, nullptr, 'n'},
|
||||||
{L"line-number", no_argument, NULL, 'n'},
|
{L"line-number", no_argument, nullptr, 'n'},
|
||||||
{L"print-stack-trace", no_argument, NULL, 't'},
|
{L"print-stack-trace", no_argument, nullptr, 't'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
/// Remember the status subcommand and disallow selecting more than one status subcommand.
|
/// Remember the status subcommand and disallow selecting more than one status subcommand.
|
||||||
static bool set_status_cmd(wchar_t *const cmd, status_cmd_opts_t &opts, status_cmd_t sub_cmd,
|
static bool set_status_cmd(wchar_t *const cmd, status_cmd_opts_t &opts, status_cmd_t sub_cmd,
|
||||||
|
@ -154,7 +154,7 @@ static int parse_cmd_opts(status_cmd_opts_t &opts, int *optind, //!OCLINT(high
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case STATUS_IS_FULL_JOB_CTRL: {
|
case STATUS_IS_FULL_JOB_CTRL: {
|
||||||
if (!set_status_cmd(cmd, opts, STATUS_IS_FULL_JOB_CTRL, streams)) {
|
if (!set_status_cmd(cmd, opts, STATUS_IS_FULL_JOB_CTRL, streams)) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ static bool string_args_from_stdin(const io_streams_t &streams) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const wchar_t *string_get_arg_argv(int *argidx, const wchar_t *const *argv) {
|
static const wchar_t *string_get_arg_argv(int *argidx, const wchar_t *const *argv) {
|
||||||
return argv && argv[*argidx] ? argv[(*argidx)++] : NULL;
|
return argv && argv[*argidx] ? argv[(*argidx)++] : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A helper type for extracting arguments from either argv or stdin.
|
// A helper type for extracting arguments from either argv or stdin.
|
||||||
|
@ -119,13 +119,13 @@ class arg_iterator_t {
|
||||||
|
|
||||||
const wcstring *nextstr() {
|
const wcstring *nextstr() {
|
||||||
if (string_args_from_stdin(streams_)) {
|
if (string_args_from_stdin(streams_)) {
|
||||||
return get_arg_stdin() ? &storage_ : NULL;
|
return get_arg_stdin() ? &storage_ : nullptr;
|
||||||
}
|
}
|
||||||
if (auto arg = string_get_arg_argv(&argidx_, argv_)) {
|
if (auto arg = string_get_arg_argv(&argidx_, argv_)) {
|
||||||
storage_ = arg;
|
storage_ = arg;
|
||||||
return &storage_;
|
return &storage_;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -176,8 +176,8 @@ typedef struct { //!OCLINT(too many fields)
|
||||||
long start = 0;
|
long start = 0;
|
||||||
|
|
||||||
const wchar_t *chars_to_trim = L" \f\n\r\t";
|
const wchar_t *chars_to_trim = L" \f\n\r\t";
|
||||||
const wchar_t *arg1 = NULL;
|
const wchar_t *arg1 = nullptr;
|
||||||
const wchar_t *arg2 = NULL;
|
const wchar_t *arg2 = nullptr;
|
||||||
|
|
||||||
escape_string_style_t escape_style = STRING_STYLE_SCRIPT;
|
escape_string_style_t escape_style = STRING_STYLE_SCRIPT;
|
||||||
} options_t;
|
} options_t;
|
||||||
|
@ -416,27 +416,27 @@ static wcstring construct_short_opts(options_t *opts) { //!OCLINT(high npath co
|
||||||
// Note that several long flags share the same short flag. That is okay. The caller is expected
|
// Note that several long flags share the same short flag. That is okay. The caller is expected
|
||||||
// to indicate that a max of one of the long flags sharing a short flag is valid.
|
// to indicate that a max of one of the long flags sharing a short flag is valid.
|
||||||
// Remember: adjust share/completions/string.fish when `string` options change
|
// Remember: adjust share/completions/string.fish when `string` options change
|
||||||
static const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'},
|
static const struct woption long_options[] = {{L"all", no_argument, nullptr, 'a'},
|
||||||
{L"chars", required_argument, NULL, 'c'},
|
{L"chars", required_argument, nullptr, 'c'},
|
||||||
{L"count", required_argument, NULL, 'n'},
|
{L"count", required_argument, nullptr, 'n'},
|
||||||
{L"entire", no_argument, NULL, 'e'},
|
{L"entire", no_argument, nullptr, 'e'},
|
||||||
{L"filter", no_argument, NULL, 'f'},
|
{L"filter", no_argument, nullptr, 'f'},
|
||||||
{L"ignore-case", no_argument, NULL, 'i'},
|
{L"ignore-case", no_argument, nullptr, 'i'},
|
||||||
{L"index", no_argument, NULL, 'n'},
|
{L"index", no_argument, nullptr, 'n'},
|
||||||
{L"invert", no_argument, NULL, 'v'},
|
{L"invert", no_argument, nullptr, 'v'},
|
||||||
{L"left", no_argument, NULL, 'l'},
|
{L"left", no_argument, nullptr, 'l'},
|
||||||
{L"length", required_argument, NULL, 'l'},
|
{L"length", required_argument, nullptr, 'l'},
|
||||||
{L"max", required_argument, NULL, 'm'},
|
{L"max", required_argument, nullptr, 'm'},
|
||||||
{L"no-empty", no_argument, NULL, 'n'},
|
{L"no-empty", no_argument, nullptr, 'n'},
|
||||||
{L"no-newline", no_argument, NULL, 'N'},
|
{L"no-newline", no_argument, nullptr, 'N'},
|
||||||
{L"no-quoted", no_argument, NULL, 'n'},
|
{L"no-quoted", no_argument, nullptr, 'n'},
|
||||||
{L"quiet", no_argument, NULL, 'q'},
|
{L"quiet", no_argument, nullptr, 'q'},
|
||||||
{L"regex", no_argument, NULL, 'r'},
|
{L"regex", no_argument, nullptr, 'r'},
|
||||||
{L"right", no_argument, NULL, 'r'},
|
{L"right", no_argument, nullptr, 'r'},
|
||||||
{L"start", required_argument, NULL, 's'},
|
{L"start", required_argument, nullptr, 's'},
|
||||||
{L"style", required_argument, NULL, 1},
|
{L"style", required_argument, nullptr, 1},
|
||||||
{L"no-trim-newlines", no_argument, NULL, 'N'},
|
{L"no-trim-newlines", no_argument, nullptr, 'N'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
static const std::unordered_map<char, decltype(*handle_flag_N)> flag_to_function = {
|
static const std::unordered_map<char, decltype(*handle_flag_N)> flag_to_function = {
|
||||||
{'N', handle_flag_N}, {'a', handle_flag_a}, {'c', handle_flag_c}, {'e', handle_flag_e},
|
{'N', handle_flag_N}, {'a', handle_flag_a}, {'c', handle_flag_c}, {'e', handle_flag_e},
|
||||||
|
@ -452,7 +452,7 @@ static int parse_opts(options_t *opts, int *optind, int n_req_args, int argc, wc
|
||||||
const wchar_t *short_options = short_opts.c_str();
|
const wchar_t *short_options = short_opts.c_str();
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
auto fn = flag_to_function.find(opt);
|
auto fn = flag_to_function.find(opt);
|
||||||
if (fn != flag_to_function.end()) {
|
if (fn != flag_to_function.end()) {
|
||||||
int retval = fn->second(argv, parser, streams, w, opts);
|
int retval = fn->second(argv, parser, streams, w, opts);
|
||||||
|
@ -685,7 +685,7 @@ struct compiled_regex_t {
|
||||||
|
|
||||||
compiled_regex_t(const wchar_t *argv0, const wcstring &pattern, bool ignore_case,
|
compiled_regex_t(const wchar_t *argv0, const wcstring &pattern, bool ignore_case,
|
||||||
io_streams_t &streams)
|
io_streams_t &streams)
|
||||||
: code(0), match(0) {
|
: code(nullptr), match(nullptr) {
|
||||||
// Disable some sequences that can lead to security problems.
|
// Disable some sequences that can lead to security problems.
|
||||||
uint32_t options = PCRE2_NEVER_UTF;
|
uint32_t options = PCRE2_NEVER_UTF;
|
||||||
#if PCRE2_CODE_UNIT_WIDTH < 32
|
#if PCRE2_CODE_UNIT_WIDTH < 32
|
||||||
|
@ -695,10 +695,10 @@ struct compiled_regex_t {
|
||||||
int err_code = 0;
|
int err_code = 0;
|
||||||
PCRE2_SIZE err_offset = 0;
|
PCRE2_SIZE err_offset = 0;
|
||||||
|
|
||||||
code =
|
code = pcre2_compile(PCRE2_SPTR(pattern.c_str()), pattern.length(),
|
||||||
pcre2_compile(PCRE2_SPTR(pattern.c_str()), pattern.length(),
|
options | (ignore_case ? PCRE2_CASELESS : 0), &err_code, &err_offset,
|
||||||
options | (ignore_case ? PCRE2_CASELESS : 0), &err_code, &err_offset, 0);
|
nullptr);
|
||||||
if (code == 0) {
|
if (code == nullptr) {
|
||||||
string_error(streams, _(L"%ls: Regular expression compile error: %ls\n"), argv0,
|
string_error(streams, _(L"%ls: Regular expression compile error: %ls\n"), argv0,
|
||||||
pcre2_strerror(err_code).c_str());
|
pcre2_strerror(err_code).c_str());
|
||||||
string_error(streams, L"%ls: %ls\n", argv0, pattern.c_str());
|
string_error(streams, L"%ls: %ls\n", argv0, pattern.c_str());
|
||||||
|
@ -706,15 +706,15 @@ struct compiled_regex_t {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
match = pcre2_match_data_create_from_pattern(code, 0);
|
match = pcre2_match_data_create_from_pattern(code, nullptr);
|
||||||
assert(match);
|
assert(match);
|
||||||
}
|
}
|
||||||
|
|
||||||
~compiled_regex_t() {
|
~compiled_regex_t() {
|
||||||
if (match != 0) {
|
if (match != nullptr) {
|
||||||
pcre2_match_data_free(match);
|
pcre2_match_data_free(match);
|
||||||
}
|
}
|
||||||
if (code != 0) {
|
if (code != nullptr) {
|
||||||
pcre2_code_free(code);
|
pcre2_code_free(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -785,7 +785,7 @@ class pcre2_matcher_t : public string_matcher_t {
|
||||||
bool report_matches(const wcstring &arg) override {
|
bool report_matches(const wcstring &arg) override {
|
||||||
// A return value of true means all is well (even if no matches were found), false indicates
|
// A return value of true means all is well (even if no matches were found), false indicates
|
||||||
// an unrecoverable error.
|
// an unrecoverable error.
|
||||||
if (regex.code == 0) {
|
if (regex.code == nullptr) {
|
||||||
// pcre2_compile() failed.
|
// pcre2_compile() failed.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -794,8 +794,8 @@ class pcre2_matcher_t : public string_matcher_t {
|
||||||
|
|
||||||
// See pcre2demo.c for an explanation of this logic.
|
// See pcre2demo.c for an explanation of this logic.
|
||||||
PCRE2_SIZE arglen = arg.length();
|
PCRE2_SIZE arglen = arg.length();
|
||||||
int rc = report_match(
|
int rc = report_match(arg, pcre2_match(regex.code, PCRE2_SPTR(arg.c_str()), arglen, 0, 0,
|
||||||
arg, pcre2_match(regex.code, PCRE2_SPTR(arg.c_str()), arglen, 0, 0, regex.match, 0));
|
regex.match, nullptr));
|
||||||
if (rc < 0) { // pcre2 match error.
|
if (rc < 0) { // pcre2 match error.
|
||||||
return false;
|
return false;
|
||||||
} else if (rc == 0) { // no match
|
} else if (rc == 0) { // no match
|
||||||
|
@ -822,7 +822,7 @@ class pcre2_matcher_t : public string_matcher_t {
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = report_match(arg, pcre2_match(regex.code, PCRE2_SPTR(arg.c_str()), arglen, offset,
|
rc = report_match(arg, pcre2_match(regex.code, PCRE2_SPTR(arg.c_str()), arglen, offset,
|
||||||
options, regex.match, 0));
|
options, regex.match, nullptr));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1008,7 +1008,7 @@ bool regex_replacer_t::replace_matches(const wcstring &arg) {
|
||||||
pcre2_rc = pcre2_substitute(regex.code, PCRE2_SPTR(arg.c_str()), arglen,
|
pcre2_rc = pcre2_substitute(regex.code, PCRE2_SPTR(arg.c_str()), arglen,
|
||||||
0, // start offset
|
0, // start offset
|
||||||
options, regex.match,
|
options, regex.match,
|
||||||
0, // match context
|
nullptr, // match context
|
||||||
PCRE2_SPTR(replacement->c_str()), replacement->length(),
|
PCRE2_SPTR(replacement->c_str()), replacement->length(),
|
||||||
reinterpret_cast<PCRE2_UCHAR *>(output), &outlen);
|
reinterpret_cast<PCRE2_UCHAR *>(output), &outlen);
|
||||||
|
|
||||||
|
@ -1332,14 +1332,13 @@ static const struct string_subcommand {
|
||||||
wchar_t **argv); //!OCLINT(unused param)
|
wchar_t **argv); //!OCLINT(unused param)
|
||||||
}
|
}
|
||||||
|
|
||||||
string_subcommands[] = {{L"escape", &string_escape}, {L"join", &string_join},
|
string_subcommands[] = {
|
||||||
{L"join0", &string_join0}, {L"length", &string_length},
|
{L"escape", &string_escape}, {L"join", &string_join}, {L"join0", &string_join0},
|
||||||
{L"match", &string_match}, {L"replace", &string_replace},
|
{L"length", &string_length}, {L"match", &string_match}, {L"replace", &string_replace},
|
||||||
{L"split", &string_split}, {L"split0", &string_split0},
|
{L"split", &string_split}, {L"split0", &string_split0}, {L"sub", &string_sub},
|
||||||
{L"sub", &string_sub}, {L"trim", &string_trim},
|
{L"trim", &string_trim}, {L"lower", &string_lower}, {L"upper", &string_upper},
|
||||||
{L"lower", &string_lower}, {L"upper", &string_upper},
|
{L"repeat", &string_repeat}, {L"unescape", &string_unescape}, {L"collect", &string_collect},
|
||||||
{L"repeat", &string_repeat}, {L"unescape", &string_unescape},
|
{nullptr, nullptr}};
|
||||||
{L"collect", &string_collect}, {NULL, NULL}};
|
|
||||||
|
|
||||||
/// The string builtin, for manipulating strings.
|
/// The string builtin, for manipulating strings.
|
||||||
int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
|
@ -1357,7 +1356,7 @@ int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const string_subcommand *subcmd = &string_subcommands[0];
|
const string_subcommand *subcmd = &string_subcommands[0];
|
||||||
while (subcmd->name != 0 && std::wcscmp(subcmd->name, argv[1]) != 0) {
|
while (subcmd->name != nullptr && std::wcscmp(subcmd->name, argv[1]) != 0) {
|
||||||
subcmd++;
|
subcmd++;
|
||||||
}
|
}
|
||||||
if (!subcmd->handler) {
|
if (!subcmd->handler) {
|
||||||
|
|
|
@ -288,7 +288,7 @@ class parenthetical_expression : public expression {
|
||||||
};
|
};
|
||||||
|
|
||||||
void test_parser::add_error(const wchar_t *fmt, ...) {
|
void test_parser::add_error(const wchar_t *fmt, ...) {
|
||||||
assert(fmt != NULL);
|
assert(fmt != nullptr);
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
this->errors.push_back(vformat_string(fmt, va));
|
this->errors.push_back(vformat_string(fmt, va));
|
||||||
|
@ -296,12 +296,12 @@ void test_parser::add_error(const wchar_t *fmt, ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<expression> test_parser::error(const wchar_t *fmt, ...) {
|
unique_ptr<expression> test_parser::error(const wchar_t *fmt, ...) {
|
||||||
assert(fmt != NULL);
|
assert(fmt != nullptr);
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
this->errors.push_back(vformat_string(fmt, va));
|
this->errors.push_back(vformat_string(fmt, va));
|
||||||
va_end(va);
|
va_end(va);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<expression> test_parser::parse_unary_expression(unsigned int start, unsigned int end) {
|
unique_ptr<expression> test_parser::parse_unary_expression(unsigned int start, unsigned int end) {
|
||||||
|
@ -315,7 +315,7 @@ unique_ptr<expression> test_parser::parse_unary_expression(unsigned int start, u
|
||||||
return make_unique<unary_operator>(tok, range_t(start, subject->range.end),
|
return make_unique<unary_operator>(tok, range_t(start, subject->range.end),
|
||||||
move(subject));
|
move(subject));
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return parse_primary(start, end);
|
return parse_primary(start, end);
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ unique_ptr<expression> test_parser::parse_unary_expression(unsigned int start, u
|
||||||
/// Parse a combining expression (AND, OR).
|
/// Parse a combining expression (AND, OR).
|
||||||
unique_ptr<expression> test_parser::parse_combining_expression(unsigned int start,
|
unique_ptr<expression> test_parser::parse_combining_expression(unsigned int start,
|
||||||
unsigned int end) {
|
unsigned int end) {
|
||||||
if (start >= end) return NULL;
|
if (start >= end) return nullptr;
|
||||||
|
|
||||||
std::vector<unique_ptr<expression>> subjects;
|
std::vector<unique_ptr<expression>> subjects;
|
||||||
std::vector<token_t> combiners;
|
std::vector<token_t> combiners;
|
||||||
|
@ -363,7 +363,7 @@ unique_ptr<expression> test_parser::parse_combining_expression(unsigned int star
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subjects.empty()) {
|
if (subjects.empty()) {
|
||||||
return NULL; // no subjects
|
return nullptr; // no subjects
|
||||||
}
|
}
|
||||||
// Our new expression takes ownership of all expressions we created. The token we pass is
|
// Our new expression takes ownership of all expressions we created. The token we pass is
|
||||||
// irrelevant.
|
// irrelevant.
|
||||||
|
@ -382,7 +382,7 @@ unique_ptr<expression> test_parser::parse_unary_primary(unsigned int start, unsi
|
||||||
|
|
||||||
// All our unary primaries are prefix, so the operator is at start.
|
// All our unary primaries are prefix, so the operator is at start.
|
||||||
const token_info_t *info = token_for_string(arg(start));
|
const token_info_t *info = token_for_string(arg(start));
|
||||||
if (!(info->flags & UNARY_PRIMARY)) return NULL;
|
if (!(info->flags & UNARY_PRIMARY)) return nullptr;
|
||||||
|
|
||||||
return make_unique<unary_primary>(info->tok, range_t(start, start + 2), arg(start + 1));
|
return make_unique<unary_primary>(info->tok, range_t(start, start + 2), arg(start + 1));
|
||||||
}
|
}
|
||||||
|
@ -416,7 +416,7 @@ unique_ptr<expression> test_parser::parse_binary_primary(unsigned int start, uns
|
||||||
|
|
||||||
// All our binary primaries are infix, so the operator is at start + 1.
|
// All our binary primaries are infix, so the operator is at start + 1.
|
||||||
const token_info_t *info = token_for_string(arg(start + 1));
|
const token_info_t *info = token_for_string(arg(start + 1));
|
||||||
if (!(info->flags & BINARY_PRIMARY)) return NULL;
|
if (!(info->flags & BINARY_PRIMARY)) return nullptr;
|
||||||
|
|
||||||
return make_unique<binary_primary>(info->tok, range_t(start, start + 3), arg(start),
|
return make_unique<binary_primary>(info->tok, range_t(start, start + 3), arg(start),
|
||||||
arg(start + 2));
|
arg(start + 2));
|
||||||
|
@ -424,15 +424,15 @@ unique_ptr<expression> test_parser::parse_binary_primary(unsigned int start, uns
|
||||||
|
|
||||||
unique_ptr<expression> test_parser::parse_parenthentical(unsigned int start, unsigned int end) {
|
unique_ptr<expression> test_parser::parse_parenthentical(unsigned int start, unsigned int end) {
|
||||||
// We need at least three arguments: open paren, argument, close paren.
|
// We need at least three arguments: open paren, argument, close paren.
|
||||||
if (start + 3 >= end) return NULL;
|
if (start + 3 >= end) return nullptr;
|
||||||
|
|
||||||
// Must start with an open expression.
|
// Must start with an open expression.
|
||||||
const token_info_t *open_paren = token_for_string(arg(start));
|
const token_info_t *open_paren = token_for_string(arg(start));
|
||||||
if (open_paren->tok != test_paren_open) return NULL;
|
if (open_paren->tok != test_paren_open) return nullptr;
|
||||||
|
|
||||||
// Parse a subexpression.
|
// Parse a subexpression.
|
||||||
unique_ptr<expression> subexpr = parse_expression(start + 1, end);
|
unique_ptr<expression> subexpr = parse_expression(start + 1, end);
|
||||||
if (!subexpr) return NULL;
|
if (!subexpr) return nullptr;
|
||||||
|
|
||||||
// Parse a close paren.
|
// Parse a close paren.
|
||||||
unsigned close_index = subexpr->range.end;
|
unsigned close_index = subexpr->range.end;
|
||||||
|
@ -455,7 +455,7 @@ unique_ptr<expression> test_parser::parse_primary(unsigned int start, unsigned i
|
||||||
return error(L"Missing argument at index %u", start);
|
return error(L"Missing argument at index %u", start);
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<expression> expr = NULL;
|
unique_ptr<expression> expr = nullptr;
|
||||||
if (!expr) expr = parse_parenthentical(start, end);
|
if (!expr) expr = parse_parenthentical(start, end);
|
||||||
if (!expr) expr = parse_unary_primary(start, end);
|
if (!expr) expr = parse_unary_primary(start, end);
|
||||||
if (!expr) expr = parse_binary_primary(start, end);
|
if (!expr) expr = parse_binary_primary(start, end);
|
||||||
|
@ -466,7 +466,7 @@ unique_ptr<expression> test_parser::parse_primary(unsigned int start, unsigned i
|
||||||
// See IEEE 1003.1 breakdown of the behavior for different parameter counts.
|
// See IEEE 1003.1 breakdown of the behavior for different parameter counts.
|
||||||
unique_ptr<expression> test_parser::parse_3_arg_expression(unsigned int start, unsigned int end) {
|
unique_ptr<expression> test_parser::parse_3_arg_expression(unsigned int start, unsigned int end) {
|
||||||
assert(end - start == 3);
|
assert(end - start == 3);
|
||||||
unique_ptr<expression> result = NULL;
|
unique_ptr<expression> result = nullptr;
|
||||||
|
|
||||||
const token_info_t *center_token = token_for_string(arg(start + 1));
|
const token_info_t *center_token = token_for_string(arg(start + 1));
|
||||||
if (center_token->flags & BINARY_PRIMARY) {
|
if (center_token->flags & BINARY_PRIMARY) {
|
||||||
|
@ -491,7 +491,7 @@ unique_ptr<expression> test_parser::parse_3_arg_expression(unsigned int start, u
|
||||||
|
|
||||||
unique_ptr<expression> test_parser::parse_4_arg_expression(unsigned int start, unsigned int end) {
|
unique_ptr<expression> test_parser::parse_4_arg_expression(unsigned int start, unsigned int end) {
|
||||||
assert(end - start == 4);
|
assert(end - start == 4);
|
||||||
unique_ptr<expression> result = NULL;
|
unique_ptr<expression> result = nullptr;
|
||||||
|
|
||||||
token_t first_token = token_for_string(arg(start))->tok;
|
token_t first_token = token_for_string(arg(start))->tok;
|
||||||
if (first_token == test_bang) {
|
if (first_token == test_bang) {
|
||||||
|
@ -565,7 +565,7 @@ unique_ptr<expression> test_parser::parse_args(const wcstring_list_t &args, wcst
|
||||||
static_cast<unsigned long>(result->range.end),
|
static_cast<unsigned long>(result->range.end),
|
||||||
args.at(result->range.end).c_str());
|
args.at(result->range.end).c_str());
|
||||||
}
|
}
|
||||||
result.reset(NULL);
|
result.reset(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,7 +641,7 @@ static bool parse_double(const wchar_t *arg, double *out_res) {
|
||||||
// Consume leading spaces.
|
// Consume leading spaces.
|
||||||
while (arg && *arg != L'\0' && iswspace(*arg)) arg++;
|
while (arg && *arg != L'\0' && iswspace(*arg)) arg++;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
wchar_t *end = NULL;
|
wchar_t *end = nullptr;
|
||||||
*out_res = fish_wcstod(arg, &end);
|
*out_res = fish_wcstod(arg, &end);
|
||||||
// Consume trailing spaces.
|
// Consume trailing spaces.
|
||||||
while (end && *end != L'\0' && iswspace(*end)) end++;
|
while (end && *end != L'\0' && iswspace(*end)) end++;
|
||||||
|
|
|
@ -43,7 +43,7 @@ static const struct resource_t resource_arr[] = {
|
||||||
#ifdef RLIMIT_AS
|
#ifdef RLIMIT_AS
|
||||||
{RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024},
|
{RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024},
|
||||||
#endif
|
#endif
|
||||||
{0, 0, 0, 0}};
|
{0, nullptr, 0, 0}};
|
||||||
|
|
||||||
/// Get the implicit multiplication factor for the specified resource limit.
|
/// Get the implicit multiplication factor for the specified resource limit.
|
||||||
static int get_multiplier(int what) {
|
static int get_multiplier(int what) {
|
||||||
|
@ -159,25 +159,25 @@ int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
|
|
||||||
static const wchar_t *const short_options = L":HSacdflmnstuvh";
|
static const wchar_t *const short_options = L":HSacdflmnstuvh";
|
||||||
static const struct woption long_options[] = {
|
static const struct woption long_options[] = {
|
||||||
{L"all", no_argument, NULL, 'a'},
|
{L"all", no_argument, nullptr, 'a'},
|
||||||
{L"hard", no_argument, NULL, 'H'},
|
{L"hard", no_argument, nullptr, 'H'},
|
||||||
{L"soft", no_argument, NULL, 'S'},
|
{L"soft", no_argument, nullptr, 'S'},
|
||||||
{L"core-size", no_argument, NULL, 'c'},
|
{L"core-size", no_argument, nullptr, 'c'},
|
||||||
{L"data-size", no_argument, NULL, 'd'},
|
{L"data-size", no_argument, nullptr, 'd'},
|
||||||
{L"file-size", no_argument, NULL, 'f'},
|
{L"file-size", no_argument, nullptr, 'f'},
|
||||||
{L"lock-size", no_argument, NULL, 'l'},
|
{L"lock-size", no_argument, nullptr, 'l'},
|
||||||
{L"resident-set-size", no_argument, NULL, 'm'},
|
{L"resident-set-size", no_argument, nullptr, 'm'},
|
||||||
{L"file-descriptor-count", no_argument, NULL, 'n'},
|
{L"file-descriptor-count", no_argument, nullptr, 'n'},
|
||||||
{L"stack-size", no_argument, NULL, 's'},
|
{L"stack-size", no_argument, nullptr, 's'},
|
||||||
{L"cpu-time", no_argument, NULL, 't'},
|
{L"cpu-time", no_argument, nullptr, 't'},
|
||||||
{L"process-count", no_argument, NULL, 'u'},
|
{L"process-count", no_argument, nullptr, 'u'},
|
||||||
{L"virtual-memory-size", no_argument, NULL, 'v'},
|
{L"virtual-memory-size", no_argument, nullptr, 'v'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a': {
|
case 'a': {
|
||||||
report_all = true;
|
report_all = true;
|
||||||
|
|
|
@ -183,12 +183,12 @@ int builtin_wait(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
bool any_flag = false; // flag for -n option
|
bool any_flag = false; // flag for -n option
|
||||||
|
|
||||||
static const wchar_t *const short_options = L":n";
|
static const wchar_t *const short_options = L":n";
|
||||||
static const struct woption long_options[] = {{L"any", no_argument, NULL, 'n'},
|
static const struct woption long_options[] = {{L"any", no_argument, nullptr, 'n'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'n':
|
case 'n':
|
||||||
any_flag = true;
|
any_flag = true;
|
||||||
|
|
|
@ -137,7 +137,7 @@ long convert_digit(wchar_t d, int base) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test whether the char is a valid hex digit as used by the `escape_string_*()` functions.
|
/// Test whether the char is a valid hex digit as used by the `escape_string_*()` functions.
|
||||||
static bool is_hex_digit(int c) { return std::strchr("0123456789ABCDEF", c) != NULL; }
|
static bool is_hex_digit(int c) { return std::strchr("0123456789ABCDEF", c) != nullptr; }
|
||||||
|
|
||||||
/// This is a specialization of `convert_digit()` that only handles base 16 and only uppercase.
|
/// This is a specialization of `convert_digit()` that only handles base 16 and only uppercase.
|
||||||
long convert_hex_digit(wchar_t d) {
|
long convert_hex_digit(wchar_t d) {
|
||||||
|
@ -216,13 +216,14 @@ bool is_windows_subsystem_for_linux() {
|
||||||
for (int i = skip_levels; i < n_frames; i++) {
|
for (int i = skip_levels; i < n_frames; i++) {
|
||||||
Dl_info info;
|
Dl_info info;
|
||||||
if (dladdr(callstack[i], &info) && info.dli_sname) {
|
if (dladdr(callstack[i], &info) && info.dli_sname) {
|
||||||
char *demangled = NULL;
|
char *demangled = nullptr;
|
||||||
int status = -1;
|
int status = -1;
|
||||||
if (info.dli_sname[0] == '_')
|
if (info.dli_sname[0] == '_')
|
||||||
demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status);
|
demangled = abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &status);
|
||||||
swprintf(text, sizeof(text) / sizeof(wchar_t), L"%-3d %s + %td", i - skip_levels,
|
swprintf(
|
||||||
status == 0 ? demangled : info.dli_sname == 0 ? symbols[i] : info.dli_sname,
|
text, sizeof(text) / sizeof(wchar_t), L"%-3d %s + %td", i - skip_levels,
|
||||||
static_cast<char *>(callstack[i]) - static_cast<char *>(info.dli_saddr));
|
status == 0 ? demangled : info.dli_sname == nullptr ? symbols[i] : info.dli_sname,
|
||||||
|
static_cast<char *>(callstack[i]) - static_cast<char *>(info.dli_saddr));
|
||||||
free(demangled);
|
free(demangled);
|
||||||
} else {
|
} else {
|
||||||
swprintf(text, sizeof(text) / sizeof(wchar_t), L"%-3d %s", i - skip_levels, symbols[i]);
|
swprintf(text, sizeof(text) / sizeof(wchar_t), L"%-3d %s", i - skip_levels, symbols[i]);
|
||||||
|
@ -287,7 +288,7 @@ int fgetws2(wcstring *s, FILE *f) {
|
||||||
/// area.
|
/// area.
|
||||||
static wcstring str2wcs_internal(const char *in, const size_t in_len) {
|
static wcstring str2wcs_internal(const char *in, const size_t in_len) {
|
||||||
if (in_len == 0) return wcstring();
|
if (in_len == 0) return wcstring();
|
||||||
assert(in != NULL);
|
assert(in != nullptr);
|
||||||
|
|
||||||
wcstring result;
|
wcstring result;
|
||||||
result.reserve(in_len);
|
result.reserve(in_len);
|
||||||
|
@ -375,7 +376,7 @@ wcstring str2wcstring(const std::string &in, size_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wcs2str(const wchar_t *in, size_t len) {
|
char *wcs2str(const wchar_t *in, size_t len) {
|
||||||
if (!in) return NULL;
|
if (!in) return nullptr;
|
||||||
size_t desired_size = MAX_UTF8_BYTES * len + 1;
|
size_t desired_size = MAX_UTF8_BYTES * len + 1;
|
||||||
char local_buff[512];
|
char local_buff[512];
|
||||||
if (desired_size <= sizeof local_buff / sizeof *local_buff) {
|
if (desired_size <= sizeof local_buff / sizeof *local_buff) {
|
||||||
|
@ -507,7 +508,7 @@ void append_formatv(wcstring &target, const wchar_t *format, va_list va_orig) {
|
||||||
const size_t max_size = (128 * 1024 * 1024);
|
const size_t max_size = (128 * 1024 * 1024);
|
||||||
wchar_t static_buff[256];
|
wchar_t static_buff[256];
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
wchar_t *buff = NULL;
|
wchar_t *buff = nullptr;
|
||||||
int status = -1;
|
int status = -1;
|
||||||
while (status < 0) {
|
while (status < 0) {
|
||||||
// Reallocate if necessary.
|
// Reallocate if necessary.
|
||||||
|
@ -520,8 +521,8 @@ void append_formatv(wcstring &target, const wchar_t *format, va_list va_orig) {
|
||||||
buff[0] = '\0';
|
buff[0] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buff = static_cast<wchar_t *>(realloc((buff == static_buff ? NULL : buff), size));
|
buff = static_cast<wchar_t *>(realloc((buff == static_buff ? nullptr : buff), size));
|
||||||
assert(buff != NULL);
|
assert(buff != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try printing.
|
// Try printing.
|
||||||
|
@ -559,18 +560,18 @@ wchar_t *quote_end(const wchar_t *pos) {
|
||||||
while (1) {
|
while (1) {
|
||||||
pos++;
|
pos++;
|
||||||
|
|
||||||
if (!*pos) return 0;
|
if (!*pos) return nullptr;
|
||||||
|
|
||||||
if (*pos == L'\\') {
|
if (*pos == L'\\') {
|
||||||
pos++;
|
pos++;
|
||||||
if (!*pos) return 0;
|
if (!*pos) return nullptr;
|
||||||
} else {
|
} else {
|
||||||
if (*pos == c) {
|
if (*pos == c) {
|
||||||
return const_cast<wchar_t *>(pos);
|
return const_cast<wchar_t *>(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fish_setlocale() {
|
void fish_setlocale() {
|
||||||
|
@ -720,7 +721,7 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para
|
||||||
const char *cursor = msg;
|
const char *cursor = msg;
|
||||||
while (*cursor != '\0') {
|
while (*cursor != '\0') {
|
||||||
const char *end = std::strchr(cursor, '%');
|
const char *end = std::strchr(cursor, '%');
|
||||||
if (end == NULL) end = cursor + std::strlen(cursor);
|
if (end == nullptr) end = cursor + std::strlen(cursor);
|
||||||
|
|
||||||
ignore_result(write(STDERR_FILENO, cursor, end - cursor));
|
ignore_result(write(STDERR_FILENO, cursor, end - cursor));
|
||||||
|
|
||||||
|
@ -1721,7 +1722,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
}
|
}
|
||||||
|
|
||||||
bool unescape_string_in_place(wcstring *str, unescape_flags_t escape_special) {
|
bool unescape_string_in_place(wcstring *str, unescape_flags_t escape_special) {
|
||||||
assert(str != NULL);
|
assert(str != nullptr);
|
||||||
wcstring output;
|
wcstring output;
|
||||||
bool success = unescape_string_internal(str->c_str(), str->size(), &output, escape_special);
|
bool success = unescape_string_internal(str->c_str(), str->size(), &output, escape_special);
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -2145,7 +2146,7 @@ int create_directory(const wcstring &d) {
|
||||||
|
|
||||||
wcstring format_size(long long sz) {
|
wcstring format_size(long long sz) {
|
||||||
wcstring result;
|
wcstring result;
|
||||||
const wchar_t *sz_name[] = {L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", 0};
|
const wchar_t *sz_name[] = {L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", nullptr};
|
||||||
|
|
||||||
if (sz < 0) {
|
if (sz < 0) {
|
||||||
result.append(L"unknown");
|
result.append(L"unknown");
|
||||||
|
@ -2201,7 +2202,7 @@ void format_size_safe(char buff[128], unsigned long long sz) {
|
||||||
const size_t max_len = buff_size - 1; // need to leave room for a null terminator
|
const size_t max_len = buff_size - 1; // need to leave room for a null terminator
|
||||||
std::memset(buff, 0, buff_size);
|
std::memset(buff, 0, buff_size);
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
const char *const sz_name[] = {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", NULL};
|
const char *const sz_name[] = {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", nullptr};
|
||||||
if (sz < 1) {
|
if (sz < 1) {
|
||||||
strncpy(buff, "empty", buff_size);
|
strncpy(buff, "empty", buff_size);
|
||||||
} else if (sz < 1024) {
|
} else if (sz < 1024) {
|
||||||
|
@ -2235,7 +2236,7 @@ void format_size_safe(char buff[128], unsigned long long sz) {
|
||||||
/// the gettimeofday function and will have the same precision as that function.
|
/// the gettimeofday function and will have the same precision as that function.
|
||||||
double timef() {
|
double timef() {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
assert_with_errno(gettimeofday(&tv, 0) != -1);
|
assert_with_errno(gettimeofday(&tv, nullptr) != -1);
|
||||||
// return (double)tv.tv_sec + 0.000001 * tv.tv_usec;
|
// return (double)tv.tv_sec + 0.000001 * tv.tv_usec;
|
||||||
return static_cast<double>(tv.tv_sec) + 1e-6 * tv.tv_usec;
|
return static_cast<double>(tv.tv_sec) + 1e-6 * tv.tv_usec;
|
||||||
}
|
}
|
||||||
|
@ -2389,7 +2390,7 @@ static CharType_t **make_null_terminated_array_helper(
|
||||||
// Now allocate their sum.
|
// Now allocate their sum.
|
||||||
unsigned char *base =
|
unsigned char *base =
|
||||||
static_cast<unsigned char *>(malloc(pointers_allocation_len + strings_allocation_len));
|
static_cast<unsigned char *>(malloc(pointers_allocation_len + strings_allocation_len));
|
||||||
if (!base) return NULL;
|
if (!base) return nullptr;
|
||||||
|
|
||||||
// Divvy it up into the pointers and strings.
|
// Divvy it up into the pointers and strings.
|
||||||
CharType_t **pointers = reinterpret_cast<CharType_t **>(base);
|
CharType_t **pointers = reinterpret_cast<CharType_t **>(base);
|
||||||
|
@ -2402,7 +2403,7 @@ static CharType_t **make_null_terminated_array_helper(
|
||||||
strings = std::copy(str.begin(), str.end(), strings); // copy the string into strings
|
strings = std::copy(str.begin(), str.end(), strings); // copy the string into strings
|
||||||
*strings++ = (CharType_t)(0); // each string needs a null terminator
|
*strings++ = (CharType_t)(0); // each string needs a null terminator
|
||||||
}
|
}
|
||||||
*pointers++ = NULL; // array of pointers needs a null terminator
|
*pointers++ = nullptr; // array of pointers needs a null terminator
|
||||||
|
|
||||||
// Make sure we know what we're doing.
|
// Make sure we know what we're doing.
|
||||||
assert((unsigned char *)pointers - base == (std::ptrdiff_t)pointers_allocation_len);
|
assert((unsigned char *)pointers - base == (std::ptrdiff_t)pointers_allocation_len);
|
||||||
|
|
22
src/common.h
22
src/common.h
|
@ -475,11 +475,13 @@ void format_size_safe(char buff[128], unsigned long long sz);
|
||||||
|
|
||||||
/// Our crappier versions of debug which is guaranteed to not allocate any memory, or do anything
|
/// Our crappier versions of debug which is guaranteed to not allocate any memory, or do anything
|
||||||
/// other than call write(). This is useful after a call to fork() with threads.
|
/// other than call write(). This is useful after a call to fork() with threads.
|
||||||
void debug_safe(int level, const char *msg, const char *param1 = NULL, const char *param2 = NULL,
|
void debug_safe(int level, const char *msg, const char *param1 = nullptr,
|
||||||
const char *param3 = NULL, const char *param4 = NULL, const char *param5 = NULL,
|
const char *param2 = nullptr, const char *param3 = nullptr,
|
||||||
const char *param6 = NULL, const char *param7 = NULL, const char *param8 = NULL,
|
const char *param4 = nullptr, const char *param5 = nullptr,
|
||||||
const char *param9 = NULL, const char *param10 = NULL, const char *param11 = NULL,
|
const char *param6 = nullptr, const char *param7 = nullptr,
|
||||||
const char *param12 = NULL);
|
const char *param8 = nullptr, const char *param9 = nullptr,
|
||||||
|
const char *param10 = nullptr, const char *param11 = nullptr,
|
||||||
|
const char *param12 = nullptr);
|
||||||
|
|
||||||
/// Writes out a long safely.
|
/// Writes out a long safely.
|
||||||
void format_long_safe(char buff[64], long val);
|
void format_long_safe(char buff[64], long val);
|
||||||
|
@ -529,7 +531,7 @@ char **make_null_terminated_array(const std::vector<std::string> &lst);
|
||||||
// Helper class for managing a null-terminated array of null-terminated strings (of some char type).
|
// Helper class for managing a null-terminated array of null-terminated strings (of some char type).
|
||||||
template <typename CharType_t>
|
template <typename CharType_t>
|
||||||
class null_terminated_array_t {
|
class null_terminated_array_t {
|
||||||
CharType_t **array{NULL};
|
CharType_t **array{nullptr};
|
||||||
|
|
||||||
// No assignment or copying.
|
// No assignment or copying.
|
||||||
void operator=(null_terminated_array_t rhs) = delete;
|
void operator=(null_terminated_array_t rhs) = delete;
|
||||||
|
@ -539,8 +541,8 @@ class null_terminated_array_t {
|
||||||
|
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
if (array != NULL) {
|
if (array != nullptr) {
|
||||||
while (array[len] != NULL) {
|
while (array[len] != nullptr) {
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,7 +551,7 @@ class null_terminated_array_t {
|
||||||
|
|
||||||
void free(void) {
|
void free(void) {
|
||||||
::free((void *)array);
|
::free((void *)array);
|
||||||
array = NULL;
|
array = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -951,7 +953,7 @@ static const wchar_t *enum_to_str(T enum_val, const enum_map<T> map[]) {
|
||||||
return entry->str;
|
return entry->str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void redirect_tty_output();
|
void redirect_tty_output();
|
||||||
|
|
|
@ -197,7 +197,7 @@ static complete_flags_t resolve_auto_space(const wcstring &comp, complete_flags_
|
||||||
if (flags & COMPLETE_AUTO_SPACE) {
|
if (flags & COMPLETE_AUTO_SPACE) {
|
||||||
new_flags &= ~COMPLETE_AUTO_SPACE;
|
new_flags &= ~COMPLETE_AUTO_SPACE;
|
||||||
size_t len = comp.size();
|
size_t len = comp.size();
|
||||||
if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != 0))
|
if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != nullptr))
|
||||||
new_flags |= COMPLETE_NO_SPACE;
|
new_flags |= COMPLETE_NO_SPACE;
|
||||||
}
|
}
|
||||||
return new_flags;
|
return new_flags;
|
||||||
|
@ -681,7 +681,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd) {
|
||||||
expand_string(str_cmd, &this->completions,
|
expand_string(str_cmd, &this->completions,
|
||||||
this->expand_flags() | expand_flag::special_for_command |
|
this->expand_flags() | expand_flag::special_for_command |
|
||||||
expand_flag::for_completions | expand_flag::executables_only,
|
expand_flag::for_completions | expand_flag::executables_only,
|
||||||
vars, parser, NULL);
|
vars, parser, nullptr);
|
||||||
if (result != expand_result_t::error && this->wants_descriptions()) {
|
if (result != expand_result_t::error && this->wants_descriptions()) {
|
||||||
this->complete_cmd_desc(str_cmd);
|
this->complete_cmd_desc(str_cmd);
|
||||||
}
|
}
|
||||||
|
@ -693,7 +693,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd) {
|
||||||
expand_string(
|
expand_string(
|
||||||
str_cmd, &this->completions,
|
str_cmd, &this->completions,
|
||||||
this->expand_flags() | expand_flag::for_completions | expand_flag::directories_only,
|
this->expand_flags() | expand_flag::for_completions | expand_flag::directories_only,
|
||||||
vars, parser, NULL);
|
vars, parser, nullptr);
|
||||||
UNUSED(ignore);
|
UNUSED(ignore);
|
||||||
|
|
||||||
if (str_cmd.empty() || (str_cmd.find(L'/') == wcstring::npos && str_cmd.at(0) != L'~')) {
|
if (str_cmd.empty() || (str_cmd.find(L'/') == wcstring::npos && str_cmd.at(0) != L'~')) {
|
||||||
|
@ -793,18 +793,18 @@ static bool param_match(const complete_entry_opt_t *e, const wchar_t *optstr) {
|
||||||
static const wchar_t *param_match2(const complete_entry_opt_t *e, const wchar_t *optstr) {
|
static const wchar_t *param_match2(const complete_entry_opt_t *e, const wchar_t *optstr) {
|
||||||
// We may get a complete_entry_opt_t with no options if it's just arguments.
|
// We may get a complete_entry_opt_t with no options if it's just arguments.
|
||||||
if (e->option.empty()) {
|
if (e->option.empty()) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify leading dashes.
|
// Verify leading dashes.
|
||||||
size_t cursor = leading_dash_count(optstr);
|
size_t cursor = leading_dash_count(optstr);
|
||||||
if (cursor != e->expected_dash_count()) {
|
if (cursor != e->expected_dash_count()) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify options match.
|
// Verify options match.
|
||||||
if (!string_prefixes_string(e->option, &optstr[cursor])) {
|
if (!string_prefixes_string(e->option, &optstr[cursor])) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
cursor += e->option.length();
|
cursor += e->option.length();
|
||||||
|
|
||||||
|
@ -812,7 +812,7 @@ static const wchar_t *param_match2(const complete_entry_opt_t *e, const wchar_t
|
||||||
// sign for long options.
|
// sign for long options.
|
||||||
assert(e->type != option_type_short);
|
assert(e->type != option_type_short);
|
||||||
if (optstr[cursor] != L'=') {
|
if (optstr[cursor] != L'=') {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
cursor += 1;
|
cursor += 1;
|
||||||
return &optstr[cursor];
|
return &optstr[cursor];
|
||||||
|
@ -954,7 +954,7 @@ bool completer_t::complete_param(const wcstring &cmd_orig, const wcstring &popt,
|
||||||
} else {
|
} else {
|
||||||
arg = param_match2(&o, str.c_str());
|
arg = param_match2(&o, str.c_str());
|
||||||
}
|
}
|
||||||
if (arg != NULL && this->condition_test(o.condition)) {
|
if (arg != nullptr && this->condition_test(o.condition)) {
|
||||||
if (o.result_mode.requires_param) use_common = false;
|
if (o.result_mode.requires_param) use_common = false;
|
||||||
if (o.result_mode.no_files) use_files = false;
|
if (o.result_mode.no_files) use_files = false;
|
||||||
if (o.result_mode.force_files) has_force = true;
|
if (o.result_mode.force_files) has_force = true;
|
||||||
|
@ -1136,7 +1136,7 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file,
|
||||||
// See #4954.
|
// See #4954.
|
||||||
const wcstring sep_string = wcstring(str, sep_index + 1);
|
const wcstring sep_string = wcstring(str, sep_index + 1);
|
||||||
std::vector<completion_t> local_completions;
|
std::vector<completion_t> local_completions;
|
||||||
if (expand_string(sep_string, &local_completions, flags, vars, parser, NULL) ==
|
if (expand_string(sep_string, &local_completions, flags, vars, parser, nullptr) ==
|
||||||
expand_result_t::error) {
|
expand_result_t::error) {
|
||||||
debug(3, L"Error while expanding string '%ls'", sep_string.c_str());
|
debug(3, L"Error while expanding string '%ls'", sep_string.c_str());
|
||||||
}
|
}
|
||||||
|
@ -1156,7 +1156,7 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file,
|
||||||
// consider relaxing this if there was a preceding double-dash argument.
|
// consider relaxing this if there was a preceding double-dash argument.
|
||||||
if (string_prefixes_string(L"-", str)) flags.clear(expand_flag::fuzzy_match);
|
if (string_prefixes_string(L"-", str)) flags.clear(expand_flag::fuzzy_match);
|
||||||
|
|
||||||
if (expand_string(str, &this->completions, flags, vars, parser, NULL) ==
|
if (expand_string(str, &this->completions, flags, vars, parser, nullptr) ==
|
||||||
expand_result_t::error) {
|
expand_result_t::error) {
|
||||||
debug(3, L"Error while expanding string '%ls'", str.c_str());
|
debug(3, L"Error while expanding string '%ls'", str.c_str());
|
||||||
}
|
}
|
||||||
|
@ -1638,7 +1638,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> *out_c
|
||||||
const wchar_t *cmdsubst_begin, *cmdsubst_end;
|
const wchar_t *cmdsubst_begin, *cmdsubst_end;
|
||||||
parse_util_cmdsubst_extent(cmd_with_subcmds.c_str(), cmd_with_subcmds.size(), &cmdsubst_begin,
|
parse_util_cmdsubst_extent(cmd_with_subcmds.c_str(), cmd_with_subcmds.size(), &cmdsubst_begin,
|
||||||
&cmdsubst_end);
|
&cmdsubst_end);
|
||||||
assert(cmdsubst_begin != NULL && cmdsubst_end != NULL && cmdsubst_end >= cmdsubst_begin);
|
assert(cmdsubst_begin != nullptr && cmdsubst_end != nullptr && cmdsubst_end >= cmdsubst_begin);
|
||||||
wcstring cmd = wcstring(cmdsubst_begin, cmdsubst_end - cmdsubst_begin);
|
wcstring cmd = wcstring(cmdsubst_begin, cmdsubst_end - cmdsubst_begin);
|
||||||
completer_t completer(vars, parser, std::move(cmd), flags);
|
completer_t completer(vars, parser, std::move(cmd), flags);
|
||||||
completer.perform();
|
completer.perform();
|
||||||
|
|
10
src/env.cpp
10
src/env.cpp
|
@ -206,7 +206,7 @@ void misc_init() {
|
||||||
// issue #3748.
|
// issue #3748.
|
||||||
if (isatty(STDOUT_FILENO)) {
|
if (isatty(STDOUT_FILENO)) {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the given paths in the environment, if we have any.
|
// Set the given paths in the environment, if we have any.
|
||||||
if (paths != NULL) {
|
if (paths != nullptr) {
|
||||||
vars.set_one(FISH_DATADIR_VAR, ENV_GLOBAL, paths->data);
|
vars.set_one(FISH_DATADIR_VAR, ENV_GLOBAL, paths->data);
|
||||||
vars.set_one(FISH_SYSCONFDIR_VAR, ENV_GLOBAL, paths->sysconf);
|
vars.set_one(FISH_SYSCONFDIR_VAR, ENV_GLOBAL, paths->sysconf);
|
||||||
vars.set_one(FISH_HELPDIR_VAR, ENV_GLOBAL, paths->doc);
|
vars.set_one(FISH_HELPDIR_VAR, ENV_GLOBAL, paths->doc);
|
||||||
|
@ -392,7 +392,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
||||||
static int set_umask(const wcstring_list_t &list_val) {
|
static int set_umask(const wcstring_list_t &list_val) {
|
||||||
long mask = -1;
|
long mask = -1;
|
||||||
if (list_val.size() == 1 && !list_val.front().empty()) {
|
if (list_val.size() == 1 && !list_val.front().empty()) {
|
||||||
mask = fish_wcstol(list_val.front().c_str(), NULL, 8);
|
mask = fish_wcstol(list_val.front().c_str(), nullptr, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno || mask > 0777 || mask < 0) return ENV_INVALID;
|
if (errno || mask > 0777 || mask < 0) return ENV_INVALID;
|
||||||
|
@ -1401,14 +1401,14 @@ wcstring env_get_runtime_path() {
|
||||||
// Check that the path is actually usable. Technically this is guaranteed by the fdo spec but in
|
// Check that the path is actually usable. Technically this is guaranteed by the fdo spec but in
|
||||||
// practice it is not always the case: see #1828 and #2222.
|
// practice it is not always the case: see #1828 and #2222.
|
||||||
int mode = R_OK | W_OK | X_OK;
|
int mode = R_OK | W_OK | X_OK;
|
||||||
if (dir != NULL && access(dir, mode) == 0 && check_runtime_path(dir) == 0) {
|
if (dir != nullptr && access(dir, mode) == 0 && check_runtime_path(dir) == 0) {
|
||||||
result = str2wcstring(dir);
|
result = str2wcstring(dir);
|
||||||
} else {
|
} else {
|
||||||
// Don't rely on $USER being set, as setup_user() has not yet been called.
|
// Don't rely on $USER being set, as setup_user() has not yet been called.
|
||||||
// See https://github.com/fish-shell/fish-shell/issues/5180
|
// See https://github.com/fish-shell/fish-shell/issues/5180
|
||||||
// getpeuid() can't fail, but getpwuid sure can.
|
// getpeuid() can't fail, but getpwuid sure can.
|
||||||
auto pwuid = getpwuid(geteuid());
|
auto pwuid = getpwuid(geteuid());
|
||||||
const char *uname = pwuid ? pwuid->pw_name : NULL;
|
const char *uname = pwuid ? pwuid->pw_name : nullptr;
|
||||||
// /tmp/fish.user
|
// /tmp/fish.user
|
||||||
std::string tmpdir = get_path_to_tmp_dir() + "/fish.";
|
std::string tmpdir = get_path_to_tmp_dir() + "/fish.";
|
||||||
if (uname) {
|
if (uname) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ struct statuses_t {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Initialize environment variable data.
|
/// Initialize environment variable data.
|
||||||
void env_init(const struct config_paths_t *paths = NULL);
|
void env_init(const struct config_paths_t *paths = nullptr);
|
||||||
|
|
||||||
/// Various things we need to initialize at run-time that don't really fit any of the other init
|
/// Various things we need to initialize at run-time that don't really fit any of the other init
|
||||||
/// routines.
|
/// routines.
|
||||||
|
|
|
@ -164,7 +164,7 @@ static void guess_emoji_width(const environment_t &vars) {
|
||||||
double version = 0;
|
double version = 0;
|
||||||
if (auto version_var = vars.get(L"TERM_PROGRAM_VERSION")) {
|
if (auto version_var = vars.get(L"TERM_PROGRAM_VERSION")) {
|
||||||
std::string narrow_version = wcs2string(version_var->as_string());
|
std::string narrow_version = wcs2string(version_var->as_string());
|
||||||
version = strtod(narrow_version.c_str(), NULL);
|
version = strtod(narrow_version.c_str(), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (term == L"Apple_Terminal" && version >= 400) {
|
if (term == L"Apple_Terminal" && version >= 400) {
|
||||||
|
@ -349,7 +349,7 @@ static void update_fish_color_support(const environment_t &vars) {
|
||||||
if (auto tp = vars.get(L"TERM_PROGRAM")) term_program = tp->as_string();
|
if (auto tp = vars.get(L"TERM_PROGRAM")) term_program = tp->as_string();
|
||||||
if (auto tpv = vars.get(L"TERM_PROGRAM_VERSION")) {
|
if (auto tpv = vars.get(L"TERM_PROGRAM_VERSION")) {
|
||||||
if (term_program == L"Apple_Terminal" &&
|
if (term_program == L"Apple_Terminal" &&
|
||||||
fish_wcstod(tpv->as_string().c_str(), NULL) > 299) {
|
fish_wcstod(tpv->as_string().c_str(), nullptr) > 299) {
|
||||||
// OS X Lion is version 299+, it has 256 color support (see github Wiki)
|
// OS X Lion is version 299+, it has 256 color support (see github Wiki)
|
||||||
support_term256 = true;
|
support_term256 = true;
|
||||||
debug(2, L"256 color support enabled for TERM=%ls on Terminal.app", term.c_str());
|
debug(2, L"256 color support enabled for TERM=%ls on Terminal.app", term.c_str());
|
||||||
|
@ -358,7 +358,7 @@ static void update_fish_color_support(const environment_t &vars) {
|
||||||
debug(2, L"256 color support enabled for TERM=%ls", term.c_str());
|
debug(2, L"256 color support enabled for TERM=%ls", term.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (cur_term != NULL) {
|
} else if (cur_term != nullptr) {
|
||||||
// See if terminfo happens to identify 256 colors
|
// See if terminfo happens to identify 256 colors
|
||||||
support_term256 = (max_colors >= 256);
|
support_term256 = (max_colors >= 256);
|
||||||
debug(2, L"256 color support: %d colors per terminfo entry for %ls", max_colors,
|
debug(2, L"256 color support: %d colors per terminfo entry for %ls", max_colors,
|
||||||
|
@ -455,7 +455,7 @@ static void init_curses(const environment_t &vars) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int err_ret;
|
int err_ret;
|
||||||
if (setupterm(NULL, STDOUT_FILENO, &err_ret) == ERR) {
|
if (setupterm(nullptr, STDOUT_FILENO, &err_ret) == ERR) {
|
||||||
auto term = vars.get(L"TERM");
|
auto term = vars.get(L"TERM");
|
||||||
if (is_interactive_session()) {
|
if (is_interactive_session()) {
|
||||||
debug(1, _(L"Could not set up terminal."));
|
debug(1, _(L"Could not set up terminal."));
|
||||||
|
@ -484,7 +484,7 @@ static void init_curses(const environment_t &vars) {
|
||||||
static void init_locale(const environment_t &vars) {
|
static void init_locale(const environment_t &vars) {
|
||||||
// We have to make a copy because the subsequent setlocale() call to change the locale will
|
// We have to make a copy because the subsequent setlocale() call to change the locale will
|
||||||
// invalidate the pointer from the this setlocale() call.
|
// invalidate the pointer from the this setlocale() call.
|
||||||
char *old_msg_locale = strdup(setlocale(LC_MESSAGES, NULL));
|
char *old_msg_locale = strdup(setlocale(LC_MESSAGES, nullptr));
|
||||||
|
|
||||||
for (const auto &var_name : locale_variables) {
|
for (const auto &var_name : locale_variables) {
|
||||||
const auto var = vars.get(var_name, ENV_EXPORT);
|
const auto var = vars.get(var_name, ENV_EXPORT);
|
||||||
|
@ -503,7 +503,7 @@ static void init_locale(const environment_t &vars) {
|
||||||
fish_setlocale();
|
fish_setlocale();
|
||||||
FLOGF(env_locale, L"init_locale() setlocale(): '%s'", locale);
|
FLOGF(env_locale, L"init_locale() setlocale(): '%s'", locale);
|
||||||
|
|
||||||
const char *new_msg_locale = setlocale(LC_MESSAGES, NULL);
|
const char *new_msg_locale = setlocale(LC_MESSAGES, nullptr);
|
||||||
FLOGF(env_locale, L"old LC_MESSAGES locale: '%s'", old_msg_locale);
|
FLOGF(env_locale, L"old LC_MESSAGES locale: '%s'", old_msg_locale);
|
||||||
FLOGF(env_locale, L"new LC_MESSAGES locale: '%s'", new_msg_locale);
|
FLOGF(env_locale, L"new LC_MESSAGES locale: '%s'", new_msg_locale);
|
||||||
#ifdef HAVE__NL_MSG_CAT_CNTR
|
#ifdef HAVE__NL_MSG_CAT_CNTR
|
||||||
|
|
|
@ -174,8 +174,8 @@ static bool append_utf8(const wcstring &input, std::string *receiver, std::strin
|
||||||
static bool append_file_entry(env_var_t::env_var_flags_t flags, const wcstring &key_in,
|
static bool append_file_entry(env_var_t::env_var_flags_t flags, const wcstring &key_in,
|
||||||
const wcstring &val_in, std::string *result, std::string *storage) {
|
const wcstring &val_in, std::string *result, std::string *storage) {
|
||||||
namespace f3 = fish3_uvars;
|
namespace f3 = fish3_uvars;
|
||||||
assert(storage != NULL);
|
assert(storage != nullptr);
|
||||||
assert(result != NULL);
|
assert(result != nullptr);
|
||||||
|
|
||||||
// Record the length on entry, in case we need to back up.
|
// Record the length on entry, in case we need to back up.
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
@ -1069,7 +1069,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
|
||||||
volatile universal_notifier_shmem_t *region;
|
volatile universal_notifier_shmem_t *region;
|
||||||
|
|
||||||
void open_shmem() {
|
void open_shmem() {
|
||||||
assert(region == NULL);
|
assert(region == nullptr);
|
||||||
|
|
||||||
// Use a path based on our uid to avoid collisions.
|
// Use a path based on our uid to avoid collisions.
|
||||||
char path[NAME_MAX];
|
char path[NAME_MAX];
|
||||||
|
@ -1108,13 +1108,13 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
|
||||||
|
|
||||||
// Memory map the region.
|
// Memory map the region.
|
||||||
if (!errored) {
|
if (!errored) {
|
||||||
void *addr = mmap(NULL, sizeof(universal_notifier_shmem_t), PROT_READ | PROT_WRITE,
|
void *addr = mmap(nullptr, sizeof(universal_notifier_shmem_t), PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED, fd, 0);
|
MAP_SHARED, fd, 0);
|
||||||
if (addr == MAP_FAILED) {
|
if (addr == MAP_FAILED) {
|
||||||
const char *error = std::strerror(errno);
|
const char *error = std::strerror(errno);
|
||||||
FLOGF(error, _(L"Unable to memory map shared memory object with path '%s': %s"),
|
FLOGF(error, _(L"Unable to memory map shared memory object with path '%s': %s"),
|
||||||
path, error);
|
path, error);
|
||||||
this->region = NULL;
|
this->region = nullptr;
|
||||||
} else {
|
} else {
|
||||||
this->region = static_cast<universal_notifier_shmem_t *>(addr);
|
this->region = static_cast<universal_notifier_shmem_t *>(addr);
|
||||||
}
|
}
|
||||||
|
@ -1136,7 +1136,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
|
||||||
// This isn't "safe" in the sense that multiple simultaneous increments may result in one being
|
// This isn't "safe" in the sense that multiple simultaneous increments may result in one being
|
||||||
// lost, but it should always result in the value being changed, which is sufficient.
|
// lost, but it should always result in the value being changed, which is sufficient.
|
||||||
void post_notification() {
|
void post_notification() {
|
||||||
if (region != NULL) {
|
if (region != nullptr) {
|
||||||
/* Read off the seed */
|
/* Read off the seed */
|
||||||
uint32_t seed = ntohl(region->universal_variable_seed); //!OCLINT(constant cond op)
|
uint32_t seed = ntohl(region->universal_variable_seed); //!OCLINT(constant cond op)
|
||||||
|
|
||||||
|
@ -1153,12 +1153,12 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
universal_notifier_shmem_poller_t() : last_change_time(0), last_seed(0), region(NULL) {
|
universal_notifier_shmem_poller_t() : last_change_time(0), last_seed(0), region(nullptr) {
|
||||||
open_shmem();
|
open_shmem();
|
||||||
}
|
}
|
||||||
|
|
||||||
~universal_notifier_shmem_poller_t() {
|
~universal_notifier_shmem_poller_t() {
|
||||||
if (region != NULL) {
|
if (region != nullptr) {
|
||||||
// Behold: C++ in all its glory!
|
// Behold: C++ in all its glory!
|
||||||
void *address = const_cast<void *>(static_cast<volatile void *>(region));
|
void *address = const_cast<void *>(static_cast<volatile void *>(region));
|
||||||
if (munmap(address, sizeof(universal_notifier_shmem_t)) < 0) {
|
if (munmap(address, sizeof(universal_notifier_shmem_t)) < 0) {
|
||||||
|
@ -1169,7 +1169,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
|
||||||
|
|
||||||
bool poll() {
|
bool poll() {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (region != NULL) {
|
if (region != nullptr) {
|
||||||
uint32_t seed = ntohl(region->universal_variable_seed); //!OCLINT(constant cond op)
|
uint32_t seed = ntohl(region->universal_variable_seed); //!OCLINT(constant cond op)
|
||||||
if (seed != last_seed) {
|
if (seed != last_seed) {
|
||||||
result = true;
|
result = true;
|
||||||
|
@ -1424,7 +1424,7 @@ class universal_notifier_named_pipe_t : public universal_notifier_t {
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(this->pipe_fd, &fds);
|
FD_SET(this->pipe_fd, &fds);
|
||||||
struct timeval timeout = {};
|
struct timeval timeout = {};
|
||||||
select(this->pipe_fd + 1, &fds, NULL, NULL, &timeout);
|
select(this->pipe_fd + 1, &fds, nullptr, nullptr, &timeout);
|
||||||
if (!FD_ISSET(this->pipe_fd, &fds)) {
|
if (!FD_ISSET(this->pipe_fd, &fds)) {
|
||||||
// No longer readable, no longer polling.
|
// No longer readable, no longer polling.
|
||||||
polling_due_to_readable_fd = false;
|
polling_due_to_readable_fd = false;
|
||||||
|
@ -1477,7 +1477,7 @@ std::unique_ptr<universal_notifier_t> universal_notifier_t::new_notifier_for_str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DIE("should never reach this statement");
|
DIE("should never reach this statement");
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default implementations.
|
// Default implementations.
|
||||||
|
|
|
@ -183,7 +183,7 @@ class universal_notifier_t {
|
||||||
|
|
||||||
// Factory constructor.
|
// Factory constructor.
|
||||||
static std::unique_ptr<universal_notifier_t> new_notifier_for_strategy(
|
static std::unique_ptr<universal_notifier_t> new_notifier_for_strategy(
|
||||||
notifier_strategy_t strat, const wchar_t *test_path = NULL);
|
notifier_strategy_t strat, const wchar_t *test_path = nullptr);
|
||||||
|
|
||||||
// Default instance. Other instances are possible for testing.
|
// Default instance. Other instances are possible for testing.
|
||||||
static universal_notifier_t &default_notifier();
|
static universal_notifier_t &default_notifier();
|
||||||
|
|
|
@ -121,7 +121,8 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter);
|
||||||
wcstring event_get_desc(const event_t &e);
|
wcstring event_get_desc(const event_t &e);
|
||||||
|
|
||||||
/// Fire a generic event with the specified name.
|
/// Fire a generic event with the specified name.
|
||||||
void event_fire_generic(parser_t &parser, const wchar_t *name, const wcstring_list_t *args = NULL);
|
void event_fire_generic(parser_t &parser, const wchar_t *name,
|
||||||
|
const wcstring_list_t *args = nullptr);
|
||||||
|
|
||||||
/// Return the event type for a given name, or none.
|
/// Return the event type for a given name, or none.
|
||||||
maybe_t<event_type_t> event_type_for_name(const wcstring &name);
|
maybe_t<event_type_t> event_type_for_name(const wcstring &name);
|
||||||
|
|
12
src/exec.cpp
12
src/exec.cpp
|
@ -113,7 +113,7 @@ char *get_interpreter(const char *command, char *interpreter, size_t buff_size)
|
||||||
return interpreter + 2;
|
return interpreter + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function is executed by the child process created by a call to fork(). It should be called
|
/// This function is executed by the child process created by a call to fork(). It should be called
|
||||||
|
@ -151,7 +151,7 @@ static void safe_launch_process(process_t *p, const char *actual_cmd, const char
|
||||||
argv2[0] = sh_command;
|
argv2[0] = sh_command;
|
||||||
for (size_t i = 1; i < sizeof argv2 / sizeof *argv2; i++) {
|
for (size_t i = 1; i < sizeof argv2 / sizeof *argv2; i++) {
|
||||||
argv2[i] = argv[i - 1];
|
argv2[i] = argv[i - 1];
|
||||||
if (argv2[i] == NULL) break;
|
if (argv2[i] == nullptr) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
execve(sh_command, argv2, envv);
|
execve(sh_command, argv2, envv);
|
||||||
|
@ -192,7 +192,7 @@ static bool resolve_file_redirections_to_fds(const io_chain_t &in_chain, const w
|
||||||
io_chain_t *out_chain,
|
io_chain_t *out_chain,
|
||||||
std::vector<autoclose_fd_t> *out_opened_fds) {
|
std::vector<autoclose_fd_t> *out_opened_fds) {
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
assert(out_chain != NULL && out_opened_fds != NULL);
|
assert(out_chain != nullptr && out_opened_fds != nullptr);
|
||||||
assert(out_chain->empty());
|
assert(out_chain->empty());
|
||||||
|
|
||||||
// Just to be clear what we do for an empty chain.
|
// Just to be clear what we do for an empty chain.
|
||||||
|
@ -1245,7 +1245,7 @@ static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, wcstrin
|
||||||
|
|
||||||
parser.libdata().is_subshell = prev_subshell;
|
parser.libdata().is_subshell = prev_subshell;
|
||||||
|
|
||||||
if (lst == NULL || !buffer) {
|
if (lst == nullptr || !buffer) {
|
||||||
return subcommand_statuses.status;
|
return subcommand_statuses.status;
|
||||||
}
|
}
|
||||||
// Walk over all the elements.
|
// Walk over all the elements.
|
||||||
|
@ -1266,7 +1266,7 @@ static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, wcstrin
|
||||||
// Look for the next separator.
|
// Look for the next separator.
|
||||||
const char *stop =
|
const char *stop =
|
||||||
static_cast<const char *>(std::memchr(cursor, '\n', end - cursor));
|
static_cast<const char *>(std::memchr(cursor, '\n', end - cursor));
|
||||||
const bool hit_separator = (stop != NULL);
|
const bool hit_separator = (stop != nullptr);
|
||||||
if (!hit_separator) {
|
if (!hit_separator) {
|
||||||
// If it's not found, just use the end.
|
// If it's not found, just use the end.
|
||||||
stop = end;
|
stop = end;
|
||||||
|
@ -1297,5 +1297,5 @@ int exec_subshell(const wcstring &cmd, parser_t &parser, wcstring_list_t &output
|
||||||
|
|
||||||
int exec_subshell(const wcstring &cmd, parser_t &parser, bool apply_exit_status, bool is_subcmd) {
|
int exec_subshell(const wcstring &cmd, parser_t &parser, bool apply_exit_status, bool is_subcmd) {
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
return exec_subshell_internal(cmd, parser, NULL, apply_exit_status, is_subcmd);
|
return exec_subshell_internal(cmd, parser, nullptr, apply_exit_status, is_subcmd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ static bool expand_is_clean(const wcstring &in) {
|
||||||
if (in.empty()) return true;
|
if (in.empty()) return true;
|
||||||
|
|
||||||
// Test characters that have a special meaning in the first character position.
|
// Test characters that have a special meaning in the first character position.
|
||||||
if (std::wcschr(UNCLEAN_FIRST, in.at(0)) != NULL) return false;
|
if (std::wcschr(UNCLEAN_FIRST, in.at(0)) != nullptr) return false;
|
||||||
|
|
||||||
// Test characters that have a special meaning in any character position.
|
// Test characters that have a special meaning in any character position.
|
||||||
return in.find_first_of(UNCLEAN) == wcstring::npos;
|
return in.find_first_of(UNCLEAN) == wcstring::npos;
|
||||||
|
@ -457,8 +457,8 @@ static expand_result_t expand_braces(const wcstring &instr, expand_flags_t flags
|
||||||
bool syntax_error = false;
|
bool syntax_error = false;
|
||||||
int brace_count = 0;
|
int brace_count = 0;
|
||||||
|
|
||||||
const wchar_t *brace_begin = NULL, *brace_end = NULL;
|
const wchar_t *brace_begin = nullptr, *brace_end = nullptr;
|
||||||
const wchar_t *last_sep = NULL;
|
const wchar_t *last_sep = nullptr;
|
||||||
|
|
||||||
const wchar_t *item_begin;
|
const wchar_t *item_begin;
|
||||||
size_t length_preceding_braces, length_following_braces, tot_len;
|
size_t length_preceding_braces, length_following_braces, tot_len;
|
||||||
|
@ -518,7 +518,7 @@ static expand_result_t expand_braces(const wcstring &instr, expand_flags_t flags
|
||||||
return expand_result_t::error;
|
return expand_result_t::error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brace_begin == NULL) {
|
if (brace_begin == nullptr) {
|
||||||
append_completion(out, instr);
|
append_completion(out, instr);
|
||||||
return expand_result_t::ok;
|
return expand_result_t::ok;
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ __warn_unused expand_result_t expand_string(wcstring input, std::vector<completi
|
||||||
///
|
///
|
||||||
/// \return Whether expansion succeeded.
|
/// \return Whether expansion succeeded.
|
||||||
bool expand_one(wcstring &string, expand_flags_t flags, const environment_t &vars,
|
bool expand_one(wcstring &string, expand_flags_t flags, const environment_t &vars,
|
||||||
const std::shared_ptr<parser_t> &parser, parse_error_list_t *errors = NULL);
|
const std::shared_ptr<parser_t> &parser, parse_error_list_t *errors = nullptr);
|
||||||
|
|
||||||
/// Expand a command string like $HOME/bin/cmd into a command and list of arguments.
|
/// Expand a command string like $HOME/bin/cmd into a command and list of arguments.
|
||||||
/// Return the command and arguments by reference.
|
/// Return the command and arguments by reference.
|
||||||
|
@ -158,7 +158,7 @@ bool expand_one(wcstring &string, expand_flags_t flags, const environment_t &var
|
||||||
// \return an expand error.
|
// \return an expand error.
|
||||||
expand_result_t expand_to_command_and_args(const wcstring &instr, const environment_t &vars,
|
expand_result_t expand_to_command_and_args(const wcstring &instr, const environment_t &vars,
|
||||||
wcstring *out_cmd, wcstring_list_t *out_args,
|
wcstring *out_cmd, wcstring_list_t *out_args,
|
||||||
parse_error_list_t *errors = NULL);
|
parse_error_list_t *errors = nullptr);
|
||||||
|
|
||||||
/// Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc.
|
/// Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc.
|
||||||
/// Suitable for pretty-printing.
|
/// Suitable for pretty-printing.
|
||||||
|
|
|
@ -78,8 +78,8 @@ int fish_mkstemp_cloexec(char *name_template) {
|
||||||
[[gnu::unused]] static wchar_t *wcsdup_fallback(const wchar_t *in) {
|
[[gnu::unused]] static wchar_t *wcsdup_fallback(const wchar_t *in) {
|
||||||
size_t len = std::wcslen(in);
|
size_t len = std::wcslen(in);
|
||||||
wchar_t *out = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (len + 1)));
|
wchar_t *out = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (len + 1)));
|
||||||
if (out == 0) {
|
if (out == nullptr) {
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(out, in, sizeof(wchar_t) * (len + 1));
|
std::memcpy(out, in, sizeof(wchar_t) * (len + 1));
|
||||||
|
@ -163,8 +163,8 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) {
|
||||||
#ifndef HAVE_WCSNDUP
|
#ifndef HAVE_WCSNDUP
|
||||||
wchar_t *wcsndup(const wchar_t *in, size_t c) {
|
wchar_t *wcsndup(const wchar_t *in, size_t c) {
|
||||||
wchar_t *res = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (c + 1)));
|
wchar_t *res = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (c + 1)));
|
||||||
if (res == 0) {
|
if (res == nullptr) {
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
wcslcpy(res, in, c + 1);
|
wcslcpy(res, in, c + 1);
|
||||||
return res;
|
return res;
|
||||||
|
|
43
src/fish.cpp
43
src/fish.cpp
|
@ -79,7 +79,7 @@ class fish_cmd_opts_t {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// If we are doing profiling, the filename to output to.
|
/// If we are doing profiling, the filename to output to.
|
||||||
static const char *s_profiling_output_filename = NULL;
|
static const char *s_profiling_output_filename = nullptr;
|
||||||
|
|
||||||
/// \return a timeval converted to milliseconds.
|
/// \return a timeval converted to milliseconds.
|
||||||
long long tv_to_msec(const struct timeval &tv) {
|
long long tv_to_msec(const struct timeval &tv) {
|
||||||
|
@ -127,7 +127,7 @@ static bool get_realpath(std::string &path) {
|
||||||
if ((ptr = realpath(path.c_str(), buff))) {
|
if ((ptr = realpath(path.c_str(), buff))) {
|
||||||
path = ptr;
|
path = ptr;
|
||||||
}
|
}
|
||||||
return ptr != NULL;
|
return ptr != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct config_paths_t determine_config_directory_paths(const char *argv0) {
|
static struct config_paths_t determine_config_directory_paths(const char *argv0) {
|
||||||
|
@ -157,7 +157,7 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
|
||||||
// The next check is that we are in a reloctable directory tree
|
// The next check is that we are in a reloctable directory tree
|
||||||
const char *installed_suffix = "/bin/fish";
|
const char *installed_suffix = "/bin/fish";
|
||||||
const char *just_a_fish = "/fish";
|
const char *just_a_fish = "/fish";
|
||||||
const char *suffix = NULL;
|
const char *suffix = nullptr;
|
||||||
|
|
||||||
if (has_suffix(exec_path, installed_suffix, false)) {
|
if (has_suffix(exec_path, installed_suffix, false)) {
|
||||||
suffix = installed_suffix;
|
suffix = installed_suffix;
|
||||||
|
@ -263,25 +263,26 @@ int run_command_list(std::vector<std::string> *cmds, const io_chain_t &io) {
|
||||||
/// Parse the argument list, return the index of the first non-flag arguments.
|
/// Parse the argument list, return the index of the first non-flag arguments.
|
||||||
static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
|
static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
|
||||||
static const char *const short_opts = "+hPilnvc:C:p:d:f:D:";
|
static const char *const short_opts = "+hPilnvc:C:p:d:f:D:";
|
||||||
static const struct option long_opts[] = {{"command", required_argument, NULL, 'c'},
|
static const struct option long_opts[] = {
|
||||||
{"init-command", required_argument, NULL, 'C'},
|
{"command", required_argument, nullptr, 'c'},
|
||||||
{"features", required_argument, NULL, 'f'},
|
{"init-command", required_argument, nullptr, 'C'},
|
||||||
{"debug", required_argument, NULL, 'd'},
|
{"features", required_argument, nullptr, 'f'},
|
||||||
{"debug-output", required_argument, NULL, 'o'},
|
{"debug", required_argument, nullptr, 'd'},
|
||||||
{"debug-stack-frames", required_argument, NULL, 'D'},
|
{"debug-output", required_argument, nullptr, 'o'},
|
||||||
{"interactive", no_argument, NULL, 'i'},
|
{"debug-stack-frames", required_argument, nullptr, 'D'},
|
||||||
{"login", no_argument, NULL, 'l'},
|
{"interactive", no_argument, nullptr, 'i'},
|
||||||
{"no-execute", no_argument, NULL, 'n'},
|
{"login", no_argument, nullptr, 'l'},
|
||||||
{"print-rusage-self", no_argument, NULL, 1},
|
{"no-execute", no_argument, nullptr, 'n'},
|
||||||
{"print-debug-categories", no_argument, NULL, 2},
|
{"print-rusage-self", no_argument, nullptr, 1},
|
||||||
{"profile", required_argument, NULL, 'p'},
|
{"print-debug-categories", no_argument, nullptr, 2},
|
||||||
{"private", no_argument, NULL, 'P'},
|
{"profile", required_argument, nullptr, 'p'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"private", no_argument, nullptr, 'P'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"help", no_argument, nullptr, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{"version", no_argument, nullptr, 'v'},
|
||||||
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
while ((opt = getopt_long(argc, argv, short_opts, long_opts, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c': {
|
case 'c': {
|
||||||
opts->batch_cmds.push_back(optarg);
|
opts->batch_cmds.push_back(optarg);
|
||||||
|
@ -413,7 +414,7 @@ int main(int argc, char **argv) {
|
||||||
// struct stat tmp;
|
// struct stat tmp;
|
||||||
// stat("----------FISH_HIT_MAIN----------", &tmp);
|
// stat("----------FISH_HIT_MAIN----------", &tmp);
|
||||||
|
|
||||||
const char *dummy_argv[2] = {"fish", NULL};
|
const char *dummy_argv[2] = {"fish", nullptr};
|
||||||
if (!argv[0]) {
|
if (!argv[0]) {
|
||||||
argv = (char **)dummy_argv; //!OCLINT(parameter reassignment)
|
argv = (char **)dummy_argv; //!OCLINT(parameter reassignment)
|
||||||
argc = 1; //!OCLINT(parameter reassignment)
|
argc = 1; //!OCLINT(parameter reassignment)
|
||||||
|
|
|
@ -353,7 +353,7 @@ static wcstring prettify(const wcstring &src, bool do_indent) {
|
||||||
parse_node_tree_t parse_tree;
|
parse_node_tree_t parse_tree;
|
||||||
int parse_flags = (parse_flag_continue_after_error | parse_flag_include_comments |
|
int parse_flags = (parse_flag_continue_after_error | parse_flag_include_comments |
|
||||||
parse_flag_leave_unterminated | parse_flag_show_blank_lines);
|
parse_flag_leave_unterminated | parse_flag_show_blank_lines);
|
||||||
if (!parse_tree_from_string(src, parse_flags, &parse_tree, NULL)) {
|
if (!parse_tree_from_string(src, parse_flags, &parse_tree, nullptr)) {
|
||||||
return src; // we return the original string on failure
|
return src; // we return the original string on failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,20 +508,20 @@ int main(int argc, char *argv[]) {
|
||||||
bool do_indent = true;
|
bool do_indent = true;
|
||||||
|
|
||||||
const char *short_opts = "+d:hvwiD:";
|
const char *short_opts = "+d:hvwiD:";
|
||||||
const struct option long_opts[] = {{"debug-level", required_argument, NULL, 'd'},
|
const struct option long_opts[] = {{"debug-level", required_argument, nullptr, 'd'},
|
||||||
{"debug-stack-frames", required_argument, NULL, 'D'},
|
{"debug-stack-frames", required_argument, nullptr, 'D'},
|
||||||
{"dump-parse-tree", no_argument, NULL, 'P'},
|
{"dump-parse-tree", no_argument, nullptr, 'P'},
|
||||||
{"no-indent", no_argument, NULL, 'i'},
|
{"no-indent", no_argument, nullptr, 'i'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, nullptr, 'h'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, nullptr, 'v'},
|
||||||
{"write", no_argument, NULL, 'w'},
|
{"write", no_argument, nullptr, 'w'},
|
||||||
{"html", no_argument, NULL, 1},
|
{"html", no_argument, nullptr, 1},
|
||||||
{"ansi", no_argument, NULL, 2},
|
{"ansi", no_argument, nullptr, 2},
|
||||||
{"pygments", no_argument, NULL, 3},
|
{"pygments", no_argument, nullptr, 3},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
while ((opt = getopt_long(argc, argv, short_opts, long_opts, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'P': {
|
case 'P': {
|
||||||
dump_parse_tree = true;
|
dump_parse_tree = true;
|
||||||
|
@ -633,7 +633,7 @@ int main(int argc, char *argv[]) {
|
||||||
// Maybe colorize.
|
// Maybe colorize.
|
||||||
std::vector<highlight_spec_t> colors;
|
std::vector<highlight_spec_t> colors;
|
||||||
if (output_type != output_type_plain_text) {
|
if (output_type != output_type_plain_text) {
|
||||||
highlight_shell_no_io(output_wtext, colors, output_wtext.size(), NULL,
|
highlight_shell_no_io(output_wtext, colors, output_wtext.size(), nullptr,
|
||||||
env_stack_t::globals());
|
env_stack_t::globals());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,10 @@
|
||||||
struct config_paths_t determine_config_directory_paths(const char *argv0);
|
struct config_paths_t determine_config_directory_paths(const char *argv0);
|
||||||
|
|
||||||
static const wchar_t *ctrl_symbolic_names[] = {
|
static const wchar_t *ctrl_symbolic_names[] = {
|
||||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, L"\\a", L"\\b", L"\\t", L"\\n",
|
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, L"\\a",
|
||||||
L"\\v", L"\\f", L"\\r", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
L"\\b", L"\\t", L"\\n", L"\\v", L"\\f", L"\\r", nullptr, nullptr,
|
||||||
NULL, NULL, NULL, NULL, NULL, L"\\e", NULL, NULL, NULL, NULL};
|
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||||
|
nullptr, nullptr, nullptr, L"\\e", nullptr, nullptr, nullptr, nullptr};
|
||||||
static bool keep_running = true;
|
static bool keep_running = true;
|
||||||
|
|
||||||
/// Return true if the recent sequence of characters indicates the user wants to exit the program.
|
/// Return true if the recent sequence of characters indicates the user wants to exit the program.
|
||||||
|
@ -95,7 +96,7 @@ static maybe_t<wcstring> sequence_name(wchar_t wc) {
|
||||||
|
|
||||||
/// Return true if the character must be escaped when used in the sequence of chars to be bound in
|
/// Return true if the character must be escaped when used in the sequence of chars to be bound in
|
||||||
/// a `bind` command.
|
/// a `bind` command.
|
||||||
static bool must_escape(wchar_t wc) { return std::wcschr(L"[]()<>{}*\\?$#;&|'\"", wc) != NULL; }
|
static bool must_escape(wchar_t wc) { return std::wcschr(L"[]()<>{}*\\?$#;&|'\"", wc) != nullptr; }
|
||||||
|
|
||||||
static void ctrl_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, bool bind_friendly) {
|
static void ctrl_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, bool bind_friendly) {
|
||||||
if (ctrl_symbolic_names[wc]) {
|
if (ctrl_symbolic_names[wc]) {
|
||||||
|
@ -344,15 +345,15 @@ static bool parse_debug_frames_flag() {
|
||||||
|
|
||||||
static bool parse_flags(int argc, char **argv, bool *continuous_mode) {
|
static bool parse_flags(int argc, char **argv, bool *continuous_mode) {
|
||||||
const char *short_opts = "+cd:D:hv";
|
const char *short_opts = "+cd:D:hv";
|
||||||
const struct option long_opts[] = {{"continuous", no_argument, NULL, 'c'},
|
const struct option long_opts[] = {{"continuous", no_argument, nullptr, 'c'},
|
||||||
{"debug-level", required_argument, NULL, 'd'},
|
{"debug-level", required_argument, nullptr, 'd'},
|
||||||
{"debug-stack-frames", required_argument, NULL, 'D'},
|
{"debug-stack-frames", required_argument, nullptr, 'D'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, nullptr, 'h'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, nullptr, 'v'},
|
||||||
{NULL, 0, NULL, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
int opt;
|
int opt;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
while (!error && (opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
while (!error && (opt = getopt_long(argc, argv, short_opts, long_opts, nullptr)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c': {
|
case 'c': {
|
||||||
*continuous_mode = true;
|
*continuous_mode = true;
|
||||||
|
|
|
@ -287,7 +287,7 @@ wcstring_list_t function_get_names(int get_hidden) {
|
||||||
const wchar_t *function_get_definition_file(const wcstring &name) {
|
const wchar_t *function_get_definition_file(const wcstring &name) {
|
||||||
const auto funcset = function_set.acquire();
|
const auto funcset = function_set.acquire();
|
||||||
const function_info_t *func = funcset->get_info(name);
|
const function_info_t *func = funcset->get_info(name);
|
||||||
return func ? func->definition_file : NULL;
|
return func ? func->definition_file : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool function_is_autoloaded(const wcstring &name) {
|
bool function_is_autoloaded(const wcstring &name) {
|
||||||
|
|
|
@ -269,7 +269,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// We do not end with a slash; it does not have to be a directory.
|
// We do not end with a slash; it does not have to be a directory.
|
||||||
DIR *dir = NULL;
|
DIR *dir = nullptr;
|
||||||
const wcstring dir_name = wdirname(abs_path);
|
const wcstring dir_name = wdirname(abs_path);
|
||||||
const wcstring filename_fragment = wbasename(abs_path);
|
const wcstring filename_fragment = wbasename(abs_path);
|
||||||
if (dir_name == L"/" && filename_fragment == L"/") {
|
if (dir_name == L"/" && filename_fragment == L"/") {
|
||||||
|
@ -287,7 +287,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
|
||||||
// access.
|
// access.
|
||||||
wcstring ent;
|
wcstring ent;
|
||||||
bool is_dir = false;
|
bool is_dir = false;
|
||||||
while (wreaddir_resolving(dir, dir_name, ent, require_dir ? &is_dir : NULL)) {
|
while (wreaddir_resolving(dir, dir_name, ent, require_dir ? &is_dir : nullptr)) {
|
||||||
// Maybe skip directories.
|
// Maybe skip directories.
|
||||||
if (require_dir && !is_dir) {
|
if (require_dir && !is_dir) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -403,7 +403,7 @@ static bool autosuggest_parse_command(const wcstring &buff, const environment_t
|
||||||
parse_node_tree_t parse_tree;
|
parse_node_tree_t parse_tree;
|
||||||
parse_tree_from_string(buff,
|
parse_tree_from_string(buff,
|
||||||
parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens,
|
parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens,
|
||||||
&parse_tree, NULL);
|
&parse_tree, nullptr);
|
||||||
|
|
||||||
// Find the first statement.
|
// Find the first statement.
|
||||||
tnode_t<g::plain_statement> first_statement{};
|
tnode_t<g::plain_statement> first_statement{};
|
||||||
|
@ -459,7 +459,7 @@ bool autosuggest_validate_from_history(const history_item_t &item,
|
||||||
|
|
||||||
// Not handled specially so handle it here.
|
// Not handled specially so handle it here.
|
||||||
bool cmd_ok = false;
|
bool cmd_ok = false;
|
||||||
if (path_get_path(parsed_command, NULL, vars)) {
|
if (path_get_path(parsed_command, nullptr, vars)) {
|
||||||
cmd_ok = true;
|
cmd_ok = true;
|
||||||
} else if (builtin_exists(parsed_command) || function_exists_no_autoload(parsed_command)) {
|
} else if (builtin_exists(parsed_command) || function_exists_no_autoload(parsed_command)) {
|
||||||
cmd_ok = true;
|
cmd_ok = true;
|
||||||
|
@ -503,7 +503,7 @@ static size_t color_variable(const wchar_t *in, size_t in_len,
|
||||||
// Handle a slice, up to dollar_count of them. Note that we currently don't do any validation of
|
// Handle a slice, up to dollar_count of them. Note that we currently don't do any validation of
|
||||||
// the slice's contents, e.g. $foo[blah] will not show an error even though it's invalid.
|
// the slice's contents, e.g. $foo[blah] will not show an error even though it's invalid.
|
||||||
for (size_t slice_count = 0; slice_count < dollar_count && in[idx] == L'['; slice_count++) {
|
for (size_t slice_count = 0; slice_count < dollar_count && in[idx] == L'['; slice_count++) {
|
||||||
wchar_t *slice_begin = NULL, *slice_end = NULL;
|
wchar_t *slice_begin = nullptr, *slice_end = nullptr;
|
||||||
int located = parse_util_locate_slice(in + idx, &slice_begin, &slice_end, false);
|
int located = parse_util_locate_slice(in + idx, &slice_begin, &slice_end, false);
|
||||||
if (located == 1) {
|
if (located == 1) {
|
||||||
size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in;
|
size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in;
|
||||||
|
@ -813,7 +813,7 @@ class highlighter_t {
|
||||||
parse_tree_from_string(buff,
|
parse_tree_from_string(buff,
|
||||||
parse_flag_continue_after_error | parse_flag_include_comments |
|
parse_flag_continue_after_error | parse_flag_include_comments |
|
||||||
parse_flag_accept_incomplete_tokens,
|
parse_flag_accept_incomplete_tokens,
|
||||||
&this->parse_tree, NULL);
|
&this->parse_tree, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform highlighting, returning an array of colors.
|
// Perform highlighting, returning an array of colors.
|
||||||
|
@ -975,7 +975,7 @@ void highlighter_t::color_redirection(tnode_t<g::redirection> redirection_node)
|
||||||
|
|
||||||
// Check if the argument contains a command substitution. If so, highlight it as a param
|
// Check if the argument contains a command substitution. If so, highlight it as a param
|
||||||
// even though it's a command redirection, and don't try to do any other validation.
|
// even though it's a command redirection, and don't try to do any other validation.
|
||||||
if (parse_util_locate_cmdsubst(target.c_str(), NULL, NULL, true) != 0) {
|
if (parse_util_locate_cmdsubst(target.c_str(), nullptr, nullptr, true) != 0) {
|
||||||
this->color_argument(redir_target);
|
this->color_argument(redir_target);
|
||||||
} else {
|
} else {
|
||||||
// No command substitution, so we can highlight the target file or fd. For example,
|
// No command substitution, so we can highlight the target file or fd. For example,
|
||||||
|
@ -1087,7 +1087,7 @@ void highlighter_t::color_children(const parse_node_t &parent, parse_token_type_
|
||||||
highlight_spec_t color) {
|
highlight_spec_t color) {
|
||||||
for (node_offset_t idx = 0; idx < parent.child_count; idx++) {
|
for (node_offset_t idx = 0; idx < parent.child_count; idx++) {
|
||||||
const parse_node_t *child = this->parse_tree.get_child(parent, idx);
|
const parse_node_t *child = this->parse_tree.get_child(parent, idx);
|
||||||
if (child != NULL && child->type == type) {
|
if (child != nullptr && child->type == type) {
|
||||||
this->color_node(*child, color);
|
this->color_node(*child, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1127,7 +1127,7 @@ static bool command_is_valid(const wcstring &cmd, enum parse_statement_decoratio
|
||||||
if (!is_valid && abbreviation_ok) is_valid = expand_abbreviation(cmd, vars).has_value();
|
if (!is_valid && abbreviation_ok) is_valid = expand_abbreviation(cmd, vars).has_value();
|
||||||
|
|
||||||
// Regular commands
|
// Regular commands
|
||||||
if (!is_valid && command_ok) is_valid = path_get_path(cmd, NULL, vars);
|
if (!is_valid && command_ok) is_valid = path_get_path(cmd, nullptr, vars);
|
||||||
|
|
||||||
// Implicit cd
|
// Implicit cd
|
||||||
if (!is_valid && implicit_cd_ok) {
|
if (!is_valid && implicit_cd_ok) {
|
||||||
|
|
|
@ -144,7 +144,7 @@ class history_lru_cache_t : public lru_cache_t<history_lru_cache_t, history_item
|
||||||
// and add it. Note that calling get_node promotes the node to the front.
|
// and add it. Note that calling get_node promotes the node to the front.
|
||||||
wcstring key = item.str();
|
wcstring key = item.str();
|
||||||
history_item_t *node = this->get(key);
|
history_item_t *node = this->get(key);
|
||||||
if (node == NULL) {
|
if (node == nullptr) {
|
||||||
this->insert(std::move(key), std::move(item));
|
this->insert(std::move(key), std::move(item));
|
||||||
} else {
|
} else {
|
||||||
node->creation_timestamp = std::max(node->timestamp(), item.timestamp());
|
node->creation_timestamp = std::max(node->timestamp(), item.timestamp());
|
||||||
|
@ -252,7 +252,7 @@ struct history_impl_t {
|
||||||
// the boundary are considered "old". Items whose timestemps are > the boundary are new, and are
|
// the boundary are considered "old". Items whose timestemps are > the boundary are new, and are
|
||||||
// ignored by this instance (unless they came from this instance). The timestamp may be adjusted
|
// ignored by this instance (unless they came from this instance). The timestamp may be adjusted
|
||||||
// by incorporate_external_changes().
|
// by incorporate_external_changes().
|
||||||
time_t boundary_timestamp{time(NULL)};
|
time_t boundary_timestamp{time(nullptr)};
|
||||||
|
|
||||||
// How many items we add until the next vacuum. Initially a random value.
|
// How many items we add until the next vacuum. Initially a random value.
|
||||||
int countdown_to_vacuum{-1};
|
int countdown_to_vacuum{-1};
|
||||||
|
@ -378,7 +378,7 @@ void history_impl_t::save_unless_disabled() {
|
||||||
// the counter.
|
// the counter.
|
||||||
const int kVacuumFrequency = 25;
|
const int kVacuumFrequency = 25;
|
||||||
if (countdown_to_vacuum < 0) {
|
if (countdown_to_vacuum < 0) {
|
||||||
unsigned int seed = static_cast<unsigned int>(time(NULL));
|
unsigned int seed = static_cast<unsigned int>(time(nullptr));
|
||||||
// Generate a number in the range [0, kVacuumFrequency).
|
// Generate a number in the range [0, kVacuumFrequency).
|
||||||
countdown_to_vacuum = rand_r(&seed) / (RAND_MAX / kVacuumFrequency + 1);
|
countdown_to_vacuum = rand_r(&seed) / (RAND_MAX / kVacuumFrequency + 1);
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ void history_impl_t::save_unless_disabled() {
|
||||||
|
|
||||||
void history_impl_t::add(const wcstring &str, history_identifier_t ident, bool pending,
|
void history_impl_t::add(const wcstring &str, history_identifier_t ident, bool pending,
|
||||||
bool do_save) {
|
bool do_save) {
|
||||||
time_t when = time(NULL);
|
time_t when = time(nullptr);
|
||||||
// Big hack: do not allow timestamps equal to our boundary date. This is because we include
|
// Big hack: do not allow timestamps equal to our boundary date. This is because we include
|
||||||
// items whose timestamps are equal to our boundary when reading old history, so we can catch
|
// items whose timestamps are equal to our boundary when reading old history, so we can catch
|
||||||
// "just closed" items. But this means that we may interpret our own items, that we just wrote,
|
// "just closed" items. But this means that we may interpret our own items, that we just wrote,
|
||||||
|
@ -1108,7 +1108,7 @@ static bool should_import_bash_history_line(const wcstring &line) {
|
||||||
if (line.empty()) return false;
|
if (line.empty()) return false;
|
||||||
|
|
||||||
parse_node_tree_t parse_tree;
|
parse_node_tree_t parse_tree;
|
||||||
if (!parse_tree_from_string(line, parse_flag_none, &parse_tree, NULL)) return false;
|
if (!parse_tree_from_string(line, parse_flag_none, &parse_tree, nullptr)) return false;
|
||||||
|
|
||||||
// In doing this test do not allow incomplete strings. Hence the "false" argument.
|
// In doing this test do not allow incomplete strings. Hence the "false" argument.
|
||||||
parse_error_list_t errors;
|
parse_error_list_t errors;
|
||||||
|
@ -1175,7 +1175,7 @@ void history_impl_t::incorporate_external_changes() {
|
||||||
// is somehwhat expensive because we will be going back over old items. An optimization would be
|
// is somehwhat expensive because we will be going back over old items. An optimization would be
|
||||||
// to preserve old_item_offsets so that they don't have to be recomputed. (However, then items
|
// to preserve old_item_offsets so that they don't have to be recomputed. (However, then items
|
||||||
// *deleted* in other instances would not show up here).
|
// *deleted* in other instances would not show up here).
|
||||||
time_t new_timestamp = time(NULL);
|
time_t new_timestamp = time(nullptr);
|
||||||
|
|
||||||
// If for some reason the clock went backwards, we don't want to start dropping items; therefore
|
// If for some reason the clock went backwards, we don't want to start dropping items; therefore
|
||||||
// we only do work if time has progressed. This also makes multiple calls cheap.
|
// we only do work if time has progressed. This also makes multiple calls cheap.
|
||||||
|
@ -1277,7 +1277,7 @@ void history_t::add_pending_with_file_detection(const wcstring &str,
|
||||||
// Find all arguments that look like they could be file paths.
|
// Find all arguments that look like they could be file paths.
|
||||||
bool needs_sync_write = false;
|
bool needs_sync_write = false;
|
||||||
parse_node_tree_t tree;
|
parse_node_tree_t tree;
|
||||||
parse_tree_from_string(str, parse_flag_none, &tree, NULL);
|
parse_tree_from_string(str, parse_flag_none, &tree, nullptr);
|
||||||
|
|
||||||
path_list_t potential_paths;
|
path_list_t potential_paths;
|
||||||
for (const parse_node_t &node : tree) {
|
for (const parse_node_t &node : tree) {
|
||||||
|
|
|
@ -126,14 +126,14 @@ std::unique_ptr<history_file_contents_t> history_file_contents_t::create(int fd)
|
||||||
if (should_mmap(fd)) {
|
if (should_mmap(fd)) {
|
||||||
// We feel confident to map the file directly. Note this is still risky: if another
|
// We feel confident to map the file directly. Note this is still risky: if another
|
||||||
// process truncates the file we risk SIGBUS.
|
// process truncates the file we risk SIGBUS.
|
||||||
mmap_start = mmap(0, size_t(len), PROT_READ, MAP_PRIVATE, fd, 0);
|
mmap_start = mmap(nullptr, size_t(len), PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if (mmap_start == MAP_FAILED) return nullptr;
|
if (mmap_start == MAP_FAILED) return nullptr;
|
||||||
} else {
|
} else {
|
||||||
// We don't want to map the file. mmap some private memory and then read into it. We use
|
// We don't want to map the file. mmap some private memory and then read into it. We use
|
||||||
// mmap instead of malloc so that the destructor can always munmap().
|
// mmap instead of malloc so that the destructor can always munmap().
|
||||||
mmap_start =
|
mmap_start =
|
||||||
#ifdef MAP_ANON
|
#ifdef MAP_ANON
|
||||||
mmap(0, size_t(len), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
mmap(nullptr, size_t(len), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||||
#else
|
#else
|
||||||
mmap(0, size_t(len), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
mmap(0, size_t(len), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -184,7 +184,7 @@ static size_t read_line(const char *base, size_t cursor, size_t len, std::string
|
||||||
assert(cursor <= len);
|
assert(cursor <= len);
|
||||||
const char *start = base + cursor;
|
const char *start = base + cursor;
|
||||||
const char *a_newline = static_cast<const char *>(std::memchr(start, '\n', len - cursor));
|
const char *a_newline = static_cast<const char *>(std::memchr(start, '\n', len - cursor));
|
||||||
if (a_newline != NULL) { // we found a newline
|
if (a_newline != nullptr) { // we found a newline
|
||||||
result.assign(start, a_newline - start);
|
result.assign(start, a_newline - start);
|
||||||
// Return the amount to advance the cursor; skip over the newline.
|
// Return the amount to advance the cursor; skip over the newline.
|
||||||
return a_newline - start + 1;
|
return a_newline - start + 1;
|
||||||
|
@ -256,7 +256,7 @@ static history_item_t decode_item_fish_2_0(const char *base, size_t len) {
|
||||||
if (key == "when") {
|
if (key == "when") {
|
||||||
// Parse an int from the timestamp. Should this fail, strtol returns 0; that's
|
// Parse an int from the timestamp. Should this fail, strtol returns 0; that's
|
||||||
// acceptable.
|
// acceptable.
|
||||||
char *end = NULL;
|
char *end = nullptr;
|
||||||
long tmp = strtol(value.c_str(), &end, 0);
|
long tmp = strtol(value.c_str(), &end, 0);
|
||||||
when = tmp;
|
when = tmp;
|
||||||
} else if (key == "paths") {
|
} else if (key == "paths") {
|
||||||
|
@ -302,7 +302,7 @@ static bool parse_timestamp(const char *str, time_t *out_when) {
|
||||||
|
|
||||||
// Try to parse a timestamp.
|
// Try to parse a timestamp.
|
||||||
long timestamp = 0;
|
long timestamp = 0;
|
||||||
if (isdigit(*cursor) && (timestamp = strtol(cursor, NULL, 0)) > 0) {
|
if (isdigit(*cursor) && (timestamp = strtol(cursor, nullptr, 0)) > 0) {
|
||||||
*out_when = static_cast<time_t>(timestamp);
|
*out_when = static_cast<time_t>(timestamp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -313,23 +313,23 @@ static bool parse_timestamp(const char *str, time_t *out_when) {
|
||||||
/// newline. Note that the string is not null terminated.
|
/// newline. Note that the string is not null terminated.
|
||||||
static const char *next_line(const char *start, const char *end) {
|
static const char *next_line(const char *start, const char *end) {
|
||||||
// Handle the hopeless case.
|
// Handle the hopeless case.
|
||||||
if (end == start) return NULL;
|
if (end == start) return nullptr;
|
||||||
|
|
||||||
// Skip past the next newline.
|
// Skip past the next newline.
|
||||||
const char *nextline = std::find(start, end, '\n');
|
const char *nextline = std::find(start, end, '\n');
|
||||||
if (nextline == end) {
|
if (nextline == end) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip past the newline character itself.
|
// Skip past the newline character itself.
|
||||||
if (++nextline >= end) {
|
if (++nextline >= end) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure this new line is itself "newline terminated". If it's not, return NULL.
|
// Make sure this new line is itself "newline terminated". If it's not, return NULL.
|
||||||
const char *next_newline = std::find(nextline, end, '\n');
|
const char *next_newline = std::find(nextline, end, '\n');
|
||||||
if (next_newline == end) {
|
if (next_newline == end) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextline;
|
return nextline;
|
||||||
|
@ -352,7 +352,7 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten
|
||||||
// Advance the cursor to the next line.
|
// Advance the cursor to the next line.
|
||||||
const char *a_newline =
|
const char *a_newline =
|
||||||
static_cast<const char *>(std::memchr(line_start, '\n', length - cursor));
|
static_cast<const char *>(std::memchr(line_start, '\n', length - cursor));
|
||||||
if (a_newline == NULL) break;
|
if (a_newline == nullptr) break;
|
||||||
|
|
||||||
// Advance the cursor past this line. +1 is for the newline.
|
// Advance the cursor past this line. +1 is for the newline.
|
||||||
cursor = a_newline - begin + 1;
|
cursor = a_newline - begin + 1;
|
||||||
|
@ -403,7 +403,7 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten
|
||||||
const char *interior_line;
|
const char *interior_line;
|
||||||
|
|
||||||
for (interior_line = next_line(line_start, end);
|
for (interior_line = next_line(line_start, end);
|
||||||
interior_line != NULL && !has_timestamp;
|
interior_line != nullptr && !has_timestamp;
|
||||||
interior_line = next_line(interior_line, end)) {
|
interior_line = next_line(interior_line, end)) {
|
||||||
// If the first character is not a space, it's not an interior line, so we're done.
|
// If the first character is not a space, it's not an interior line, so we're done.
|
||||||
if (interior_line[0] != ' ') break;
|
if (interior_line[0] != ' ') break;
|
||||||
|
|
|
@ -436,7 +436,7 @@ void inputter_t::push_front(char_event_t ch) { event_queue_.push_front(ch); }
|
||||||
/// \return the first mapping that matches, walking first over the user's mapping list, then the
|
/// \return the first mapping that matches, walking first over the user's mapping list, then the
|
||||||
/// preset list. \return null if nothing matches.
|
/// preset list. \return null if nothing matches.
|
||||||
maybe_t<input_mapping_t> inputter_t::find_mapping() {
|
maybe_t<input_mapping_t> inputter_t::find_mapping() {
|
||||||
const input_mapping_t *generic = NULL;
|
const input_mapping_t *generic = nullptr;
|
||||||
const auto &vars = parser_->vars();
|
const auto &vars = parser_->vars();
|
||||||
const wcstring bind_mode = input_get_bind_mode(vars);
|
const wcstring bind_mode = input_get_bind_mode(vars);
|
||||||
|
|
||||||
|
@ -553,7 +553,7 @@ std::vector<input_mapping_name_t> input_mapping_set_t::get_names(bool user) cons
|
||||||
void input_mapping_set_t::clear(const wchar_t *mode, bool user) {
|
void input_mapping_set_t::clear(const wchar_t *mode, bool user) {
|
||||||
all_mappings_cache_.reset();
|
all_mappings_cache_.reset();
|
||||||
mapping_list_t &ml = user ? mapping_list_ : preset_mapping_list_;
|
mapping_list_t &ml = user ? mapping_list_ : preset_mapping_list_;
|
||||||
auto should_erase = [=](const input_mapping_t &m) { return mode == NULL || mode == m.mode; };
|
auto should_erase = [=](const input_mapping_t &m) { return mode == nullptr || mode == m.mode; };
|
||||||
ml.erase(std::remove_if(ml.begin(), ml.end(), should_erase), ml.end());
|
ml.erase(std::remove_if(ml.begin(), ml.end(), should_erase), ml.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ class input_mapping_set_t {
|
||||||
~input_mapping_set_t();
|
~input_mapping_set_t();
|
||||||
|
|
||||||
/// Erase all bindings.
|
/// Erase all bindings.
|
||||||
void clear(const wchar_t *mode = NULL, bool user = true);
|
void clear(const wchar_t *mode = nullptr, bool user = true);
|
||||||
|
|
||||||
/// Erase binding for specified key sequence.
|
/// Erase binding for specified key sequence.
|
||||||
bool erase(const wcstring &sequence, const wcstring &mode = DEFAULT_BIND_MODE,
|
bool erase(const wcstring &sequence, const wcstring &mode = DEFAULT_BIND_MODE,
|
||||||
|
|
|
@ -75,7 +75,7 @@ char_event_t input_event_queue_t::readb() {
|
||||||
tv.tv_usec = static_cast<int>(usecs_delay % usecs_per_sec);
|
tv.tv_usec = static_cast<int>(usecs_delay % usecs_per_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = select(fd_max + 1, &fdset, 0, 0, usecs_delay > 0 ? &tv : NULL);
|
res = select(fd_max + 1, &fdset, nullptr, nullptr, usecs_delay > 0 ? &tv : nullptr);
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
if (errno == EINTR || errno == EAGAIN) {
|
if (errno == EINTR || errno == EAGAIN) {
|
||||||
if (interrupt_handler) {
|
if (interrupt_handler) {
|
||||||
|
@ -213,7 +213,7 @@ char_event_t input_event_queue_t::readch_timed(bool dequeue_timeouts) {
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(STDIN_FILENO, &fds);
|
FD_SET(STDIN_FILENO, &fds);
|
||||||
struct timeval tm = {wait_on_escape_ms / 1000, 1000 * (wait_on_escape_ms % 1000)};
|
struct timeval tm = {wait_on_escape_ms / 1000, 1000 * (wait_on_escape_ms % 1000)};
|
||||||
if (select(1, &fds, 0, 0, &tm) > 0) {
|
if (select(1, &fds, nullptr, nullptr, &tm) > 0) {
|
||||||
result = readch();
|
result = readch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ bool string_less_than_string(const wchar_t *a, const wchar_t *b) { return std::w
|
||||||
owning_lock<std::vector<const wchar_t *>> string_table;
|
owning_lock<std::vector<const wchar_t *>> string_table;
|
||||||
|
|
||||||
static const wchar_t *intern_with_dup(const wchar_t *in, bool dup) {
|
static const wchar_t *intern_with_dup(const wchar_t *in, bool dup) {
|
||||||
if (!in) return NULL;
|
if (!in) return nullptr;
|
||||||
|
|
||||||
debug(5, L"intern %ls", in);
|
debug(5, L"intern %ls", in);
|
||||||
auto table = string_table.acquire();
|
auto table = string_table.acquire();
|
||||||
|
|
|
@ -79,7 +79,7 @@ void io_buffer_t::run_background_fillthread(autoclose_fd_t readfd) {
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fd, &fds);
|
FD_SET(fd, &fds);
|
||||||
int ret = select(fd + 1, &fds, NULL, NULL, &tv);
|
int ret = select(fd + 1, &fds, nullptr, nullptr, &tv);
|
||||||
// select(2) is allowed to (and does) update `tv` to indicate how much time was left, so we
|
// select(2) is allowed to (and does) update `tv` to indicate how much time was left, so we
|
||||||
// need to restore the desired value each time.
|
// need to restore the desired value each time.
|
||||||
tv.tv_usec = poll_timeout_usec;
|
tv.tv_usec = poll_timeout_usec;
|
||||||
|
@ -234,7 +234,7 @@ void io_print(const io_chain_t &chain)
|
||||||
for (size_t i=0; i < chain.size(); i++)
|
for (size_t i=0; i < chain.size(); i++)
|
||||||
{
|
{
|
||||||
const shared_ptr<io_data_t> &io = chain.at(i);
|
const shared_ptr<io_data_t> &io = chain.at(i);
|
||||||
if (io.get() == NULL)
|
if (io.get() == nullptr)
|
||||||
{
|
{
|
||||||
std::fwprintf(stderr, L"\t(null)\n");
|
std::fwprintf(stderr, L"\t(null)\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,7 @@ static bool iothread_wait_for_pending_completions(long timeout_usec) {
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fd, &fds);
|
FD_SET(fd, &fds);
|
||||||
int ret = select(fd + 1, &fds, NULL, NULL, &tv);
|
int ret = select(fd + 1, &fds, nullptr, nullptr, &tv);
|
||||||
return ret > 0;
|
return ret > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ bool make_pthread(pthread_t *result, void *(*func)(void *), void *param) {
|
||||||
// unlikely that they are all on the verge of exiting, so one is likely to be ready to handle
|
// unlikely that they are all on the verge of exiting, so one is likely to be ready to handle
|
||||||
// extant requests. So we can ignore failure with some confidence.
|
// extant requests. So we can ignore failure with some confidence.
|
||||||
pthread_t thread = 0;
|
pthread_t thread = 0;
|
||||||
int err = pthread_create(&thread, NULL, func, param);
|
int err = pthread_create(&thread, nullptr, func, param);
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
// Success, return the thread.
|
// Success, return the thread.
|
||||||
debug(5, "pthread %p spawned", (void *)(intptr_t)thread);
|
debug(5, "pthread %p spawned", (void *)(intptr_t)thread);
|
||||||
|
@ -425,7 +425,7 @@ bool make_pthread(pthread_t *result, void *(*func)(void *), void *param) {
|
||||||
perror("pthread_create");
|
perror("pthread_create");
|
||||||
}
|
}
|
||||||
// Restore our sigmask.
|
// Restore our sigmask.
|
||||||
DIE_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &saved_set, NULL));
|
DIE_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &saved_set, nullptr));
|
||||||
return err == 0;
|
return err == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/lru.h
10
src/lru.h
|
@ -24,8 +24,8 @@ class lru_cache_t {
|
||||||
struct lru_link_t {
|
struct lru_link_t {
|
||||||
// Our doubly linked list
|
// Our doubly linked list
|
||||||
// The base class is used for the mouth only
|
// The base class is used for the mouth only
|
||||||
lru_link_t *prev = NULL;
|
lru_link_t *prev = nullptr;
|
||||||
lru_link_t *next = NULL;
|
lru_link_t *next = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The node type in our LRU cache
|
// The node type in our LRU cache
|
||||||
|
@ -36,7 +36,7 @@ class lru_cache_t {
|
||||||
lru_node_t(lru_node_t &&) = default;
|
lru_node_t(lru_node_t &&) = default;
|
||||||
|
|
||||||
// Our key in the map. This is owned by the map itself.
|
// Our key in the map. This is owned by the map itself.
|
||||||
const wcstring *key = NULL;
|
const wcstring *key = nullptr;
|
||||||
|
|
||||||
// The value from the client
|
// The value from the client
|
||||||
Contents value;
|
Contents value;
|
||||||
|
@ -78,7 +78,7 @@ class lru_cache_t {
|
||||||
// Remove the node
|
// Remove the node
|
||||||
void evict_node(lru_node_t *node) {
|
void evict_node(lru_node_t *node) {
|
||||||
// We should never evict the mouth.
|
// We should never evict the mouth.
|
||||||
assert(node != &mouth && node != NULL && node->key != NULL);
|
assert(node != &mouth && node != nullptr && node->key != nullptr);
|
||||||
|
|
||||||
auto iter = this->node_map.find(*node->key);
|
auto iter = this->node_map.find(*node->key);
|
||||||
assert(iter != this->node_map.end());
|
assert(iter != this->node_map.end());
|
||||||
|
@ -188,7 +188,7 @@ class lru_cache_t {
|
||||||
auto where = this->node_map.find(key);
|
auto where = this->node_map.find(key);
|
||||||
if (where == this->node_map.end()) {
|
if (where == this->node_map.end()) {
|
||||||
// not found
|
// not found
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
promote_node(&where->second);
|
promote_node(&where->second);
|
||||||
return &where->second.value;
|
return &where->second.value;
|
||||||
|
|
|
@ -401,7 +401,7 @@ int outputter_t::writech(wint_t ch) {
|
||||||
void outputter_t::writestr(const wchar_t *str) {
|
void outputter_t::writestr(const wchar_t *str) {
|
||||||
assert(str && "Empty input string");
|
assert(str && "Empty input string");
|
||||||
|
|
||||||
size_t len = wcstombs(0, str, 0); // figure amount of space needed
|
size_t len = wcstombs(nullptr, str, 0); // figure amount of space needed
|
||||||
if (len == static_cast<size_t>(-1)) {
|
if (len == static_cast<size_t>(-1)) {
|
||||||
debug(1, L"Tried to print invalid wide character string");
|
debug(1, L"Tried to print invalid wide character string");
|
||||||
return;
|
return;
|
||||||
|
@ -526,7 +526,7 @@ rgb_color_t parse_color(const env_var_t &var, bool is_background) {
|
||||||
/// Write specified multibyte string.
|
/// Write specified multibyte string.
|
||||||
void writembs_check(outputter_t &outp, const char *mbs, const char *mbs_name, bool critical,
|
void writembs_check(outputter_t &outp, const char *mbs, const char *mbs_name, bool critical,
|
||||||
const char *file, long line) {
|
const char *file, long line) {
|
||||||
if (mbs != NULL) {
|
if (mbs != nullptr) {
|
||||||
outp.term_puts(mbs, 1);
|
outp.term_puts(mbs, 1);
|
||||||
} else if (critical) {
|
} else if (critical) {
|
||||||
auto term = env_stack_t::globals().get(L"TERM");
|
auto term = env_stack_t::globals().get(L"TERM");
|
||||||
|
|
|
@ -809,7 +809,7 @@ bool pager_t::is_navigating_contents() const {
|
||||||
void pager_t::set_fully_disclosed(bool flag) { fully_disclosed = flag; }
|
void pager_t::set_fully_disclosed(bool flag) { fully_disclosed = flag; }
|
||||||
|
|
||||||
const completion_t *pager_t::selected_completion(const page_rendering_t &rendering) const {
|
const completion_t *pager_t::selected_completion(const page_rendering_t &rendering) const {
|
||||||
const completion_t *result = NULL;
|
const completion_t *result = nullptr;
|
||||||
size_t idx = visual_selected_completion_index(rendering.rows, rendering.cols);
|
size_t idx = visual_selected_completion_index(rendering.rows, rendering.cols);
|
||||||
if (idx != PAGER_SELECTION_NONE) {
|
if (idx != PAGER_SELECTION_NONE) {
|
||||||
result = &completion_infos.at(idx).representative;
|
result = &completion_infos.at(idx).representative;
|
||||||
|
|
|
@ -92,7 +92,7 @@ const enum_map<parse_token_type_t> token_enum_map[] = {
|
||||||
#define ELEM(sym) {symbol_##sym, L"symbol_" #sym},
|
#define ELEM(sym) {symbol_##sym, L"symbol_" #sym},
|
||||||
#include "parse_grammar_elements.inc"
|
#include "parse_grammar_elements.inc"
|
||||||
{token_type_invalid, L"token_type_invalid"},
|
{token_type_invalid, L"token_type_invalid"},
|
||||||
{token_type_invalid, NULL}};
|
{token_type_invalid, nullptr}};
|
||||||
#define token_enum_map_len (sizeof token_enum_map / sizeof *token_enum_map)
|
#define token_enum_map_len (sizeof token_enum_map / sizeof *token_enum_map)
|
||||||
|
|
||||||
// IMPORTANT: If the following enum is modified you must update the corresponding keyword_enum_map
|
// IMPORTANT: If the following enum is modified you must update the corresponding keyword_enum_map
|
||||||
|
@ -137,7 +137,7 @@ const enum_map<parse_keyword_t> keyword_enum_map[] = {{parse_keyword_exclam, L"!
|
||||||
{parse_keyword_or, L"or"},
|
{parse_keyword_or, L"or"},
|
||||||
{parse_keyword_switch, L"switch"},
|
{parse_keyword_switch, L"switch"},
|
||||||
{parse_keyword_while, L"while"},
|
{parse_keyword_while, L"while"},
|
||||||
{parse_keyword_none, NULL}};
|
{parse_keyword_none, nullptr}};
|
||||||
#define keyword_enum_map_len (sizeof keyword_enum_map / sizeof *keyword_enum_map)
|
#define keyword_enum_map_len (sizeof keyword_enum_map / sizeof *keyword_enum_map)
|
||||||
|
|
||||||
// Node tag values.
|
// Node tag values.
|
||||||
|
|
|
@ -138,7 +138,7 @@ tnode_t<g::plain_statement> parse_execution_context_t::infinite_recursive_statem
|
||||||
cmd == forbidden_function_name) {
|
cmd == forbidden_function_name) {
|
||||||
// This is it.
|
// This is it.
|
||||||
infinite_recursive_statement = plain_statement;
|
infinite_recursive_statement = plain_statement;
|
||||||
if (out_func_name != NULL) {
|
if (out_func_name != nullptr) {
|
||||||
*out_func_name = forbidden_function_name;
|
*out_func_name = forbidden_function_name;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -783,8 +783,8 @@ parse_execution_result_t parse_execution_context_t::expand_command(
|
||||||
/// Creates a 'normal' (non-block) process.
|
/// Creates a 'normal' (non-block) process.
|
||||||
parse_execution_result_t parse_execution_context_t::populate_plain_process(
|
parse_execution_result_t parse_execution_context_t::populate_plain_process(
|
||||||
job_t *job, process_t *proc, tnode_t<grammar::plain_statement> statement) {
|
job_t *job, process_t *proc, tnode_t<grammar::plain_statement> statement) {
|
||||||
assert(job != NULL);
|
assert(job != nullptr);
|
||||||
assert(proc != NULL);
|
assert(proc != nullptr);
|
||||||
|
|
||||||
// We may decide that a command should be an implicit cd.
|
// We may decide that a command should be an implicit cd.
|
||||||
bool use_implicit_cd = false;
|
bool use_implicit_cd = false;
|
||||||
|
@ -1009,7 +1009,7 @@ bool parse_execution_context_t::determine_io_chain(tnode_t<g::arguments_or_redir
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the new_io if we got one.
|
// Append the new_io if we got one.
|
||||||
if (new_io.get() != NULL) {
|
if (new_io.get() != nullptr) {
|
||||||
result.push_back(new_io);
|
result.push_back(new_io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1258,7 +1258,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
||||||
// Profiling support.
|
// Profiling support.
|
||||||
long long start_time = 0, parse_time = 0, exec_time = 0;
|
long long start_time = 0, parse_time = 0, exec_time = 0;
|
||||||
profile_item_t *profile_item = this->parser->create_profile_item();
|
profile_item_t *profile_item = this->parser->create_profile_item();
|
||||||
if (profile_item != NULL) {
|
if (profile_item != nullptr) {
|
||||||
start_time = get_time();
|
start_time = get_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1303,7 +1303,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile_item != NULL) {
|
if (profile_item != nullptr) {
|
||||||
// Block-types profile a little weird. They have no 'parse' time, and their command is
|
// Block-types profile a little weird. They have no 'parse' time, and their command is
|
||||||
// just the block type.
|
// just the block type.
|
||||||
exec_time = get_time();
|
exec_time = get_time();
|
||||||
|
@ -1353,7 +1353,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
||||||
parser->libdata().caller_job_id = saved_caller_jid;
|
parser->libdata().caller_job_id = saved_caller_jid;
|
||||||
|
|
||||||
// Store time it took to 'parse' the command.
|
// Store time it took to 'parse' the command.
|
||||||
if (profile_item != NULL) {
|
if (profile_item != nullptr) {
|
||||||
parse_time = get_time();
|
parse_time = get_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1384,7 +1384,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile_item != NULL) {
|
if (profile_item != nullptr) {
|
||||||
exec_time = get_time();
|
exec_time = get_time();
|
||||||
profile_item->level = parser->eval_level;
|
profile_item->level = parser->eval_level;
|
||||||
profile_item->parse = static_cast<int>(parse_time - start_time);
|
profile_item->parse = static_cast<int>(parse_time - start_time);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
using namespace parse_productions;
|
using namespace parse_productions;
|
||||||
using namespace grammar;
|
using namespace grammar;
|
||||||
|
|
||||||
#define NO_PRODUCTION NULL
|
#define NO_PRODUCTION nullptr
|
||||||
|
|
||||||
// Herein are encoded the productions for our LL2 fish grammar.
|
// Herein are encoded the productions for our LL2 fish grammar.
|
||||||
//
|
//
|
||||||
|
@ -408,7 +408,7 @@ const production_element_t *parse_productions::production_for_token(parse_token_
|
||||||
const production_element_t *(*resolver)(const parse_token_t &input1, //!OCLINT(unused param)
|
const production_element_t *(*resolver)(const parse_token_t &input1, //!OCLINT(unused param)
|
||||||
const parse_token_t &input2, //!OCLINT(unused param)
|
const parse_token_t &input2, //!OCLINT(unused param)
|
||||||
parse_node_tag_t *out_tag) = //!OCLINT(unused param)
|
parse_node_tag_t *out_tag) = //!OCLINT(unused param)
|
||||||
NULL;
|
nullptr;
|
||||||
switch (node_type) {
|
switch (node_type) {
|
||||||
// Handle all of our grammar elements
|
// Handle all of our grammar elements
|
||||||
#define ELEM(SYM) \
|
#define ELEM(SYM) \
|
||||||
|
@ -445,10 +445,10 @@ const production_element_t *parse_productions::production_for_token(parse_token_
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PARSE_ASSERT(resolver != NULL);
|
PARSE_ASSERT(resolver != nullptr);
|
||||||
|
|
||||||
const production_element_t *result = resolver(input1, input2, out_tag);
|
const production_element_t *result = resolver(input1, input2, out_tag);
|
||||||
if (result == NULL) {
|
if (result == nullptr) {
|
||||||
debug(5, L"Node type '%ls' has no production for input '%ls' (in %s)",
|
debug(5, L"Node type '%ls' has no production for input '%ls' (in %s)",
|
||||||
token_type_description(node_type), input1.describe().c_str(), __FUNCTION__);
|
token_type_description(node_type), input1.describe().c_str(), __FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ wcstring parse_error_t::describe(const wcstring &src, bool is_interactive) const
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) {
|
void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) {
|
||||||
assert(errors != NULL);
|
assert(errors != nullptr);
|
||||||
if (amt > 0) {
|
if (amt > 0) {
|
||||||
size_t i, max = errors->size();
|
size_t i, max = errors->size();
|
||||||
for (i = 0; i < max; i++) {
|
for (i = 0; i < max; i++) {
|
||||||
|
@ -593,10 +593,10 @@ void parse_ll_t::determine_node_ranges() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_ll_t::acquire_output(parse_node_tree_t *output, parse_error_list_t *errors) {
|
void parse_ll_t::acquire_output(parse_node_tree_t *output, parse_error_list_t *errors) {
|
||||||
if (output != NULL) {
|
if (output != nullptr) {
|
||||||
*output = std::move(this->nodes);
|
*output = std::move(this->nodes);
|
||||||
}
|
}
|
||||||
if (errors != NULL) {
|
if (errors != nullptr) {
|
||||||
*errors = std::move(this->errors);
|
*errors = std::move(this->errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -752,14 +752,14 @@ bool parse_ll_t::report_error_for_unclosed_block() {
|
||||||
// switch_statement, etc., each with different node structures. But keep descending the first
|
// switch_statement, etc., each with different node structures. But keep descending the first
|
||||||
// child and eventually you hit a keyword: begin, if, etc. That's the keyword we care about.
|
// child and eventually you hit a keyword: begin, if, etc. That's the keyword we care about.
|
||||||
const parse_node_t *end_command = this->nodes.get_parent(top_node, symbol_end_command);
|
const parse_node_t *end_command = this->nodes.get_parent(top_node, symbol_end_command);
|
||||||
const parse_node_t *block_node = end_command ? this->nodes.get_parent(*end_command) : NULL;
|
const parse_node_t *block_node = end_command ? this->nodes.get_parent(*end_command) : nullptr;
|
||||||
|
|
||||||
if (block_node && block_node->type == symbol_block_statement) {
|
if (block_node && block_node->type == symbol_block_statement) {
|
||||||
// Get the header.
|
// Get the header.
|
||||||
block_node = this->nodes.get_child(*block_node, 0, symbol_block_header);
|
block_node = this->nodes.get_child(*block_node, 0, symbol_block_header);
|
||||||
block_node = this->nodes.get_child(*block_node, 0); // specific statement
|
block_node = this->nodes.get_child(*block_node, 0); // specific statement
|
||||||
}
|
}
|
||||||
if (block_node == NULL) {
|
if (block_node == nullptr) {
|
||||||
return reported_error;
|
return reported_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -773,7 +773,7 @@ bool parse_ll_t::report_error_for_unclosed_block() {
|
||||||
const parse_node_t *cursor = block_node;
|
const parse_node_t *cursor = block_node;
|
||||||
while (cursor->child_count > 0) {
|
while (cursor->child_count > 0) {
|
||||||
cursor = this->nodes.get_child(*cursor, 0);
|
cursor = this->nodes.get_child(*cursor, 0);
|
||||||
assert(cursor != NULL);
|
assert(cursor != nullptr);
|
||||||
}
|
}
|
||||||
if (cursor->source_start != NODE_OFFSET_INVALID) {
|
if (cursor->source_start != NODE_OFFSET_INVALID) {
|
||||||
const wcstring node_desc = block_type_user_presentable_description(block_node->type);
|
const wcstring node_desc = block_type_user_presentable_description(block_node->type);
|
||||||
|
@ -917,7 +917,7 @@ void parse_ll_t::accept_tokens(parse_token_t token1, parse_token_t token2) {
|
||||||
const production_element_t *production =
|
const production_element_t *production =
|
||||||
production_for_token(stack_elem.type, token1, token2, &tag);
|
production_for_token(stack_elem.type, token1, token2, &tag);
|
||||||
node.tag = tag;
|
node.tag = tag;
|
||||||
if (production == NULL) {
|
if (production == nullptr) {
|
||||||
parse_error_failed_production(stack_elem, token1);
|
parse_error_failed_production(stack_elem, token1);
|
||||||
// The above sets fatal_errored, which ends the loop.
|
// The above sets fatal_errored, which ends the loop.
|
||||||
} else {
|
} else {
|
||||||
|
@ -1066,7 +1066,7 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t parse_flags,
|
||||||
parse_node_tree_t *output, parse_error_list_t *errors,
|
parse_node_tree_t *output, parse_error_list_t *errors,
|
||||||
parse_token_type_t goal) {
|
parse_token_type_t goal) {
|
||||||
parse_ll_t parser(goal);
|
parse_ll_t parser(goal);
|
||||||
parser.set_should_generate_error_messages(errors != NULL);
|
parser.set_should_generate_error_messages(errors != nullptr);
|
||||||
|
|
||||||
// A string whose storage we reuse.
|
// A string whose storage we reuse.
|
||||||
wcstring storage;
|
wcstring storage;
|
||||||
|
@ -1147,7 +1147,7 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t parse_flags,
|
||||||
|
|
||||||
const parse_node_t *parse_node_tree_t::get_child(const parse_node_t &parent, node_offset_t which,
|
const parse_node_t *parse_node_tree_t::get_child(const parse_node_t &parent, node_offset_t which,
|
||||||
parse_token_type_t expected_type) const {
|
parse_token_type_t expected_type) const {
|
||||||
const parse_node_t *result = NULL;
|
const parse_node_t *result = nullptr;
|
||||||
|
|
||||||
// We may get nodes with no children if we had an incomplete parse. Don't consider than an
|
// We may get nodes with no children if we had an incomplete parse. Don't consider than an
|
||||||
// error.
|
// error.
|
||||||
|
@ -1185,7 +1185,7 @@ const parse_node_t &parse_node_tree_t::find_child(const parse_node_t &parent,
|
||||||
|
|
||||||
const parse_node_t *parse_node_tree_t::get_parent(const parse_node_t &node,
|
const parse_node_t *parse_node_tree_t::get_parent(const parse_node_t &node,
|
||||||
parse_token_type_t expected_type) const {
|
parse_token_type_t expected_type) const {
|
||||||
const parse_node_t *result = NULL;
|
const parse_node_t *result = nullptr;
|
||||||
if (node.parent != NODE_OFFSET_INVALID) {
|
if (node.parent != NODE_OFFSET_INVALID) {
|
||||||
PARSE_ASSERT(node.parent < this->size());
|
PARSE_ASSERT(node.parent < this->size());
|
||||||
const parse_node_t &parent = this->at(node.parent);
|
const parse_node_t &parent = this->at(node.parent);
|
||||||
|
@ -1213,10 +1213,10 @@ static bool node_has_ancestor(const parse_node_tree_t &tree, const parse_node_t
|
||||||
|
|
||||||
const parse_node_t *parse_node_tree_t::find_node_matching_source_location(
|
const parse_node_t *parse_node_tree_t::find_node_matching_source_location(
|
||||||
parse_token_type_t type, size_t source_loc, const parse_node_t *parent) const {
|
parse_token_type_t type, size_t source_loc, const parse_node_t *parent) const {
|
||||||
const parse_node_t *result = NULL;
|
const parse_node_t *result = nullptr;
|
||||||
// Find nodes of the given type in the tree, working backwards.
|
// Find nodes of the given type in the tree, working backwards.
|
||||||
const size_t len = this->size();
|
const size_t len = this->size();
|
||||||
for (size_t idx = 0; idx < len && result == NULL; idx++) {
|
for (size_t idx = 0; idx < len && result == nullptr; idx++) {
|
||||||
const parse_node_t &node = this->at(idx);
|
const parse_node_t &node = this->at(idx);
|
||||||
|
|
||||||
// Types must match.
|
// Types must match.
|
||||||
|
@ -1226,7 +1226,7 @@ const parse_node_t *parse_node_tree_t::find_node_matching_source_location(
|
||||||
if (!node.location_in_or_at_end_of_source_range(source_loc)) continue;
|
if (!node.location_in_or_at_end_of_source_range(source_loc)) continue;
|
||||||
|
|
||||||
// If a parent is given, it must be an ancestor.
|
// If a parent is given, it must be an ancestor.
|
||||||
if (parent != NULL && !node_has_ancestor(*this, node, *parent)) continue;
|
if (parent != nullptr && !node_has_ancestor(*this, node, *parent)) continue;
|
||||||
|
|
||||||
// Found it.
|
// Found it.
|
||||||
result = &node;
|
result = &node;
|
||||||
|
|
|
@ -116,7 +116,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
|
||||||
int syntax_error = 0;
|
int syntax_error = 0;
|
||||||
int paran_count = 0;
|
int paran_count = 0;
|
||||||
|
|
||||||
wchar_t *paran_begin = 0, *paran_end = 0;
|
wchar_t *paran_begin = nullptr, *paran_end = nullptr;
|
||||||
|
|
||||||
assert(in && "null parameter");
|
assert(in && "null parameter");
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (*pos == open_type) {
|
if (*pos == open_type) {
|
||||||
if ((paran_count == 0) && (paran_begin == 0)) {
|
if ((paran_count == 0) && (paran_begin == nullptr)) {
|
||||||
paran_begin = pos;
|
paran_begin = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
|
||||||
} else if (*pos == close_type) {
|
} else if (*pos == close_type) {
|
||||||
paran_count--;
|
paran_count--;
|
||||||
|
|
||||||
if ((paran_count == 0) && (paran_end == 0)) {
|
if ((paran_count == 0) && (paran_end == nullptr)) {
|
||||||
paran_end = pos;
|
paran_end = pos;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paran_begin == 0) {
|
if (paran_begin == nullptr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c
|
||||||
const wchar_t *const buff = str.c_str();
|
const wchar_t *const buff = str.c_str();
|
||||||
const wchar_t *const valid_range_start = buff + *inout_cursor_offset,
|
const wchar_t *const valid_range_start = buff + *inout_cursor_offset,
|
||||||
*valid_range_end = buff + str.size();
|
*valid_range_end = buff + str.size();
|
||||||
wchar_t *bracket_range_begin = NULL, *bracket_range_end = NULL;
|
wchar_t *bracket_range_begin = nullptr, *bracket_range_end = nullptr;
|
||||||
int ret = parse_util_locate_brackets_of_type(valid_range_start, &bracket_range_begin,
|
int ret = parse_util_locate_brackets_of_type(valid_range_start, &bracket_range_begin,
|
||||||
&bracket_range_end, accept_incomplete, open_type,
|
&bracket_range_end, accept_incomplete, open_type,
|
||||||
close_type);
|
close_type);
|
||||||
|
@ -212,9 +212,9 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c
|
||||||
|
|
||||||
// The command substitutions must not be NULL and must be in the valid pointer range, and
|
// The command substitutions must not be NULL and must be in the valid pointer range, and
|
||||||
// the end must be bigger than the beginning.
|
// the end must be bigger than the beginning.
|
||||||
assert(bracket_range_begin != NULL && bracket_range_begin >= valid_range_start &&
|
assert(bracket_range_begin != nullptr && bracket_range_begin >= valid_range_start &&
|
||||||
bracket_range_begin <= valid_range_end);
|
bracket_range_begin <= valid_range_end);
|
||||||
assert(bracket_range_end != NULL && bracket_range_end > bracket_range_begin &&
|
assert(bracket_range_end != nullptr && bracket_range_end > bracket_range_begin &&
|
||||||
bracket_range_end >= valid_range_start && bracket_range_end <= valid_range_end);
|
bracket_range_end >= valid_range_start && bracket_range_end <= valid_range_end);
|
||||||
|
|
||||||
// Assign the substring to the out_contents.
|
// Assign the substring to the out_contents.
|
||||||
|
@ -252,13 +252,13 @@ void parse_util_cmdsubst_extent(const wchar_t *buff, size_t cursor_pos, const wc
|
||||||
const wchar_t *ap = buff, *bp = buff + bufflen;
|
const wchar_t *ap = buff, *bp = buff + bufflen;
|
||||||
const wchar_t *pos = buff;
|
const wchar_t *pos = buff;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
wchar_t *begin = NULL, *end = NULL;
|
wchar_t *begin = nullptr, *end = nullptr;
|
||||||
if (parse_util_locate_cmdsubst(pos, &begin, &end, true) <= 0) {
|
if (parse_util_locate_cmdsubst(pos, &begin, &end, true) <= 0) {
|
||||||
// No subshell found, all done.
|
// No subshell found, all done.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Interpret NULL to mean the end.
|
// Interpret NULL to mean the end.
|
||||||
if (end == NULL) {
|
if (end == nullptr) {
|
||||||
end = const_cast<wchar_t *>(buff) + bufflen;
|
end = const_cast<wchar_t *>(buff) + bufflen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,8 +283,8 @@ void parse_util_cmdsubst_extent(const wchar_t *buff, size_t cursor_pos, const wc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a != NULL) *a = ap;
|
if (a != nullptr) *a = ap;
|
||||||
if (b != NULL) *b = bp;
|
if (b != nullptr) *b = bp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the beginning and end of the job or process definition under the cursor.
|
/// Get the beginning and end of the job or process definition under the cursor.
|
||||||
|
@ -357,7 +357,7 @@ void parse_util_token_extent(const wchar_t *buff, size_t cursor_pos, const wchar
|
||||||
const wchar_t **tok_end, const wchar_t **prev_begin,
|
const wchar_t **tok_end, const wchar_t **prev_begin,
|
||||||
const wchar_t **prev_end) {
|
const wchar_t **prev_end) {
|
||||||
assert(buff && "Null buffer");
|
assert(buff && "Null buffer");
|
||||||
const wchar_t *a = NULL, *b = NULL, *pa = NULL, *pb = NULL;
|
const wchar_t *a = nullptr, *b = nullptr, *pa = nullptr, *pb = nullptr;
|
||||||
|
|
||||||
const wchar_t *cmdsubst_begin, *cmdsubst_end;
|
const wchar_t *cmdsubst_begin, *cmdsubst_end;
|
||||||
parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsubst_begin, &cmdsubst_end);
|
parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsubst_begin, &cmdsubst_end);
|
||||||
|
@ -471,7 +471,7 @@ static wchar_t get_quote(const wcstring &cmd_str, size_t len) {
|
||||||
if (cmd[i] == L'\'' || cmd[i] == L'\"') {
|
if (cmd[i] == L'\'' || cmd[i] == L'\"') {
|
||||||
const wchar_t *end = quote_end(&cmd[i]);
|
const wchar_t *end = quote_end(&cmd[i]);
|
||||||
// std::fwprintf( stderr, L"Jump %d\n", end-cmd );
|
// std::fwprintf( stderr, L"Jump %d\n", end-cmd );
|
||||||
if ((end == 0) || (!*end) || (end > cmd + len)) {
|
if ((end == nullptr) || (!*end) || (end > cmd + len)) {
|
||||||
res = cmd[i];
|
res = cmd[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -496,7 +496,7 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_
|
||||||
if (token->type == token_type_t::string)
|
if (token->type == token_type_t::string)
|
||||||
last_quote = get_quote(tok.text_of(*token), pos - token->offset);
|
last_quote = get_quote(tok.text_of(*token), pos - token->offset);
|
||||||
|
|
||||||
if (out_type != NULL) *out_type = token->type;
|
if (out_type != nullptr) *out_type = token->type;
|
||||||
|
|
||||||
prev_pos = token->offset;
|
prev_pos = token->offset;
|
||||||
}
|
}
|
||||||
|
@ -506,7 +506,7 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_
|
||||||
size_t cmdlen = pos;
|
size_t cmdlen = pos;
|
||||||
bool finished = cmdlen != 0;
|
bool finished = cmdlen != 0;
|
||||||
if (finished) {
|
if (finished) {
|
||||||
finished = (quote == NULL);
|
finished = (quote == nullptr);
|
||||||
if (finished && std::wcschr(L" \t\n\r", cmd_tmp[cmdlen - 1])) {
|
if (finished && std::wcschr(L" \t\n\r", cmd_tmp[cmdlen - 1])) {
|
||||||
finished = cmdlen > 1 && cmd_tmp[cmdlen - 2] == L'\\';
|
finished = cmdlen > 1 && cmd_tmp[cmdlen - 2] == L'\\';
|
||||||
}
|
}
|
||||||
|
@ -514,9 +514,9 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_
|
||||||
|
|
||||||
if (quote) *quote = last_quote;
|
if (quote) *quote = last_quote;
|
||||||
|
|
||||||
if (offset != 0) {
|
if (offset != nullptr) {
|
||||||
if (finished) {
|
if (finished) {
|
||||||
while ((cmd_tmp[prev_pos] != 0) && (std::wcschr(L";|", cmd_tmp[prev_pos]) != 0))
|
while ((cmd_tmp[prev_pos] != 0) && (std::wcschr(L";|", cmd_tmp[prev_pos]) != nullptr))
|
||||||
prev_pos++;
|
prev_pos++;
|
||||||
*offset = prev_pos;
|
*offset = prev_pos;
|
||||||
} else {
|
} else {
|
||||||
|
@ -688,7 +688,7 @@ std::vector<int> parse_util_compute_indents(const wcstring &src) {
|
||||||
parse_tree_from_string(src,
|
parse_tree_from_string(src,
|
||||||
parse_flag_continue_after_error | parse_flag_include_comments |
|
parse_flag_continue_after_error | parse_flag_include_comments |
|
||||||
parse_flag_accept_incomplete_tokens,
|
parse_flag_accept_incomplete_tokens,
|
||||||
&tree, NULL /* errors */);
|
&tree, nullptr /* errors */);
|
||||||
|
|
||||||
// Start indenting at the first node. If we have a parse error, we'll have to start indenting
|
// Start indenting at the first node. If we have a parse error, we'll have to start indenting
|
||||||
// from the top again.
|
// from the top again.
|
||||||
|
@ -832,7 +832,7 @@ void parse_util_expand_variable_error(const wcstring &token, size_t global_token
|
||||||
size_t dollar_pos, parse_error_list_t *errors) {
|
size_t dollar_pos, parse_error_list_t *errors) {
|
||||||
// Note that dollar_pos is probably VARIABLE_EXPAND or VARIABLE_EXPAND_SINGLE, not a literal
|
// Note that dollar_pos is probably VARIABLE_EXPAND or VARIABLE_EXPAND_SINGLE, not a literal
|
||||||
// dollar sign.
|
// dollar sign.
|
||||||
assert(errors != NULL);
|
assert(errors != nullptr);
|
||||||
assert(dollar_pos < token.size());
|
assert(dollar_pos < token.size());
|
||||||
const bool double_quotes = token.at(dollar_pos) == VARIABLE_EXPAND_SINGLE;
|
const bool double_quotes = token.at(dollar_pos) == VARIABLE_EXPAND_SINGLE;
|
||||||
const size_t start_error_count = errors->size();
|
const size_t start_error_count = errors->size();
|
||||||
|
@ -934,7 +934,7 @@ static parser_test_error_bits_t detect_dollar_cmdsub_errors(size_t arg_src_offse
|
||||||
wchar_t last = unescaped_arg_src.at(unescaped_arg_src.size() - 1);
|
wchar_t last = unescaped_arg_src.at(unescaped_arg_src.size() - 1);
|
||||||
if (last == VARIABLE_EXPAND) {
|
if (last == VARIABLE_EXPAND) {
|
||||||
result_bits |= PARSER_TEST_ERROR;
|
result_bits |= PARSER_TEST_ERROR;
|
||||||
if (out_errors != NULL) {
|
if (out_errors != nullptr) {
|
||||||
wcstring subcommand_first_token = tok_first(cmdsubst_src);
|
wcstring subcommand_first_token = tok_first(cmdsubst_src);
|
||||||
if (subcommand_first_token.empty()) {
|
if (subcommand_first_token.empty()) {
|
||||||
// e.g. $(). Report somthing.
|
// e.g. $(). Report somthing.
|
||||||
|
@ -995,7 +995,7 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(tnode_t<grammar::a
|
||||||
size_t error_offset = cmd_sub_start + 1 + source_start;
|
size_t error_offset = cmd_sub_start + 1 + source_start;
|
||||||
parse_error_offset_source_start(&subst_errors, error_offset);
|
parse_error_offset_source_start(&subst_errors, error_offset);
|
||||||
|
|
||||||
if (out_errors != NULL) {
|
if (out_errors != nullptr) {
|
||||||
out_errors->insert(out_errors->end(), subst_errors.begin(), subst_errors.end());
|
out_errors->insert(out_errors->end(), subst_errors.begin(), subst_errors.end());
|
||||||
|
|
||||||
// Hackish. Take this opportunity to report $(...) errors. We do this because
|
// Hackish. Take this opportunity to report $(...) errors. We do this because
|
||||||
|
@ -1319,11 +1319,11 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
|
||||||
if (has_unclosed_block || has_unclosed_quote_or_subshell || has_unclosed_pipe)
|
if (has_unclosed_block || has_unclosed_quote_or_subshell || has_unclosed_pipe)
|
||||||
res |= PARSER_TEST_INCOMPLETE;
|
res |= PARSER_TEST_INCOMPLETE;
|
||||||
|
|
||||||
if (out_errors != NULL) {
|
if (out_errors != nullptr) {
|
||||||
*out_errors = std::move(parse_errors);
|
*out_errors = std::move(parse_errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_pstree != NULL) {
|
if (out_pstree != nullptr) {
|
||||||
*out_pstree = std::make_shared<parsed_source_t>(buff_src, std::move(node_tree));
|
*out_pstree = std::make_shared<parsed_source_t>(buff_src, std::move(node_tree));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,9 +129,9 @@ std::vector<int> parse_util_compute_indents(const wcstring &src);
|
||||||
/// error. If out_pstree is not NULL, the resulting tree is returned by reference.
|
/// error. If out_pstree is not NULL, the resulting tree is returned by reference.
|
||||||
class parse_node_tree_t;
|
class parse_node_tree_t;
|
||||||
parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
|
parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
|
||||||
parse_error_list_t *out_errors = NULL,
|
parse_error_list_t *out_errors = nullptr,
|
||||||
bool allow_incomplete = true,
|
bool allow_incomplete = true,
|
||||||
parsed_source_ref_t *out_pstree = NULL);
|
parsed_source_ref_t *out_pstree = nullptr);
|
||||||
|
|
||||||
/// Detect errors in the specified string when parsed as an argument list. Returns the text of an
|
/// Detect errors in the specified string when parsed as an argument list. Returns the text of an
|
||||||
/// error, or none if no error occurred.
|
/// error, or none if no error occurred.
|
||||||
|
@ -144,7 +144,7 @@ maybe_t<wcstring> parse_util_detect_errors_in_argument_list(const wcstring &arg_
|
||||||
class parse_node_t;
|
class parse_node_t;
|
||||||
parser_test_error_bits_t parse_util_detect_errors_in_argument(
|
parser_test_error_bits_t parse_util_detect_errors_in_argument(
|
||||||
tnode_t<grammar::argument> node, const wcstring &arg_src,
|
tnode_t<grammar::argument> node, const wcstring &arg_src,
|
||||||
parse_error_list_t *out_errors = NULL);
|
parse_error_list_t *out_errors = nullptr);
|
||||||
|
|
||||||
/// Given a string containing a variable expansion error, append an appropriate error to the errors
|
/// Given a string containing a variable expansion error, append an appropriate error to the errors
|
||||||
/// list. The global_token_pos is the offset of the token in the larger source, and the dollar_pos
|
/// list. The global_token_pos is the offset of the token in the larger source, and the dollar_pos
|
||||||
|
|
|
@ -89,17 +89,17 @@ static const struct block_lookup_entry block_lookup[] = {
|
||||||
{WHILE, L"while", WHILE_BLOCK},
|
{WHILE, L"while", WHILE_BLOCK},
|
||||||
{FOR, L"for", FOR_BLOCK},
|
{FOR, L"for", FOR_BLOCK},
|
||||||
{IF, L"if", IF_BLOCK},
|
{IF, L"if", IF_BLOCK},
|
||||||
{FUNCTION_CALL, 0, FUNCTION_CALL_BLOCK},
|
{FUNCTION_CALL, nullptr, FUNCTION_CALL_BLOCK},
|
||||||
{FUNCTION_CALL_NO_SHADOW, 0, FUNCTION_CALL_NO_SHADOW_BLOCK},
|
{FUNCTION_CALL_NO_SHADOW, nullptr, FUNCTION_CALL_NO_SHADOW_BLOCK},
|
||||||
{SWITCH, L"switch", SWITCH_BLOCK},
|
{SWITCH, L"switch", SWITCH_BLOCK},
|
||||||
{TOP, 0, TOP_BLOCK},
|
{TOP, nullptr, TOP_BLOCK},
|
||||||
{SUBST, 0, SUBST_BLOCK},
|
{SUBST, nullptr, SUBST_BLOCK},
|
||||||
{BEGIN, L"begin", BEGIN_BLOCK},
|
{BEGIN, L"begin", BEGIN_BLOCK},
|
||||||
{SOURCE, L"source", SOURCE_BLOCK},
|
{SOURCE, L"source", SOURCE_BLOCK},
|
||||||
{EVENT, 0, EVENT_BLOCK},
|
{EVENT, nullptr, EVENT_BLOCK},
|
||||||
{BREAKPOINT, L"breakpoint", BREAKPOINT_BLOCK},
|
{BREAKPOINT, L"breakpoint", BREAKPOINT_BLOCK},
|
||||||
{VARIABLE_ASSIGNMENT, L"variable assignment", VARIABLE_ASSIGNMENT_BLOCK},
|
{VARIABLE_ASSIGNMENT, L"variable assignment", VARIABLE_ASSIGNMENT_BLOCK},
|
||||||
{static_cast<block_type_t>(0), 0, 0}};
|
{static_cast<block_type_t>(0), nullptr, nullptr}};
|
||||||
|
|
||||||
// Given a file path, return something nicer. Currently we just "unexpand" tildes.
|
// Given a file path, return something nicer. Currently we just "unexpand" tildes.
|
||||||
wcstring parser_t::user_presentable_path(const wcstring &path) const {
|
wcstring parser_t::user_presentable_path(const wcstring &path) const {
|
||||||
|
@ -141,7 +141,7 @@ block_t *parser_t::push_block(block_t &&block) {
|
||||||
new_current.src_lineno = parser_t::get_lineno();
|
new_current.src_lineno = parser_t::get_lineno();
|
||||||
|
|
||||||
const wchar_t *filename = parser_t::current_filename();
|
const wchar_t *filename = parser_t::current_filename();
|
||||||
if (filename != NULL) {
|
if (filename != nullptr) {
|
||||||
new_current.src_filename = intern(filename);
|
new_current.src_filename = intern(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,15 +234,15 @@ wcstring parser_t::block_stack_description() const {
|
||||||
const block_t *parser_t::block_at_index(size_t idx) const {
|
const block_t *parser_t::block_at_index(size_t idx) const {
|
||||||
// Zero corresponds to the last element in our vector.
|
// Zero corresponds to the last element in our vector.
|
||||||
size_t count = block_stack.size();
|
size_t count = block_stack.size();
|
||||||
return idx < count ? &block_stack.at(count - idx - 1) : NULL;
|
return idx < count ? &block_stack.at(count - idx - 1) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
block_t *parser_t::block_at_index(size_t idx) {
|
block_t *parser_t::block_at_index(size_t idx) {
|
||||||
size_t count = block_stack.size();
|
size_t count = block_stack.size();
|
||||||
return idx < count ? &block_stack.at(count - idx - 1) : NULL;
|
return idx < count ? &block_stack.at(count - idx - 1) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
block_t *parser_t::current_block() { return block_stack.empty() ? NULL : &block_stack.back(); }
|
block_t *parser_t::current_block() { return block_stack.empty() ? nullptr : &block_stack.back(); }
|
||||||
|
|
||||||
/// Print profiling information to the specified stream.
|
/// Print profiling information to the specified stream.
|
||||||
static void print_profile(const std::vector<std::unique_ptr<profile_item_t>> &items, FILE *out) {
|
static void print_profile(const std::vector<std::unique_ptr<profile_item_t>> &items, FILE *out) {
|
||||||
|
@ -320,7 +320,7 @@ std::vector<completion_t> parser_t::expand_argument_list(const wcstring &arg_lis
|
||||||
const std::shared_ptr<parser_t> &parser) {
|
const std::shared_ptr<parser_t> &parser) {
|
||||||
// Parse the string as an argument list.
|
// Parse the string as an argument list.
|
||||||
parse_node_tree_t tree;
|
parse_node_tree_t tree;
|
||||||
if (!parse_tree_from_string(arg_list_src, parse_flag_none, &tree, NULL /* errors */,
|
if (!parse_tree_from_string(arg_list_src, parse_flag_none, &tree, nullptr /* errors */,
|
||||||
symbol_freestanding_argument_list)) {
|
symbol_freestanding_argument_list)) {
|
||||||
// Failed to parse. Here we expect to have reported any errors in test_args.
|
// Failed to parse. Here we expect to have reported any errors in test_args.
|
||||||
return {};
|
return {};
|
||||||
|
@ -332,7 +332,7 @@ std::vector<completion_t> parser_t::expand_argument_list(const wcstring &arg_lis
|
||||||
tnode_t<grammar::freestanding_argument_list> arg_list(&tree, &tree.at(0));
|
tnode_t<grammar::freestanding_argument_list> arg_list(&tree, &tree.at(0));
|
||||||
while (auto arg = arg_list.next_in_list<grammar::argument>()) {
|
while (auto arg = arg_list.next_in_list<grammar::argument>()) {
|
||||||
const wcstring arg_src = arg.get_source(arg_list_src);
|
const wcstring arg_src = arg.get_source(arg_list_src);
|
||||||
if (expand_string(arg_src, &result, eflags, vars, parser, NULL /* errors */) ==
|
if (expand_string(arg_src, &result, eflags, vars, parser, nullptr /* errors */) ==
|
||||||
expand_result_t::error) {
|
expand_result_t::error) {
|
||||||
break; // failed to expand a string
|
break; // failed to expand a string
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ const wchar_t *parser_t::is_function(size_t idx) const {
|
||||||
// PCA: Have to make this a string somehow.
|
// PCA: Have to make this a string somehow.
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
|
|
||||||
const wchar_t *result = NULL;
|
const wchar_t *result = nullptr;
|
||||||
for (size_t block_idx = idx; block_idx < this->block_count(); block_idx++) {
|
for (size_t block_idx = idx; block_idx < this->block_count(); block_idx++) {
|
||||||
const block_t *b = this->block_at_index(block_idx);
|
const block_t *b = this->block_at_index(block_idx);
|
||||||
if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) {
|
if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) {
|
||||||
|
@ -462,7 +462,7 @@ const wchar_t *parser_t::get_function_name(int level) {
|
||||||
}
|
}
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
return NULL; // couldn't find a breakpoint frame
|
return nullptr; // couldn't find a breakpoint frame
|
||||||
} else if (level == 1) {
|
} else if (level == 1) {
|
||||||
// Return the function name for the current level.
|
// Return the function name for the current level.
|
||||||
return this->is_function();
|
return this->is_function();
|
||||||
|
@ -477,7 +477,7 @@ const wchar_t *parser_t::get_function_name(int level) {
|
||||||
}
|
}
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
return NULL; // couldn't find that function level
|
return nullptr; // couldn't find that function level
|
||||||
}
|
}
|
||||||
|
|
||||||
int parser_t::get_lineno() const {
|
int parser_t::get_lineno() const {
|
||||||
|
@ -487,7 +487,7 @@ int parser_t::get_lineno() const {
|
||||||
|
|
||||||
// If we are executing a function, we have to add in its offset.
|
// If we are executing a function, we have to add in its offset.
|
||||||
const wchar_t *function_name = is_function();
|
const wchar_t *function_name = is_function();
|
||||||
if (function_name != NULL) {
|
if (function_name != nullptr) {
|
||||||
lineno += function_get_definition_lineno(function_name);
|
lineno += function_get_definition_lineno(function_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -569,7 +569,7 @@ wcstring parser_t::current_line() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void parser_t::job_add(shared_ptr<job_t> job) {
|
void parser_t::job_add(shared_ptr<job_t> job) {
|
||||||
assert(job != NULL);
|
assert(job != nullptr);
|
||||||
assert(!job->processes.empty());
|
assert(!job->processes.empty());
|
||||||
job_list.push_front(std::move(job));
|
job_list.push_front(std::move(job));
|
||||||
}
|
}
|
||||||
|
@ -591,14 +591,14 @@ job_t *parser_t::job_get(job_id_t id) {
|
||||||
for (const auto &job : job_list) {
|
for (const auto &job : job_list) {
|
||||||
if (id <= 0 || job->job_id == id) return job.get();
|
if (id <= 0 || job->job_id == id) return job.get();
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
job_t *parser_t::job_get_from_pid(pid_t pid) const {
|
job_t *parser_t::job_get_from_pid(pid_t pid) const {
|
||||||
pid_t pgid = getpgid(pid);
|
pid_t pgid = getpgid(pid);
|
||||||
|
|
||||||
if (pgid == -1) {
|
if (pgid == -1) {
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &job : jobs()) {
|
for (const auto &job : jobs()) {
|
||||||
|
@ -610,7 +610,7 @@ job_t *parser_t::job_get_from_pid(pid_t pid) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
profile_item_t *parser_t::create_profile_item() {
|
profile_item_t *parser_t::create_profile_item() {
|
||||||
|
@ -802,7 +802,7 @@ wcstring block_t::description() const {
|
||||||
if (this->src_lineno >= 0) {
|
if (this->src_lineno >= 0) {
|
||||||
append_format(result, L" (line %d)", this->src_lineno);
|
append_format(result, L" (line %d)", this->src_lineno);
|
||||||
}
|
}
|
||||||
if (this->src_filename != NULL) {
|
if (this->src_filename != nullptr) {
|
||||||
append_format(result, L" (file %ls)", this->src_filename);
|
append_format(result, L" (file %ls)", this->src_filename);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -199,7 +199,7 @@ pid_t execute_fork() {
|
||||||
// Don't sleep on the final lap - sleeping might change the value of errno, which will break
|
// Don't sleep on the final lap - sleeping might change the value of errno, which will break
|
||||||
// the error reporting below.
|
// the error reporting below.
|
||||||
if (i != FORK_LAPS - 1) {
|
if (i != FORK_LAPS - 1) {
|
||||||
nanosleep(&pollint, NULL);
|
nanosleep(&pollint, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,7 +262,7 @@ static void handle_child_status(process_t *proc, proc_status_t status) {
|
||||||
sigemptyset(&act.sa_mask);
|
sigemptyset(&act.sa_mask);
|
||||||
act.sa_flags = 0;
|
act.sa_flags = 0;
|
||||||
act.sa_handler = SIG_DFL;
|
act.sa_handler = SIG_DFL;
|
||||||
sigaction(sig, &act, 0);
|
sigaction(sig, &act, nullptr);
|
||||||
kill(getpid(), sig);
|
kill(getpid(), sig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -560,7 +560,7 @@ static bool process_clean_after_marking(parser_t &parser, bool allow_interactive
|
||||||
|
|
||||||
// This may be invoked in an exit handler, after the TERM has been torn down
|
// This may be invoked in an exit handler, after the TERM has been torn down
|
||||||
// Don't try to print in that case (#3222)
|
// Don't try to print in that case (#3222)
|
||||||
const bool interactive = allow_interactive && cur_term != NULL;
|
const bool interactive = allow_interactive && cur_term != nullptr;
|
||||||
|
|
||||||
// Remove all disowned jobs.
|
// Remove all disowned jobs.
|
||||||
remove_disowned_jobs(parser.jobs());
|
remove_disowned_jobs(parser.jobs());
|
||||||
|
@ -686,7 +686,7 @@ unsigned long proc_get_jiffies(process_t *p) {
|
||||||
void proc_update_jiffies(parser_t &parser) {
|
void proc_update_jiffies(parser_t &parser) {
|
||||||
for (const auto &job : parser.jobs()) {
|
for (const auto &job : parser.jobs()) {
|
||||||
for (process_ptr_t &p : job->processes) {
|
for (process_ptr_t &p : job->processes) {
|
||||||
gettimeofday(&p->last_time, 0);
|
gettimeofday(&p->last_time, nullptr);
|
||||||
p->last_jiffies = proc_get_jiffies(p.get());
|
p->last_jiffies = proc_get_jiffies(p.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -923,7 +923,7 @@ void job_t::continue_job(parser_t &parser, bool reclaim_foreground_pgrp, bool se
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc_sanity_check(const parser_t &parser) {
|
void proc_sanity_check(const parser_t &parser) {
|
||||||
const job_t *fg_job = NULL;
|
const job_t *fg_job = nullptr;
|
||||||
|
|
||||||
for (const auto &j : parser.jobs()) {
|
for (const auto &j : parser.jobs()) {
|
||||||
if (!j->is_constructed()) continue;
|
if (!j->is_constructed()) continue;
|
||||||
|
|
|
@ -210,14 +210,14 @@ class process_t {
|
||||||
/// Returns argv[idx].
|
/// Returns argv[idx].
|
||||||
const wchar_t *argv(size_t idx) const {
|
const wchar_t *argv(size_t idx) const {
|
||||||
const wchar_t *const *argv = argv_array.get();
|
const wchar_t *const *argv = argv_array.get();
|
||||||
assert(argv != NULL);
|
assert(argv != nullptr);
|
||||||
return argv[idx];
|
return argv[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns argv[0], or NULL.
|
/// Returns argv[0], or NULL.
|
||||||
const wchar_t *argv0() const {
|
const wchar_t *argv0() const {
|
||||||
const wchar_t *const *argv = argv_array.get();
|
const wchar_t *const *argv = argv_array.get();
|
||||||
return argv ? argv[0] : NULL;
|
return argv ? argv[0] : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// IO chain getter and setter.
|
/// IO chain getter and setter.
|
||||||
|
|
|
@ -566,8 +566,8 @@ wcstring combine_command_and_autosuggestion(const wcstring &cmdline,
|
||||||
} else {
|
} else {
|
||||||
// We have an autosuggestion which is not a prefix of the command line, i.e. a case
|
// We have an autosuggestion which is not a prefix of the command line, i.e. a case
|
||||||
// disagreement. Decide whose case we want to use.
|
// disagreement. Decide whose case we want to use.
|
||||||
const wchar_t *begin = NULL, *cmd = cmdline.c_str();
|
const wchar_t *begin = nullptr, *cmd = cmdline.c_str();
|
||||||
parse_util_token_extent(cmd, cmdline.size() - 1, &begin, NULL, NULL, NULL);
|
parse_util_token_extent(cmd, cmdline.size() - 1, &begin, nullptr, nullptr, nullptr);
|
||||||
bool last_token_contains_uppercase = false;
|
bool last_token_contains_uppercase = false;
|
||||||
if (begin) {
|
if (begin) {
|
||||||
const wchar_t *end = begin + std::wcslen(begin);
|
const wchar_t *end = begin + std::wcslen(begin);
|
||||||
|
@ -720,7 +720,7 @@ void reader_data_t::pager_selection_changed() {
|
||||||
size_t cursor_pos = this->cycle_cursor_pos;
|
size_t cursor_pos = this->cycle_cursor_pos;
|
||||||
wcstring new_cmd_line;
|
wcstring new_cmd_line;
|
||||||
|
|
||||||
if (completion == NULL) {
|
if (completion == nullptr) {
|
||||||
new_cmd_line = this->cycle_command_line;
|
new_cmd_line = this->cycle_command_line;
|
||||||
} else {
|
} else {
|
||||||
new_cmd_line =
|
new_cmd_line =
|
||||||
|
@ -739,10 +739,10 @@ maybe_t<wcstring> reader_expand_abbreviation_in_command(const wcstring &cmdline,
|
||||||
// See if we are at "command position". Get the surrounding command substitution, and get the
|
// See if we are at "command position". Get the surrounding command substitution, and get the
|
||||||
// extent of the first token.
|
// extent of the first token.
|
||||||
const wchar_t *const buff = cmdline.c_str();
|
const wchar_t *const buff = cmdline.c_str();
|
||||||
const wchar_t *cmdsub_begin = NULL, *cmdsub_end = NULL;
|
const wchar_t *cmdsub_begin = nullptr, *cmdsub_end = nullptr;
|
||||||
parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsub_begin, &cmdsub_end);
|
parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsub_begin, &cmdsub_end);
|
||||||
assert(cmdsub_begin != NULL && cmdsub_begin >= buff);
|
assert(cmdsub_begin != nullptr && cmdsub_begin >= buff);
|
||||||
assert(cmdsub_end != NULL && cmdsub_end >= cmdsub_begin);
|
assert(cmdsub_end != nullptr && cmdsub_end >= cmdsub_begin);
|
||||||
|
|
||||||
// Determine the offset of this command substitution.
|
// Determine the offset of this command substitution.
|
||||||
const size_t subcmd_offset = cmdsub_begin - buff;
|
const size_t subcmd_offset = cmdsub_begin - buff;
|
||||||
|
@ -754,7 +754,7 @@ maybe_t<wcstring> reader_expand_abbreviation_in_command(const wcstring &cmdline,
|
||||||
parse_node_tree_t parse_tree;
|
parse_node_tree_t parse_tree;
|
||||||
parse_tree_from_string(subcmd,
|
parse_tree_from_string(subcmd,
|
||||||
parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens,
|
parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens,
|
||||||
&parse_tree, NULL);
|
&parse_tree, nullptr);
|
||||||
|
|
||||||
// Look for plain statements where the cursor is at the end of the command.
|
// Look for plain statements where the cursor is at the end of the command.
|
||||||
using namespace grammar;
|
using namespace grammar;
|
||||||
|
@ -1168,7 +1168,7 @@ wcstring completion_apply_to_command_line(const wcstring &val, complete_flags_t
|
||||||
const wchar_t *begin, *end;
|
const wchar_t *begin, *end;
|
||||||
|
|
||||||
const wchar_t *buff = command_line.c_str();
|
const wchar_t *buff = command_line.c_str();
|
||||||
parse_util_token_extent(buff, cursor_pos, &begin, 0, 0, 0);
|
parse_util_token_extent(buff, cursor_pos, &begin, nullptr, nullptr, nullptr);
|
||||||
end = buff + cursor_pos;
|
end = buff + cursor_pos;
|
||||||
|
|
||||||
wcstring sb(buff, begin - buff);
|
wcstring sb(buff, begin - buff);
|
||||||
|
@ -1208,7 +1208,7 @@ wcstring completion_apply_to_command_line(const wcstring &val, complete_flags_t
|
||||||
// substitution as one token.
|
// substitution as one token.
|
||||||
parse_util_get_parameter_info(
|
parse_util_get_parameter_info(
|
||||||
command_line.substr(cmdsub_offset, (cmdsub_end - cmdsub_begin)),
|
command_line.substr(cmdsub_offset, (cmdsub_end - cmdsub_begin)),
|
||||||
cursor_pos - cmdsub_offset, "e, NULL, NULL);
|
cursor_pos - cmdsub_offset, "e, nullptr, nullptr);
|
||||||
|
|
||||||
// If the token is reported as unquoted, but ends with a (unescaped) quote, and we can
|
// If the token is reported as unquoted, but ends with a (unescaped) quote, and we can
|
||||||
// modify the command line, then delete the trailing quote so that we can insert within
|
// modify the command line, then delete the trailing quote so that we can insert within
|
||||||
|
@ -1435,7 +1435,7 @@ void reader_data_t::flash() {
|
||||||
|
|
||||||
pollint.tv_sec = 0;
|
pollint.tv_sec = 0;
|
||||||
pollint.tv_nsec = 100 * 1000000;
|
pollint.tv_nsec = 100 * 1000000;
|
||||||
nanosleep(&pollint, NULL);
|
nanosleep(&pollint, nullptr);
|
||||||
|
|
||||||
super_highlight_me_plenty();
|
super_highlight_me_plenty();
|
||||||
repaint();
|
repaint();
|
||||||
|
@ -1660,7 +1660,7 @@ static bool check_for_orphaned_process(unsigned long loop_count, pid_t shell_pgi
|
||||||
char buf[L_ctermid];
|
char buf[L_ctermid];
|
||||||
char *tty = ctermid_r(buf);
|
char *tty = ctermid_r(buf);
|
||||||
#else
|
#else
|
||||||
char *tty = ctermid(NULL);
|
char *tty = ctermid(nullptr);
|
||||||
#endif
|
#endif
|
||||||
if (!tty) {
|
if (!tty) {
|
||||||
wperror(L"ctermid");
|
wperror(L"ctermid");
|
||||||
|
@ -1834,7 +1834,7 @@ void reader_data_t::replace_current_token(const wcstring &new_token) {
|
||||||
// Find current token.
|
// Find current token.
|
||||||
editable_line_t *el = active_edit_line();
|
editable_line_t *el = active_edit_line();
|
||||||
const wchar_t *buff = el->text.c_str();
|
const wchar_t *buff = el->text.c_str();
|
||||||
parse_util_token_extent(buff, el->position, &begin, &end, 0, 0);
|
parse_util_token_extent(buff, el->position, &begin, &end, nullptr, nullptr);
|
||||||
|
|
||||||
if (!begin || !end) return;
|
if (!begin || !end) return;
|
||||||
|
|
||||||
|
@ -1950,12 +1950,12 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) {
|
||||||
reader_write_title(cmd, parser);
|
reader_write_title(cmd, parser);
|
||||||
term_donate(outp);
|
term_donate(outp);
|
||||||
|
|
||||||
gettimeofday(&time_before, NULL);
|
gettimeofday(&time_before, nullptr);
|
||||||
|
|
||||||
parser.eval(cmd, io_chain_t(), TOP);
|
parser.eval(cmd, io_chain_t(), TOP);
|
||||||
job_reap(parser, true);
|
job_reap(parser, true);
|
||||||
|
|
||||||
gettimeofday(&time_after, NULL);
|
gettimeofday(&time_after, nullptr);
|
||||||
|
|
||||||
// update the execution duration iff a command is requested for execution
|
// update the execution duration iff a command is requested for execution
|
||||||
// issue - #4926
|
// issue - #4926
|
||||||
|
@ -2041,7 +2041,7 @@ static std::function<highlight_result_t(void)> get_highlight_performer(
|
||||||
}
|
}
|
||||||
s_thread_generation = generation_count;
|
s_thread_generation = generation_count;
|
||||||
std::vector<highlight_spec_t> colors(text.size(), highlight_spec_t{});
|
std::vector<highlight_spec_t> colors(text.size(), highlight_spec_t{});
|
||||||
highlight_func(text, colors, match_highlight_pos, NULL /* error */, *vars);
|
highlight_func(text, colors, match_highlight_pos, nullptr /* error */, *vars);
|
||||||
return {std::move(colors), text};
|
return {std::move(colors), text};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2056,7 +2056,7 @@ static std::function<highlight_result_t(void)> get_highlight_performer(
|
||||||
/// an asynchronous highlight in the background, which may perform disk I/O.
|
/// an asynchronous highlight in the background, which may perform disk I/O.
|
||||||
void reader_data_t::super_highlight_me_plenty(int match_highlight_pos_adjust, bool no_io) {
|
void reader_data_t::super_highlight_me_plenty(int match_highlight_pos_adjust, bool no_io) {
|
||||||
const editable_line_t *el = &command_line;
|
const editable_line_t *el = &command_line;
|
||||||
assert(el != NULL);
|
assert(el != nullptr);
|
||||||
long match_highlight_pos = static_cast<long>(el->position) + match_highlight_pos_adjust;
|
long match_highlight_pos = static_cast<long>(el->position) + match_highlight_pos_adjust;
|
||||||
assert(match_highlight_pos >= 0);
|
assert(match_highlight_pos >= 0);
|
||||||
|
|
||||||
|
@ -2318,7 +2318,7 @@ static int can_read(int fd) {
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fd, &fds);
|
FD_SET(fd, &fds);
|
||||||
return select(fd + 1, &fds, 0, 0, &can_read_timeout) == 1;
|
return select(fd + 1, &fds, nullptr, nullptr, &can_read_timeout) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the specified character in the specified string is backslashed. pos may be at the end of
|
/// Test if the specified character in the specified string is backslashed. pos may be at the end of
|
||||||
|
@ -2551,7 +2551,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
|
||||||
// pass cmdsub_begin here, not buff.
|
// pass cmdsub_begin here, not buff.
|
||||||
const wchar_t *token_begin, *token_end;
|
const wchar_t *token_begin, *token_end;
|
||||||
parse_util_token_extent(cmdsub_begin, el->position - (cmdsub_begin - buff),
|
parse_util_token_extent(cmdsub_begin, el->position - (cmdsub_begin - buff),
|
||||||
&token_begin, &token_end, 0, 0);
|
&token_begin, &token_end, nullptr, nullptr);
|
||||||
|
|
||||||
// Hack: the token may extend past the end of the command substitution, e.g. in
|
// Hack: the token may extend past the end of the command substitution, e.g. in
|
||||||
// (echo foo) the last token is 'foo)'. Don't let that happen.
|
// (echo foo) the last token is 'foo)'. Don't let that happen.
|
||||||
|
@ -2771,7 +2771,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
|
||||||
// Finished command, execute it. Don't add items that start with a leading
|
// Finished command, execute it. Don't add items that start with a leading
|
||||||
// space.
|
// space.
|
||||||
const editable_line_t *el = &command_line;
|
const editable_line_t *el = &command_line;
|
||||||
if (history != NULL && !el->empty() && el->text.at(0) != L' ') {
|
if (history != nullptr && !el->empty() && el->text.at(0) != L' ') {
|
||||||
history->add_pending_with_file_detection(el->text, vars.get_pwd_slash());
|
history->add_pending_with_file_detection(el->text, vars.get_pwd_slash());
|
||||||
}
|
}
|
||||||
rls.finished = true;
|
rls.finished = true;
|
||||||
|
@ -2810,7 +2810,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
|
||||||
// Searching by token.
|
// Searching by token.
|
||||||
const wchar_t *begin, *end;
|
const wchar_t *begin, *end;
|
||||||
const wchar_t *buff = el->text.c_str();
|
const wchar_t *buff = el->text.c_str();
|
||||||
parse_util_token_extent(buff, el->position, &begin, &end, 0, 0);
|
parse_util_token_extent(buff, el->position, &begin, &end, nullptr, nullptr);
|
||||||
if (begin) {
|
if (begin) {
|
||||||
wcstring token(begin, end);
|
wcstring token(begin, end);
|
||||||
history_search.reset_to_mode(token, history,
|
history_search.reset_to_mode(token, history,
|
||||||
|
@ -3452,13 +3452,13 @@ void reader_react_to_color_change() {
|
||||||
const wchar_t *reader_get_buffer() {
|
const wchar_t *reader_get_buffer() {
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
reader_data_t *data = current_data_or_null();
|
reader_data_t *data = current_data_or_null();
|
||||||
return data ? data->command_line.text.c_str() : NULL;
|
return data ? data->command_line.text.c_str() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
history_t *reader_get_history() {
|
history_t *reader_get_history() {
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
reader_data_t *data = current_data_or_null();
|
reader_data_t *data = current_data_or_null();
|
||||||
return data ? data->history : NULL;
|
return data ? data->history : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader_sanity_check() {
|
void reader_sanity_check() {
|
||||||
|
@ -3486,7 +3486,7 @@ size_t reader_get_cursor_pos() {
|
||||||
bool reader_get_selection(size_t *start, size_t *len) {
|
bool reader_get_selection(size_t *start, size_t *len) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
reader_data_t *data = current_data_or_null();
|
reader_data_t *data = current_data_or_null();
|
||||||
if (data != NULL && data->sel_active) {
|
if (data != nullptr && data->sel_active) {
|
||||||
*start = data->sel_start_pos;
|
*start = data->sel_start_pos;
|
||||||
*len = std::min(data->sel_stop_pos - data->sel_start_pos, data->command_line.size());
|
*len = std::min(data->sel_stop_pos - data->sel_start_pos, data->command_line.size());
|
||||||
result = true;
|
result = true;
|
||||||
|
@ -3509,7 +3509,7 @@ static int read_ni(parser_t &parser, int fd, const io_chain_t &io) {
|
||||||
}
|
}
|
||||||
|
|
||||||
in_stream = fdopen(des, "r");
|
in_stream = fdopen(des, "r");
|
||||||
if (in_stream != 0) {
|
if (in_stream != nullptr) {
|
||||||
while (!feof(in_stream)) {
|
while (!feof(in_stream)) {
|
||||||
char buff[4096];
|
char buff[4096];
|
||||||
size_t c = fread(buff, 1, 4096, in_stream);
|
size_t c = fread(buff, 1, 4096, in_stream);
|
||||||
|
|
|
@ -29,7 +29,7 @@ void validate_pointer(const void *ptr, const wchar_t *err, int null_ok) {
|
||||||
sanity_lose();
|
sanity_lose();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!null_ok) && (ptr == 0)) {
|
if ((!null_ok) && (ptr == nullptr)) {
|
||||||
FLOGF(error, _(L"The pointer '%ls' is null"), err);
|
FLOGF(error, _(L"The pointer '%ls' is null"), err);
|
||||||
sanity_lose();
|
sanity_lose();
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ static bool is_screen_name_escape_seq(const wchar_t *code, size_t *resulting_len
|
||||||
}
|
}
|
||||||
const wchar_t *const screen_name_end_sentinel = L"\x1B\\";
|
const wchar_t *const screen_name_end_sentinel = L"\x1B\\";
|
||||||
const wchar_t *screen_name_end = std::wcsstr(&code[2], screen_name_end_sentinel);
|
const wchar_t *screen_name_end = std::wcsstr(&code[2], screen_name_end_sentinel);
|
||||||
if (screen_name_end == NULL) {
|
if (screen_name_end == nullptr) {
|
||||||
// Consider just <esc>k to be the code.
|
// Consider just <esc>k to be the code.
|
||||||
*resulting_length = 2;
|
*resulting_length = 2;
|
||||||
} else {
|
} else {
|
||||||
|
@ -246,7 +246,7 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length)
|
||||||
/// that begin with \x1B. If it doesn't we return zero. We also return zero if we don't recognize
|
/// 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.
|
/// the escape sequence based on querying terminfo and other heuristics.
|
||||||
size_t escape_code_length(const wchar_t *code) {
|
size_t escape_code_length(const wchar_t *code) {
|
||||||
assert(code != NULL);
|
assert(code != nullptr);
|
||||||
if (*code != L'\x1B') return 0;
|
if (*code != L'\x1B') return 0;
|
||||||
|
|
||||||
size_t esc_seq_len = cached_layouts.find_escape_code(code);
|
size_t esc_seq_len = cached_layouts.find_escape_code(code);
|
||||||
|
@ -498,7 +498,7 @@ static void s_move(screen_t *s, int new_x, int new_y) {
|
||||||
x_steps = 0;
|
x_steps = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *multi_str = NULL;
|
const char *multi_str = nullptr;
|
||||||
if (x_steps < 0) {
|
if (x_steps < 0) {
|
||||||
str = cursor_left;
|
str = cursor_left;
|
||||||
multi_str = parm_left_cursor;
|
multi_str = parm_left_cursor;
|
||||||
|
@ -509,7 +509,7 @@ 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
|
// 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).
|
// Note that this is required to avoid some visual glitches in iTerm (issue #1448).
|
||||||
bool use_multi = multi_str != NULL && multi_str[0] != '\0' &&
|
bool use_multi = multi_str != nullptr && multi_str[0] != '\0' &&
|
||||||
abs(x_steps) * std::strlen(str) > std::strlen(multi_str);
|
abs(x_steps) * std::strlen(str) > std::strlen(multi_str);
|
||||||
if (use_multi && cur_term) {
|
if (use_multi && cur_term) {
|
||||||
char *multi_param = tparm(const_cast<char *>(multi_str), abs(x_steps));
|
char *multi_param = tparm(const_cast<char *>(multi_str), abs(x_steps));
|
||||||
|
@ -663,7 +663,7 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
|
||||||
|
|
||||||
// If this is the last line, maybe we should clear the screen.
|
// If this is the last line, maybe we should clear the screen.
|
||||||
const bool should_clear_screen_this_line =
|
const bool should_clear_screen_this_line =
|
||||||
need_clear_screen && i + 1 == scr->desired.line_count() && clr_eos != NULL;
|
need_clear_screen && i + 1 == scr->desired.line_count() && clr_eos != nullptr;
|
||||||
|
|
||||||
// Note that skip_remaining is a width, not a character count.
|
// Note that skip_remaining is a width, not a character count.
|
||||||
size_t skip_remaining = start_pos;
|
size_t skip_remaining = start_pos;
|
||||||
|
|
|
@ -268,10 +268,10 @@ void signal_reset_handlers() {
|
||||||
for (const auto &data : signal_table) {
|
for (const auto &data : signal_table) {
|
||||||
if (data.signal == SIGHUP) {
|
if (data.signal == SIGHUP) {
|
||||||
struct sigaction oact;
|
struct sigaction oact;
|
||||||
sigaction(SIGHUP, NULL, &oact);
|
sigaction(SIGHUP, nullptr, &oact);
|
||||||
if (oact.sa_handler == SIG_IGN) continue;
|
if (oact.sa_handler == SIG_IGN) continue;
|
||||||
}
|
}
|
||||||
sigaction(data.signal, &act, NULL);
|
sigaction(data.signal, &act, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,35 +284,35 @@ static void set_interactive_handlers() {
|
||||||
// Interactive mode. Ignore interactive signals. We are a shell, we know what is best for
|
// Interactive mode. Ignore interactive signals. We are a shell, we know what is best for
|
||||||
// the user.
|
// the user.
|
||||||
act.sa_handler = SIG_IGN;
|
act.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGTSTP, &act, NULL);
|
sigaction(SIGTSTP, &act, nullptr);
|
||||||
sigaction(SIGTTOU, &act, NULL);
|
sigaction(SIGTTOU, &act, nullptr);
|
||||||
|
|
||||||
// We don't ignore SIGTTIN because we might send it to ourself.
|
// We don't ignore SIGTTIN because we might send it to ourself.
|
||||||
act.sa_sigaction = &fish_signal_handler;
|
act.sa_sigaction = &fish_signal_handler;
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
sigaction(SIGTTIN, &act, NULL);
|
sigaction(SIGTTIN, &act, nullptr);
|
||||||
|
|
||||||
// SIGTERM restores the terminal controlling process before dying.
|
// SIGTERM restores the terminal controlling process before dying.
|
||||||
act.sa_sigaction = &fish_signal_handler;
|
act.sa_sigaction = &fish_signal_handler;
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
sigaction(SIGTERM, &act, NULL);
|
sigaction(SIGTERM, &act, nullptr);
|
||||||
|
|
||||||
sigaction(SIGHUP, NULL, &oact);
|
sigaction(SIGHUP, nullptr, &oact);
|
||||||
if (oact.sa_handler == SIG_DFL) {
|
if (oact.sa_handler == SIG_DFL) {
|
||||||
act.sa_sigaction = &fish_signal_handler;
|
act.sa_sigaction = &fish_signal_handler;
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
sigaction(SIGHUP, &act, NULL);
|
sigaction(SIGHUP, &act, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SIGALARM as part of our signal torture test
|
// SIGALARM as part of our signal torture test
|
||||||
act.sa_sigaction = &fish_signal_handler;
|
act.sa_sigaction = &fish_signal_handler;
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
sigaction(SIGALRM, &act, NULL);
|
sigaction(SIGALRM, &act, nullptr);
|
||||||
|
|
||||||
#ifdef SIGWINCH
|
#ifdef SIGWINCH
|
||||||
act.sa_sigaction = &fish_signal_handler;
|
act.sa_sigaction = &fish_signal_handler;
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
sigaction(SIGWINCH, &act, NULL);
|
sigaction(SIGWINCH, &act, nullptr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,22 +326,22 @@ void signal_set_handlers(bool interactive) {
|
||||||
// this signal interrupting other syscalls or terminating us.
|
// this signal interrupting other syscalls or terminating us.
|
||||||
act.sa_sigaction = nullptr;
|
act.sa_sigaction = nullptr;
|
||||||
act.sa_handler = SIG_IGN;
|
act.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGPIPE, &act, 0);
|
sigaction(SIGPIPE, &act, nullptr);
|
||||||
|
|
||||||
// Ignore SIGQUIT.
|
// Ignore SIGQUIT.
|
||||||
act.sa_handler = SIG_IGN;
|
act.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGQUIT, &act, 0);
|
sigaction(SIGQUIT, &act, nullptr);
|
||||||
|
|
||||||
// Apply our SIGINT handler.
|
// Apply our SIGINT handler.
|
||||||
act.sa_sigaction = &fish_signal_handler;
|
act.sa_sigaction = &fish_signal_handler;
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
sigaction(SIGINT, &act, NULL);
|
sigaction(SIGINT, &act, nullptr);
|
||||||
|
|
||||||
// Whether or not we're interactive we want SIGCHLD to not interrupt restartable syscalls.
|
// Whether or not we're interactive we want SIGCHLD to not interrupt restartable syscalls.
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
act.sa_sigaction = &fish_signal_handler;
|
act.sa_sigaction = &fish_signal_handler;
|
||||||
act.sa_flags = SA_SIGINFO | SA_RESTART;
|
act.sa_flags = SA_SIGINFO | SA_RESTART;
|
||||||
if (sigaction(SIGCHLD, &act, 0)) {
|
if (sigaction(SIGCHLD, &act, nullptr)) {
|
||||||
wperror(L"sigaction");
|
wperror(L"sigaction");
|
||||||
FATAL_EXIT();
|
FATAL_EXIT();
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,7 @@ void get_signals_with_handlers(sigset_t *set) {
|
||||||
sigemptyset(set);
|
sigemptyset(set);
|
||||||
for (const auto &data : signal_table) {
|
for (const auto &data : signal_table) {
|
||||||
struct sigaction act = {};
|
struct sigaction act = {};
|
||||||
sigaction(data.signal, NULL, &act);
|
sigaction(data.signal, nullptr, &act);
|
||||||
// If SIGHUP is being ignored (e.g., because were were run via `nohup`) don't reset it.
|
// If SIGHUP is being ignored (e.g., because were were run via `nohup`) don't reset it.
|
||||||
// We don't special case other signals because if they're being ignored that shouldn't
|
// We don't special case other signals because if they're being ignored that shouldn't
|
||||||
// affect processes we spawn. They should get the default behavior for those signals.
|
// affect processes we spawn. They should get the default behavior for those signals.
|
||||||
|
@ -391,7 +391,7 @@ void get_signals_with_handlers(sigset_t *set) {
|
||||||
void signal_unblock_all() {
|
void signal_unblock_all() {
|
||||||
sigset_t iset;
|
sigset_t iset;
|
||||||
sigemptyset(&iset);
|
sigemptyset(&iset);
|
||||||
sigprocmask(SIG_SETMASK, &iset, NULL);
|
sigprocmask(SIG_SETMASK, &iset, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
sigint_checker_t::sigint_checker_t() {
|
sigint_checker_t::sigint_checker_t() {
|
||||||
|
|
|
@ -205,7 +205,7 @@ static const te_builtin *find_builtin(const char *name, int len) {
|
||||||
});
|
});
|
||||||
// We need to compare again because we might have gotten the first "larger" element.
|
// We need to compare again because we might have gotten the first "larger" element.
|
||||||
if (found != end && std::strncmp(found->name, name, len) == 0) return found;
|
if (found != end && std::strncmp(found->name, name, len) == 0) return found;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr double add(double a, double b) { return a + b; }
|
static constexpr double add(double a, double b) { return a + b; }
|
||||||
|
@ -336,13 +336,13 @@ static te_expr *base(state *s) {
|
||||||
|
|
||||||
switch (s->type) {
|
switch (s->type) {
|
||||||
case TOK_NUMBER:
|
case TOK_NUMBER:
|
||||||
ret = new_expr(TE_CONSTANT, 0);
|
ret = new_expr(TE_CONSTANT, nullptr);
|
||||||
ret->value = s->value;
|
ret->value = s->value;
|
||||||
next_token(s);
|
next_token(s);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TE_FUNCTION0:
|
case TE_FUNCTION0:
|
||||||
ret = new_expr(s->type, 0);
|
ret = new_expr(s->type, nullptr);
|
||||||
ret->function = s->function;
|
ret->function = s->function;
|
||||||
next_token(s);
|
next_token(s);
|
||||||
if (s->type == TOK_OPEN) {
|
if (s->type == TOK_OPEN) {
|
||||||
|
@ -361,7 +361,7 @@ static te_expr *base(state *s) {
|
||||||
case TE_FUNCTION3:
|
case TE_FUNCTION3:
|
||||||
arity = get_arity(s->type);
|
arity = get_arity(s->type);
|
||||||
|
|
||||||
ret = new_expr(s->type, 0);
|
ret = new_expr(s->type, nullptr);
|
||||||
ret->function = s->function;
|
ret->function = s->function;
|
||||||
next_token(s);
|
next_token(s);
|
||||||
|
|
||||||
|
@ -404,13 +404,13 @@ static te_expr *base(state *s) {
|
||||||
// This means we have too few things.
|
// This means we have too few things.
|
||||||
// Instead of introducing another error, just call it
|
// Instead of introducing another error, just call it
|
||||||
// "too few args".
|
// "too few args".
|
||||||
ret = new_expr(0, 0);
|
ret = new_expr(0, nullptr);
|
||||||
s->type = TOK_ERROR;
|
s->type = TOK_ERROR;
|
||||||
s->error = TE_ERROR_TOO_FEW_ARGS;
|
s->error = TE_ERROR_TOO_FEW_ARGS;
|
||||||
ret->value = NAN;
|
ret->value = NAN;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = new_expr(0, 0);
|
ret = new_expr(0, nullptr);
|
||||||
s->type = TOK_ERROR;
|
s->type = TOK_ERROR;
|
||||||
s->error = TE_ERROR_UNEXPECTED_TOKEN;
|
s->error = TE_ERROR_UNEXPECTED_TOKEN;
|
||||||
ret->value = NAN;
|
ret->value = NAN;
|
||||||
|
@ -444,7 +444,7 @@ static te_expr *factor(state *s) {
|
||||||
/* <factor> = <power> {"^" <power>} */
|
/* <factor> = <power> {"^" <power>} */
|
||||||
te_expr *ret = power(s);
|
te_expr *ret = power(s);
|
||||||
|
|
||||||
te_expr *insertion = 0;
|
te_expr *insertion = nullptr;
|
||||||
|
|
||||||
while (s->type == TOK_INFIX &&
|
while (s->type == TOK_INFIX &&
|
||||||
(s->function == reinterpret_cast<const void *>(static_cast<te_fun2>(pow)))) {
|
(s->function == reinterpret_cast<const void *>(static_cast<te_fun2>(pow)))) {
|
||||||
|
@ -566,7 +566,7 @@ te_expr *te_compile(const char *expression, te_error_t *error) {
|
||||||
error->type = TE_ERROR_TOO_MANY_ARGS;
|
error->type = TE_ERROR_TOO_MANY_ARGS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
optimize(root);
|
optimize(root);
|
||||||
if (error) error->position = 0;
|
if (error) error->position = 0;
|
||||||
|
|
|
@ -9,12 +9,12 @@ const parse_node_t *parse_node_tree_t::next_node_in_node_list(
|
||||||
assert(list_type != entry_type);
|
assert(list_type != entry_type);
|
||||||
|
|
||||||
const parse_node_t *list_cursor = &node_list;
|
const parse_node_t *list_cursor = &node_list;
|
||||||
const parse_node_t *list_entry = NULL;
|
const parse_node_t *list_entry = nullptr;
|
||||||
|
|
||||||
// Loop while we don't have an item but do have a list. Note that some nodes may contain
|
// Loop while we don't have an item but do have a list. Note that some nodes may contain
|
||||||
// nothing; e.g. job_list contains blank lines as a production.
|
// nothing; e.g. job_list contains blank lines as a production.
|
||||||
while (list_entry == NULL && list_cursor != NULL) {
|
while (list_entry == nullptr && list_cursor != nullptr) {
|
||||||
const parse_node_t *next_cursor = NULL;
|
const parse_node_t *next_cursor = nullptr;
|
||||||
|
|
||||||
// Walk through the children.
|
// Walk through the children.
|
||||||
for (node_offset_t i = 0; i < list_cursor->child_count; i++) {
|
for (node_offset_t i = 0; i < list_cursor->child_count; i++) {
|
||||||
|
@ -32,9 +32,9 @@ const parse_node_t *parse_node_tree_t::next_node_in_node_list(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return what we got.
|
// Return what we got.
|
||||||
assert(list_cursor == NULL || list_cursor->type == list_type);
|
assert(list_cursor == nullptr || list_cursor->type == list_type);
|
||||||
assert(list_entry == NULL || list_entry->type == entry_type);
|
assert(list_entry == nullptr || list_entry->type == entry_type);
|
||||||
if (out_list_tail != NULL) *out_list_tail = list_cursor;
|
if (out_list_tail != nullptr) *out_list_tail = list_cursor;
|
||||||
return list_entry;
|
return list_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ maybe_t<pipe_or_redir_t> redirection_for_node(tnode_t<grammar::redirection> redi
|
||||||
assert(result.has_value() && "Failed to parse valid redirection");
|
assert(result.has_value() && "Failed to parse valid redirection");
|
||||||
assert(!result->is_pipe && "Should not be a pipe");
|
assert(!result->is_pipe && "Should not be a pipe");
|
||||||
}
|
}
|
||||||
if (out_target != NULL) {
|
if (out_target != nullptr) {
|
||||||
tnode_t<grammar::tok_string> target = redirection.child<1>(); // like 1 or file path
|
tnode_t<grammar::tok_string> target = redirection.child<1>(); // like 1 or file path
|
||||||
*out_target = target.has_source() ? target.get_source(src) : wcstring();
|
*out_target = target.has_source() ? target.get_source(src) : wcstring();
|
||||||
}
|
}
|
||||||
|
|
20
src/utf8.cpp
20
src/utf8.cpp
|
@ -65,7 +65,7 @@ bool wchar_to_utf8_string(const std::wstring &str, std::string *result) {
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
const wchar_t *input = str.c_str();
|
const wchar_t *input = str.c_str();
|
||||||
size_t outlen = wchar_to_utf8(input, inlen, NULL, 0, 0);
|
size_t outlen = wchar_to_utf8(input, inlen, nullptr, 0, 0);
|
||||||
if (outlen > 0) {
|
if (outlen > 0) {
|
||||||
char *tmp = new char[outlen];
|
char *tmp = new char[outlen];
|
||||||
size_t outlen2 = wchar_to_utf8(input, inlen, tmp, outlen, 0);
|
size_t outlen2 = wchar_to_utf8(input, inlen, tmp, outlen, 0);
|
||||||
|
@ -79,15 +79,15 @@ bool wchar_to_utf8_string(const std::wstring &str, std::string *result) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t utf8_to_wchar(const char *in, size_t insize, std::wstring *out, int flags) {
|
size_t utf8_to_wchar(const char *in, size_t insize, std::wstring *out, int flags) {
|
||||||
if (in == NULL || insize == 0) {
|
if (in == nullptr || insize == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t result;
|
size_t result;
|
||||||
if (sizeof(wchar_t) == sizeof(utf8_wchar_t)) { //!OCLINT(constant if expression)
|
if (sizeof(wchar_t) == sizeof(utf8_wchar_t)) { //!OCLINT(constant if expression)
|
||||||
result = utf8_to_wchar_internal(in, insize, reinterpret_cast<utf8_wstring_t *>(out), flags);
|
result = utf8_to_wchar_internal(in, insize, reinterpret_cast<utf8_wstring_t *>(out), flags);
|
||||||
} else if (out == NULL) {
|
} else if (out == nullptr) {
|
||||||
result = utf8_to_wchar_internal(in, insize, NULL, flags);
|
result = utf8_to_wchar_internal(in, insize, nullptr, flags);
|
||||||
} else {
|
} else {
|
||||||
// Allocate a temporary buffer to hold the output, invoke the conversion with the temporary,
|
// Allocate a temporary buffer to hold the output, invoke the conversion with the temporary,
|
||||||
// and then copy it back.
|
// and then copy it back.
|
||||||
|
@ -99,7 +99,7 @@ size_t utf8_to_wchar(const char *in, size_t insize, std::wstring *out, int flags
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out, size_t outsize, int flags) {
|
size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out, size_t outsize, int flags) {
|
||||||
if (in == NULL || insize == 0 || (outsize == 0 && out != NULL)) {
|
if (in == nullptr || insize == 0 || (outsize == 0 && out != nullptr)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,9 +171,9 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring
|
||||||
utf8_wchar_t high;
|
utf8_wchar_t high;
|
||||||
size_t n, total, i, n_bits;
|
size_t n, total, i, n_bits;
|
||||||
|
|
||||||
if (in == NULL || insize == 0) return 0;
|
if (in == nullptr || insize == 0) return 0;
|
||||||
|
|
||||||
if (out_string != NULL) out_string->clear();
|
if (out_string != nullptr) out_string->clear();
|
||||||
|
|
||||||
total = 0;
|
total = 0;
|
||||||
p = (unsigned char *)in;
|
p = (unsigned char *)in;
|
||||||
|
@ -220,7 +220,7 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring
|
||||||
}
|
}
|
||||||
|
|
||||||
total++;
|
total++;
|
||||||
if (out_string == NULL) continue;
|
if (out_string == nullptr) continue;
|
||||||
|
|
||||||
uint32_t out_val = 0;
|
uint32_t out_val = 0;
|
||||||
n_bits = 0;
|
n_bits = 0;
|
||||||
|
@ -272,7 +272,7 @@ static size_t wchar_to_utf8_internal(const utf8_wchar_t *in, size_t insize, char
|
||||||
unsigned char *p, *lim;
|
unsigned char *p, *lim;
|
||||||
size_t total, n;
|
size_t total, n;
|
||||||
|
|
||||||
if (in == NULL || insize == 0 || (outsize == 0 && out != NULL)) return 0;
|
if (in == nullptr || insize == 0 || (outsize == 0 && out != nullptr)) return 0;
|
||||||
|
|
||||||
w = in;
|
w = in;
|
||||||
wlim = w + insize;
|
wlim = w + insize;
|
||||||
|
@ -306,7 +306,7 @@ static size_t wchar_to_utf8_internal(const utf8_wchar_t *in, size_t insize, char
|
||||||
|
|
||||||
total += n;
|
total += n;
|
||||||
|
|
||||||
if (out == NULL) continue;
|
if (out == nullptr) continue;
|
||||||
if (size_t(lim - p) <= n - 1) return 0; // no space left
|
if (size_t(lim - p) <= n - 1) return 0; // no space left
|
||||||
|
|
||||||
// Extract the wchar_t as big-endian. If wchar_t is UCS-16, the first two bytes will be 0.
|
// Extract the wchar_t as big-endian. If wchar_t is UCS-16, the first two bytes will be 0.
|
||||||
|
|
|
@ -103,6 +103,6 @@ int wcsfilecmp(const wchar_t *a, const wchar_t *b) {
|
||||||
/// Return microseconds since the epoch.
|
/// Return microseconds since the epoch.
|
||||||
long long get_time() {
|
long long get_time() {
|
||||||
struct timeval time_struct;
|
struct timeval time_struct;
|
||||||
gettimeofday(&time_struct, 0);
|
gettimeofday(&time_struct, nullptr);
|
||||||
return 1000000ll * time_struct.tv_sec + time_struct.tv_usec;
|
return 1000000ll * time_struct.tv_sec + time_struct.tv_usec;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ void wgetopter_t::_wgetopt_initialize(const wchar_t *optstring) {
|
||||||
// Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the
|
// Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the
|
||||||
// sequence of previously skipped non-option ARGV-elements is empty.
|
// sequence of previously skipped non-option ARGV-elements is empty.
|
||||||
first_nonopt = last_nonopt = woptind = 1;
|
first_nonopt = last_nonopt = woptind = 1;
|
||||||
nextchar = NULL;
|
nextchar = nullptr;
|
||||||
|
|
||||||
// Determine how to handle the ordering of options and nonoptions.
|
// Determine how to handle the ordering of options and nonoptions.
|
||||||
if (optstring[0] == '-') {
|
if (optstring[0] == '-') {
|
||||||
|
@ -191,7 +191,7 @@ int wgetopter_t::_advance_to_next_argv( //!OCLINT(high cyclomatic complexity)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have found another option-ARGV-element. Skip the initial punctuation.
|
// We have found another option-ARGV-element. Skip the initial punctuation.
|
||||||
nextchar = (argv[woptind] + 1 + (longopts != NULL && argv[woptind][1] == '-'));
|
nextchar = (argv[woptind] + 1 + (longopts != nullptr && argv[woptind][1] == '-'));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
|
||||||
// Increment `woptind' when we start to process its last character.
|
// Increment `woptind' when we start to process its last character.
|
||||||
if (*nextchar == '\0') ++woptind;
|
if (*nextchar == '\0') ++woptind;
|
||||||
|
|
||||||
if (temp == NULL || c == ':') {
|
if (temp == nullptr || c == ':') {
|
||||||
if (wopterr) {
|
if (wopterr) {
|
||||||
std::fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0],
|
std::fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0],
|
||||||
static_cast<wint_t>(c));
|
static_cast<wint_t>(c));
|
||||||
|
@ -225,9 +225,9 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
|
||||||
woptarg = nextchar;
|
woptarg = nextchar;
|
||||||
woptind++;
|
woptind++;
|
||||||
} else {
|
} else {
|
||||||
woptarg = NULL;
|
woptarg = nullptr;
|
||||||
}
|
}
|
||||||
nextchar = NULL;
|
nextchar = nullptr;
|
||||||
} else {
|
} else {
|
||||||
// This is an option that requires an argument.
|
// This is an option that requires an argument.
|
||||||
if (*nextchar != '\0') {
|
if (*nextchar != '\0') {
|
||||||
|
@ -248,7 +248,7 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
|
||||||
// ARGV-elt as argument.
|
// ARGV-elt as argument.
|
||||||
woptarg = argv[woptind++];
|
woptarg = argv[woptind++];
|
||||||
}
|
}
|
||||||
nextchar = NULL;
|
nextchar = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
@ -290,7 +290,7 @@ void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woptio
|
||||||
}
|
}
|
||||||
|
|
||||||
nextchar += std::wcslen(nextchar);
|
nextchar += std::wcslen(nextchar);
|
||||||
if (longind != NULL) *longind = option_index;
|
if (longind != nullptr) *longind = option_index;
|
||||||
if (pfound->flag) {
|
if (pfound->flag) {
|
||||||
*(pfound->flag) = pfound->val;
|
*(pfound->flag) = pfound->val;
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
|
@ -303,7 +303,7 @@ void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woptio
|
||||||
const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption *longopts,
|
const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption *longopts,
|
||||||
wchar_t *nameend, int *exact, int *ambig,
|
wchar_t *nameend, int *exact, int *ambig,
|
||||||
int *indfound) {
|
int *indfound) {
|
||||||
const struct woption *pfound = NULL;
|
const struct woption *pfound = nullptr;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
// Test all long options for either exact match or abbreviated matches.
|
// Test all long options for either exact match or abbreviated matches.
|
||||||
|
@ -316,7 +316,7 @@ const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption
|
||||||
*indfound = option_index;
|
*indfound = option_index;
|
||||||
*exact = 1;
|
*exact = 1;
|
||||||
break;
|
break;
|
||||||
} else if (pfound == NULL) {
|
} else if (pfound == nullptr) {
|
||||||
// First nonexact match found.
|
// First nonexact match found.
|
||||||
pfound = p;
|
pfound = p;
|
||||||
*indfound = option_index;
|
*indfound = option_index;
|
||||||
|
@ -361,7 +361,7 @@ bool wgetopter_t::_handle_long_opt(int argc, wchar_t **argv, const struct woptio
|
||||||
// Can't find it as a long option. If this is not getopt_long_only, or the option starts
|
// Can't find it as a long option. If this is not getopt_long_only, or the option starts
|
||||||
// with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a
|
// with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a
|
||||||
// short option.
|
// short option.
|
||||||
if (!long_only || argv[woptind][1] == '-' || std::wcschr(shortopts, *nextchar) == NULL) {
|
if (!long_only || argv[woptind][1] == '-' || std::wcschr(shortopts, *nextchar) == nullptr) {
|
||||||
if (wopterr) {
|
if (wopterr) {
|
||||||
if (argv[woptind][1] == '-') // --option
|
if (argv[woptind][1] == '-') // --option
|
||||||
std::fwprintf(stderr, _(L"%ls: Unrecognized option '--%ls'\n"), argv[0], nextchar);
|
std::fwprintf(stderr, _(L"%ls: Unrecognized option '--%ls'\n"), argv[0], nextchar);
|
||||||
|
@ -422,9 +422,9 @@ bool wgetopter_t::_handle_long_opt(int argc, wchar_t **argv, const struct woptio
|
||||||
int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *optstring,
|
int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *optstring,
|
||||||
const struct woption *longopts, int *longind, int long_only) {
|
const struct woption *longopts, int *longind, int long_only) {
|
||||||
if (!initialized) _wgetopt_initialize(optstring);
|
if (!initialized) _wgetopt_initialize(optstring);
|
||||||
woptarg = NULL;
|
woptarg = nullptr;
|
||||||
|
|
||||||
if (nextchar == NULL || *nextchar == '\0') {
|
if (nextchar == nullptr || *nextchar == '\0') {
|
||||||
int retval = _advance_to_next_argv(argc, argv, longopts);
|
int retval = _advance_to_next_argv(argc, argv, longopts);
|
||||||
if (retval != 0) return retval;
|
if (retval != 0) return retval;
|
||||||
}
|
}
|
||||||
|
@ -442,7 +442,7 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
|
||||||
// "u".
|
// "u".
|
||||||
//
|
//
|
||||||
// This distinction seems to be the most useful approach.
|
// This distinction seems to be the most useful approach.
|
||||||
if (longopts != NULL &&
|
if (longopts != nullptr &&
|
||||||
(argv[woptind][1] == '-' ||
|
(argv[woptind][1] == '-' ||
|
||||||
(long_only && (argv[woptind][2] || !std::wcschr(shortopts, argv[woptind][1]))))) {
|
(long_only && (argv[woptind][2] || !std::wcschr(shortopts, argv[woptind][1]))))) {
|
||||||
int retval;
|
int retval;
|
||||||
|
|
|
@ -62,7 +62,7 @@ static size_t wildcard_find(const wchar_t *wc) {
|
||||||
|
|
||||||
/// Implementation of wildcard_has. Needs to take the length to handle embedded nulls (issue #1631).
|
/// Implementation of wildcard_has. Needs to take the length to handle embedded nulls (issue #1631).
|
||||||
static bool wildcard_has_impl(const wchar_t *str, size_t len, bool internal) {
|
static bool wildcard_has_impl(const wchar_t *str, size_t len, bool internal) {
|
||||||
assert(str != NULL);
|
assert(str != nullptr);
|
||||||
bool qmark_is_wild = !feature_test(features_t::qmark_noglob);
|
bool qmark_is_wild = !feature_test(features_t::qmark_noglob);
|
||||||
const wchar_t *end = str + len;
|
const wchar_t *end = str + len;
|
||||||
if (internal) {
|
if (internal) {
|
||||||
|
@ -82,7 +82,7 @@ static bool wildcard_has_impl(const wchar_t *str, size_t len, bool internal) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wildcard_has(const wchar_t *str, bool internal) {
|
bool wildcard_has(const wchar_t *str, bool internal) {
|
||||||
assert(str != NULL);
|
assert(str != nullptr);
|
||||||
return wildcard_has_impl(str, std::wcslen(str), internal);
|
return wildcard_has_impl(str, std::wcslen(str), internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ struct wc_complete_pack_t {
|
||||||
|
|
||||||
// Weirdly specific and non-reusable helper function that makes its one call site much clearer.
|
// Weirdly specific and non-reusable helper function that makes its one call site much clearer.
|
||||||
static bool has_prefix_match(const std::vector<completion_t> *comps, size_t first) {
|
static bool has_prefix_match(const std::vector<completion_t> *comps, size_t first) {
|
||||||
if (comps != NULL) {
|
if (comps != nullptr) {
|
||||||
const size_t after_count = comps->size();
|
const size_t after_count = comps->size();
|
||||||
for (size_t j = first; j < after_count; j++) {
|
for (size_t j = first; j < after_count; j++) {
|
||||||
if (comps->at(j).match.type <= fuzzy_match_prefix) {
|
if (comps->at(j).match.type <= fuzzy_match_prefix) {
|
||||||
|
@ -202,8 +202,8 @@ static bool has_prefix_match(const std::vector<completion_t> *comps, size_t firs
|
||||||
static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
|
static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
|
||||||
const wc_complete_pack_t ¶ms, complete_flags_t flags,
|
const wc_complete_pack_t ¶ms, complete_flags_t flags,
|
||||||
std::vector<completion_t> *out, bool is_first_call = false) {
|
std::vector<completion_t> *out, bool is_first_call = false) {
|
||||||
assert(str != NULL);
|
assert(str != nullptr);
|
||||||
assert(wc != NULL);
|
assert(wc != nullptr);
|
||||||
|
|
||||||
// Maybe early out for hidden files. We require that the wildcard match these exactly (i.e. a
|
// Maybe early out for hidden files. We require that the wildcard match these exactly (i.e. a
|
||||||
// dot); ANY_STRING not allowed.
|
// dot); ANY_STRING not allowed.
|
||||||
|
@ -226,7 +226,7 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
|
||||||
match_acceptable = match_type_shares_prefix(match.type);
|
match_acceptable = match_type_shares_prefix(match.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!match_acceptable || out == NULL) {
|
if (!match_acceptable || out == nullptr) {
|
||||||
return match_acceptable;
|
return match_acceptable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
|
||||||
|
|
||||||
// If out is NULL, we don't care about the actual matches. If out is not
|
// If out is NULL, we don't care about the actual matches. If out is not
|
||||||
// NULL but we have a prefix match, stop there.
|
// NULL but we have a prefix match, stop there.
|
||||||
if (out == NULL || has_prefix_match(out, before_count)) {
|
if (out == nullptr || has_prefix_match(out, before_count)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ bool wildcard_complete(const wcstring &str, const wchar_t *wc,
|
||||||
std::vector<completion_t> *out, expand_flags_t expand_flags,
|
std::vector<completion_t> *out, expand_flags_t expand_flags,
|
||||||
complete_flags_t flags) {
|
complete_flags_t flags) {
|
||||||
// Note out may be NULL.
|
// Note out may be NULL.
|
||||||
assert(wc != NULL);
|
assert(wc != nullptr);
|
||||||
wc_complete_pack_t params(str, desc_func, expand_flags);
|
wc_complete_pack_t params(str, desc_func, expand_flags);
|
||||||
return wildcard_complete_internal(str.c_str(), wc, params, flags, out, true /* first call */);
|
return wildcard_complete_internal(str.c_str(), wc, params, flags, out, true /* first call */);
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ static bool wildcard_test_flags_then_complete(const wcstring &filepath, const wc
|
||||||
const wchar_t *wc, expand_flags_t expand_flags,
|
const wchar_t *wc, expand_flags_t expand_flags,
|
||||||
std::vector<completion_t> *out) {
|
std::vector<completion_t> *out) {
|
||||||
// Check if it will match before stat().
|
// Check if it will match before stat().
|
||||||
if (!wildcard_complete(filename, wc, {}, NULL, expand_flags, 0)) {
|
if (!wildcard_complete(filename, wc, {}, nullptr, expand_flags, 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,7 +634,7 @@ class wildcard_expander_t {
|
||||||
did_interrupt(false),
|
did_interrupt(false),
|
||||||
did_add(false),
|
did_add(false),
|
||||||
has_fuzzy_ancestor(false) {
|
has_fuzzy_ancestor(false) {
|
||||||
assert(resolved_completions != NULL);
|
assert(resolved_completions != nullptr);
|
||||||
|
|
||||||
// Insert initial completions into our set to avoid duplicates.
|
// Insert initial completions into our set to avoid duplicates.
|
||||||
for (std::vector<completion_t>::const_iterator iter = resolved_completions->begin();
|
for (std::vector<completion_t>::const_iterator iter = resolved_completions->begin();
|
||||||
|
@ -813,7 +813,7 @@ void wildcard_expander_t::expand_last_segment(const wcstring &base_dir, DIR *bas
|
||||||
// expansions
|
// expansions
|
||||||
void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||||
const wcstring &effective_prefix) {
|
const wcstring &effective_prefix) {
|
||||||
assert(wc != NULL);
|
assert(wc != nullptr);
|
||||||
|
|
||||||
if (interrupted()) {
|
if (interrupted()) {
|
||||||
return;
|
return;
|
||||||
|
@ -822,12 +822,12 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||||
// Get the current segment and compute interesting properties about it.
|
// Get the current segment and compute interesting properties about it.
|
||||||
const size_t wc_len = std::wcslen(wc);
|
const size_t wc_len = std::wcslen(wc);
|
||||||
const wchar_t *const next_slash = std::wcschr(wc, L'/');
|
const wchar_t *const next_slash = std::wcschr(wc, L'/');
|
||||||
const bool is_last_segment = (next_slash == NULL);
|
const bool is_last_segment = (next_slash == nullptr);
|
||||||
const size_t wc_segment_len = next_slash ? next_slash - wc : wc_len;
|
const size_t wc_segment_len = next_slash ? next_slash - wc : wc_len;
|
||||||
const wcstring wc_segment = wcstring(wc, wc_segment_len);
|
const wcstring wc_segment = wcstring(wc, wc_segment_len);
|
||||||
const bool segment_has_wildcards =
|
const bool segment_has_wildcards =
|
||||||
wildcard_has(wc_segment, true /* internal, i.e. look for ANY_CHAR instead of ? */);
|
wildcard_has(wc_segment, true /* internal, i.e. look for ANY_CHAR instead of ? */);
|
||||||
const wchar_t *const wc_remainder = next_slash ? next_slash + 1 : NULL;
|
const wchar_t *const wc_remainder = next_slash ? next_slash + 1 : nullptr;
|
||||||
|
|
||||||
if (wc_segment.empty()) {
|
if (wc_segment.empty()) {
|
||||||
// Handle empty segment.
|
// Handle empty segment.
|
||||||
|
@ -841,7 +841,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||||
} else if (!segment_has_wildcards && !is_last_segment) {
|
} else if (!segment_has_wildcards && !is_last_segment) {
|
||||||
// Literal intermediate match. Note that we may not be able to actually read the directory
|
// Literal intermediate match. Note that we may not be able to actually read the directory
|
||||||
// (issue #2099).
|
// (issue #2099).
|
||||||
assert(next_slash != NULL);
|
assert(next_slash != nullptr);
|
||||||
|
|
||||||
// Absolute path of the intermediate directory
|
// Absolute path of the intermediate directory
|
||||||
const wcstring intermediate_dirpath = base_dir + wc_segment + L'/';
|
const wcstring intermediate_dirpath = base_dir + wc_segment + L'/';
|
||||||
|
@ -859,7 +859,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||||
waccess(intermediate_dirpath, F_OK) != 0) {
|
waccess(intermediate_dirpath, F_OK) != 0) {
|
||||||
assert(this->flags & expand_flag::for_completions);
|
assert(this->flags & expand_flag::for_completions);
|
||||||
DIR *base_dir_fd = open_dir(base_dir);
|
DIR *base_dir_fd = open_dir(base_dir);
|
||||||
if (base_dir_fd != NULL) {
|
if (base_dir_fd != nullptr) {
|
||||||
this->expand_literal_intermediate_segment_with_fuzz(
|
this->expand_literal_intermediate_segment_with_fuzz(
|
||||||
base_dir, base_dir_fd, wc_segment, wc_remainder, effective_prefix);
|
base_dir, base_dir_fd, wc_segment, wc_remainder, effective_prefix);
|
||||||
closedir(base_dir_fd);
|
closedir(base_dir_fd);
|
||||||
|
@ -874,7 +874,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||||
this->expand_last_segment(base_dir, dir, wc_segment, effective_prefix);
|
this->expand_last_segment(base_dir, dir, wc_segment, effective_prefix);
|
||||||
} else {
|
} else {
|
||||||
// Not the last segment, nonempty wildcard.
|
// Not the last segment, nonempty wildcard.
|
||||||
assert(next_slash != NULL);
|
assert(next_slash != nullptr);
|
||||||
this->expand_intermediate_segment(base_dir, dir, wc_segment, wc_remainder,
|
this->expand_intermediate_segment(base_dir, dir, wc_segment, wc_remainder,
|
||||||
effective_prefix + wc_segment + L'/');
|
effective_prefix + wc_segment + L'/');
|
||||||
}
|
}
|
||||||
|
@ -901,7 +901,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||||
|
|
||||||
int wildcard_expand_string(const wcstring &wc, const wcstring &working_directory,
|
int wildcard_expand_string(const wcstring &wc, const wcstring &working_directory,
|
||||||
expand_flags_t flags, std::vector<completion_t> *output) {
|
expand_flags_t flags, std::vector<completion_t> *output) {
|
||||||
assert(output != NULL);
|
assert(output != nullptr);
|
||||||
// Fuzzy matching only if we're doing completions.
|
// Fuzzy matching only if we're doing completions.
|
||||||
assert(flags.get(expand_flag::for_completions) || !flags.get(expand_flag::fuzzy_match));
|
assert(flags.get(expand_flag::for_completions) || !flags.get(expand_flag::fuzzy_match));
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ bool wreaddir(DIR *dir, wcstring &out_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wreaddir_for_dirs(DIR *dir, wcstring *out_name) {
|
bool wreaddir_for_dirs(DIR *dir, wcstring *out_name) {
|
||||||
struct dirent *result = NULL;
|
struct dirent *result = nullptr;
|
||||||
while (!result) {
|
while (!result) {
|
||||||
result = readdir(dir);
|
result = readdir(dir);
|
||||||
if (!result) break;
|
if (!result) break;
|
||||||
|
@ -162,7 +162,7 @@ FILE *wfopen(const wcstring &path, const char *mode) {
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Skip binary.
|
// Skip binary.
|
||||||
|
@ -172,9 +172,9 @@ FILE *wfopen(const wcstring &path, const char *mode) {
|
||||||
if (mode[idx] == '+') permissions = O_RDWR;
|
if (mode[idx] == '+') permissions = O_RDWR;
|
||||||
|
|
||||||
int fd = wopen_cloexec(path, permissions | options, 0666);
|
int fd = wopen_cloexec(path, permissions | options, 0666);
|
||||||
if (fd < 0) return NULL;
|
if (fd < 0) return nullptr;
|
||||||
FILE *result = fdopen(fd, mode);
|
FILE *result = fdopen(fd, mode);
|
||||||
if (result == NULL) close(fd);
|
if (result == nullptr) close(fd);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ const char *safe_strerror(int err) {
|
||||||
return std::strerror(err);
|
return std::strerror(err);
|
||||||
#elif defined(HAVE__SYS__ERRS) || defined(HAVE_SYS_ERRLIST)
|
#elif defined(HAVE__SYS__ERRS) || defined(HAVE_SYS_ERRLIST)
|
||||||
#ifdef HAVE_SYS_ERRLIST
|
#ifdef HAVE_SYS_ERRLIST
|
||||||
if (err >= 0 && err < sys_nerr && sys_errlist[err] != NULL) {
|
if (err >= 0 && err < sys_nerr && sys_errlist[err] != nullptr) {
|
||||||
return sys_errlist[err];
|
return sys_errlist[err];
|
||||||
}
|
}
|
||||||
#elif defined(HAVE__SYS__ERRS)
|
#elif defined(HAVE__SYS__ERRS)
|
||||||
|
@ -618,7 +618,7 @@ int fish_wcswidth(const wchar_t *str) { return fish_wcswidth(str, std::wcslen(st
|
||||||
int fish_wcswidth(const wcstring &str) { return fish_wcswidth(str.c_str(), str.size()); }
|
int fish_wcswidth(const wcstring &str) { return fish_wcswidth(str.c_str(), str.size()); }
|
||||||
|
|
||||||
locale_t fish_c_locale() {
|
locale_t fish_c_locale() {
|
||||||
static const locale_t loc = newlocale(LC_ALL_MASK, "C", NULL);
|
static const locale_t loc = newlocale(LC_ALL_MASK, "C", nullptr);
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,10 +142,11 @@ int fish_wcswidth(const wcstring &str);
|
||||||
// returns an immortal locale_t corresponding to the C locale.
|
// returns an immortal locale_t corresponding to the C locale.
|
||||||
locale_t fish_c_locale();
|
locale_t fish_c_locale();
|
||||||
|
|
||||||
int fish_wcstoi(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
int fish_wcstoi(const wchar_t *str, const wchar_t **endptr = nullptr, int base = 10);
|
||||||
long fish_wcstol(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
long fish_wcstol(const wchar_t *str, const wchar_t **endptr = nullptr, int base = 10);
|
||||||
long long fish_wcstoll(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
long long fish_wcstoll(const wchar_t *str, const wchar_t **endptr = nullptr, int base = 10);
|
||||||
unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr = nullptr,
|
||||||
|
int base = 10);
|
||||||
double fish_wcstod(const wchar_t *str, wchar_t **endptr);
|
double fish_wcstod(const wchar_t *str, wchar_t **endptr);
|
||||||
|
|
||||||
/// Class for representing a file's inode. We use this to detect and avoid symlink loops, among
|
/// Class for representing a file's inode. We use this to detect and avoid symlink loops, among
|
||||||
|
|
Loading…
Reference in a new issue