mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 20:16:12 +08:00
Make arguments to builtins const
Prior to this change, builtins would take their arguments as `wchar_t **`. This implies that the order of the arguments may be changed (which is true, `wgetopter` does so) but also that the strings themselves may be changed, which no builtin should do. Switch them all to take `const wchar_t **` instead: now the arguments may be rearranged but their contents may no longer be modified.
This commit is contained in:
parent
0b06a0ee07
commit
e0e4b11dbd
|
@ -119,8 +119,8 @@ static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
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 *cmd = argv[0];
|
||||
const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -204,7 +204,7 @@ void builtin_print_error_trailer(parser_t &parser, output_stream_t &b, const wch
|
|||
|
||||
/// A generic bultin that only supports showing a help message. This is only a placeholder that
|
||||
/// prints the help message. Useful for commands that live in the parser.
|
||||
static maybe_t<int> builtin_generic(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
static maybe_t<int> builtin_generic(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
help_only_cmd_opts_t opts;
|
||||
|
@ -231,7 +231,7 @@ static maybe_t<int> builtin_generic(parser_t &parser, io_streams_t &streams, wch
|
|||
// Since this is just for counting, it can be massive.
|
||||
#define COUNT_CHUNK_SIZE (512 * 256)
|
||||
/// Implementation of the builtin count command, used to count the number of arguments sent to it.
|
||||
static maybe_t<int> builtin_count(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
static maybe_t<int> builtin_count(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
UNUSED(parser);
|
||||
int argc = 0;
|
||||
|
||||
|
@ -266,7 +266,7 @@ static maybe_t<int> builtin_count(parser_t &parser, io_streams_t &streams, wchar
|
|||
/// This function handles both the 'continue' and the 'break' builtins that are used for loop
|
||||
/// control.
|
||||
static maybe_t<int> builtin_break_continue(parser_t &parser, io_streams_t &streams,
|
||||
wchar_t **argv) {
|
||||
const wchar_t **argv) {
|
||||
int is_break = (std::wcscmp(argv[0], L"break") == 0);
|
||||
int argc = builtin_count_args(argv);
|
||||
|
||||
|
@ -297,8 +297,9 @@ static maybe_t<int> builtin_break_continue(parser_t &parser, io_streams_t &strea
|
|||
}
|
||||
|
||||
/// Implementation of the builtin breakpoint command, used to launch the interactive debugger.
|
||||
static maybe_t<int> builtin_breakpoint(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
static maybe_t<int> builtin_breakpoint(parser_t &parser, io_streams_t &streams,
|
||||
const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
if (argv[1] != nullptr) {
|
||||
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, cmd, 0, builtin_count_args(argv) - 1);
|
||||
return STATUS_INVALID_ARGS;
|
||||
|
@ -323,21 +324,21 @@ static maybe_t<int> builtin_breakpoint(parser_t &parser, io_streams_t &streams,
|
|||
return parser.get_last_status();
|
||||
}
|
||||
|
||||
maybe_t<int> builtin_true(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_true(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
UNUSED(parser);
|
||||
UNUSED(streams);
|
||||
UNUSED(argv);
|
||||
return STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
maybe_t<int> builtin_false(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_false(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
UNUSED(parser);
|
||||
UNUSED(streams);
|
||||
UNUSED(argv);
|
||||
return STATUS_CMD_ERROR;
|
||||
}
|
||||
|
||||
maybe_t<int> builtin_gettext(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_gettext(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
UNUSED(parser);
|
||||
UNUSED(streams);
|
||||
for (int i = 1; i < builtin_count_args(argv); i++) {
|
||||
|
@ -455,7 +456,7 @@ static const wchar_t *const help_builtins[] = {L"for", L"while", L"function", L
|
|||
static bool cmd_needs_help(const wchar_t *cmd) { return contains(help_builtins, cmd); }
|
||||
|
||||
/// Execute a builtin command
|
||||
proc_status_t builtin_run(parser_t &parser, wchar_t **argv, io_streams_t &streams) {
|
||||
proc_status_t builtin_run(parser_t &parser, const wchar_t **argv, io_streams_t &streams) {
|
||||
UNUSED(parser);
|
||||
UNUSED(streams);
|
||||
if (argv == nullptr || argv[0] == nullptr)
|
||||
|
|
|
@ -20,7 +20,7 @@ struct builtin_data_t {
|
|||
// Name of the builtin.
|
||||
const wchar_t *name;
|
||||
// Function pointer to the builtin implementation.
|
||||
maybe_t<int> (*func)(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> (*func)(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
// Description of what the builtin does.
|
||||
const wchar_t *desc;
|
||||
|
||||
|
@ -85,7 +85,7 @@ enum { COMMAND_NOT_BUILTIN, BUILTIN_REGULAR, BUILTIN_FUNCTION };
|
|||
void builtin_init();
|
||||
bool builtin_exists(const wcstring &cmd);
|
||||
|
||||
proc_status_t builtin_run(parser_t &parser, wchar_t **argv, io_streams_t &streams);
|
||||
proc_status_t builtin_run(parser_t &parser, const wchar_t **argv, io_streams_t &streams);
|
||||
|
||||
wcstring_list_t builtin_get_names();
|
||||
void builtin_get_names(completion_list_t *list);
|
||||
|
@ -110,6 +110,6 @@ void builtin_wperror(const wchar_t *s, io_streams_t &streams);
|
|||
struct help_only_cmd_opts_t {
|
||||
bool print_help = false;
|
||||
};
|
||||
int parse_help_only_cmd_opts(help_only_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams);
|
||||
int parse_help_only_cmd_opts(help_only_cmd_opts_t &opts, int *optind, int argc,
|
||||
const wchar_t **argv, parser_t &parser, io_streams_t &streams);
|
||||
#endif
|
||||
|
|
|
@ -321,9 +321,9 @@ static bool parse_option_spec(argparse_cmd_opts_t &opts, //!OCLINT(high npath c
|
|||
return true;
|
||||
}
|
||||
|
||||
static int collect_option_specs(argparse_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
||||
io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
static int collect_option_specs(argparse_cmd_opts_t &opts, int *optind, int argc,
|
||||
const wchar_t **argv, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
|
||||
// A counter to give short chars to long-only options because getopt needs that.
|
||||
// Luckily we have wgetopt so we can use wchars - this is one of the private use areas so we
|
||||
|
@ -360,8 +360,8 @@ static int collect_option_specs(argparse_cmd_opts_t &opts, int *optind, int argc
|
|||
}
|
||||
|
||||
static int parse_cmd_opts(argparse_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -564,7 +564,7 @@ static int handle_flag(parser_t &parser, const argparse_cmd_opts_t &opts, option
|
|||
|
||||
static int argparse_parse_flags(parser_t &parser, argparse_cmd_opts_t &opts,
|
||||
const wchar_t *short_options, const woption *long_options,
|
||||
const wchar_t *cmd, int argc, wchar_t **argv, int *optind,
|
||||
const wchar_t *cmd, int argc, const wchar_t **argv, int *optind,
|
||||
io_streams_t &streams) {
|
||||
int opt;
|
||||
int long_idx = -1;
|
||||
|
@ -704,7 +704,7 @@ static void set_argparse_result_vars(env_stack_t &vars, const argparse_cmd_opts_
|
|||
/// an external command also means its output has to be in a form that can be eval'd. Because our
|
||||
/// version is a builtin it can directly set variables local to the current scope (e.g., a
|
||||
/// function). It doesn't need to write anything to stdout that then needs to be eval'd.
|
||||
maybe_t<int> builtin_argparse(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_argparse(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
argparse_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_argparse(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_argparse(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,7 @@ static int send_to_bg(parser_t &parser, io_streams_t &streams, job_t *j) {
|
|||
}
|
||||
|
||||
/// Builtin for putting a job in the background.
|
||||
maybe_t<int> builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_bg(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
help_only_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_bg(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -188,8 +188,8 @@ bool builtin_bind_t::add(const wcstring &seq, const wchar_t *const *cmds, size_t
|
|||
/// @param use_terminfo
|
||||
/// Whether to look use terminfo -k name
|
||||
///
|
||||
bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo,
|
||||
bool user, io_streams_t &streams) {
|
||||
bool builtin_bind_t::erase(const wchar_t *const *seq, bool all, const wchar_t *mode,
|
||||
bool use_terminfo, bool user, io_streams_t &streams) {
|
||||
if (all) {
|
||||
input_mappings_->clear(mode, user);
|
||||
return false;
|
||||
|
@ -214,8 +214,8 @@ bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool us
|
|||
return res;
|
||||
}
|
||||
|
||||
bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
bool builtin_bind_t::insert(int optind, int argc, const wchar_t **argv, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int arg_count = argc - optind;
|
||||
|
||||
if (arg_count < 2) {
|
||||
|
@ -300,8 +300,8 @@ void builtin_bind_t::list_modes(io_streams_t &streams) {
|
|||
}
|
||||
|
||||
static int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
static const wchar_t *const short_options = L":aehkKfM:Lm:s";
|
||||
static const struct woption long_options[] = {{L"all", no_argument, nullptr, 'a'},
|
||||
{L"erase", no_argument, nullptr, 'e'},
|
||||
|
@ -399,8 +399,9 @@ static int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
|
|||
}
|
||||
|
||||
/// The bind builtin, used for setting character sequences.
|
||||
maybe_t<int> builtin_bind_t::builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_bind_t::builtin_bind(parser_t &parser, io_streams_t &streams,
|
||||
const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
bind_cmd_opts_t opts;
|
||||
this->opts = &opts;
|
||||
|
|
|
@ -11,7 +11,7 @@ struct bind_cmd_opts_t;
|
|||
|
||||
class builtin_bind_t {
|
||||
public:
|
||||
maybe_t<int> builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
|
||||
builtin_bind_t() : input_mappings_(input_mappings()) {}
|
||||
|
||||
|
@ -28,17 +28,17 @@ class builtin_bind_t {
|
|||
void function_names(io_streams_t &streams);
|
||||
bool add(const wcstring &seq, const wchar_t *const *cmds, size_t cmds_len, const wchar_t *mode,
|
||||
const wchar_t *sets_mode, bool terminfo, bool user, io_streams_t &streams);
|
||||
bool erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo, bool user,
|
||||
io_streams_t &streams);
|
||||
bool erase(const wchar_t *const *seq, bool all, const wchar_t *mode, bool use_terminfo,
|
||||
bool user, io_streams_t &streams);
|
||||
bool get_terminfo_sequence(const wcstring &seq, wcstring *out_seq, io_streams_t &streams) const;
|
||||
bool insert(int optind, int argc, wchar_t **argv, io_streams_t &streams);
|
||||
bool insert(int optind, int argc, const wchar_t **argv, io_streams_t &streams);
|
||||
void list_modes(io_streams_t &streams);
|
||||
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, io_streams_t &streams);
|
||||
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset,
|
||||
io_streams_t &streams);
|
||||
};
|
||||
|
||||
inline maybe_t<int> builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
inline maybe_t<int> builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
builtin_bind_t bind;
|
||||
return bind.builtin_bind(parser, streams, argv);
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ struct block_cmd_opts_t {
|
|||
};
|
||||
|
||||
static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
static const wchar_t *const short_options = L":eghl";
|
||||
static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'},
|
||||
{L"local", no_argument, nullptr, 'l'},
|
||||
|
@ -70,7 +70,7 @@ static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high n
|
|||
}
|
||||
|
||||
/// The block builtin, used for temporarily blocking events.
|
||||
maybe_t<int> builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_block(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
block_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_block(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -25,9 +25,9 @@ static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h
|
|||
{L"query", no_argument, nullptr, 'q'},
|
||||
{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, const wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -65,7 +65,7 @@ static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, wchar
|
|||
/// The builtin builtin, used for giving builtins precedence over functions. Mostly handled by the
|
||||
/// parser. All this code does is some additional operational modes, such as printing a list of all
|
||||
/// builtins, printing help, etc.
|
||||
maybe_t<int> builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_builtin(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
builtin_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_builtin(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
/// The cd builtin. Changes the current directory to the one specified or to $HOME if none is
|
||||
/// specified. The directory can be relative to any directory in the CDPATH variable.
|
||||
maybe_t<int> builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_cd(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
help_only_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_cd(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -28,9 +28,9 @@ static const struct woption long_options[] = {
|
|||
{L"quiet", no_argument, nullptr, 'q'}, {L"query", no_argument, nullptr, 'q'},
|
||||
{L"search", no_argument, nullptr, 's'}, {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, const wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -72,7 +72,7 @@ static int parse_cmd_opts(command_cmd_opts_t &opts, int *optind, int argc, wchar
|
|||
|
||||
/// Implementation of the builtin 'command'. Actual command running is handled by the parser, this
|
||||
/// just processes the flags.
|
||||
maybe_t<int> builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_command(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
command_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_command(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -124,7 +124,7 @@ static void write_part(const wchar_t *begin, const wchar_t *end, int cut_at_curs
|
|||
}
|
||||
|
||||
/// The commandline builtin. It is used for specifying a new value for the commandline.
|
||||
maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
// Pointer to what the commandline builtin considers to be the current contents of the command
|
||||
// line buffer.
|
||||
const wchar_t *current_buffer = nullptr;
|
||||
|
@ -132,7 +132,7 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_
|
|||
// What the commandline builtin considers to be the current cursor position.
|
||||
auto current_cursor_pos = static_cast<size_t>(-1);
|
||||
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int buffer_part = 0;
|
||||
bool cut_at_cursor = false;
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
class parser_t;
|
||||
|
||||
maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -123,10 +123,10 @@ static void builtin_complete_print(const wcstring &cmd, io_streams_t &streams, p
|
|||
|
||||
/// The complete builtin. Used for specifying programmable tab-completions. Calls the functions in
|
||||
// complete.cpp for any heavy lifting.
|
||||
maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
completion_mode_t result_mode{};
|
||||
int remove = 0;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
class parser_t;
|
||||
|
||||
maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -23,9 +23,9 @@ static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h
|
|||
{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, const wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -58,7 +58,7 @@ static int parse_cmd_opts(contains_cmd_opts_t &opts, int *optind, int argc, wcha
|
|||
|
||||
/// Implementation of the builtin contains command, used to check if a specified string is part of
|
||||
/// a list.
|
||||
maybe_t<int> builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_contains(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
contains_cmd_opts_t opts;
|
||||
|
@ -72,7 +72,7 @@ maybe_t<int> builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t *
|
|||
return STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
wchar_t *needle = argv[optind];
|
||||
const wchar_t *needle = argv[optind];
|
||||
if (!needle) {
|
||||
streams.err.append_format(_(L"%ls: Key not specified\n"), cmd);
|
||||
} else {
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_contains(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -42,7 +42,7 @@ static int disown_job(const wchar_t *cmd, parser_t &parser, io_streams_t &stream
|
|||
}
|
||||
|
||||
/// Builtin for removing jobs from the job list.
|
||||
maybe_t<int> builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_disown(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
help_only_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_disown(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -21,11 +21,11 @@ struct echo_cmd_opts_t {
|
|||
static const wchar_t *const short_options = L"+:Eens";
|
||||
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, const wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
UNUSED(parser);
|
||||
UNUSED(streams);
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
echo_cmd_opts_t oldopts = opts;
|
||||
|
@ -194,8 +194,8 @@ static bool builtin_echo_parse_numeric_sequence(const wchar_t *str, size_t *cons
|
|||
///
|
||||
/// Bash only respects -n if it's the first argument. We'll do the same. We also support a new,
|
||||
/// fish specific, option -s to mean "no spaces".
|
||||
maybe_t<int> builtin_echo(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_echo(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
UNUSED(cmd);
|
||||
int argc = builtin_count_args(argv);
|
||||
echo_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_echo(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_echo(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "wutil.h" // IWYU pragma: keep
|
||||
|
||||
/// Implementation of the builtin emit command, used to create events.
|
||||
maybe_t<int> builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_emit(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
help_only_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_emit(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "wutil.h" // IWYU pragma: keep
|
||||
|
||||
/// Implementation of eval builtin.
|
||||
maybe_t<int> builtin_eval(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_eval(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
int argc = builtin_count_args(argv);
|
||||
if (argc <= 1) {
|
||||
return STATUS_CMD_OK;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_eval(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_eval(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -24,10 +24,10 @@ static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
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, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
UNUSED(parser);
|
||||
UNUSED(streams);
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -58,7 +58,7 @@ static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
|
|||
}
|
||||
|
||||
/// The exit builtin. Calls reader_exit to exit and returns the value specified.
|
||||
maybe_t<int> builtin_exit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_exit(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
exit_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_exit(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_exit(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "wutil.h" // IWYU pragma: keep
|
||||
|
||||
/// Builtin for putting a job in the foreground.
|
||||
maybe_t<int> builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_fg(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
help_only_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_fg(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -54,7 +54,7 @@ static const struct woption long_options[] = {
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
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, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = L"function";
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
|
@ -210,8 +210,8 @@ maybe_t<int> builtin_function(parser_t &parser, io_streams_t &streams,
|
|||
args.insert(args.end(), c_args.begin(), c_args.end());
|
||||
|
||||
null_terminated_array_t<wchar_t> argv_array(args);
|
||||
wchar_t **argv = argv_array.get();
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t **argv = argv_array.get();
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
|
||||
// A valid function name has to be the first argument.
|
||||
|
|
|
@ -42,8 +42,8 @@ struct functions_cmd_opts_t {
|
|||
bool report_metadata = false;
|
||||
bool verbose = false;
|
||||
bool handlers = false;
|
||||
wchar_t *handlers_type = nullptr;
|
||||
wchar_t *description = nullptr;
|
||||
const wchar_t *handlers_type = nullptr;
|
||||
const wchar_t *description = nullptr;
|
||||
};
|
||||
static const wchar_t *const short_options = L":Ht:Dacd:ehnqv";
|
||||
static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'},
|
||||
|
@ -60,8 +60,8 @@ static const struct woption long_options[] = {{L"erase", no_argument, nullptr, '
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -184,7 +184,7 @@ static int report_function_metadata(const wchar_t *funcname, bool verbose, io_st
|
|||
}
|
||||
|
||||
/// The functions builtin, used for listing and erasing functions.
|
||||
maybe_t<int> builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_functions(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
functions_cmd_opts_t opts;
|
||||
|
@ -212,15 +212,13 @@ maybe_t<int> builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t
|
|||
}
|
||||
|
||||
if (opts.description) {
|
||||
wchar_t *func;
|
||||
|
||||
if (argc - optind != 1) {
|
||||
streams.err.append_format(_(L"%ls: Expected exactly one function name\n"), cmd);
|
||||
builtin_print_error_trailer(parser, streams.err, cmd);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
func = argv[optind];
|
||||
const wchar_t *func = argv[optind];
|
||||
if (!function_exists(func, parser)) {
|
||||
streams.err.append_format(_(L"%ls: Function '%ls' does not exist\n"), cmd, func);
|
||||
builtin_print_error_trailer(parser, streams.err, cmd);
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_functions(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -61,7 +61,7 @@ static const struct woption long_options[] = {{L"prefix", no_argument, nullptr,
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
/// 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(const wchar_t *cmd, hist_cmd_t *hist_cmd, hist_cmd_t sub_cmd,
|
||||
io_streams_t &streams) {
|
||||
if (*hist_cmd != HIST_UNDEF) {
|
||||
wchar_t err_text[1024];
|
||||
|
@ -95,8 +95,8 @@ static bool check_for_unexpected_hist_args(const history_cmd_opts_t &opts, const
|
|||
}
|
||||
|
||||
static int parse_cmd_opts(history_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -200,8 +200,8 @@ static int parse_cmd_opts(history_cmd_opts_t &opts, int *optind, //!OCLINT(high
|
|||
}
|
||||
|
||||
/// Manipulate history of interactive commands executed by the user.
|
||||
maybe_t<int> builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_history(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
history_cmd_opts_t opts;
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_history(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -121,8 +121,8 @@ static void builtin_jobs_print(const job_t *j, int mode, int header, io_streams_
|
|||
}
|
||||
|
||||
/// The jobs builtin. Used for printing running jobs. Defined in builtin_jobs.c.
|
||||
maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
bool found = false;
|
||||
int mode = JOBS_DEFAULT;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
class parser_t;
|
||||
|
||||
maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -43,7 +43,7 @@ static const struct woption long_options[] = {{L"scale", required_argument, null
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
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, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = L"math";
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
|
@ -140,13 +140,13 @@ static const wchar_t *math_get_arg_stdin(wcstring *storage, const io_streams_t &
|
|||
}
|
||||
|
||||
/// 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, const wchar_t **argv) {
|
||||
return argv && argv[*argidx] ? argv[(*argidx)++] : nullptr;
|
||||
}
|
||||
|
||||
/// Get the arguments from argv or stdin based on the execution context. This mimics how builtin
|
||||
/// `string` does it.
|
||||
static const wchar_t *math_get_arg(int *argidx, wchar_t **argv, wcstring *storage,
|
||||
static const wchar_t *math_get_arg(int *argidx, const wchar_t **argv, wcstring *storage,
|
||||
const io_streams_t &streams) {
|
||||
if (math_args_from_stdin(streams)) {
|
||||
assert(streams.stdin_fd >= 0 &&
|
||||
|
@ -272,8 +272,8 @@ static int evaluate_expression(const wchar_t *cmd, const parser_t &parser, io_st
|
|||
}
|
||||
|
||||
/// The math builtin evaluates math expressions.
|
||||
maybe_t<int> builtin_math(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_math(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
math_cmd_opts_t opts;
|
||||
int optind;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_math(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_math(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -90,7 +90,7 @@ struct builtin_printf_state_t {
|
|||
void print_direc(const wchar_t *start, size_t length, wchar_t conversion, bool have_field_width,
|
||||
int field_width, bool have_precision, int precision, wchar_t const *argument);
|
||||
|
||||
int print_formatted(const wchar_t *format, int argc, wchar_t **argv);
|
||||
int print_formatted(const wchar_t *format, int argc, const wchar_t **argv);
|
||||
|
||||
void nonfatal_error(const wchar_t *fmt, ...);
|
||||
void fatal_error(const wchar_t *fmt, ...);
|
||||
|
@ -585,7 +585,7 @@ static inline void modify_allowed_format_specifiers(bool ok[UCHAR_MAX + 1], cons
|
|||
|
||||
/// Print the text in FORMAT, using ARGV (with ARGC elements) for arguments to any `%' directives.
|
||||
/// Return the number of elements of ARGV used.
|
||||
int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wchar_t **argv) {
|
||||
int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, const wchar_t **argv) {
|
||||
int save_argc = argc; /* Preserve original value. */
|
||||
const wchar_t *f; /* Pointer into `format'. */
|
||||
const wchar_t *direc_start; /* Start of % directive. */
|
||||
|
@ -737,7 +737,7 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wch
|
|||
}
|
||||
|
||||
/// The printf builtin.
|
||||
maybe_t<int> builtin_printf(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_printf(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
help_only_cmd_opts_t opts;
|
||||
|
@ -759,7 +759,7 @@ maybe_t<int> builtin_printf(parser_t &parser, io_streams_t &streams, wchar_t **a
|
|||
|
||||
builtin_printf_state_t state(streams);
|
||||
int args_used;
|
||||
wchar_t *format = argv[0];
|
||||
const wchar_t *format = argv[0];
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
class parser_t;
|
||||
|
||||
maybe_t<int> builtin_printf(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_printf(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,7 @@ static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h
|
|||
{L"logical", no_argument, nullptr, 'L'},
|
||||
{L"physical", no_argument, nullptr, 'P'},
|
||||
{nullptr, 0, nullptr, 0}};
|
||||
maybe_t<int> builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_pwd(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
UNUSED(parser);
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_pwd(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -27,8 +27,8 @@ static std::minstd_rand get_seeded_engine() {
|
|||
}
|
||||
|
||||
/// The random builtin generates random numbers.
|
||||
maybe_t<int> builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_random(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
help_only_cmd_opts_t opts;
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_random(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -80,8 +80,8 @@ static const struct woption long_options[] = {{L"array", no_argument, nullptr, '
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -434,8 +434,8 @@ static int validate_read_args(const wchar_t *cmd, read_cmd_opts_t &opts, int arg
|
|||
}
|
||||
|
||||
/// The read builtin. Reads from stdin and stores the values in environment variables.
|
||||
maybe_t<int> builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
wcstring buff;
|
||||
int exit_res = STATUS_CMD_OK;
|
||||
|
@ -475,7 +475,7 @@ maybe_t<int> builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **arg
|
|||
opts.shell = false;
|
||||
}
|
||||
|
||||
wchar_t *const *var_ptr = argv;
|
||||
const wchar_t *const *var_ptr = argv;
|
||||
auto vars_left = [&]() { return argv + argc - var_ptr; };
|
||||
auto clear_remaining_vars = [&]() {
|
||||
while (vars_left()) {
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,7 @@ static const struct woption long_options[] = {{L"no-symlinks", no_argument, null
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
static int parse_cmd_opts(realpath_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
|
@ -61,7 +61,7 @@ static int parse_cmd_opts(realpath_cmd_opts_t &opts, int *optind, //!OCLINT(hig
|
|||
/// An implementation of the external realpath command. Doesn't support any options.
|
||||
/// In general scripts shouldn't invoke this directly. They should just use `realpath` which
|
||||
/// will fallback to this builtin if an external command cannot be found.
|
||||
maybe_t<int> builtin_realpath(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_realpath(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
realpath_cmd_opts_t opts;
|
||||
int argc = builtin_count_args(argv);
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_realpath(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_realpath(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -23,10 +23,10 @@ static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
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, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
UNUSED(parser);
|
||||
UNUSED(streams);
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -57,7 +57,7 @@ static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high
|
|||
}
|
||||
|
||||
/// Function for handling the return builtin.
|
||||
maybe_t<int> builtin_return(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_return(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
return_cmd_opts_t opts;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_return(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_return(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -81,8 +81,8 @@ static const struct woption long_options[] = {
|
|||
static int is_path_variable(const wcstring &env) { return env == L"PATH" || env == L"CDPATH"; }
|
||||
|
||||
static int parse_cmd_opts(set_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
|
@ -470,8 +470,8 @@ static env_mode_flags_t compute_scope(const set_cmd_opts_t &opts) {
|
|||
|
||||
/// Print the names of all environment variables in the scope. It will include the values unless the
|
||||
/// `set --names` flag was used.
|
||||
static int builtin_set_list(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
static int builtin_set_list(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
|
||||
const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
UNUSED(cmd);
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
|
@ -520,8 +520,8 @@ static int builtin_set_list(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
|
|||
}
|
||||
|
||||
// Query mode. Return the number of variables that do NOT exist out of the specified variables.
|
||||
static int builtin_set_query(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
static int builtin_set_query(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
|
||||
const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
int retval = 0;
|
||||
env_mode_flags_t scope = compute_scope(opts);
|
||||
|
||||
|
@ -596,7 +596,7 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams
|
|||
|
||||
/// Show mode. Show information about the named variable(s).
|
||||
static int builtin_set_show(const wchar_t *cmd, const set_cmd_opts_t &opts, int argc,
|
||||
wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
UNUSED(opts);
|
||||
const auto &vars = parser.vars();
|
||||
if (argc == 0) { // show all vars
|
||||
|
@ -610,7 +610,7 @@ static int builtin_set_show(const wchar_t *cmd, const set_cmd_opts_t &opts, int
|
|||
}
|
||||
} else {
|
||||
for (int i = 0; i < argc; i++) {
|
||||
wchar_t *arg = argv[i];
|
||||
const wchar_t *arg = argv[i];
|
||||
|
||||
if (!valid_var_name(arg)) {
|
||||
streams.err.append_format(BUILTIN_ERR_VARNAME, cmd, arg);
|
||||
|
@ -635,8 +635,8 @@ static int builtin_set_show(const wchar_t *cmd, const set_cmd_opts_t &opts, int
|
|||
}
|
||||
|
||||
/// Erase a variable.
|
||||
static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
|
||||
const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
int ret = STATUS_CMD_OK;
|
||||
env_mode_flags_t scope = compute_scope(opts);
|
||||
for (int i = 0; i < argc; i++) {
|
||||
|
@ -745,7 +745,7 @@ static wcstring_list_t new_var_values_by_index(const split_var_t &split, int arg
|
|||
}
|
||||
|
||||
/// Set a variable.
|
||||
static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, wchar_t **argv,
|
||||
static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, const wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
if (argc == 0) {
|
||||
streams.err.append_format(BUILTIN_ERR_MIN_ARG_COUNT1, cmd, 1);
|
||||
|
@ -819,8 +819,8 @@ static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, w
|
|||
}
|
||||
|
||||
/// The set builtin creates, updates, and erases (removes, deletes) variables.
|
||||
maybe_t<int> builtin_set(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_set(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
set_cmd_opts_t opts;
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
class parser_t;
|
||||
|
||||
maybe_t<int> builtin_set(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_set(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -105,7 +105,7 @@ static char dim_esc[] = "\x1B[2m";
|
|||
#endif
|
||||
|
||||
/// set_color builtin.
|
||||
maybe_t<int> builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_set_color(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
// By the time this is called we should have initialized the curses subsystem.
|
||||
assert(curses_initialized);
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
class parser_t;
|
||||
|
||||
maybe_t<int> builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_set_color(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
/// The source builtin, sometimes called `.`. Evaluates the contents of a file in the current
|
||||
/// context.
|
||||
maybe_t<int> builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_source(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_source(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -82,7 +82,7 @@ const enum_map<status_cmd_t> status_enum_map[] = {
|
|||
/// Values that may be returned from the test-feature option to status.
|
||||
enum { TEST_FEATURE_ON, TEST_FEATURE_OFF, TEST_FEATURE_NOT_RECOGNIZED };
|
||||
|
||||
static maybe_t<job_control_t> job_control_str_to_mode(const wchar_t *mode, wchar_t *cmd,
|
||||
static maybe_t<job_control_t> job_control_str_to_mode(const wchar_t *mode, const wchar_t *cmd,
|
||||
io_streams_t &streams) {
|
||||
if (std::wcscmp(mode, L"full") == 0) {
|
||||
return job_control_t::all;
|
||||
|
@ -129,7 +129,7 @@ static const struct woption long_options[] = {
|
|||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
/// 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(const wchar_t *cmd, status_cmd_opts_t &opts, status_cmd_t sub_cmd,
|
||||
io_streams_t &streams) {
|
||||
if (opts.status_cmd != STATUS_UNDEF) {
|
||||
wchar_t err_text[1024];
|
||||
|
@ -156,8 +156,8 @@ static void print_features(io_streams_t &streams) {
|
|||
}
|
||||
|
||||
static int parse_cmd_opts(status_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
wchar_t *cmd = argv[0];
|
||||
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -274,8 +274,8 @@ static int parse_cmd_opts(status_cmd_opts_t &opts, int *optind, //!OCLINT(high
|
|||
}
|
||||
|
||||
/// The status builtin. Gives various status information on fish.
|
||||
maybe_t<int> builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_status(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
status_cmd_opts_t opts;
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_status(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -197,7 +197,7 @@ struct options_t { //!OCLINT(too many fields)
|
|||
};
|
||||
|
||||
/// This handles the `--style=xxx` flag.
|
||||
static int handle_flag_1(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_1(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
|
||||
|
@ -221,7 +221,7 @@ static int handle_flag_1(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_N(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_N(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->no_newline_valid) {
|
||||
opts->no_newline = true;
|
||||
|
@ -234,7 +234,7 @@ static int handle_flag_N(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_a(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_a(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->all_valid) {
|
||||
opts->all = true;
|
||||
|
@ -247,7 +247,7 @@ static int handle_flag_a(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_c(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_c(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->chars_to_trim_valid) {
|
||||
opts->chars_to_trim = w.woptarg;
|
||||
|
@ -265,7 +265,7 @@ static int handle_flag_c(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_e(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_e(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->end_valid) {
|
||||
opts->end = fish_wcstol(w.woptarg);
|
||||
|
@ -285,7 +285,7 @@ static int handle_flag_e(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_f(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_f(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->filter_valid) {
|
||||
opts->filter = true;
|
||||
|
@ -340,7 +340,7 @@ static int handle_flag_f(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_i(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_i(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->ignore_case_valid) {
|
||||
opts->ignore_case = true;
|
||||
|
@ -353,7 +353,7 @@ static int handle_flag_i(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_l(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_l(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->length_valid) {
|
||||
opts->length = fish_wcstol(w.woptarg);
|
||||
|
@ -373,7 +373,7 @@ static int handle_flag_l(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_m(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_m(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->max_valid) {
|
||||
opts->max = fish_wcstol(w.woptarg);
|
||||
|
@ -390,7 +390,7 @@ static int handle_flag_m(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_n(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_n(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->count_valid) {
|
||||
opts->count = fish_wcstol(w.woptarg);
|
||||
|
@ -416,7 +416,7 @@ static int handle_flag_n(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_q(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_q(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->quiet_valid) {
|
||||
opts->quiet = true;
|
||||
|
@ -426,7 +426,7 @@ static int handle_flag_q(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_r(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_r(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->regex_valid) {
|
||||
opts->regex = true;
|
||||
|
@ -439,7 +439,7 @@ static int handle_flag_r(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_s(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_s(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->start_valid) {
|
||||
opts->start = fish_wcstol(w.woptarg);
|
||||
|
@ -456,7 +456,7 @@ static int handle_flag_s(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_v(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_v(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
if (opts->invert_valid) {
|
||||
opts->invert_match = true;
|
||||
|
@ -466,7 +466,7 @@ static int handle_flag_v(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
static int handle_flag_w(wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
static int handle_flag_w(const wchar_t **argv, parser_t &parser, io_streams_t &streams,
|
||||
const wgetopter_t &w, options_t *opts) {
|
||||
long width = 0;
|
||||
if (opts->width_valid) {
|
||||
|
@ -553,7 +553,7 @@ static const std::unordered_map<char, decltype(*handle_flag_N)> flag_to_function
|
|||
{'v', handle_flag_v}, {'w', handle_flag_w}, {1, handle_flag_1}};
|
||||
|
||||
/// Parse the arguments for flags recognized by a specific string subcommand.
|
||||
static int parse_opts(options_t *opts, int *optind, int n_req_args, int argc, wchar_t **argv,
|
||||
static int parse_opts(options_t *opts, int *optind, int n_req_args, int argc, const wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
wcstring short_opts = construct_short_opts(opts);
|
||||
|
@ -606,7 +606,7 @@ static int parse_opts(options_t *opts, int *optind, int n_req_args, int argc, wc
|
|||
return STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
static int string_escape(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_escape(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
options_t opts;
|
||||
opts.no_quoted_valid = true;
|
||||
opts.style_valid = true;
|
||||
|
@ -634,7 +634,8 @@ static int string_escape(parser_t &parser, io_streams_t &streams, int argc, wcha
|
|||
DIE("should never reach this statement");
|
||||
}
|
||||
|
||||
static int string_unescape(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_unescape(parser_t &parser, io_streams_t &streams, int argc,
|
||||
const wchar_t **argv) {
|
||||
options_t opts;
|
||||
opts.no_quoted_valid = true;
|
||||
opts.style_valid = true;
|
||||
|
@ -659,8 +660,8 @@ static int string_unescape(parser_t &parser, io_streams_t &streams, int argc, wc
|
|||
DIE("should never reach this statement");
|
||||
}
|
||||
|
||||
static int string_join_maybe0(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv,
|
||||
bool is_join0) {
|
||||
static int string_join_maybe0(parser_t &parser, io_streams_t &streams, int argc,
|
||||
const wchar_t **argv, bool is_join0) {
|
||||
options_t opts;
|
||||
opts.quiet_valid = true;
|
||||
int optind;
|
||||
|
@ -688,15 +689,15 @@ static int string_join_maybe0(parser_t &parser, io_streams_t &streams, int argc,
|
|||
return nargs > 1 ? STATUS_CMD_OK : STATUS_CMD_ERROR;
|
||||
}
|
||||
|
||||
static int string_join(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_join(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
return string_join_maybe0(parser, streams, argc, argv, false /* is_join0 */);
|
||||
}
|
||||
|
||||
static int string_join0(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_join0(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
return string_join_maybe0(parser, streams, argc, argv, true /* is_join0 */);
|
||||
}
|
||||
|
||||
static int string_length(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_length(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
options_t opts;
|
||||
opts.quiet_valid = true;
|
||||
int optind;
|
||||
|
@ -1120,8 +1121,8 @@ class pcre2_matcher_t : public string_matcher_t {
|
|||
}
|
||||
};
|
||||
|
||||
static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
static int string_match(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
|
||||
options_t opts;
|
||||
opts.all_valid = true;
|
||||
|
@ -1160,7 +1161,7 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
|
|||
return matcher->match_count() > 0 ? STATUS_CMD_OK : STATUS_CMD_ERROR;
|
||||
}
|
||||
|
||||
static int string_pad(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_pad(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
options_t opts;
|
||||
opts.char_to_pad_valid = true;
|
||||
opts.right_valid = true;
|
||||
|
@ -1384,7 +1385,7 @@ bool regex_replacer_t::replace_matches(const wcstring &arg) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_replace(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
options_t opts;
|
||||
opts.all_valid = true;
|
||||
opts.filter_valid = true;
|
||||
|
@ -1414,9 +1415,9 @@ static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wch
|
|||
return replacer->replace_count() > 0 ? STATUS_CMD_OK : STATUS_CMD_ERROR;
|
||||
}
|
||||
|
||||
static int string_split_maybe0(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv,
|
||||
bool is_split0) {
|
||||
wchar_t *cmd = argv[0];
|
||||
static int string_split_maybe0(parser_t &parser, io_streams_t &streams, int argc,
|
||||
const wchar_t **argv, bool is_split0) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
options_t opts;
|
||||
opts.quiet_valid = true;
|
||||
opts.right_valid = true;
|
||||
|
@ -1502,15 +1503,15 @@ static int string_split_maybe0(parser_t &parser, io_streams_t &streams, int argc
|
|||
return split_count > arg_count ? STATUS_CMD_OK : STATUS_CMD_ERROR;
|
||||
}
|
||||
|
||||
static int string_split(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_split(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
return string_split_maybe0(parser, streams, argc, argv, false /* is_split0 */);
|
||||
}
|
||||
|
||||
static int string_split0(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_split0(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
return string_split_maybe0(parser, streams, argc, argv, true /* is_split0 */);
|
||||
}
|
||||
|
||||
static int string_collect(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_collect(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
options_t opts;
|
||||
opts.no_trim_newlines_valid = true;
|
||||
int optind;
|
||||
|
@ -1557,7 +1558,7 @@ static wcstring wcsrepeat_until(const wcstring &to_repeat, size_t max) {
|
|||
return wcsrepeat(to_repeat, count) + to_repeat.substr(0, mod);
|
||||
}
|
||||
|
||||
static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
options_t opts;
|
||||
opts.count_valid = true;
|
||||
opts.max_valid = true;
|
||||
|
@ -1603,8 +1604,8 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
|
|||
return all_empty ? STATUS_CMD_ERROR : STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
static int string_sub(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
|
||||
options_t opts;
|
||||
opts.length_valid = true;
|
||||
|
@ -1667,7 +1668,7 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
|
|||
return nsub > 0 ? STATUS_CMD_OK : STATUS_CMD_ERROR;
|
||||
}
|
||||
|
||||
static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_trim(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
options_t opts;
|
||||
opts.chars_to_trim_valid = true;
|
||||
opts.left_valid = true;
|
||||
|
@ -1711,7 +1712,7 @@ static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_
|
|||
}
|
||||
|
||||
// A helper function for lower and upper.
|
||||
static int string_transform(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv,
|
||||
static int string_transform(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv,
|
||||
std::wint_t (*func)(std::wint_t)) {
|
||||
options_t opts;
|
||||
opts.quiet_valid = true;
|
||||
|
@ -1737,12 +1738,12 @@ static int string_transform(parser_t &parser, io_streams_t &streams, int argc, w
|
|||
}
|
||||
|
||||
/// Implementation of `string lower`.
|
||||
static int string_lower(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_lower(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
return string_transform(parser, streams, argc, argv, std::towlower);
|
||||
}
|
||||
|
||||
/// Implementation of `string upper`.
|
||||
static int string_upper(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
static int string_upper(parser_t &parser, io_streams_t &streams, int argc, const wchar_t **argv) {
|
||||
return string_transform(parser, streams, argc, argv, std::towupper);
|
||||
}
|
||||
|
||||
|
@ -1750,7 +1751,7 @@ static int string_upper(parser_t &parser, io_streams_t &streams, int argc, wchar
|
|||
static constexpr const struct string_subcommand {
|
||||
const wchar_t *name;
|
||||
int (*handler)(parser_t &, io_streams_t &, int argc, //!OCLINT(unused param)
|
||||
wchar_t **argv); //!OCLINT(unused param)
|
||||
const wchar_t **argv); //!OCLINT(unused param)
|
||||
} string_subcommands[] = {
|
||||
{L"collect", &string_collect}, {L"escape", &string_escape}, {L"join", &string_join},
|
||||
{L"join0", &string_join0}, {L"length", &string_length}, {L"lower", &string_lower},
|
||||
|
@ -1762,8 +1763,8 @@ static constexpr const struct string_subcommand {
|
|||
ASSERT_SORT_ORDER(string_subcommands, .name);
|
||||
|
||||
/// The string builtin, for manipulating strings.
|
||||
maybe_t<int> builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_string(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
if (argc <= 1) {
|
||||
streams.err.append_format(BUILTIN_ERR_MISSING_SUBCMD, cmd);
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
class parser_t;
|
||||
|
||||
maybe_t<int> builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_string(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -209,7 +209,7 @@ class test_parser {
|
|||
unique_ptr<expression> parse_just_a_string(unsigned int start, unsigned int end);
|
||||
|
||||
static unique_ptr<expression> parse_args(const wcstring_list_t &args, wcstring &err,
|
||||
wchar_t *program_name);
|
||||
const wchar_t *program_name);
|
||||
};
|
||||
|
||||
struct range_t {
|
||||
|
@ -549,7 +549,7 @@ unique_ptr<expression> test_parser::parse_expression(unsigned int start, unsigne
|
|||
}
|
||||
|
||||
unique_ptr<expression> test_parser::parse_args(const wcstring_list_t &args, wcstring &err,
|
||||
wchar_t *program_name) {
|
||||
const wchar_t *program_name) {
|
||||
// Empty list and one-arg list should be handled by caller.
|
||||
assert(args.size() > 1);
|
||||
|
||||
|
@ -850,7 +850,7 @@ static bool unary_primary_evaluate(test_expressions::token_t token, const wcstri
|
|||
/// supports a more limited range of functionality.
|
||||
///
|
||||
/// Return status is the final shell status, i.e. 0 for true, 1 for false and 2 for error.
|
||||
maybe_t<int> builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_test(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
UNUSED(parser);
|
||||
using namespace test_expressions;
|
||||
|
||||
|
@ -858,7 +858,7 @@ maybe_t<int> builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **arg
|
|||
if (!argv[0]) return STATUS_INVALID_ARGS;
|
||||
|
||||
// Whether we are invoked with bracket '[' or not.
|
||||
wchar_t *program_name = argv[0];
|
||||
const wchar_t *program_name = argv[0];
|
||||
const bool is_bracket = !std::wcscmp(program_name, L"[");
|
||||
|
||||
size_t argc = 0;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_test(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -43,10 +43,10 @@ static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h
|
|||
{L"quiet", no_argument, nullptr, 'q'},
|
||||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
static int parse_cmd_opts(type_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
||||
static int parse_cmd_opts(type_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv,
|
||||
parser_t &parser, io_streams_t &streams) {
|
||||
UNUSED(parser);
|
||||
wchar_t *cmd = argv[0];
|
||||
const wchar_t *cmd = argv[0];
|
||||
int opt;
|
||||
wgetopter_t w;
|
||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||
|
@ -102,7 +102,7 @@ static int parse_cmd_opts(type_cmd_opts_t &opts, int *optind, int argc, wchar_t
|
|||
}
|
||||
|
||||
/// Implementation of the builtin 'type'.
|
||||
maybe_t<int> builtin_type(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_type(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
UNUSED(parser);
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_type(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_type(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -149,8 +149,8 @@ static int set_limit(int resource, int hard, int soft, rlim_t value, io_streams_
|
|||
}
|
||||
|
||||
/// The ulimit builtin, used for setting resource limits.
|
||||
maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
bool report_all = false;
|
||||
bool hard = false;
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
class parser_t;
|
||||
|
||||
maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -170,7 +170,7 @@ static bool find_job_by_name(const wchar_t *proc, std::vector<job_id_t> &ids,
|
|||
return found;
|
||||
}
|
||||
|
||||
maybe_t<int> builtin_wait(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
maybe_t<int> builtin_wait(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
||||
int retval = STATUS_CMD_OK;
|
||||
const wchar_t *cmd = argv[0];
|
||||
int argc = builtin_count_args(argv);
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
class parser_t;
|
||||
struct io_streams_t;
|
||||
|
||||
maybe_t<int> builtin_wait(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
maybe_t<int> builtin_wait(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
#endif
|
||||
|
|
|
@ -2768,31 +2768,24 @@ static void test_is_potential_path() {
|
|||
}
|
||||
|
||||
/// Test the 'test' builtin.
|
||||
maybe_t<int> builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
static bool run_one_test_test(int expected, wcstring_list_t &lst, bool bracket) {
|
||||
maybe_t<int> builtin_test(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
static bool run_one_test_test(int expected, const wcstring_list_t &lst, bool bracket) {
|
||||
parser_t &parser = parser_t::principal_parser();
|
||||
size_t i, count = lst.size();
|
||||
wchar_t **argv = new wchar_t *[count + 3];
|
||||
argv[0] = (wchar_t *)(bracket ? L"[" : L"test");
|
||||
for (i = 0; i < count; i++) {
|
||||
argv[i + 1] = (wchar_t *)lst.at(i).c_str();
|
||||
}
|
||||
if (bracket) {
|
||||
argv[i + 1] = (wchar_t *)L"]";
|
||||
i++;
|
||||
}
|
||||
argv[i + 1] = NULL;
|
||||
wcstring_list_t argv;
|
||||
argv.push_back(bracket ? L"[" : L"test");
|
||||
argv.insert(argv.end(), lst.begin(), lst.end());
|
||||
if (bracket) argv.push_back(L"]");
|
||||
|
||||
null_terminated_array_t<wchar_t> cargv(argv);
|
||||
|
||||
null_output_stream_t null{};
|
||||
io_streams_t streams(null, null);
|
||||
maybe_t<int> result = builtin_test(parser, streams, argv);
|
||||
maybe_t<int> result = builtin_test(parser, streams, cargv.get());
|
||||
|
||||
if (result != expected) {
|
||||
std::wstring got = result ? std::to_wstring(result.value()) : L"nothing";
|
||||
err(L"expected builtin_test() to return %d, got %s", expected, got.c_str());
|
||||
}
|
||||
|
||||
delete[] argv;
|
||||
|
||||
return result == expected;
|
||||
}
|
||||
|
||||
|
@ -5551,20 +5544,26 @@ static void test_pcre2_escape() {
|
|||
}
|
||||
}
|
||||
|
||||
maybe_t<int> builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
||||
static void run_one_string_test(const wchar_t *const *argv, int expected_rc,
|
||||
maybe_t<int> builtin_string(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
||||
static void run_one_string_test(const wchar_t *const *argv_raw, int expected_rc,
|
||||
const wchar_t *expected_out) {
|
||||
// Copy to a null terminated array, as builtin_string may wish to rearrange our pointers.
|
||||
wcstring_list_t argv_list(argv_raw, argv_raw + null_terminated_array_length(argv_raw));
|
||||
null_terminated_array_t<wchar_t> argv(argv_list);
|
||||
|
||||
parser_t &parser = parser_t::principal_parser();
|
||||
string_output_stream_t outs{};
|
||||
null_output_stream_t errs{};
|
||||
io_streams_t streams(outs, errs);
|
||||
streams.stdin_is_directly_redirected = false; // read from argv instead of stdin
|
||||
maybe_t<int> rc = builtin_string(parser, streams, const_cast<wchar_t **>(argv));
|
||||
maybe_t<int> rc = builtin_string(parser, streams, argv.get());
|
||||
|
||||
wcstring args;
|
||||
for (int i = 0; argv[i] != NULL; i++) {
|
||||
args += escape_string(argv[i], ESCAPE_ALL) + L' ';
|
||||
for (const wcstring &arg : argv_list) {
|
||||
args += escape_string(arg, ESCAPE_ALL) + L' ';
|
||||
}
|
||||
args.resize(args.size() - 1);
|
||||
|
||||
if (rc != expected_rc) {
|
||||
std::wstring got = rc ? std::to_wstring(rc.value()) : L"nothing";
|
||||
err(L"Test failed on line %lu: [%ls]: expected return code %d but got %s", __LINE__,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "null_terminated_array.h"
|
||||
|
||||
template <typename CharT>
|
||||
static CharT **make_null_terminated_array_helper(
|
||||
static const CharT **make_null_terminated_array_helper(
|
||||
const std::vector<std::basic_string<CharT> > &argv) {
|
||||
size_t count = argv.size();
|
||||
|
||||
|
@ -48,14 +48,14 @@ static CharT **make_null_terminated_array_helper(
|
|||
assert(reinterpret_cast<unsigned char *>(strings) - base ==
|
||||
static_cast<std::ptrdiff_t>(pointers_allocation_len + strings_allocation_len));
|
||||
|
||||
return reinterpret_cast<CharT **>(base);
|
||||
return reinterpret_cast<const CharT **>(base);
|
||||
}
|
||||
|
||||
wchar_t **make_null_terminated_array(const wcstring_list_t &lst) {
|
||||
const wchar_t **make_null_terminated_array(const wcstring_list_t &lst) {
|
||||
return make_null_terminated_array_helper(lst);
|
||||
}
|
||||
|
||||
char **make_null_terminated_array(const std::vector<std::string> &lst) {
|
||||
const char **make_null_terminated_array(const std::vector<std::string> &lst) {
|
||||
return make_null_terminated_array_helper(lst);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,29 +9,32 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
wchar_t **make_null_terminated_array(const wcstring_list_t &lst);
|
||||
char **make_null_terminated_array(const std::vector<std::string> &lst);
|
||||
const wchar_t **make_null_terminated_array(const wcstring_list_t &lst);
|
||||
const char **make_null_terminated_array(const std::vector<std::string> &lst);
|
||||
|
||||
/// \return the length of a null terminated array.
|
||||
template <typename CharT>
|
||||
inline size_t null_terminated_array_length(const CharT *const *arr) {
|
||||
if (!arr) return 0;
|
||||
size_t len = 0;
|
||||
while (arr[len] != nullptr) {
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
// Helper class for managing a null-terminated array of null-terminated strings (of some char type).
|
||||
template <typename CharT>
|
||||
class null_terminated_array_t {
|
||||
using string_list_t = std::vector<std::basic_string<CharT>>;
|
||||
|
||||
CharT **array{nullptr};
|
||||
const CharT **array{nullptr};
|
||||
|
||||
// No assignment or copying.
|
||||
void operator=(null_terminated_array_t rhs) = delete;
|
||||
null_terminated_array_t(const null_terminated_array_t &) = delete;
|
||||
|
||||
size_t size() const {
|
||||
size_t len = 0;
|
||||
if (array != nullptr) {
|
||||
while (array[len] != nullptr) {
|
||||
len++;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
size_t size() const { return nullterm_array_length(array); }
|
||||
|
||||
void free(void) {
|
||||
::free(reinterpret_cast<void *>(array));
|
||||
|
@ -74,7 +77,7 @@ class null_terminated_array_t {
|
|||
string_list_t to_list() const { return to_list(array); }
|
||||
|
||||
const CharT *const *get() const { return array; }
|
||||
CharT **get() { return array; }
|
||||
const CharT **get() { return array; }
|
||||
|
||||
void clear() { this->free(); }
|
||||
};
|
||||
|
|
|
@ -233,7 +233,7 @@ class process_t {
|
|||
void set_argv(const wcstring_list_t &argv) { argv_array.set(argv); }
|
||||
|
||||
/// Returns argv.
|
||||
wchar_t **get_argv() { return argv_array.get(); }
|
||||
const wchar_t **get_argv() { return argv_array.get(); }
|
||||
const wchar_t *const *get_argv() const { return argv_array.get(); }
|
||||
const null_terminated_array_t<wchar_t> &get_argv_array() const { return argv_array; }
|
||||
|
||||
|
|
|
@ -65,11 +65,11 @@
|
|||
//
|
||||
// `first_nonopt' and `last_nonopt' are relocated so that they describe the new indices of the
|
||||
// non-options in ARGV after they are moved.
|
||||
void wgetopter_t::exchange(wchar_t **argv) {
|
||||
void wgetopter_t::exchange(string_array_t argv) {
|
||||
int bottom = first_nonopt;
|
||||
int middle = last_nonopt;
|
||||
int top = woptind;
|
||||
wchar_t *tem;
|
||||
const wchar_t *tem{};
|
||||
|
||||
// Exchange the shorter segment with the far end of the longer segment. That puts the shorter
|
||||
// segment into the right place. It leaves the longer segment in the right place overall, but it
|
||||
|
@ -139,7 +139,7 @@ void wgetopter_t::_wgetopt_initialize(const wchar_t *optstring) {
|
|||
|
||||
// Advance to the next ARGV-element.
|
||||
int wgetopter_t::_advance_to_next_argv( //!OCLINT(high cyclomatic complexity)
|
||||
int argc, wchar_t **argv, const struct woption *longopts) {
|
||||
int argc, string_array_t argv, const struct woption *longopts) {
|
||||
if (ordering == PERMUTE) {
|
||||
// If we have just processed some options following some non-options, exchange them so
|
||||
// that the options come first.
|
||||
|
@ -196,7 +196,7 @@ int wgetopter_t::_advance_to_next_argv( //!OCLINT(high cyclomatic complexity)
|
|||
}
|
||||
|
||||
// Check for a matching short opt.
|
||||
int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
|
||||
int wgetopter_t::_handle_short_opt(int argc, string_array_t argv) {
|
||||
// Look at and handle the next short option-character.
|
||||
wchar_t c = *nextchar++;
|
||||
const wchar_t *temp = std::wcschr(shortopts, c);
|
||||
|
@ -254,8 +254,9 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
|
|||
return c;
|
||||
}
|
||||
|
||||
void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woption *pfound,
|
||||
wchar_t *nameend, int *longind, int option_index, int *retval) {
|
||||
void wgetopter_t::_update_long_opt(int argc, string_array_t argv, const struct woption *pfound,
|
||||
const wchar_t *nameend, int *longind, int option_index,
|
||||
int *retval) {
|
||||
woptind++;
|
||||
if (*nameend) {
|
||||
// Don't test has_arg with >, because some C compilers don't allow it to be used on
|
||||
|
@ -301,8 +302,8 @@ void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woptio
|
|||
|
||||
// Find a matching long opt.
|
||||
const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption *longopts,
|
||||
wchar_t *nameend, int *exact, int *ambig,
|
||||
int *indfound) const {
|
||||
const wchar_t *nameend, int *exact,
|
||||
int *ambig, int *indfound) const {
|
||||
const struct woption *pfound = nullptr;
|
||||
int option_index = 0;
|
||||
|
||||
|
@ -330,13 +331,13 @@ const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption
|
|||
}
|
||||
|
||||
// Check for a matching long opt.
|
||||
bool wgetopter_t::_handle_long_opt(int argc, wchar_t **argv, const struct woption *longopts,
|
||||
bool wgetopter_t::_handle_long_opt(int argc, string_array_t argv, const struct woption *longopts,
|
||||
int *longind, int long_only, int *retval) {
|
||||
int exact = 0;
|
||||
int ambig = 0;
|
||||
int indfound = 0;
|
||||
|
||||
wchar_t *nameend;
|
||||
const wchar_t *nameend;
|
||||
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
|
||||
; //!OCLINT(empty body)
|
||||
|
||||
|
@ -419,7 +420,7 @@ bool wgetopter_t::_handle_long_opt(int argc, wchar_t **argv, const struct woptio
|
|||
// long-named option has been found by the most recent call.
|
||||
//
|
||||
// If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options.
|
||||
int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *optstring,
|
||||
int wgetopter_t::_wgetopt_internal(int argc, string_array_t argv, const wchar_t *optstring,
|
||||
const struct woption *longopts, int *longind, int long_only) {
|
||||
if (!initialized) _wgetopt_initialize(optstring);
|
||||
woptarg = nullptr;
|
||||
|
@ -452,7 +453,7 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
|
|||
return _handle_short_opt(argc, argv);
|
||||
}
|
||||
|
||||
int wgetopter_t::wgetopt_long(int argc, wchar_t **argv, const wchar_t *options,
|
||||
int wgetopter_t::wgetopt_long(int argc, string_array_t argv, const wchar_t *options,
|
||||
const struct woption *long_options, int *opt_index) {
|
||||
return _wgetopt_internal(argc, argv, options, long_options, opt_index, 0);
|
||||
}
|
||||
|
|
|
@ -43,28 +43,17 @@ Cambridge, MA 02139, USA. */
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
/// Instanced getopt() wrapper.
|
||||
class wgetopter_t {
|
||||
private:
|
||||
void exchange(wchar_t **argv);
|
||||
void _wgetopt_initialize(const wchar_t *optstring);
|
||||
int _wgetopt_internal(int argc, wchar_t **argv, const wchar_t *optstring,
|
||||
const struct woption *longopts, int *longind, int long_only);
|
||||
int _advance_to_next_argv(int argc, wchar_t **argv, const struct woption *longopts);
|
||||
int _handle_short_opt(int argc, wchar_t **argv);
|
||||
bool _handle_long_opt(int argc, wchar_t **argv, const struct woption *longopts, int *longind,
|
||||
int long_only, int *retval);
|
||||
const struct woption *_find_matching_long_opt(const struct woption *longopts, wchar_t *nameend,
|
||||
int *exact, int *ambig, int *indfound) const;
|
||||
void _update_long_opt(int argc, wchar_t **argv, const struct woption *pfound, wchar_t *nameend,
|
||||
int *longind, int option_index, int *retval);
|
||||
bool initialized = false;
|
||||
bool missing_arg_return_colon = false;
|
||||
|
||||
public:
|
||||
/// Note wgetopter expects an mutable array of const strings. It modifies the order of the
|
||||
/// strings, but not their contents.
|
||||
using string_array_t = const wchar_t **;
|
||||
|
||||
// For communication from `getopt' to the caller. When `getopt' finds an option that takes an
|
||||
// argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each
|
||||
// non-option ARGV-element is returned here.
|
||||
wchar_t *woptarg = nullptr;
|
||||
const wchar_t *woptarg = nullptr;
|
||||
|
||||
const wchar_t *shortopts = nullptr;
|
||||
|
||||
|
@ -73,7 +62,7 @@ class wgetopter_t {
|
|||
//
|
||||
// If this is zero, or a null string, it means resume the scan by advancing to the next
|
||||
// ARGV-element.
|
||||
wchar_t *nextchar = nullptr;
|
||||
const wchar_t *nextchar = nullptr;
|
||||
|
||||
// Index in ARGV of the next element to be scanned. This is used for communication to and from
|
||||
// the caller and for communication between successive calls to `getopt'.
|
||||
|
@ -128,8 +117,25 @@ class wgetopter_t {
|
|||
|
||||
wgetopter_t() {}
|
||||
|
||||
int wgetopt_long(int argc, wchar_t **argv, const wchar_t *options,
|
||||
int wgetopt_long(int argc, string_array_t argv, const wchar_t *options,
|
||||
const struct woption *long_options, int *opt_index);
|
||||
|
||||
private:
|
||||
void exchange(string_array_t argv);
|
||||
void _wgetopt_initialize(const wchar_t *optstring);
|
||||
int _wgetopt_internal(int argc, string_array_t argv, const wchar_t *optstring,
|
||||
const struct woption *longopts, int *longind, int long_only);
|
||||
int _advance_to_next_argv(int argc, string_array_t argv, const struct woption *longopts);
|
||||
int _handle_short_opt(int argc, string_array_t argv);
|
||||
bool _handle_long_opt(int argc, string_array_t argv, const struct woption *longopts,
|
||||
int *longind, int long_only, int *retval);
|
||||
const struct woption *_find_matching_long_opt(const struct woption *longopts,
|
||||
const wchar_t *nameend, int *exact, int *ambig,
|
||||
int *indfound) const;
|
||||
void _update_long_opt(int argc, string_array_t argv, const struct woption *pfound,
|
||||
const wchar_t *nameend, int *longind, int option_index, int *retval);
|
||||
bool initialized = false;
|
||||
bool missing_arg_return_colon = false;
|
||||
};
|
||||
|
||||
/// Describe the long-named options requested by the application. The LONG_OPTIONS argument to
|
||||
|
|
Loading…
Reference in New Issue
Block a user